Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Same trained model, a shortcut path
A trained DDPM is slow because its sampler takes a thousand small random steps. DDIM noticed that training never cared how the noise was added step by step, only how noisy each step’s image is. So you are free to invent a different, more direct path through the same noise levels, and even to make it completely deterministic. Then one starting noise image always leads to the same final image, whether you take 10 steps or 1000, and you can run the path backwards to find which noise produces a given real image. The demo lets you slide η from 0 (deterministic) to 1 (DDPM-like randomness) and change the number of steps.
DDIM made diffusion practical: Stable Diffusion’s early default sampler, image editing by inversion (prompt-to-prompt, null-text inversion) and the deterministic ODE view behind DPM-Solver and consistency models all start here.
- 1. DDIM needs a newly trained network…
- 2. With η = 0, DDIM sampling is…
- 3. Running DDIM backwards on a real image gives…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The DDIM update
- Marginals are all that matter: L_simple only uses q(x_t | x0) = N(√ā_t x0, (1 − ā_t) I). Any forward process with these marginals shares the same optimal ε_θ.
- Non-Markovian family: q_σ(x_(t−1) | x_t, x0) = N(√ā_(t−1) x0 + √(1 − ā_(t−1) − σ_t²) · (x_t − √ā_t x0)/√(1 − ā_t), σ_t² I) keeps all marginals for any σ_t.
- Update: x̂0 = (x_t − √(1 − ā_t) ε_θ)/√ā_t, then x_(t−1) = √ā_(t−1) x̂0 + √(1 − ā_(t−1) − σ_t²) ε_θ + σ_t z.
- Noise scale: σ_t(η) = η √((1 − ā_(t−1))/(1 − ā_t)) √(1 − ā_t/ā_(t−1)). η = 1 gives σ² = β̃ (DDPM’s posterior variance); η = 0 is deterministic. DDPM’s larger choice σ² = β (written σ̂) is not in this family’s sweet spot and fails at few steps.
- Sub-sequences: because only marginals matter, sample on any increasing sub-sequence τ of 1…T (evenly or quadratically spaced) with ā_(τ_i) in the formulas.
- ODE view: with x̄ = x/√ā and σ̄ = √((1 − ā)/ā), η = 0 DDIM is exactly Euler’s method on dx̄ = ε_θ dσ̄, the probability-flow ODE in these variables (h7-3).
- Inversion: run the deterministic update with increasing ā to encode x0 into x_T; with enough steps decoding reproduces x0.
- Results (CIFAR-10, same network): DDIM with 100 steps reached FID 4.16, close to the 1000-step DDPM’s 3.17, while DDPM-style sampling degraded badly at 10–50 steps.
- Worked number: x_t = 1, ε̂ = 0.5, ā = 0.64 gives x̂0 = (1 − 0.6·0.5)/0.8 = 0.875.
- 1. η = 1 corresponds to σ² equal to…
- 2. DDIM with η = 0 is Euler's method on…
- 3. DDIM can sample on any sub-sequence of timesteps because…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Coding DDIM and its inversion
Exercise 1.
- The DDIM noise scale σ(η) (checking that η = 1 gives β̃).
- One DDIM update and its ODE form (they must agree).
- One inversion step (exact with the true ε), and evenly spaced sub-sequences.
Practice.
- In diffusers use DDIMScheduler (eta argument) with 20–50 steps; ‘trailing’ timestep spacing and ‘zero terminal SNR’ fixes (Lin et al., 2024) avoid a train–test mismatch at the last step.
- For editing, invert with DDIM (η = 0) and the same conditioning; with classifier-free guidance, null-text inversion (Mokady et al., 2023) corrects inversion drift.
- Interpolate between latents with spherical interpolation (slerp), since Gaussian latents concentrate on a sphere.
- For under ~20 steps, prefer higher-order ODE solvers (DPM-Solver, h7-5) over DDIM.
- Clip or threshold x̂0 for pixel-space models (dynamic thresholding in Imagen).
import torch
@torch.no_grad()
def ddim_sample(model, x, abar, ts, eta=0.0): # ts: descending timesteps, abar: tensor
for i, t in enumerate(ts):
a = abar[t]; ap = abar[ts[i + 1]] if i + 1 < len(ts) else torch.tensor(1.0)
eps = model(x, torch.full((x.shape[0],), t))
x0 = (x - (1 - a).sqrt() * eps) / a.sqrt()
sig = eta * ((1 - ap) / (1 - a) * (1 - a / ap)).sqrt()
x = ap.sqrt() * x0 + (1 - ap - sig ** 2).sqrt() * eps + sig * torch.randn_like(x)
return x- 1. Latent interpolation for DDIM uses…
- 2. Null-text inversion fixes inversion drift under…
- 3. For very few steps a better choice than DDIM is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Marginal preservation. Suppose q_σ(x_t | x0) = N(√ā_t x0, (1 − ā_t) I). Then x_(t−1) from q_σ(x_(t−1) | x_t, x0) has mean √ā_(t−1) x0 + √(1 − ā_(t−1) − σ²) · E[(x_t − √ā_t x0)/√(1 − ā_t)] = √ā_(t−1) x0, and variance (1 − ā_(t−1) − σ²) · 1 + σ² = 1 − ā_(t−1). By induction from t = T, every marginal is the DDPM one.
Same objective. The ELBO for q_σ is a sum of KLs whose means are linear in ε_θ; for each σ it equals Σ_t γ_t E‖ε − ε_θ(x_t, t)‖² + const with positive weights γ_t. If ε_θ does not share parameters across t, each term is minimised by the same ε_θ (the conditional mean of ε), so the DDPM-trained network is optimal for every member of the family.
ODE limit. With η = 0 and x̄ = x/√ā, σ̄ = √((1 − ā)/ā): x̄_(t−1) = x̄_t + (σ̄_(t−1) − σ̄_t) ε_θ. That is Euler on dx̄/dσ̄ = ε_θ(x̄/√(1 + σ̄²), t), the probability-flow ODE of the VE-type process x̄ = x0 + σ̄ ε. In this form the trajectories are nearly straight lines at high noise (ε_θ changes little), so large steps are accurate, unlike in the VP variables where the drift itself grows with β.
Consistency. A deterministic sampler is a function of x_T, so the step count only changes the discretisation error; samples at 10 and 100 steps from the same x_T stay close. With η > 0 the injected noise decorrelates them.
Exercise check. At 100 steps with the exact ε, η = 0 gave spread 0.951 and η = 1 gave 0.850 (seed 0): the deterministic sampler is closer to the data.
- 1. The DDIM family keeps…
- 2. The DDPM-trained ε_θ is optimal for every η because…
- 3. In variables x̄ = x/√ā, DDIM paths at high noise are…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How do η and the number of steps trade off, and how consistent and invertible is DDIM?
History.
- J. Song, C. Meng and S. Ermon, “Denoising diffusion implicit models” (ICLR 2021).
- J. Ho, A. Jain and P. Abbeel, “Denoising diffusion probabilistic models” (NeurIPS 2020).
- R. Mokady, A. Hertz, K. Aberman, Y. Pritch and D. Cohen-Or, “Null-text inversion for editing real images using guided diffusion models” (CVPR 2023).
- S. Lin, B. Liu, J. Li and X. Yang, “Common diffusion noise schedules and sample steps are flawed” (WACV 2024).
Exercise 2.
- Model: T = 1000 linear schedule and the exact Bayes-optimal ε of the 8-mode ring (std 0.15, radius 2): a perfect ε-network, so differences come from the sampler alone.
- Samplers: DDIM with η = 0, 0.5, 1 and DDPM ancestral sampling with σ² = β (DDIM’s σ̂), on S = 10, 20, 50, 100 evenly spaced steps, from the same 1000 starting noises.
- Consistency: the share of samples whose nearest mode is the same at S = 10 and S = 100 from the same noise.
- Inversion: 300 data points encoded with deterministic DDIM and decoded on the same S-step grid.
- Metrics: spread = RMS distance to the nearest mode / (0.15·√2), 1 = data-like; off-mode = share farther than 4 std from every mode.
| measure | seed 0 | seed 1 | seed 2 |
|---|---|---|---|
| S = 10: η = 0 / η = 1 / DDPM-β spread | 1.405 / 1.486 / 2.521 | 1.405 / 1.433 / 2.562 | 1.373 / 1.333 / 2.511 |
| S = 10: η = 0 / DDPM-β off-mode | 8.0% / 30.6% | 7.8% / 32.6% | 7.1% / 30.0% |
| S = 20: η = 0 / η = 1 / DDPM-β spread | 0.913 / 0.839 / 1.622 | 0.922 / 0.839 / 1.627 | 0.905 / 0.895 / 1.593 |
| S = 50: η = 0 / η = 1 / DDPM-β spread | 0.922 / 0.799 / 1.216 | 0.934 / 0.790 / 1.226 | 0.921 / 0.799 / 1.205 |
| S = 100: η = 0 / η = 1 / DDPM-β spread | 0.951 / 0.850 / 1.117 | 0.963 / 0.860 / 1.112 | 0.951 / 0.878 / 1.107 |
| same mode at 10 vs 100 steps: η = 0 / η = 1 | 1.000 / 0.135 | 1.000 / 0.113 | 1.000 / 0.130 |
| inversion error: 10 / 50 / 200 steps | 0.184 / 0.057 / 0.014 | 0.176 / 0.060 / 0.015 | 0.176 / 0.059 / 0.013 |
- DDIM versus DDPM-β: at 10 steps the deterministic sampler had about a quarter of the off-mode samples, and it was closer to the data at every step count, reproducing the paper’s main finding.
- η at few steps, a null result: at 10 steps η = 0 and η = 1 were within the seed-to-seed variation (η = 0 better on two seeds, worse on one). On images, DDIM found η = 0 clearly best at small S; on this low-dimensional toy the difference is not visible.
- Bias at many steps: η = 1 (σ² = β̃) stays too sharp (0.79–0.88) even at 50–100 steps, while η = 0 sits at 0.91–0.96 and approaches 1 slowly.
- Consistency: deterministic DDIM put every sample in the same mode at 10 and 100 steps; with η = 1 agreement was 11–14%, close to the 12.5% expected by chance.
- Inversion: encode–decode error fell roughly in proportion to the step size, from 0.18 (10 steps) to 0.014 (200 steps), compared with a mode std of 0.15.
DDIM in AI, robotics and aerospace
- Image editing: DDIM inversion underlies prompt-to-prompt, null-text inversion and many ‘edit a real photo with text’ tools.
- Robotics: Diffusion Policy commonly samples actions with DDIM in 10–16 steps to meet real-time control rates.
- Earth observation: deterministic samplers make diffusion super-resolution and gap-filling reproducible, which matters when products must be regenerated identically.
- Data assimilation: deterministic encodings of states into latents allow interpolation and ensemble perturbation in latent space.
References
- J. Song, C. Meng and S. Ermon (2021). “Denoising diffusion implicit models.” ICLR.
- J. Ho, A. Jain and P. Abbeel (2020). “Denoising diffusion probabilistic models.” NeurIPS.
- R. Mokady, A. Hertz, K. Aberman, Y. Pritch and D. Cohen-Or (2023). “Null-text inversion for editing real images using guided diffusion models.” CVPR.
- S. Lin, B. Liu, J. Li and X. Yang (2024). “Common diffusion noise schedules and sample steps are flawed.” WACV.
- C. Chi et al. (2023). “Diffusion Policy: visuomotor policy learning via action diffusion.” RSS.