{"record":{"id":"244d1166d26a3896","repo":"Comfy-Org/ComfyUI","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":"comfy/k_diffusion/sampling.py","lineNumber":408,"sourceCode":"        if sigma_down == 0:\n            # 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 = (alpha_ip1/alpha_down) * x + noise_sampler(sigmas[i], sigmas[i + 1]) * s_noise * renoise_coeff\n    return x\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":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/k_diffusion/sampling.py#L390-L426","documentation":"Raised by linear_multistep_coeff, the coefficient helper for sample_lms (linear multistep sampler). An order-N Adams-Bashforth step at position i needs i+1 previous points; if order-1 > i (i.e. the very first steps of the schedule don't yet have enough history), the Lagrange product would index negative positions, so it refuses up front.","triggerScenarios":"Calling sample_lms (or linear_multistep_coeff directly) with order > number of warmup steps available — concretely order=4 is fine because sample_lms clamps with min(order, i+1), but direct calls to linear_multistep_coeff(order, t, i, j) with order-1 > i raise. Also custom samplers that forget the warmup clamp.","commonSituations":"Copy-pasting sample_lms into a custom sampler without the `order = min(order, i + 1)` warmup line; calling the coefficient helper standalone for unit tests with small i; schedules with very few steps combined with high order in modified code.","solutions":["Clamp order during warmup: order = min(order, i + 1) exactly as sample_lms does","Lower the global order to <= number of early steps you can skip, or start integration after enough history exists","When calling linear_multistep_coeff directly, ensure i >= order-1"],"exampleFix":"# before\ncoeff = linear_multistep_coeff(4, t, i=1, j=1)  # order-1 > i\n# after\norder = min(4, i + 1)\ncoeff = linear_multistep_coeff(order, t, i=1, j=1)","handlingStrategy":"validation","validationCode":"order = min(order, i + 1)  # warmup clamp, mirrors sample_lms\ncoeff = linear_multistep_coeff(order, t, i, j)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always clamp multistep order to available history (i+1 points)","Keep the min(order, i+1) line when copying sample_lms"],"tags":["sampling","lms","multistep","warmup","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}