lllyasviel/Fooocus · error · ValueError
Order {order} too high for step {i}
Error message
Order {order} too high for step {i} What it means
linear_multistep_coeff() computes Adams-Bashforth coefficients for sample_lms using the previous `order` steps; at step i fewer than order-1 earlier results exist, so the formula would index before the start of the sigma array. The guard raises ValueError when order-1 > i. sample_lms already handles this internally by using min(order, i+1) per step, so seeing this error usually means the helper was called directly or a modified sampler skipped that clamping.
Source
Thrown at ldm_patched/k_diffusion/sampling.py:258
# Euler method
dt = sigma_down - sigmas[i]
x = x + d * dt
else:
# DPM-Solver-2
sigma_mid = sigmas[i].log().lerp(sigma_down.log(), 0.5).exp()
dt_1 = sigma_mid - sigmas[i]
dt_2 = sigma_down - sigmas[i]
x_2 = x + d * dt_1
denoised_2 = model(x_2, sigma_mid * s_in, **extra_args)
d_2 = to_d(x_2, sigma_mid, denoised_2)
x = x + d_2 * dt_2
x = x + noise_sampler(sigmas[i], sigmas[i + 1]) * s_noise * sigma_up
return x
def linear_multistep_coeff(order, t, i, j):
if order - 1 > i:
raise ValueError(f'Order {order} too high for step {i}')
def fn(tau):
prod = 1.
for k in range(order):
if j == k:
continue
prod *= (tau - t[i - k]) / (t[i - j] - t[i - k])
return prod
return integrate.quad(fn, t[i], t[i + 1], epsrel=1e-4)[0]
@torch.no_grad()
def sample_lms(model, x, sigmas, extra_args=None, callback=None, disable=None, order=4):
extra_args = {} if extra_args is None else extra_args
s_in = x.new_ones([x.shape[0]])
sigmas_cpu = sigmas.detach().cpu().numpy()
ds = []
for i in trange(len(sigmas) - 1, disable=disable):
denoised = model(x, sigmas[i] * s_in, **extra_args)View on GitHub (pinned to ae05379cc9)
Solutions
- Clamp like the reference: eff_order = min(order, i + 1) and pass eff_order to linear_multistep_coeff.
- Prepend burn-in: use Euler/simple steps for the first order-1 iterations, then switch to full-order LMS.
- Reduce order (order=2 or 3) so fewer warm-up steps are needed.
- Do not call linear_multistep_coeff standalone without honoring the i >= order-1 precondition.
Example fix
# before
for i in range(len(sigmas) - 1):
for j in range(4):
coeff = linear_multistep_coeff(4, ts, i, j) # fails at i<3
# after
for i in range(len(sigmas) - 1):
eff = min(4, i + 1)
for j in range(eff):
coeff = linear_multistep_coeff(eff, ts, i, j) Defensive patterns
Strategy: validation
Validate before calling
eff_order = min(order, i + 1)
assert eff_order - 1 <= i, f'order {eff_order} exceeds history at step {i}'
coeff = linear_multistep_coeff(eff_order, ts, i, j) Type guard
def coeff_available(order: int, i: int) -> bool:
return order - 1 <= i Try / catch
try:
c = linear_multistep_coeff(order, ts, i, j)
except ValueError:
c = linear_multistep_coeff(min(order, i + 1), ts, i, j) # degrade gracefully Prevention
- Always clamp multistep order to available history: min(order, i+1).
- Warm up with lower-order steps before switching to full order.
- Never call coefficient helpers standalone without honoring their preconditions.
When it happens
Trigger: Calling linear_multistep_coeff(order=4, t=ts, i=0..2, j=...) directly — e.g. implementing a custom LMS variant — without clamping the effective order to available history. With sigmas arrays shorter than order, the clamp still caps at len(sigmas)-1.
Common situations: Custom multistep samplers copied from sample_lms but with the order clamp removed; unit tests exercising the coefficient function from i=0; porting the sampler to another framework and losing the min(order, i+1) logic.
Related errors
- eta must be 0 for reverse sampling
- order should be 2 or 3
- sigma_min and sigma_max must not be 0
- solver_type must be 'heun' or 'midpoint'
- input has {x.ndim} dims but target_dims is {target_dims}, wh
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/6d5a224b32b26101.
Report an issue: GitHub.