Dive into Deep Learning · §17.5
Fast Diffusion Samplers, Inversion, and Editing
DDIM family (η) · Heun & multistep ODE solvers · step-grid placement · ODE inversion & slerp · partial-noising edits · inpainting
Motivation
Marginal-Preserving Reverse Steps
\mathbf{x}_s = \alpha_s \hat{\mathbf{x}}_0 + \sqrt{\sigma_s^2 - \tilde\sigma^2}\,\hat{\boldsymbol\epsilon} + \tilde\sigma\,\boldsymbol\xi, \qquad \tilde\sigma = \eta\,\sigma_s\sqrt{1 - \kappa^2}
Deterministic ODE vs. Stochastic Chains
Setting \eta = 0, \eta = 1, or using Ho et al.’s ancestral variance defines three distinct reverse processes from the exact same network predictions (\hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon}):
Exact Predictor Across Step Budgets
Running DDIM (\eta = 0, 1) and the ancestral chain with the exact mixture predictor pred_exact from 20{,}000 starts across N \in \{5, 10, 20, 50, 200, 1000\} steps isolates pure discretization error:

Exact Predictor Across Step Budgets
5 steps: distance to 1,000 steps 0.411, spread 0.309 (eta = 1: 0.321, ancestral: 0.386)
10 steps: distance to 1,000 steps 0.210, spread 0.380 (eta = 1: 0.320, ancestral: 0.528)
20 steps: distance to 1,000 steps 0.107, spread 0.420 (eta = 1: 0.342, ancestral: 0.520)
50 steps: distance to 1,000 steps 0.043, spread 0.451 (eta = 1: 0.397, ancestral: 0.502)
200 steps: distance to 1,000 steps 0.009, spread 0.469 (eta = 1: 0.452, ancestral: 0.480)
1000 steps: distance to 1,000 steps 0.000, spread 0.474 (eta = 1: 0.475, ancestral: 0.479)
Cutting Discretization Error from O(h) to O(h²)
\bar{\mathbf{x}}' = \bar{\mathbf{x}}_t + (\bar\sigma_s - \bar\sigma_t)\,\hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}_t, \bar\sigma_t), \qquad \bar{\mathbf{x}}_s = \bar{\mathbf{x}}_t + (\bar\sigma_s - \bar\sigma_t)\,\frac{\hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}_t, \bar\sigma_t) + \hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}', \bar\sigma_s)}{2}
Second-Order Accuracy at One Evaluation per Step
\bar{\mathbf{x}}_s = \bar{\mathbf{x}}_t + \Delta\!\left(\hat{\boldsymbol\epsilon}_t + \frac{\Delta}{2\Delta'}\big(\hat{\boldsymbol\epsilon}_t - \hat{\boldsymbol\epsilon}'\big)\right)
multistep_sample / DPM-Solver++): Reuses the cached slope \hat{\boldsymbol\epsilon}' from the previous step \Delta' to extrapolate linearly to the midpoint at 1 NFE per step.Where Should a Solver Spend Its Evaluations?
Karras et al. (2022) decoupled the sampling step grid \{\bar\sigma_0, \ldots, \bar\sigma_N\} from the training schedule, proposing the polynomial EDM grid spaced evenly in \bar\sigma^{1/\rho} (\bar\sigma_{\max} = 80, \bar\sigma_{\min} = 0.002, \rho = 7):
\bar\sigma_i = \Big(\bar\sigma_{\max}^{1/\rho} + \frac{i}{N - 1}\big(\bar\sigma_{\min}^{1/\rho} - \bar\sigma_{\max}^{1/\rho}\big)\Big)^\rho, \qquad i = 0, \ldots, N - 1, \quad \bar\sigma_N = 0
VP 152 58.8 25.1 11.8 6.1 3.41 2.03 1.23 0.72 0.34 0
linear inf 9 4 2.33 1.5 1 0.667 0.429 0.25 0.111 0
EDM 80 42.4 21.1 9.72 4.07 1.5 0.47 0.117 0.0204 0.002 0
Empirical Benchmark Across Step Counts
On our trained class-conditional Fashion-MNIST U-Net, we evaluate 1,000-sample FD across three paired noise draws (mean \pm half-range; real-vs.-real floor is about 0.9, with a half-range of 0.15–0.2):
steps 10 20 50 100 200 1000
DDIM, eta = 0 5.41±0.32 2.95±0.19 1.76±0.12 1.45±0.11 1.33±0.10 1.32±0.10
DDIM, eta = 1 7.81±0.23 4.90±0.16 3.06±0.09 2.32±0.06 1.98±0.08 1.52±0.05
ancestral 28.66±0.26 19.22±0.63 7.85±0.10 3.45±0.14 1.78±0.13 1.34±0.03
Benchmarking Euler, Heun, and Multistep Solvers
Comparing Euler, Heun (2 NFE/step), and 2nd-order Adams–Bashforth multistep (1 NFE/step) at equal network function evaluations (NFE) across three grids shows that grid placement and solver order interact strongly:
evaluations 10 20 50 100
Euler, linear 3.33±0.25 1.99±0.15 1.46±0.11 1.36±0.10
Euler, EDM 6.81±0.38 3.14±0.22 1.86±0.15 1.58±0.14
Euler, EDM, rho = 3 9.74±0.47 4.02±0.25 2.02±0.16 1.62±0.14
Heun, linear 1.60±0.12 1.27±0.07 1.20±0.08 1.25±0.09
Heun, EDM 11.71±0.29 1.69±0.08 1.32±0.10 1.37±0.11
Heun, EDM, rho = 3 84.52±0.45 8.10±0.26 1.47±0.11 1.39±0.11
multistep, linear 2.12±0.17 1.42±0.11 1.29±0.10 1.30±0.10
multistep, EDM 4.50±0.28 1.96±0.16 1.46±0.12 1.41±0.12
multistep, EDM, rho = 3 6.56±0.35 2.37±0.17 1.46±0.12 1.39±0.12
Reaching the Model’s Asymptotic Plateau
Plotting FD against total network evaluations on log–log axes shows how quickly each solver saturates the model’s asymptotic quality ceiling (\mathrm{FD} \approx 1.15–1.30):
Comparing Solvers Against a 200-NFE Reference
Does lower FD always mean smaller per-image ODE integration error? We measure per-pixel RMS distance to a 200-NFE Heun reference alongside FD at \gamma = 1 (un-guided conditional) and \gamma = 2 (CFG):
gamma = 1, reference: FD 1.29±0.09; FD and RMS distance to it
evaluations 10 20 50
Euler 3.33±0.25 0.108 1.99±0.15 0.063 1.46±0.11 0.030
Heun 1.60±0.12 0.127 1.27±0.07 0.044 1.20±0.08 0.014
multistep 2.12±0.17 0.094 1.42±0.11 0.044 1.29±0.10 0.015
gamma = 2, reference: FD 2.29±0.11; FD and RMS distance to it
evaluations 10 20 50
Euler 3.88±0.14 0.109 3.07±0.11 0.066 2.57±0.10 0.035
Heun 3.51±0.15 0.142 2.77±0.10 0.066 2.43±0.10 0.021
multistep 3.31±0.12 0.099 2.71±0.10 0.051 2.38±0.10 0.021
Deterministic Convergence vs. Ancestral Speckle
Generating eight garments from the exact same initial noise \mathbf{z} and class labels across four samplers makes the quantitative table visible at a glance:
How to Tune Sampling for a New Model
Because optimal step counts depend on image resolution, training schedule, and guidance scale \gamma, use a paired doubling protocol whenever deploying a new model:
Running the Probability-Flow ODE Forward
Because the probability-flow ODE is deterministic and reversible, running Euler steps upward from t = 0 to 1 (ddim_invert) encodes any real image \mathbf{x}_0 into a latent noise code \mathbf{z} = \mathbf{x}_1:
\bar{\mathbf{x}}_{t'} = \bar{\mathbf{x}}_t + (\bar\sigma_{t'} - \bar\sigma_t)\,\hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}_t, \bar\sigma_t), \qquad t' > t
10 steps: squared error per pixel 0.0347, code std 0.69; mixture 0.3097
20 steps: squared error per pixel 0.0148, code std 0.76; mixture 0.0878
50 steps: squared error per pixel 0.0039, code std 0.81; mixture 0.0192
100 steps: squared error per pixel 0.0011, code std 0.84; mixture 0.0074
200 steps: squared error per pixel 0.0002, code std 0.86; mixture 0.0023
Why Inverted Codes Are Narrower Than N(0, I)
std \approx 0.7–0.85 < 1): Forward Euler under-amplifies variance on curved paths.Traversing Between Two Real Images
Why can we not interpolate linearly ((1 - u)\mathbf{z}_0 + u\mathbf{z}_1) between two inverted noise codes \mathbf{z}_0, \mathbf{z}_1 \in \mathbb{R}^{784}?
Trading Input Fidelity for Sample Realism
Given a coarse user sketch or blurred composite \mathbf{y} (here the 10 blurred class-mean silhouettes, \mathrm{FD} \approx 87), SDEdit (Meng et al., 2022) corrupts \mathbf{y} to an intermediate time t_0 \in (0, 1] and integrates backward from t_0 to 0:
\mathbf{x}_{t_0} = \alpha_{t_0}\mathbf{y} + \sigma_{t_0}\boldsymbol\epsilon \implies \hat{\mathbf{x}}_0
Trading Input Fidelity for Sample Realism
As t_0 grows, the distance to the input \mathbf{y} rises while FD falls:
t0 = 0.0: squared distance to the input 0.000, FD 87.04
t0 = 0.3: squared distance to the input 0.018, FD 30.71
t0 = 0.5: squared distance to the input 0.045, FD 12.19
t0 = 0.7: squared distance to the input 0.087, FD 4.01
t0 = 1.0: squared distance to the input 0.168, FD 1.88
Conditioning on Partial Pixel Observations
Given known pixels \mathbf{y} on a binary mask \mathbf{m} \in \{0, 1\}^{28 \times 28} (here the top half of an image), replacement inpainting (Song et al., 2021) runs standard DDIM steps and overwrites the masked region at every level s with a freshly noised copy of \mathbf{y}:
\mathbf{x}_s \leftarrow \mathbf{m} \odot \big(\alpha_s\mathbf{y} + \sigma_s\boldsymbol\xi\big) + (\mathbf{1} - \mathbf{m}) \odot \mathbf{x}_s
Check Your Understanding
Test your understanding of fast diffusion solvers and deterministic inversion:
ddim_sample(ddim_invert(x0)) exact in just 1 step, and why does linear interpolation between two codes \mathbf{z}_0, \mathbf{z}_1 fail?Answers:
Key Takeaways
| Method / Tool | Update Rule in (\bar{\mathbf{x}}, \bar\sigma) = (\mathbf{x}/\alpha, \sigma/\alpha) | Order & Cost per Step | Key Empirical Result & Role |
|---|---|---|---|
| DDIM (\eta = 0) | \bar{\mathbf{x}}_s = \bar{\mathbf{x}}_t + (\bar\sigma_s - \bar\sigma_t)\hat{\boldsymbol\epsilon}_t | 1st-order (O(h)), 1 NFE | Exact Euler on flow ODE; reaches plateau in 50 NFE |
| Stochastic DDIM (\eta > 0) | \mathbf{x}_s = \alpha_s\hat{\mathbf{x}}_0 + \sqrt{\sigma_s^2 - \tilde\sigma^2}\hat{\boldsymbol\epsilon} + \tilde\sigma\boldsymbol\xi | 1st-order SDE, 1 NFE | \eta = 1 uses posterior variance; trails \eta = 0 at \le 200 steps |
| Heun’s Method | Average of Euler start & trial slopes | 2nd-order (O(h^2)), 2 NFE | Reaches asymptotic FD plateau in 20 NFE on linear grid |
| Multistep (AB2 / DPM++) | \bar{\mathbf{x}}_t + \Delta\big(\hat{\boldsymbol\epsilon}_t + \frac{\Delta}{2\Delta'}(\hat{\boldsymbol\epsilon}_t - \hat{\boldsymbol\epsilon}')\big) | 2nd-order (O(h^2)), 1 NFE | Reuses previous slope; best solver under CFG (\gamma = 2) |
| DDIM Inversion & Slerp | Forward Euler t: 0 \to 1; great-circle arc | O(h) round-trip error | Encodes real images to noise codes \mathbf{z} while preserving \|\mathbf{z}\| |
| SDEdit & Inpainting | Start at t_0 \in (0, 1) or overwrite mask \mathbf{m} | Zero-shot (no retraining) | t_0 trades fidelity vs. realism; mask overwrite fills missing regions |