17  Diffusion Models

The adversarial generators of Chapter 16 required a second network, a discriminator or critic, because a generator mapping noise to data has no direct regression target. Diffusion and flow-matching models construct a regression target by progressively corrupting each training example with Gaussian noise. Reversing a small Gaussian noise step requires estimating the conditional expectation of the clean data given the noisy observation.

This perspective unites three lines of work: non-equilibrium thermodynamics and denoising diffusion probabilistic models (DDPM) (Sohl-Dickstein et al. 2015; Ho et al. 2020), score-based generative modeling (Song and Ermon 2019; Song et al. 2021), and flow matching or stochastic interpolants (Lipman et al. 2023; Liu et al. 2023; Albergo et al. 2023). In all three formulations, a single neural network learns to predict the clean data (or equivalently the added noise, the score \(\nabla_{\mathbf{x}} \log p_t(\mathbf{x})\), or the velocity along the path) at every noise level \(t \in [0, 1]\), and a numerical sampler integrates those predictions from pure noise at \(t = 1\) back to data at \(t = 0\).

Replacing the adversarial minimax objective with regression resolves three limitations of GANs: training requires only a single network optimized by squared error, the weighted regression loss provides a variational bound on the log-likelihood (and an exact log-likelihood via the probability-flow ODE), and the likelihood objective penalizes missing modes. Throughout this chapter, our default formulation regresses the velocity along the linear path \(\mathbf{x}_t = (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon\) (Esser et al. 2024), alongside DDPM’s noise predictor on the variance-preserving path.

The first three sections develop the complete mathematical and algorithmic core on a two-dimensional mixture of three Gaussians, where the true density, score, posterior mean, and velocity field are available in closed form. Section 17.4 moves to Fashion-MNIST images, introducing the time-conditioned U-Net, Fréchet distance evaluation, and classifier-free guidance. The next four sections examine the sampler (Section 17.5), the likelihood bound and design space (Section 17.6), latent diffusion and transformer backbones (Section 17.7), and few-step distillation via flow maps (Section 17.8). Finally, Section 17.9 extends diffusion to discrete tokens by replacing Gaussian noise with token masking. Longer mathematical proofs appear in Chapter 38, and external tutorials, courses, and reference implementations are collected in Section 17.10.