Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Spend the noise budget where it matters
A diffusion model learns to undo noise added over many steps. With DDPM’s original linear schedule, the picture is already pure static long before the last step, so roughly the last third of the steps carry almost no signal and mostly cost sampling time. Improved DDPM uses a cosine-shaped schedule that removes information steadily, and it lets the model decide how much randomness to add back at each reverse step instead of fixing it. With those two changes you can skip most of the steps at sampling time and still get good results. The demo plots both schedules: watch how quickly the linear one drives the signal level to zero.
Every widely used diffusion codebase since 2021 (guided diffusion, Stable Diffusion’s schedulers, diffusers’ respacing) inherits these tricks; the cosine schedule and learned variances remain the defaults for pixel-space models.
- 1. Improved DDPM replaced the linear schedule with…
- 2. In Improved DDPM the reverse-step variance is…
- 3. The main practical payoff was…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The three changes
- Cosine schedule: ā_t = f(t)/f(0) with f(t) = cos²((t/T + s)/(1 + s) · π/2), offset s = 0.008 so that β_1 is not too small; β_t = 1 − ā_t/ā_(t−1), clipped at 0.999 to avoid a singularity at t = T. It crosses ā = 0.5 at t = 497 of 1000, against t = 260 for the linear schedule; at t = 750 ā is 0.144 (cosine) against 0.0034 (linear).
- Learned variance: Σ_θ(x_t, t) = exp(v log β_t + (1 − v) log β̃_t), with v output per dimension. Both bounds are good choices for very different data (β is optimal when x0 is itself N(0, I), β̃ when x0 is a single point), so interpolating in log space is easy to learn.
- Hybrid loss: L_hybrid = L_simple + λ L_vlb with λ = 0.001; the mean gets gradients only from L_simple (stop-gradient in L_vlb), the variance only from L_vlb.
- Importance sampling of t: L_vlb is dominated by its first few terms; sample t with p_t ∝ √E[L_t²] (kept as a history of the last 10 values per t) and weight by 1/p_t. This made pure L_vlb training stable.
- Strided sampling (respacing): pick K timesteps from 1…T; on the subsequence set β_k = 1 − ā_(t_k)/ā_(t_(k−1)) and β̃ accordingly. A model with learned Σ sampled with 50–100 steps reached nearly the FID of the full chain; with fixed σ² = β the quality fell off much faster.
- Results: CIFAR-10 about 2.94 bits/dim with L_vlb (DDPM: 3.70 or less), ImageNet 64×64 competitive likelihoods, and precision–recall showing better mode coverage than BigGAN at similar FID.
- Worked number: jumping in one strided step from ā = 0.8 to ā = 0.5 needs β = 1 − 0.5/0.8 = 0.375.
- 1. The cosine schedule crosses ā = 0.5 at about…
- 2. v = 0.5 in the variance interpolation gives…
- 3. The weight λ on L_vlb in the hybrid loss is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Schedules, variances and respacing in code
Exercise 1.
- The cosine schedule with its β cap.
- The log-space variance interpolation.
- Respacing to K steps (checking that the respaced β reproduce ā on the kept steps).
- The hybrid loss and importance-sampling probabilities.
Practice.
- For pixel-space models, use the cosine schedule (or a shifted variant at high resolution: larger images keep more signal at a given noise level, so shift the log-SNR down).
- Predict Σ via v and train with L_hybrid; stop the gradient of L_vlb into the mean.
- Respace for inference: 50–250 steps are typical; diffusers’ schedulers and OpenAI’s improved-diffusion (timestep_respacing=‘ddim50’ or ‘100’) implement this.
- Report likelihoods in bits/dim with the discretised decoder, and FID with a fixed number of samples (50k).
- For very few steps (under ~25), deterministic samplers (DDIM, DPM-Solver) usually beat ancestral sampling.
import numpy as np, torch
def cosine_abar(T, s=0.008):
f = np.cos((np.arange(T + 1) / T + s) / (1 + s) * np.pi / 2) ** 2
return np.cumprod(1 - np.minimum(1 - f[1:] / f[:-1], 0.999))
def p_mean_var(model, xt, t, beta, beta_tilde): # model outputs [eps, v] stacked on channels
eps, v = model(xt, t).chunk(2, dim=1)
v = (v + 1) / 2 # network output in [-1, 1] -> v in [0, 1]
logvar = v * torch.log(beta[t]) + (1 - v) * torch.log(beta_tilde[t])
return eps, logvar # mean from eps as in DDPM; Σ = exp(logvar)
# loss = mse(eps, target) + 0.001 * vlb(mean.detach(), logvar)- 1. Respaced βs are computed from…
- 2. Larger images usually need the log-SNR schedule…
- 3. In L_hybrid, the mean is trained by…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why the optimal variance lies between β̃ and β. For a fixed mean μ_θ, the KL term of step t is minimised (averaging over data) by σ² = β̃_t + E‖μ̃_t − μ_θ‖²/d: the true posterior spread plus the mean-squared error of the mean. If x0 is known exactly (a point mass), the mean is perfect and σ² = β̃; if x0 ~ N(0, I), the reverse step is exactly Gaussian with variance β_t. Real data sit in between (Bao et al., Analytic-DPM, 2022, derive the optimum in closed form from the score norm).
Why respacing works. The forward marginals q(x_t | x0) depend only on ā_t, so any subsequence t_1 < … < t_K defines a valid shorter diffusion with β_k = 1 − ā_(t_k)/ā_(t_(k−1)). A model trained on all t is a valid model for the subsequence; but each strided reverse step is now a large jump whose true reverse is far from Gaussian, so a fixed variance is poorly matched; a learned (or optimal) one adapts.
Why the cosine schedule helps. The linear schedule’s log-SNR plunges near the end: at T = 1000 its last 327 steps (from t = 674) have ā below 0.01. Those steps cost compute and contribute little to the bound or to sample quality. The cosine schedule makes log-SNR nearly linear in t over most of the range, so every step carries comparable information; it matters most for low-resolution images and for few-step sampling.
Variance of L_vlb. The bound’s terms differ by orders of magnitude across t (the decoder term and the first few KLs are largest), so a uniformly sampled single-t estimate T · L_t has huge variance. Importance sampling with p_t ∝ √E[L_t²] is the variance-minimising choice among proposals of that form.
Exercise check. With the exact mean, the per-step optimal variance tightened the bound by 0.016 nats (linear schedule, seed 0, standard error 0.002); σ² = β̃ loosened it by 0.90 nats. Importance sampling cut the single-t estimate’s standard deviation from 237.5 to 14.6 nats.
- 1. The optimal reverse variance equals β̃ plus…
- 2. Respacing is valid because q(x_t | x0) depends only on…
- 3. Importance sampling of t is needed because L_vlb's terms…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.With a perfect mean, how much do the schedule and the variance matter for the bound and for few-step sampling?
History.
- A. Nichol and P. Dhariwal, “Improved denoising diffusion probabilistic models” (ICML 2021).
- J. Ho, A. Jain and P. Abbeel, “Denoising diffusion probabilistic models” (NeurIPS 2020).
- F. Bao, C. Li, J. Zhu and B. Zhang, “Analytic-DPM: an analytic estimate of the optimal reverse variance in diffusion probabilistic models” (ICLR 2022).
- P. Dhariwal and A. Nichol, “Diffusion models beat GANs on image synthesis” (NeurIPS 2021): the follow-up that used these components with classifier guidance (h7-6).
Exercise 2.
- Data and mean: the 8-mode ring (std 0.15, radius 2) with the exact Bayes-optimal mean E[x0 | x_t]. A learned network is replaced by this exact mean so that only the schedule and the variance vary; the ‘learned variance’ is replaced by the per-step optimum β̃ + E‖μ̃ − μ‖²/2, clipped to iDDPM’s range [β̃, β] (an ideal stand-in for a trained v).
- Bound: T = 1000, full sum of all KL terms, a Gaussian decoder at t = 1, and the prior term, on 400 test points with shared noise, compared with the exact NLL of the mixture.
- Sampling: strided ancestral sampling with 10 and 25 steps, 1000 samples; spread = RMS distance to the nearest mode / (0.15·√2), 1 = data-like.
| measure | seed 0 | seed 1 | seed 2 |
|---|---|---|---|
| true NLL (nats per point) | 1.086 | 1.123 | 1.176 |
| bound gap, linear: β / β̃ / optimum (± s.e. about 0.07) | 0.062 / 0.896 / 0.046 | 0.043 / 0.825 / 0.023 | 0.027 / 0.857 / 0.012 |
| bound gap, cosine: β / β̃ / optimum | −0.082 / 0.662 / −0.092 | 0.010 / 0.715 / 0.001 | 0.018 / 0.762 / 0.010 |
| optimum minus β, paired (linear / cosine) | −0.0164 / −0.0095 | −0.0206 / −0.0094 | −0.0148 / −0.0076 |
| 10-step spread, linear: β / β̃ / optimum | 2.560 / 1.401 / 2.162 | 2.462 / 1.458 / 2.018 | 2.473 / 1.486 / 2.168 |
| 10-step spread, cosine: β / β̃ / optimum | 1.664 / 0.876 / 1.280 | 1.680 / 0.863 / 1.304 | 1.677 / 0.860 / 1.277 |
| 25-step spread, linear: β / β̃ / optimum | 1.447 / 0.820 / 1.171 | 1.456 / 0.801 / 1.164 | 1.470 / 0.804 / 1.193 |
| 25-step spread, cosine: β / β̃ / optimum | 1.189 / 0.797 / 1.062 | 1.205 / 0.836 / 1.054 | 1.219 / 0.815 / 1.069 |
| std of the single-t estimate: uniform / importance | 237.5 / 14.6 | 235.8 / 14.7 | 235.7 / 14.5 |
- Bound: with the exact mean, the bound is already tight within its Monte Carlo noise for σ² = β (the negative cosine gap on seed 0 is noise); the optimal variance improved it by only 0.008–0.021 nats, a small effect that is nonetheless several standard errors from zero in the paired comparison. σ² = β̃ was clearly bad for the bound (+0.66 to +0.90 nats). In iDDPM the big likelihood gains came from learning Σ when the mean is imperfect and from L_vlb training.
- Few steps: the cosine schedule beat the linear one at 10 steps for every variance choice. Fixed β over-blurs and fixed β̃ over-sharpens at few steps; the optimum lands between, and with the cosine schedule at 25 steps it was within 7% of the data’s spread.
- Importance sampling: a 16× smaller standard deviation of the single-t bound estimate, mostly because the decoder and earliest terms dominate.
Improved DDPM in AI, robotics and aerospace
- Guided diffusion and beyond: OpenAI’s guided-diffusion and ADM models, and the upsamplers in DALL·E 2 and Imagen, use learned variances and cosine-type schedules.
- Earth observation: pixel-space diffusion super-resolution of satellite imagery (e.g. SR3-style models) uses respacing to keep inference affordable on large tiles.
- Robotics: Diffusion Policy runs with tens of respaced steps to meet control-loop deadlines.
References
- A. Nichol and P. Dhariwal (2021). “Improved denoising diffusion probabilistic models.” ICML.
- J. Ho, A. Jain and P. Abbeel (2020). “Denoising diffusion probabilistic models.” NeurIPS.
- F. Bao, C. Li, J. Zhu and B. Zhang (2022). “Analytic-DPM: an analytic estimate of the optimal reverse variance in diffusion probabilistic models.” ICLR.
- P. Dhariwal and A. Nichol (2021). “Diffusion models beat GANs on image synthesis.” NeurIPS.