Diffusion Models

Dive into Deep Learning · §17

Diffusion and Flow-Based Generative Models
denoising & scores · Gaussian probability paths · ODE & SDE integration · U-Net & DiT · fast samplers · discrete masking

Why Diffusion Replaces the Adversarial Minimax Game

Motivation

A generator mapping random noise to data has no direct supervision target—forcing GANs to train a competing discriminator. Progressive Gaussian corruption creates an explicit regression target at every noise level:

  • Single-network regression: Corrupting a training example \mathbf{x}_0 into \mathbf{x}_t = \alpha_t \mathbf{x}_0 + \sigma_t \boldsymbol\epsilon lets one network regress directly onto the clean point, added noise, score, or velocity by squared error.
  • Exact likelihoods and bounds: The weighted denoising loss bounds the negative log-likelihood -\log p_{\boldsymbol\theta}(\mathbf{x}_0), while the deterministic probability-flow ODE yields exact log-densities via change of variables.
  • Mode coverage guarantee: Minimizing expected negative log-likelihood \mathbb{E}_p[-\log p_{\boldsymbol\theta}] = H(p) + D_{\textrm{KL}}(p \,\|\, p_{\boldsymbol\theta}) heavily penalizes dropping any data mode.

Gaussian Paths and the Shared Log-SNR Clock

Forward Corruption & Time Conventions

Every continuous model in this chapter interpolates between clean data at t = 0 and standard Gaussian noise \boldsymbol\epsilon \sim \mathcal{N}(\mathbf{0}, \mathbf{I}) at t = 1:

\mathbf{x}_t = \alpha_t \mathbf{x}_0 + \sigma_t \boldsymbol\epsilon

  • Linear path (flow matching default): \alpha_t = 1 - t and \sigma_t = t, moving each training pair at constant conditional velocity \dot{\mathbf{x}}_t = \boldsymbol\epsilon - \mathbf{x}_0.
  • Variance-preserving (VP) path (DDPM): \alpha_t^2 + \sigma_t^2 = 1, preserving unit variance across T = 1{,}000 discrete forward steps.
  • Canonical log-SNR clock: \lambda_t = \log(\alpha_t^2 / \sigma_t^2) decreases from +\infty at t = 0 to -\infty at t = 1; samplers always integrate backward from t = 1 to t = 0.

One Posterior Mean Unifies Four Regression Targets

The Mathematical Core

Because squared error is minimized by the conditional expectation given the input, training on per-example targets recovers the posterior mean \hat{\mathbf{x}}_0(\mathbf{x}_t) = \mathbb{E}[\mathbf{x}_0 \mid \mathbf{x}_t]:

  • Tweedie’s identity: The posterior mean of the clean point and the posterior mean of the noise \hat{\boldsymbol\epsilon} = \mathbb{E}[\boldsymbol\epsilon \mid \mathbf{x}_t] determine the score of the marginal density p_t: \nabla_{\mathbf{x}_t} \log p_t(\mathbf{x}_t) = -\frac{\hat{\boldsymbol\epsilon}(\mathbf{x}_t)}{\sigma_t}
  • Affine target equivalence: Since \mathbf{x}_t = \alpha_t \hat{\mathbf{x}}_0 + \sigma_t \hat{\boldsymbol\epsilon}, the clean prediction \hat{\mathbf{x}}_0, noise \hat{\boldsymbol\epsilon}, score \nabla \log p_t, and marginal velocity \mathbf{u}_t = \dot\alpha_t \hat{\mathbf{x}}_0 + \dot\sigma_t \hat{\boldsymbol\epsilon} are affine reparameterizations of one another.
  • Reverse-time integration: A numerical ODE or SDE solver integrates \mathbf{u}_t(\mathbf{x}) from \mathbf{x}_1 \sim \mathcal{N}(\mathbf{0}, \mathbf{I}) down to \mathbf{x}_0.

Translating Time Conventions Across the Literature

Reading Diffusion vs. Flow-Matching Papers

Diffusion papers place clean data at t = 0, whereas many flow-matching papers reverse the clock and place noise at t = 0:

  • Our convention (diffusion standard): Clean data sit at t = 0 (\mathbf{x}_0), pure noise sits at t = 1 (\mathbf{x}_1 = \boldsymbol\epsilon), and generation integrates from t = 1 down to t = 0.
  • Converting flow-matching papers: Replace their time t_{\textrm{FM}} with 1 - t, map their initial noise \mathbf{x}_0^{\textrm{FM}} to \boldsymbol\epsilon and target data \mathbf{x}_1^{\textrm{FM}} to \mathbf{x}_0, and negate every velocity vector (\mathbf{v}_t^{\textrm{FM}} = -\mathbf{u}_{1-t}).
  • Sanity check via log-SNR: Always verify whether a paper’s time t = 0.8 corresponds to high SNR (\lambda > 0, mostly data) or low SNR (\lambda < 0, mostly noise).

Concrete Running Benchmarks Across Chapter 17

Empirical Grounding

Every theoretical claim and architectural choice is tested on controlled benchmarks where exact references or calibrated feature metrics exist:

  • 2D Three-Mode Gaussian Mixture (§17.1–17.3, §17.6, §17.8): Weights (0.5, 0.3, 0.2) and width s = 0.5 where exact density, score, posterior mean, velocity, and entropy (\approx 2.5 nats) are available in closed form.
  • Fashion-MNIST Pixels & Latents (§17.4–17.8): 28 \times 28 images in [-1, 1] and 7 \times 7 \times 4 VAE latents, evaluated by Fréchet distance (FD) against the finite-sample real-vs.-real reference floor.
  • Discrete Token Sequences (§17.9): Quantized 32 \times 32 grid pairs and 784-token binary garments corrupted by token masking [\textrm{M}].

Chapter 17 Roadmap: From Score Matching to Tokens

Study Guide

  • §§17.1–17.3 Core Theory: Denoising score matching, Tweedie’s formula, Gaussian paths (\lambda_t), and reverse ODE/SDE transport (trained MLP matches exact 2D oracle weights within 0.004).
  • §§17.4–17.6 Images, Fast Solvers & Design Space: U-Net + CFG (\approx 90\% class agreement), 20-NFE Heun and multistep solvers, continuous ELBO (w(\lambda) \equiv 1), and EDM preconditioning.
  • §§17.7–17.9 Latents, Few-Step & Discrete Tokens: KL-autoencoders + adaLN-Zero DiT (>10\times fewer FLOPs), two-time flow-map distillation (2 jumps match 15 Euler steps), and absorbing masked diffusion (0.17 bpp).