@@ -219,8 +219,11 @@ def sample(
219219 """
220220 if sigmas .ndim != 1 :
221221 raise ValueError (f"sigmas must be 1-D, got shape { sigmas .shape } " )
222- if sigmas [- 1 ] != 0.0 :
223- raise ValueError ("last element of sigmas must be 0" )
222+ # Clamp near-zero last sigma to exactly 0 for compatibility with
223+ # KSamplerAdvanced and similar nodes that may pass a sliced schedule.
224+ if sigmas [- 1 ].abs () > 1e-6 :
225+ sigmas = sigmas .clone ()
226+ sigmas [- 1 ] = 0.0
224227 if sigmas .numel () < 2 :
225228 raise ValueError ("sigmas must have at least 2 elements" )
226229
@@ -277,16 +280,19 @@ def sample(
277280 reversed_dir = cos_sim < 0.0
278281
279282 # Self-correcting scheduler: if an invariant triggered, insert a step
280- # and redo this step for finer resolution.
281- if clamped or reversed_dir :
282- mid = (sigmas_list [i ] + sigmas_list [i + 1 ]) * 0.5
283- sigmas_list .insert (i + 1 , mid )
284- continue # redo `i` with finer resolution
283+ # and redo this step for finer resolution. The gap check prevents
284+ # infinite loops when the step is already too small to split further.
285+ if (clamped or reversed_dir ) and i < len (sigmas_list ) - 1 :
286+ current_gap = (sigmas_list [i ] - sigmas_list [i + 1 ]).abs ().item ()
287+ if current_gap > 1e-6 :
288+ mid = (sigmas_list [i ] + sigmas_list [i + 1 ]) * 0.5
289+ sigmas_list .insert (i + 1 , mid )
290+ continue
285291
286292 # Fallback: Euler step if both invariants fail
287293 if clamped and reversed_dir :
288294 correction = torch .zeros_like (raw_correction )
289- elif reversed_dir :
295+ elif inv_reversed :
290296 correction = raw_correction * 0.5
291297 else :
292298 correction = raw_correction
0 commit comments