{"record":{"id":"b60146b39ab925f2","repo":"Stability-AI/generative-models","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":"sgm/modules/diffusionmodules/sampling_utils.py","lineNumber":9,"sourceCode":"import torch\nfrom scipy import integrate\n\nfrom ...util import append_dims\n\n\ndef linear_multistep_coeff(order, t, i, j, epsrel=1e-4):\n    if order - 1 > i:\n        raise ValueError(f\"Order {order} too high for step {i}\")\n\n    def fn(tau):\n        prod = 1.0\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\n    return integrate.quad(fn, t[i], t[i + 1], epsrel=epsrel)[0]\n\n\ndef get_ancestral_step(sigma_from, sigma_to, eta=1.0):\n    if not eta:\n        return sigma_to, 0.0\n    sigma_up = torch.minimum(\n        sigma_to,\n        eta","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/diffusionmodules/sampling_utils.py#L1-L27","documentation":"linear_multistep_coeff builds the linear multistep coefficient for order-order solvers; it needs `order-1` previous steps, so calling it at step i with order-1 > i raises ValueError.","triggerScenarios":"Running a linear multistep sampler (e.g. LDMS) with order > i+1 at early steps — e.g. sampler order=4 while ramping starts at i=0 and the sampler does not reduce order for the first steps.","commonSituations":"Custom sampling loops calling LinearMultistepCoeff/Sampler.sample with a high order and too few warm-up steps; misconfigured sampler args (order larger than allowed for the step schedule).","solutions":["Use min(order, i+1) as the effective order for the first steps in the sampling loop","Lower the sampler order (e.g. order=2 or 3) in the sampling config","Ensure the sampler's ramp-up logic (self.rampup / get_order) is invoked rather than calling linear_multistep_coeff directly with a fixed order"],"exampleFix":"// before\ncoef = linear_multistep_coeff(4, t, i, old_order)\n// after\norder = min(4, i + 1)\ncoef = linear_multistep_coeff(order, t, i, old_order)","handlingStrategy":"validation","validationCode":"def assert_order_fits(order, i):\n    if order - 1 > i:\n        raise ValueError(f\"order {order} needs {order-1} prior steps, but i={i}\")\nassert_order_fits(sampler.order, step_index)","typeGuard":"def order_fits(order: int, i: int) -> bool:\n    return order - 1 <= i","tryCatchPattern":"try:\n    x = sampler.sample(S, shape, order=4)\nexcept ValueError as e:\n    if \"too high for step\" in str(e):\n        x = sampler.sample(S, shape, order=2)\n    else:\n        raise","preventionTips":["Use the sampler's built-in ramp-up (min(order, i+1)) instead of calling linear_multistep_coeff directly","Keep sampler order small (2-3) for short schedules","Add an assertion early in custom sampling loops that order <= num_steps"],"tags":["python","sampling","value-error","diffusion"],"backgroundTag":"solver-order-too-high","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}