Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Fewer, smarter steps along the same path
A trained diffusion model defines a smooth path from each noise sample to an image; the sampler’s job is to follow that path using as few network calls as possible, because each call is the expensive part. Two ideas matter most. First, where you put the steps: big steps where the path is straight (very noisy images), small ones where details form (little noise). Second, how each step is computed: like a better GPS that uses the last two readings to predict the curve, higher-order solvers take bigger steps with the same accuracy. The demo compares the simple Euler step, EDM’s Heun step and DPM-Solver++ at the same number of network calls, and shows the error against the exact path.
These solvers made diffusion fast enough for products: DPM-Solver++(2M) and EDM-style ‘Karras’ schedules are the defaults in Stable Diffusion tools, and EDM’s preconditioning is used in weather (GenCast), video and protein models.
- 1. Sampling cost of a diffusion model is mostly…
- 2. EDM places most steps…
- 3. DPM-Solver++(2M) gets second-order accuracy by…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.DPM-Solver and EDM in brief
- Semi-linear ODE (VP): dx/dt = f(t) x + (g²(t)/2σ_t) ε_θ(x, t). With λ = log(α_t/σ_t) (half the log-SNR), the exact solution is x_t = (α_t/α_s) x_s − α_t ∫_(λ_s)^(λ_t) e^(−λ) ε̂ dλ: the linear part is exact, only the network term is approximated.
- DPM-Solver-1 = DDIM: treat ε̂ as constant over the step: x_t = (α_t/α_s) x_s − σ_t (e^h − 1) ε̂, h = λ_t − λ_s.
- DPM-Solver-2, -3: Taylor-expand ε̂ in λ using an intermediate evaluation (single-step); 10–20 NFE gave good samples on CIFAR-10 and ImageNet (Lu et al., NeurIPS 2022).
- DPM-Solver++: the same with the data prediction x̂0, which is bounded and works better with guidance; 2M (multistep) reuses D_(i−1): D̃ = (1 + 1/2r) D_i − (1/2r) D_(i−1), r = h_(i−1)/h_i, one evaluation per step. In VE form (α = 1): x_(i+1) = (σ_(i+1)/σ_i) x_i + (1 − σ_(i+1)/σ_i) D̃.
- EDM’s ODE: with x = x0 + σ n, dx/dσ = (x − D(x, σ))/σ. Any VP model can be mapped to this form (x_EDM = x_VP/√ā, σ = √((1 − ā)/ā)).
- EDM time grid: σ_i = (σ_max^(1/ρ) + i/(N−1)(σ_min^(1/ρ) − σ_max^(1/ρ)))^ρ with σ_max = 80, σ_min = 0.002, ρ = 7, then σ_N = 0.
- EDM sampler: Heun (trapezoidal) steps, Euler on the last; 18 steps = 35 NFE on CIFAR-10. An optional stochastic version adds noise (S_churn) and helps on harder datasets (ImageNet-64 FID 1.36).
- Preconditioning: D(x, σ) = c_skip x + c_out F_θ(c_in x, c_noise) with c_skip = σ_d²/(σ² + σ_d²), c_out = σσ_d/√(σ² + σ_d²), c_in = 1/√(σ² + σ_d²), c_noise = ¼ ln σ, σ_d = 0.5. Loss weight λ(σ) = (σ² + σ_d²)/(σσ_d)², training σ ~ lognormal(−1.2, 1.2).
- Worked number: at σ = 0.5 = σ_d, c_skip = 0.5, c_out = 0.354, c_in = 1.414.
- 1. DPM-Solver-1 is the same as…
- 2. EDM's ρ = 7 grid concentrates steps at…
- 3. EDM's Heun sampler with 18 steps uses how many NFE?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Preconditioning and solver steps in code
Exercise 1.
- EDM’s preconditioning coefficients and loss weight (checking unit-variance inputs and targets).
- EDM’s ρ-spaced σ grid.
- A Heun step and a DPM-Solver++(2M) step, compared with Euler on Gaussian data where the ODE has a closed-form solution.
Practice.
- Default for latent image models: DPM-Solver++(2M) with Karras (ρ = 7) σ spacing, 20–30 steps; with strong classifier-free guidance prefer 2M over single-step third-order.
- For pixel models trained with EDM: Heun, 18–40 steps, ρ = 7; add stochasticity (S_churn) on hard datasets.
- UniPC (2023) and DEIS are related multistep exponential integrators; for under ~8 steps use distillation (h7-14, h7-15) instead of better solvers.
- Measure solver quality as distance to a high-NFE reference with the same noise, not only FID.
- In diffusers: DPMSolverMultistepScheduler(use_karras_sigmas=True), EulerDiscreteScheduler, HeunDiscreteScheduler.
import torch
def edm_denoiser(F, x, sigma, sigma_data=0.5): # EDM preconditioning around a raw network F
v = sigma ** 2 + sigma_data ** 2
c_skip, c_out, c_in = sigma_data ** 2 / v, sigma * sigma_data / v.sqrt(), 1 / v.sqrt()
return c_skip * x + c_out * F(c_in * x, sigma.log() / 4)
@torch.no_grad()
def dpmpp_2m(D, x, sigmas): # sigmas descending, last = 0
old = None
for i in range(len(sigmas) - 1):
s0, s1 = sigmas[i], sigmas[i + 1]; d = D(x, s0)
if s1 == 0: x = d; break
h = (s0 / s1).log(); dd = d
if old is not None:
r = h_prev / h; dd = (1 + 1 / (2 * r)) * d - old / (2 * r)
x = (s1 / s0) * x + (1 - s1 / s0) * dd
old, h_prev = d, h # store the raw D_i, not the extrapolation
return x- 1. A common default for latent diffusion sampling is…
- 2. Below ~8 steps the better tool is usually…
- 3. Solver error is best measured against…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Exponential integrators. The VP probability-flow ODE in ε-form is dx/dt = f(t) x + (g(t)²/(2σ_t)) ε_θ(x, t), linear in x apart from the network. Variation of constants with λ_t = log(α_t/σ_t) gives the exact x_t = (α_t/α_s) x_s − α_t ∫ e^(−λ) ε̂_θ(x_λ, λ) dλ. Expanding ε̂ (or x̂0 for DPM-Solver++) as a Taylor polynomial in λ and integrating each term exactly gives solvers of any order; the zeroth-order term is DDIM. Because the linear part is not discretised, these solvers stay stable with large steps where generic Runge–Kutta methods on the same ODE do not.
Multistep second order. If D(λ) ≈ D_i + (λ − λ_i) D′, a backward difference D′ ≈ (D_i − D_(i−1))/h_(i−1) and exact integration of e^λ times this line over [λ_i, λ_i + h] gives, to second order, the D̃ = (1 + 1/2r) D_i − (1/2r) D_(i−1) rule. Cost: one network call per step.
Heun. The trapezoidal rule averages the slope at both ends of the step; its local error is O(h³) when the slope is smooth on the step. When one step spans a huge range of σ (here a factor of 32 on a 3-step grid), the slope (x − D)/σ changes qualitatively within the step and the average misleads: second-order methods need steps small enough for their Taylor model to hold.
Why ρ = 7. The truncation error of a step scales with the curvature of the trajectory, which in σ-space is concentrated at small σ (where D varies quickly as modes separate). Spacing uniform in σ^(1/ρ) puts most steps there; ρ = 3 equalises errors in their experiments, ρ = 7 was better for FID. Uniform-in-log-σ spacing (DPM-Solver’s uniform λ) behaves similarly.
Why preconditioning. With x = x0 + σn, Var(x) = σ_d² + σ²; c_in normalises the input. The network’s target (x0 − c_skip x)/c_out has unit variance for every σ, and c_skip makes the network predict a correction rather than x0 at low noise (where x itself is almost right) and x0 at high noise. The loss weight λ(σ) = 1/c_out² equalises the effective weight on F across noise levels.
Exercise check. On Gaussian data, 8 steps from σ = 80 to 1 gave maximum errors 0.0298 (Euler), 0.0191 (Heun) and 0.0113 (DPM-Solver++(2M)).
- 1. Exponential integrators discretise…
- 2. EDM's target for F has variance…
- 3. Second-order methods can fail when…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.At a fixed budget of network evaluations, which solver and which step spacing follow the ODE best?
History.
- C. Lu, Y. Zhou, F. Bao, J. Chen, C. Li and J. Zhu, “DPM-Solver: a fast ODE solver for diffusion probabilistic model sampling in around 10 steps” (NeurIPS 2022), and “DPM-Solver++: fast solver for guided sampling of diffusion probabilistic models” (2022).
- T. Karras, M. Aittala, T. Aila and S. Laine, “Elucidating the design space of diffusion-based generative models” (NeurIPS 2022): EDM.
- Q. Zhang and Y. Chen, “Fast sampling of diffusion models with exponential integrator” (ICLR 2023): DEIS.
- W. Zhao, L. Bai, Y. Rao, J. Zhou and J. Lu, “UniPC: a unified predictor-corrector framework for fast sampling of diffusion models” (NeurIPS 2023).
- T. Karras et al., “Analyzing and improving the training dynamics of diffusion models” (CVPR 2024): EDM2.
Exercise 2.
- Model: the 8-mode ring (std 0.15, radius 2) with its exact denoiser D(x, σ) in EDM form, so the ODE is known exactly and only the solver varies.
- Reference: 500 Heun steps on the ρ = 7 grid (self-consistency about 2 × 10⁻⁵) from 500 fixed noises.
- Solvers: Euler (= DDIM = DPM-Solver-1), DPM-Solver++(2M) and Heun, at matched NFE = 5, 9, 19, 39 (Heun uses (NFE + 1)/2 steps); grids: EDM ρ = 7, uniform in log σ, uniform in σ (Euler only); σ from 80 to 0.002.
- Metrics: RMS distance to the reference solution (the solver error) and spread (RMS distance to the nearest mode / (0.15·√2); the reference has 0.977).
| ODE error (spread) | seed 0 | seed 1 | seed 2 |
|---|---|---|---|
| Euler, ρ = 7: 9 / 19 / 39 NFE | 0.204 / 0.085 / 0.039 | 0.204 / 0.086 / 0.040 | 0.206 / 0.086 / 0.040 |
| Euler, uniform σ: 19 NFE | 1.474 (7.08) | 1.471 (7.05) | 1.466 (7.00) |
| DPM-Solver++(2M), ρ = 7: 9 / 19 / 39 | 0.380 / 0.044 / 0.008 | 0.378 / 0.045 / 0.010 | 0.374 / 0.044 / 0.009 |
| DPM-Solver++(2M), log σ: 9 / 19 / 39 | 0.213 / 0.028 / 0.007 | 0.212 / 0.030 / 0.009 | 0.212 / 0.029 / 0.008 |
| Heun, ρ = 7: 9 / 19 / 39 | 2.536 / 0.166 / 0.022 | 2.521 / 0.166 / 0.023 | 2.517 / 0.167 / 0.023 |
| spread at 19 NFE: Euler / DPM++ / Heun (ρ = 7) | 1.187 / 0.994 / 1.258 | 1.205 / 1.022 / 1.289 | 1.199 / 1.030 / 1.301 |
| at 5 NFE: Euler / DPM++ / Heun error | 0.482 / 0.503 / 7.391 | 0.479 / 0.505 / 7.456 | 0.477 / 0.510 / 7.635 |
- Ranking at 39 NFE: DPM-Solver++(2M) beat Heun by 2.2–2.7× and Euler by 4–5×, as expected from their orders (one call per step for 2M versus two for Heun).
- At 19 NFE: DPM-Solver++ was 2–3× more accurate than Euler (best on the log-σ grid), and its samples had the right spread (0.99–1.03). Heun, with only 10 steps, was worse than Euler.
- Very few steps, a negative result: at 5–9 NFE second order did not help (2M on ρ = 7 was worse than Euler at 9 NFE), and Heun diverged (errors 2.5–7.6): the first step spans a factor of 4.6–32 in σ, too much for a second-order Taylor model with this sharply multimodal data. EDM’s 35-NFE operating point is no accident.
- Spacing matters most: uniform σ spacing wasted nearly all steps at high noise, giving 17× the error of ρ = 7 at 19 NFE.
Fast samplers in AI, robotics and aerospace
- Image and video generation: DPM-Solver++(2M) Karras is the common default in Stable Diffusion tools; EDM-style samplers and preconditioning are used in many video and audio models.
- Weather: GenCast (2024) uses EDM-style preconditioning and solvers to draw 15-day ensemble members in minutes.
- Robotics and control: fewer evaluations means diffusion planners and policies fit within control-loop deadlines on embedded GPUs.
- Science: protein and materials generators use EDM training (lognormal σ, preconditioning) because it is robust across data scales.
References
- C. Lu, Y. Zhou, F. Bao, J. Chen, C. Li and J. Zhu (2022). “DPM-Solver: a fast ODE solver for diffusion probabilistic model sampling in around 10 steps.” NeurIPS.
- C. Lu, Y. Zhou, F. Bao, J. Chen, C. Li and J. Zhu (2022). “DPM-Solver++: fast solver for guided sampling of diffusion probabilistic models.” arXiv:2211.01095.
- T. Karras, M. Aittala, T. Aila and S. Laine (2022). “Elucidating the design space of diffusion-based generative models.” NeurIPS.
- Q. Zhang and Y. Chen (2023). “Fast sampling of diffusion models with exponential integrator.” ICLR.
- W. Zhao, L. Bai, Y. Rao, J. Zhou and J. Lu (2023). “UniPC: a unified predictor-corrector framework for fast sampling of diffusion models.” NeurIPS.