lllyasviel/Fooocus · error · ValueError

eta must be 0 for reverse sampling

Error message

eta must be 0 for reverse sampling

What it means

In DPMSolver.dpm_solver_fast, stochastic noise injection (eta>0) is only physically defined when integrating forward in log-SNR time (t_end > t_start); the Brownian correction assumes increasing t. When t_end <= t_start (reverse/inversion direction) and eta is nonzero, it raises ValueError. sample_dpm_fast forwards eta through, so callers can trigger it via the wrapper.

Source

Thrown at ldm_patched/k_diffusion/sampling.py:376

        return x_2, eps_cache

    def dpm_solver_3_step(self, x, t, t_next, r1=1 / 3, r2=2 / 3, eps_cache=None):
        eps_cache = {} if eps_cache is None else eps_cache
        h = t_next - t
        eps, eps_cache = self.eps(eps_cache, 'eps', x, t)
        s1 = t + r1 * h
        s2 = t + r2 * h
        u1 = x - self.sigma(s1) * (r1 * h).expm1() * eps
        eps_r1, eps_cache = self.eps(eps_cache, 'eps_r1', u1, s1)
        u2 = x - self.sigma(s2) * (r2 * h).expm1() * eps - self.sigma(s2) * (r2 / r1) * ((r2 * h).expm1() / (r2 * h) - 1) * (eps_r1 - eps)
        eps_r2, eps_cache = self.eps(eps_cache, 'eps_r2', u2, s2)
        x_3 = x - self.sigma(t_next) * h.expm1() * eps - self.sigma(t_next) / r2 * (h.expm1() / h - 1) * (eps_r2 - eps)
        return x_3, eps_cache

    def dpm_solver_fast(self, x, t_start, t_end, nfe, eta=0., s_noise=1., noise_sampler=None):
        noise_sampler = default_noise_sampler(x) if noise_sampler is None else noise_sampler
        if not t_end > t_start and eta:
            raise ValueError('eta must be 0 for reverse sampling')

        m = math.floor(nfe / 3) + 1
        ts = torch.linspace(t_start, t_end, m + 1, device=x.device)

        if nfe % 3 == 0:
            orders = [3] * (m - 2) + [2, 1]
        else:
            orders = [3] * (m - 1) + [nfe % 3]

        for i in range(len(orders)):
            eps_cache = {}
            t, t_next = ts[i], ts[i + 1]
            if eta:
                sd, su = get_ancestral_step(self.sigma(t), self.sigma(t_next), eta)
                t_next_ = torch.minimum(t_end, self.t(sd))
                su = (self.sigma(t_next) ** 2 - self.sigma(t_next_) ** 2) ** 0.5
            else:
                t_next_, su = t_next, 0.

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Set eta=0 when sampling in reverse (t_end <= t_start).
  2. For forward sampling ensure sigma_max > sigma_min (schedule goes high noise -> low noise).
  3. Use sample_dpm_adaptive or the deterministic dpm_solver variants for reverse ODE work.
  4. Validate argument order at the call site: sample_dpm_fast(model, x, sigma_min=0.1, sigma_max=10.0, ...).

Example fix

# before
x = sample_dpm_fast(model, x, 10.0, 0.1, n=20, eta=1.0)  # reversed + eta -> ValueError

# after (reverse pass must be deterministic)
x = sample_dpm_fast(model, x, 10.0, 0.1, n=20, eta=0.0)
Defensive patterns

Strategy: validation

Validate before calling

if eta != 0 and sigma_min >= sigma_max:
    raise ValueError('eta must be 0 when sampling in reverse (sigma_min >= sigma_max)')
eta = 0 if sigma_min >= sigma_max else eta

Type guard

def can_use_eta(sigma_min: float, sigma_max: float, eta: float) -> bool:
    return eta == 0 or sigma_max > sigma_min

Try / catch

try:
    x = sample_dpm_fast(model, x, sigma_min, sigma_max, n, eta=eta)
except ValueError as e:
    if 'eta must be 0' in str(e):
        x = sample_dpm_fast(model, x, sigma_min, sigma_max, n, eta=0.)
    else:
        raise

Prevention

When it happens

Trigger: Calling sample_dpm_fast(..., sigma_min > sigma_max, eta=1.0) — i.e. swapped sigma bounds producing a reversed schedule — or calling dpm_solver_fast directly with t_end < t_start and eta != 0.

Common situations: Prompt-inversion / noise-scheduling experiments that run the ODE backwards; accidentally swapping sigma_min and sigma_max arguments; UIs exposing an eta slider while sigma order is reversed.

Related errors


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