You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UniPCMultistepScheduler returns NaN on the last step with final_sigmas_type='zero' (solver_type='bh1' or lower_order_final=False) #15263
UniPCMultistepScheduler returns a fully-NaN sample on the last step with the default final_sigmas_type="zero" in two configurations:
solver_type="bh1" (the docstring recommends bh1 "for unconditional sampling when steps < 10") - any step count, any solver_order.
lower_order_final=False (any solver_type) - the docstring describes this as valid for >= 15 steps.
The final sigma is 0, so lambda_t = +inf, h = inf. In multistep_uni_p_bh_update:
bh1: B_h = hh = -inf, and for a first-order step pred_res = 0, so the code evaluates alpha_t * (-inf) * 0 = NaN.
lower_order_final=False: the last predictor step runs at solver_order, with rk = (lambda_si - lambda_s0) / h = 0, so D1s = (mi - m0) / rk = inf.
DPMSolverMultistepScheduler already forces the last step to first order when final_sigmas_type == "zero"; UniPC has no equivalent guard. The existing UniPC tests all use final_sigmas_type="sigma_min", which hides it (the library default is "zero").
Output on current main (f9316b0, CPU, torch 2.15):
bh1 default : non-finite at step 20/20
unipc lof=False : non-finite at step 20/20
dpm lof=False : finite
Same for 3, 5, 9, 20 steps with bh1 (epsilon, v_prediction, sample).
Context
Found by a differential sweep of step() over solver/scheduler variants (an AI agent - Claude Code - wrote and ran the sweep; I did not hit this in a production pipeline, only in the scheduler loop with a dummy model). Impact: with the documented bh1 recommendation the final denoised latent is NaN (black image) unless the user also sets final_sigmas_type="sigma_min".
Possible fix (not yet a PR - waiting for maintainer ack per the AI contribution rules)
Two small changes in scheduling_unipc_multistep.py:
in step, force this_order = 1 on the last step when final_sigmas_type == "zero";
in multistep_uni_p_bh_update, only apply the B_h * pred_res term when D1s is not None (mathematically identical, avoids inf * 0).
Plus a regression test (bh1/bh2 x lower_order_final True/False with final_sigmas_type="zero"). I have this prepared locally; after it the repro above is finite and the UniPC loop matches DPMSolverMultistepScheduler bit-for-bit for lower_order_final=False; the scheduler test file passes (64 passed) and ruff is clean.
Out of scope here: predict_x0=False with final_sigmas_type="zero" also yields NaN (0 * expm1(inf)), but that combination looks inherently unsupported.
System Info
diffusers 0.42.0.dev0 (main f9316b0), Python 3.x, torch 2.15.0+cpu, Windows 10, CPU only.
Independent confirmation on the shipped release (diffusers 0.43.0, torch 2.14.0+cpu, CPU), running the report above verbatim plus extra step counts and controls:
The failure needs exactly the two ingredients named in the report — a final sigma of 0 under the default final_sigmas_type="zero", reached through the bh1 path or a non-lowered final order — and the controls isolate it: the same scheduler is fine with sigma_min, bh2 defaults are fine, and the DPM sibling, which already forces first order on the final step, is fine.
The proposed direction (force first order on the last step when final_sigmas_type == "zero", and apply the B_h * pred_res term only when D1s is not None) matches that DPM precedent, and the table gives it a direct regression target: every row finite, with the currently finite rows unchanged.
Activity
1OF1Research commentedon Nov 14, 2026
Independent confirmation on the shipped release (diffusers 0.43.0, torch 2.14.0+cpu, CPU), running the report above verbatim plus extra step counts and controls:
bh1, defaults, 20 stepsbh1, defaults, 3 / 5 / 9 stepslower_order_final=False, defaults, 20 stepsbh2, defaults, 20 stepsbh1withfinal_sigmas_type="sigma_min"DPMSolverMultistepScheduler,lower_order_final=FalseThe failure needs exactly the two ingredients named in the report — a final sigma of 0 under the default
final_sigmas_type="zero", reached through thebh1path or a non-lowered final order — and the controls isolate it: the same scheduler is fine withsigma_min,bh2defaults are fine, and the DPM sibling, which already forces first order on the final step, is fine.The proposed direction (force first order on the last step when
final_sigmas_type == "zero", and apply theB_h * pred_resterm only whenD1s is not None) matches that DPM precedent, and the table gives it a direct regression target: every row finite, with the currently finite rows unchanged.