lllyasviel/Fooocus · error · ValueError

order should be 2 or 3

Error message

order should be 2 or 3

What it means

dpm_solver_adaptive implements DPM-Solver-12 and DPM-Solver-23, i.e. only 2nd and 3rd order multistep corrections. The adaptive controller, error estimator, and step doubling logic are hard-coded for these orders, so order not in {2,3} raises ValueError up front.

Source

Thrown at ldm_patched/k_diffusion/sampling.py:415

            denoised = x - self.sigma(t) * eps
            if self.info_callback is not None:
                self.info_callback({'x': x, 'i': i, 't': ts[i], 't_up': t, 'denoised': denoised})

            if orders[i] == 1:
                x, eps_cache = self.dpm_solver_1_step(x, t, t_next_, eps_cache=eps_cache)
            elif orders[i] == 2:
                x, eps_cache = self.dpm_solver_2_step(x, t, t_next_, eps_cache=eps_cache)
            else:
                x, eps_cache = self.dpm_solver_3_step(x, t, t_next_, eps_cache=eps_cache)

            x = x + su * s_noise * noise_sampler(self.sigma(t), self.sigma(t_next))

        return x

    def dpm_solver_adaptive(self, x, t_start, t_end, order=3, rtol=0.05, atol=0.0078, h_init=0.05, pcoeff=0., icoeff=1., dcoeff=0., accept_safety=0.81, eta=0., s_noise=1., noise_sampler=None):
        noise_sampler = default_noise_sampler(x) if noise_sampler is None else noise_sampler
        if order not in {2, 3}:
            raise ValueError('order should be 2 or 3')
        forward = t_end > t_start
        if not forward and eta:
            raise ValueError('eta must be 0 for reverse sampling')
        h_init = abs(h_init) * (1 if forward else -1)
        atol = torch.tensor(atol)
        rtol = torch.tensor(rtol)
        s = t_start
        x_prev = x
        accept = True
        pid = PIDStepSizeController(h_init, pcoeff, icoeff, dcoeff, 1.5 if eta else order, accept_safety)
        info = {'steps': 0, 'nfe': 0, 'n_accept': 0, 'n_reject': 0}

        while s < t_end - 1e-5 if forward else s > t_end + 1e-5:
            eps_cache = {}
            t = torch.minimum(t_end, s + pid.h) if forward else torch.maximum(t_end, s + pid.h)
            if eta:
                sd, su = get_ancestral_step(self.sigma(s), self.sigma(t), eta)
                t_ = torch.minimum(t_end, self.t(sd))

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Use order=2 (DPM-Solver-12) or order=3 (default, DPM-Solver-23).
  2. Keep sampler-specific defaults: do not share the order value with sample_lms/sample_dpmpp.* configs.
  3. If you need higher order, use a different sampler (e.g. sample_dpmpp_3m_sde) rather than raising order here.
  4. Validate order in {2,3} before dispatching to the sampler.

Example fix

# before
x = sample_dpm_adaptive(model, x, 0.1, 10.0, order=4)  # ValueError

# after
x = sample_dpm_adaptive(model, x, 0.1, 10.0, order=3)
Defensive patterns

Strategy: validation

Validate before calling

if order not in {2, 3}:
    raise ValueError(f'order must be 2 or 3, got {order}')

Type guard

def is_valid_dpm_order(order: int) -> bool:
    return order in {2, 3}

Try / catch

try:
    x = sample_dpm_adaptive(model, x, smin, smax, order=order)
except ValueError as e:
    if 'order' in str(e):
        x = sample_dpm_adaptive(model, x, smin, smax, order=3)
    else:
        raise

Prevention

When it happens

Trigger: Calling sample_dpm_adaptive(..., order=4) or order=1, or reading order from a config that defaults to another sampler's order (e.g. LMS's 4).

Common situations: Exposing one shared 'order' setting across multiple samplers in a UI; copying a config block from sample_lms (order=4) into the dpm_adaptive settings; misreading the paper's DPM-Solver-3 as 'order 3 anywhere'.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/dfc5774acde734a9. Report an issue: GitHub.