lllyasviel/Fooocus · error · ValueError
sigma_min and sigma_max must not be 0
Error message
sigma_min and sigma_max must not be 0
What it means
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.
Source
Thrown at ldm_patched/k_diffusion/sampling.py:470
x = x_high + su * s_noise * noise_sampler(self.sigma(s), self.sigma(t))
s = t
info['n_accept'] += 1
else:
info['n_reject'] += 1
info['nfe'] += order
info['steps'] += 1
if self.info_callback is not None:
self.info_callback({'x': x, 'i': info['steps'] - 1, 't': s, 't_up': s, 'denoised': denoised, 'error': error, 'h': pid.h, **info})
return x, info
@torch.no_grad()
def 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):
"""DPM-Solver-Fast (fixed step size). See https://arxiv.org/abs/2206.00927."""
if sigma_min <= 0 or sigma_max <= 0:
raise ValueError('sigma_min and sigma_max must not be 0')
with tqdm(total=n, disable=disable) as pbar:
dpm_solver = DPMSolver(model, extra_args, eps_callback=pbar.update)
if callback is not None:
dpm_solver.info_callback = lambda info: callback({'sigma': dpm_solver.sigma(info['t']), 'sigma_hat': dpm_solver.sigma(info['t_up']), **info})
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)
@torch.no_grad()
def 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):
"""DPM-Solver-12 and 23 (adaptive step size). See https://arxiv.org/abs/2206.00927."""
if sigma_min <= 0 or sigma_max <= 0:
raise ValueError('sigma_min and sigma_max must not be 0')
with tqdm(disable=disable) as pbar:
dpm_solver = DPMSolver(model, extra_args, eps_callback=pbar.update)
if callback is not None:
dpm_solver.info_callback = lambda info: callback({'sigma': dpm_solver.sigma(info['t']), 'sigma_hat': dpm_solver.sigma(info['t_up']), **info})
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)
if return_info:View on GitHub (pinned to ae05379cc9)
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.
Example fix
# before x = sample_dpm_fast(model, x, sigmas[-1], sigmas[0], n=25) # sigmas[-1]==0 -> ValueError # after x = sample_dpm_fast(model, x, max(float(sigmas[-1]), 1e-5), float(sigmas[0]), n=25)
Defensive patterns
Strategy: validation
Validate before calling
if sigma_min <= 0 or sigma_max <= 0:
raise ValueError('sigma_min and sigma_max must be positive')
sigma_min = max(float(sigma_min), 1e-5)
sigma_max = max(float(sigma_max), 1e-5) Type guard
def are_valid_sigmas(smin: float, smax: float) -> bool:
return smin > 0 and smax > 0 Try / catch
try:
x = sample_dpm_fast(model, x, sigma_min, sigma_max, n)
except ValueError as e:
if 'sigma_min' in str(e):
x = sample_dpm_fast(model, x, max(sigma_min, 1e-5), max(sigma_max, 1e-5), n)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- eta must be 0 for reverse sampling
- order should be 2 or 3
- solver_type must be 'heun' or 'midpoint'
- provide num_res_blocks either as an int (globally constant)
- Order {order} too high for step {i}
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/830626011f403d5b.
Report an issue: GitHub.