{"record":{"id":"dfc5774acde734a9","repo":"lllyasviel/Fooocus","slug":"order-should-be-2-or-3","errorCode":null,"errorMessage":"order should be 2 or 3","messagePattern":"order should be 2 or 3","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ldm_patched/k_diffusion/sampling.py","lineNumber":415,"sourceCode":"            denoised = x - self.sigma(t) * eps\n            if self.info_callback is not None:\n                self.info_callback({'x': x, 'i': i, 't': ts[i], 't_up': t, 'denoised': denoised})\n\n            if orders[i] == 1:\n                x, eps_cache = self.dpm_solver_1_step(x, t, t_next_, eps_cache=eps_cache)\n            elif orders[i] == 2:\n                x, eps_cache = self.dpm_solver_2_step(x, t, t_next_, eps_cache=eps_cache)\n            else:\n                x, eps_cache = self.dpm_solver_3_step(x, t, t_next_, eps_cache=eps_cache)\n\n            x = x + su * s_noise * noise_sampler(self.sigma(t), self.sigma(t_next))\n\n        return x\n\n    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):\n        noise_sampler = default_noise_sampler(x) if noise_sampler is None else noise_sampler\n        if order not in {2, 3}:\n            raise ValueError('order should be 2 or 3')\n        forward = t_end > t_start\n        if not forward and eta:\n            raise ValueError('eta must be 0 for reverse sampling')\n        h_init = abs(h_init) * (1 if forward else -1)\n        atol = torch.tensor(atol)\n        rtol = torch.tensor(rtol)\n        s = t_start\n        x_prev = x\n        accept = True\n        pid = PIDStepSizeController(h_init, pcoeff, icoeff, dcoeff, 1.5 if eta else order, accept_safety)\n        info = {'steps': 0, 'nfe': 0, 'n_accept': 0, 'n_reject': 0}\n\n        while s < t_end - 1e-5 if forward else s > t_end + 1e-5:\n            eps_cache = {}\n            t = torch.minimum(t_end, s + pid.h) if forward else torch.maximum(t_end, s + pid.h)\n            if eta:\n                sd, su = get_ancestral_step(self.sigma(s), self.sigma(t), eta)\n                t_ = torch.minimum(t_end, self.t(sd))","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/k_diffusion/sampling.py#L397-L433","documentation":"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.","triggerScenarios":"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).","commonSituations":"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'.","solutions":["Use order=2 (DPM-Solver-12) or order=3 (default, DPM-Solver-23).","Keep sampler-specific defaults: do not share the order value with sample_lms/sample_dpmpp.* configs.","If you need higher order, use a different sampler (e.g. sample_dpmpp_3m_sde) rather than raising order here.","Validate order in {2,3} before dispatching to the sampler."],"exampleFix":"# before\nx = sample_dpm_adaptive(model, x, 0.1, 10.0, order=4)  # ValueError\n\n# after\nx = sample_dpm_adaptive(model, x, 0.1, 10.0, order=3)","handlingStrategy":"validation","validationCode":"if order not in {2, 3}:\n    raise ValueError(f'order must be 2 or 3, got {order}')","typeGuard":"def is_valid_dpm_order(order: int) -> bool:\n    return order in {2, 3}","tryCatchPattern":"try:\n    x = sample_dpm_adaptive(model, x, smin, smax, order=order)\nexcept ValueError as e:\n    if 'order' in str(e):\n        x = sample_dpm_adaptive(model, x, smin, smax, order=3)\n    else:\n        raise","preventionTips":["Constrain adaptive-sampler order settings to {2,3} in schemas/UIs.","Do not share an 'order' knob across samplers with different contracts.","Default to order=3 unless tuning tolerance instead."],"tags":["k-diffusion","dpm-solver","sampler-config","adaptive"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}