{"record":{"id":"830626011f403d5b","repo":"lllyasviel/Fooocus","slug":"sigma-min-and-sigma-max-must-not-be-0","errorCode":null,"errorMessage":"sigma_min and sigma_max must not be 0","messagePattern":"sigma_min and sigma_max must not be 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ldm_patched/k_diffusion/sampling.py","lineNumber":470,"sourceCode":"                x = x_high + su * s_noise * noise_sampler(self.sigma(s), self.sigma(t))\n                s = t\n                info['n_accept'] += 1\n            else:\n                info['n_reject'] += 1\n            info['nfe'] += order\n            info['steps'] += 1\n\n            if self.info_callback is not None:\n                self.info_callback({'x': x, 'i': info['steps'] - 1, 't': s, 't_up': s, 'denoised': denoised, 'error': error, 'h': pid.h, **info})\n\n        return x, info\n\n\n@torch.no_grad()\ndef sample_dpm_fast(model, x, sigma_min, sigma_max, n, extra_args=None, callback=None, disable=None, eta=0., s_noise=1., noise_sampler=None):\n    \"\"\"DPM-Solver-Fast (fixed step size). See https://arxiv.org/abs/2206.00927.\"\"\"\n    if sigma_min <= 0 or sigma_max <= 0:\n        raise ValueError('sigma_min and sigma_max must not be 0')\n    with tqdm(total=n, disable=disable) as pbar:\n        dpm_solver = DPMSolver(model, extra_args, eps_callback=pbar.update)\n        if callback is not None:\n            dpm_solver.info_callback = lambda info: callback({'sigma': dpm_solver.sigma(info['t']), 'sigma_hat': dpm_solver.sigma(info['t_up']), **info})\n        return dpm_solver.dpm_solver_fast(x, dpm_solver.t(torch.tensor(sigma_max)), dpm_solver.t(torch.tensor(sigma_min)), n, eta, s_noise, noise_sampler)\n\n\n@torch.no_grad()\ndef sample_dpm_adaptive(model, x, sigma_min, sigma_max, extra_args=None, callback=None, disable=None, 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, return_info=False):\n    \"\"\"DPM-Solver-12 and 23 (adaptive step size). See https://arxiv.org/abs/2206.00927.\"\"\"\n    if sigma_min <= 0 or sigma_max <= 0:\n        raise ValueError('sigma_min and sigma_max must not be 0')\n    with tqdm(disable=disable) as pbar:\n        dpm_solver = DPMSolver(model, extra_args, eps_callback=pbar.update)\n        if callback is not None:\n            dpm_solver.info_callback = lambda info: callback({'sigma': dpm_solver.sigma(info['t']), 'sigma_hat': dpm_solver.sigma(info['t_up']), **info})\n        x, info = dpm_solver.dpm_solver_adaptive(x, dpm_solver.t(torch.tensor(sigma_max)), dpm_solver.t(torch.tensor(sigma_min)), order, rtol, atol, h_init, pcoeff, icoeff, dcoeff, accept_safety, eta, s_noise, noise_sampler)\n    if return_info:","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/k_diffusion/sampling.py#L452-L488","documentation":"sample_dpm_fast (fixed-step DPM-Solver) converts sigma_min/sigma_max into log-SNR time via t = log(sigma), so both endpoints must be strictly positive; zero would be log(0) = -inf. The up-front check raises ValueError when either bound is <= 0 before any sampling starts.","triggerScenarios":"Calling sample_dpm_fast(model, x, sigma_min=0, ...) — typical when a schedule ends exactly at 0 (sigmas[-1] == 0 as produced by get_sigmas) and callers pass that terminal value as sigma_min. Also negative or zero custom bounds.","commonSituations":"Feeding Karras sigmas' terminal 0 into the DPM wrapper; schedulers that terminate at sigma=0 for 'final step off'; arithmetic that floors small sigmas to 0.","solutions":["Clamp the lower bound: sigma_min = max(sigma_min, 1e-5) or another small positive epsilon.","Pass the last strictly-positive sigma from your schedule instead of sigmas[-1].","Prefer the sigmas-array DPM samplers (sample_dpmpp_2m etc.) which handle terminal 0 natively.","Validate 0 < sigma_min < sigma_max before calling."],"exampleFix":"# before\nx = sample_dpm_fast(model, x, sigmas[-1], sigmas[0], n=25)  # sigmas[-1]==0 -> ValueError\n\n# after\nx = sample_dpm_fast(model, x, max(float(sigmas[-1]), 1e-5), float(sigmas[0]), n=25)","handlingStrategy":"validation","validationCode":"if sigma_min <= 0 or sigma_max <= 0:\n    raise ValueError('sigma_min and sigma_max must be positive')\nsigma_min = max(float(sigma_min), 1e-5)\nsigma_max = max(float(sigma_max), 1e-5)","typeGuard":"def are_valid_sigmas(smin: float, smax: float) -> bool:\n    return smin > 0 and smax > 0","tryCatchPattern":"try:\n    x = sample_dpm_fast(model, x, sigma_min, sigma_max, n)\nexcept ValueError as e:\n    if 'sigma_min' in str(e):\n        x = sample_dpm_fast(model, x, max(sigma_min, 1e-5), max(sigma_max, 1e-5), n)\n    else:\n        raise","preventionTips":["Clamp schedule endpoints to a small positive epsilon before DPM wrapper calls.","Never pass sigmas[-1] from discrete schedules that terminate at 0.","Prefer sigmas-array samplers when the exact terminal value matters."],"tags":["k-diffusion","dpm-solver","sigma-schedule","validation"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}