{"record":{"id":"6d5a224b32b26101","repo":"lllyasviel/Fooocus","slug":"order-order-too-high-for-step-i","errorCode":null,"errorMessage":"Order {order} too high for step {i}","messagePattern":"Order (.+?) too high for step (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ldm_patched/k_diffusion/sampling.py","lineNumber":258,"sourceCode":"            # Euler method\n            dt = sigma_down - sigmas[i]\n            x = x + d * dt\n        else:\n            # DPM-Solver-2\n            sigma_mid = sigmas[i].log().lerp(sigma_down.log(), 0.5).exp()\n            dt_1 = sigma_mid - sigmas[i]\n            dt_2 = sigma_down - sigmas[i]\n            x_2 = x + d * dt_1\n            denoised_2 = model(x_2, sigma_mid * s_in, **extra_args)\n            d_2 = to_d(x_2, sigma_mid, denoised_2)\n            x = x + d_2 * dt_2\n            x = x + noise_sampler(sigmas[i], sigmas[i + 1]) * s_noise * sigma_up\n    return x\n\n\ndef linear_multistep_coeff(order, t, i, j):\n    if order - 1 > i:\n        raise ValueError(f'Order {order} too high for step {i}')\n    def fn(tau):\n        prod = 1.\n        for k in range(order):\n            if j == k:\n                continue\n            prod *= (tau - t[i - k]) / (t[i - j] - t[i - k])\n        return prod\n    return integrate.quad(fn, t[i], t[i + 1], epsrel=1e-4)[0]\n\n\n@torch.no_grad()\ndef sample_lms(model, x, sigmas, extra_args=None, callback=None, disable=None, order=4):\n    extra_args = {} if extra_args is None else extra_args\n    s_in = x.new_ones([x.shape[0]])\n    sigmas_cpu = sigmas.detach().cpu().numpy()\n    ds = []\n    for i in trange(len(sigmas) - 1, disable=disable):\n        denoised = model(x, sigmas[i] * s_in, **extra_args)","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/k_diffusion/sampling.py#L240-L276","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nfor i in range(len(sigmas) - 1):\n    for j in range(4):\n        coeff = linear_multistep_coeff(4, ts, i, j)  # fails at i<3\n\n# after\nfor i in range(len(sigmas) - 1):\n    eff = min(4, i + 1)\n    for j in range(eff):\n        coeff = linear_multistep_coeff(eff, ts, i, j)","handlingStrategy":"validation","validationCode":"eff_order = min(order, i + 1)\nassert eff_order - 1 <= i, f'order {eff_order} exceeds history at step {i}'\ncoeff = linear_multistep_coeff(eff_order, ts, i, j)","typeGuard":"def coeff_available(order: int, i: int) -> bool:\n    return order - 1 <= i","tryCatchPattern":"try:\n    c = linear_multistep_coeff(order, ts, i, j)\nexcept ValueError:\n    c = linear_multistep_coeff(min(order, i + 1), ts, i, j)  # degrade gracefully","preventionTips":["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."],"tags":["k-diffusion","sampler","lms","multistep"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}