6.5 Diffusion and score matching
1. Learn
Section titled “1. Learn”- Understanding Deep Learning (Prince)chapter 18 Diffusion models, sections 18.1–18.6: the encoder (forward process), the decoder, training, reparameterising in terms of the noise, and sampling
- Ho, Jain and Abbeel, Denoising Diffusion Probabilistic Modelssections 2–3 and algorithms 1–2
- MIT 6.S184 lecture notes: Flow Matching and Diffusion Modelsthe sections on score matching and on training diffusion models
- Song, Meng and Ermon, Denoising Diffusion Implicit Modelssection 4.1 and equation 12 (the deterministic sampler)
2. Bridge
Section titled “2. Bridge”Destroy the data, then learn to undo it. 6.4 ended with annealed Langevin: sample a blurred p first, then sharpen. A diffusion model fixes the blurring in advance. The forward process adds a little Gaussian noise at each of T steps, xt = √(1 − βt) xt−1 + √βt ε. Gaussians compose, so any step can be reached in one jump: xt = √ᾱt x0 + √(1 − ᾱt) ε, with ᾱt the product of the (1 − βs). By t = T almost nothing of x0 is left (Ho et al. 2020, section 2).
What to learn. Running the process backwards needs the score ∇log pt of every noised distribution, which we cannot compute for real data. Denoising score matching gets around this: the score of q(xt | x0), which is −ε / √(1 − ᾱt), averages to the true score over all the x0 that could have produced xt. So a network ε̂(xt, t) trained to predict the added noise with a squared loss learns −√(1 − ᾱt) times the score (Song and Ermon 2019, section 2.1). Ho et al.’s “simple” loss is exactly this regression, with t drawn uniformly.
Sampling. DDPM steps from t to t − 1 using the mean of q(xt−1 | xt, x0) with x0 estimated from ε̂, plus fresh noise; it needs all T steps. DDIM reuses the same network but takes a deterministic path, so it can skip most steps and the same noise always gives the same sample (Song, Meng and Ermon 2020, section 4). The schedule matters too: a cosine schedule spends fewer steps on near-pure noise than the linear one (Nichol and Dhariwal 2021, section 3.2).
Checking it. If the data is a mixture of Gaussians, every pt is too (each component is only scaled and widened by the forward process of Ho et al.), so here the exact score is known and the learned one can be compared with it.
3. Explore
Section titled “3. Explore”Watch the time direction. This module uses DDPM’s convention: x0 is data and t counts up toward pure noise. Module 6.4 and modules 6.6–6.8 use the flow convention instead, with noise at t = 0 and data at t = 1. Formulas carry over once you flip t. Symbols differ between sources too: here αt = 1 − βt and ᾱt is their running product, but UDL chapter 18 and the DDIM paper (eq. 12) write αt for what this page calls ᾱt, and 6.S184 uses βt for a noise standard deviation. Translate before you copy a formula.
Diffusion and score matching: edit exercises/stubs/m6_5_diffusion.py on your own machine. This task needs PyTorch, which the in-page runner does not have.
pip install torch # CPU build is enough for the tests
mlc check 6.5Then run the lab. Open notebooks/6.5-diffusion.ipynb (a CPU is enough) and paste in your 6.5 file. It trains your EpsNet on 20,000 points from the three-blob mixture, compares the learned score with the exact one at three noise levels, and samples with 1000 DDPM steps and 50 DDIM steps.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.