Gaussian Paths: Diffusion and Flow Matching

Dive into Deep Learning · §17.2

Gaussian Probability Paths: Diffusion and Flow Matching
VP, linear & cosine schedules · log-SNR clock · annealed Langevin ladder · conditional flow matching · target dictionary · loss floors

Why We Need a Continuum of Noise Levels

Motivation

  • High noise (\sigma \gg s) resolves global weights: When Gaussian blur fills the 10\text{--}12 nat valleys between modes, trajectories establish the true 0.5 / 0.3 / 0.2 mode proportions.
  • Low noise (\sigma \ll s) resolves local geometry: As \sigma \to 0, \nabla\log p_\sigma \to \nabla\log p, pulling points tightly into each mode center.
  • Unifying continuous path: Interpolate \mathbf{x}_t = \alpha_t\mathbf{x}_0 + \sigma_t\boldsymbol\epsilon across t \in [0, 1] and train one time-conditioned network across all scales.

Annealed Langevin Dynamics on Exact Scores

Proof of Concept Before Training

Before training any network, we test multi-scale annealing using the exact mixture scores \nabla \log p_{\tilde\sigma} down a geometric ladder of 10 noise levels \tilde\sigma_i \in [3.0, 0.05] (100 steps per level, step size h_i = 0.1\tilde\sigma_i^2):

  • Single fine level (1{,}000 steps at \tilde\sigma = 0.05): Chains stay trapped in their initial modes, returning equal weights \approx [0.33, 0.33, 0.33].
  • Ten annealed levels (10 \times 100 steps): Coarse levels mix across smoothed valleys and fine levels sharpen each mode, recovering [0.50, 0.30, 0.20] within \pm 0.03 and \approx 1.5\% strays.
  • Why move from a ladder to a continuous path: Hand-tuning discrete levels \tilde\sigma_i and step sizes h_i in high dimensions is fragile; a continuous path t \in [0, 1] replaces the ladder with a smooth ODE or SDE.

finest level only: {'weights': [0.339, 0.331, 0.33], 'stray': 0.0145, 'spread': 0.493}
ten levels:        {'weights': [0.496, 0.297, 0.208], 'stray': 0.015, 'spread': 0.516}

Gaussian Probability Paths: VE, VP, and Linear

Forward Interpolation Schedules

While the variance-exploding (VE) path \tilde{\mathbf{x}}_t = \mathbf{x}_0 + \sigma_t\boldsymbol\epsilon lets input norms grow fiftyfold, modern schedules shrink the signal coefficient \alpha_t as noise \sigma_t grows so inputs stay O(1):

\mathbf{x}_t = \alpha_t \mathbf{x}_0 + \sigma_t \boldsymbol\epsilon, \qquad t \in [0, 1]

  • Variance-Preserving (VP / DDPM): Enforces \alpha_t^2 + \sigma_t^2 = 1 via a linear noise rate \beta(t) = 0.1 + 19.9t: \bar\alpha_t = \alpha_t^2 = \exp\!\Big(-\int_0^t \beta(r)\,dr\Big)
  • Linear path (Flow Matching / Rectified Flow): Joins \mathbf{x}_0 to \boldsymbol\epsilon by a straight line at constant speed across t \in [0, 1]: \alpha_t = 1 - t and \sigma_t = t.

The Shared Clock: Log Signal-to-Noise Ratio

Equivalence Across Schedules

\lambda_t = \log\!\left(\frac{\alpha_t^2}{\sigma_t^2}\right), \qquad c\,\mathbf{x}_t = (1 - t_{\textrm{lin}})\,\mathbf{x}_0 + t_{\textrm{lin}}\,\boldsymbol\epsilon

  • Exact rescaling onto the linear path: Dividing \mathbf{x}_t = \alpha_t\mathbf{x}_0 + \sigma_t\boldsymbol\epsilon by \alpha_t + \sigma_t (c = 1/(\alpha_t + \sigma_t)) lands on the linear path at t_{\textrm{lin}} = \sigma_t/(\alpha_t + \sigma_t) with identical log-SNR \lambda_t.
  • Schedule = time reparameterization: All Gaussian paths traverse the exact same family of distributions indexed by \lambda \in (-\infty, +\infty), differing only in clock speed.

Comparing VP, Linear, and Cosine Clocks in Code

Schedule Pacing

Evaluating GaussianPath.vp() and GaussianPath.linear() at t \in \{0.1, 0.5, 0.9\} shows how differently they allocate time across log-SNR:

vp, linear = GaussianPath.vp(), GaussianPath.linear()
t = torch.tensor([0.1, 0.5, 0.9])
r2 = lambda v: [round(u, 2) for u in v.tolist()]
for name, path in (('vp', vp), ('linear', linear)):
    print(f'{name:>6}: alpha {r2(path.alpha(t))} sigma {r2(path.sigma(t))} '
          f'log-SNR {r2(path.log_snr(t))}')
    vp: alpha [0.95, 0.28, 0.02] sigma [0.32, 0.96, 1.0] log-SNR [2.16, -2.46, -8.15]
linear: alpha [0.9, 0.5, 0.1] sigma [0.1, 0.5, 0.9] log-SNR [4.39, 0.0, -4.39]

Why Nichol & Dhariwal (2021) introduced the cosine schedule: The linear-\beta VP path crosses \lambda_t = 0 (equal signal and noise) at t \approx 0.26, spending 74\% of its time where noise dominates. The cosine path \alpha_t \approx \cos(\pi t / 2) spreads log-SNR decay much more evenly across [0, 1].

The DDPM Markov Chain Is the VP Path on a Grid

Discrete-Time Forward Process

Ho et al. (2020) defined DDPM as a T-step Markov chain that shrinks the state by \sqrt{1 - \beta_k} and injects independent Gaussian noise \sqrt{\beta_k}\,\boldsymbol\epsilon_k at each step k = 1, \ldots, T:

\mathbf{x}_k = \sqrt{1 - \beta_k}\,\mathbf{x}_{k-1} + \sqrt{\beta_k}\,\boldsymbol\epsilon_k

  • Closed-form k-step marginal: Because independent Gaussians add in variance, composing k steps telescopes into a single draw from \mathbf{x}_0 with \bar\alpha_k = \prod_{j=1}^k (1 - \beta_j): \mathbf{x}_k = \sqrt{\bar\alpha_k}\,\mathbf{x}_0 + \sqrt{1 - \bar\alpha_k}\,\boldsymbol\epsilon
  • Zero-chain training: Training never simulates k sequential steps—any \mathbf{x}_k is sampled in O(1) from (\mathbf{x}_0, \boldsymbol\epsilon).

beta_1 = 1.1e-04, beta_T = 0.0198, alpha_bar_T = 4.3e-05

Conditional Velocity vs. Marginal Velocity Fields

Flow Matching Formulation

\mathbf{u}_t(\mathbf{x}) = \mathbb{E}\big[\dot\alpha_t \mathbf{x}_0 + \dot\sigma_t \boldsymbol\epsilon \,\big|\, \mathbf{x}_t = \mathbf{x}\big] = \dot\alpha_t \hat{\mathbf{x}}_0(\mathbf{x}) + \dot\sigma_t \hat{\boldsymbol\epsilon}(\mathbf{x})

  • Conditional velocity \dot{\mathbf{x}}_t = \dot\alpha_t\mathbf{x}_0 + \dot\sigma_t\boldsymbol\epsilon: Single-pair velocity (on the linear path: \boldsymbol\epsilon - \mathbf{x}_0); chords from different pairs cross throughout space.
  • Marginal velocity field \mathbf{u}_t(\mathbf{x}): Posterior-averaged velocity of all trajectories passing through (\mathbf{x}, t), defining a single-valued vector field that transports p_t.

Visualizing Conditional vs. Marginal Fields

Geometric Blueprint on the 2D Mixture

On our three-mode mixture, both the single-point conditional path p_t(\mathbf{x} \mid \mathbf{x}_0) and the full marginal velocity field \mathbf{u}_t(\mathbf{x}) can be plotted in closed form:

  • (a) Conditional path: Expanding circles of radius 2\sigma_t centered at \alpha_t\mathbf{x}_0 for a single data point \mathbf{x}_0.
  • (b) Marginal density p_t: As t goes from 0 to 1, the three sharp modes merge into a single unit Gaussian \mathcal{N}(\mathbf{0}, \mathbf{I}).
  • (c) Conditional field -(\mathbf{x} - \mathbf{x}_0)/t: Points straight toward that single training example \mathbf{x}_0.
  • (d) Marginal field -\mathbf{u}_t(\mathbf{x}): Averages over all possible clean points weighted by p(\mathbf{x}_0 \mid \mathbf{x}_t = \mathbf{x}), pointing smoothly into the three modes.

Conditional Flow Matching (CFM) Regression

Training Without the Marginal Field

\mathbb{E}_{t, \mathbf{x}_0, \boldsymbol\epsilon}\big[\|\mathbf{u}_{\boldsymbol\theta}(\mathbf{x}_t, t) - (\dot\alpha_t \mathbf{x}_0 + \dot\sigma_t \boldsymbol\epsilon)\|^2\big] = \mathbb{E}_{t, \mathbf{x}_t}\big[\|\mathbf{u}_{\boldsymbol\theta}(\mathbf{x}_t, t) - \mathbf{u}_t(\mathbf{x}_t)\|^2\big] + C

  • Conditional Flow Matching identity (Lipman et al., 2022): Conditioning on \mathbf{x}_t splits the loss into the marginal field error plus a \boldsymbol\theta-independent variance floor C.
  • Identical gradients: Because \nabla_{\boldsymbol\theta} C = \mathbf{0}, SGD on random pairs (\mathbf{x}_0, \boldsymbol\epsilon) has the exact same expected gradient as regressing onto the unknown oracle \mathbf{u}_t(\mathbf{x}_t).

Training a Velocity Network in Five Lines of Code

Implementation & Convergence

Training TimeMLP(256, 3) on the linear path draws fresh batches of 512 mixture points, uniform times t \sim U(0, 1), and noise \boldsymbol\epsilon \sim \mathcal{N}(\mathbf{0}, \mathbf{I}) for 40{,}000 Adam steps:

  • Per-example target: On the linear path, path.target('velocity', x0, eps, t) is simply eps - x0.
  • Sinusoidal time features: TimeMLP embeds t \in [0, 1] at geometric frequencies from 1 to 64\,\text{rad} so nearby noise levels remain distinct.
  • Why does the loss plateau near 4.9? The training curve drops rapidly and flattens far above zero—not because training stalled, but because of the irreducible variance floor C.

The Target Dictionary: Five Views of One Oracle

Score, Noise, Clean Point, v, and Velocity

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

  • One posterior oracle, five coordinates: Because conditional expectation is linear, the posterior means \hat{\mathbf{x}}_0 = \mathbb{E}[\mathbf{x}_0 \mid \mathbf{x}_t] and \hat{\boldsymbol\epsilon} = \mathbb{E}[\boldsymbol\epsilon \mid \mathbf{x}_t] determine all five targets:
    • Score: \nabla\log p_t(\mathbf{x}_t) = -\hat{\boldsymbol\epsilon}/\sigma_t
    • Angular velocity: \hat{\mathbf{v}} = \alpha_t\hat{\boldsymbol\epsilon} - \sigma_t\hat{\mathbf{x}}_0
    • Marginal velocity: \mathbf{u}_t = \dot\alpha_t\hat{\mathbf{x}}_0 + \dot\sigma_t\hat{\boldsymbol\epsilon}

The Score–Velocity Identity Across Paths

Connecting Score Models and Flow Matching

\mathbf{u}_t(\mathbf{x}) = \frac{\dot\alpha_t}{\alpha_t}\,\mathbf{x} - \Big(\sigma_t\dot\sigma_t - \sigma_t^2\frac{\dot\alpha_t}{\alpha_t}\Big)\nabla_{\mathbf{x}} \log p_t(\mathbf{x})

  • Linear path (\alpha_t = 1 - t, \sigma_t = t): \mathbf{u}_t(\mathbf{x}) = \hat{\boldsymbol\epsilon} - \hat{\mathbf{x}}_0 = -\frac{\mathbf{x} + t\nabla\log p_t(\mathbf{x})}{1 - t}.
  • VP path (\alpha_t^2 + \sigma_t^2 = 1): \mathbf{u}_t(\mathbf{x}) = -\frac{1}{2}\beta(t)\big(\mathbf{x} + \nabla\log p_t(\mathbf{x})\big).
  • Takeaway: Flow-matching velocity networks and score-based diffusion models learn the exact same object in different coordinates.

Verifying the Target Dictionary at a Single Point

Cross-Path Translation in Code

At \mathbf{x} = (0.5, -0.5) on the VP path at t = 0.5 (\alpha_t = 0.28, \sigma_t = 0.96), we query the exact mixture oracle for all five targets and translate the point onto the linear path:

      x0 on vp: [0.29, -0.98]
     eps on vp: [0.44, -0.23]
   score on vp: [-0.46, 0.24]
       v on vp: [-0.15, 0.88]
velocity on vp: [-0.22, 1.29]
velocity on linear at t = 0.773: [0.15, 0.75]  eps_hat - x0_hat: [0.15, 0.75]

Practical Conditioning: Which Target Fits Which Path?

Numerical & Weighting Differences

  • Division-by-zero singularity at pure noise (\alpha_1 = 0): Noise prediction ('eps') reconstructs \hat{\mathbf{x}}_0 = (\mathbf{x}_t - \sigma_t\hat{\boldsymbol\epsilon})/\alpha_t, dividing by \alpha_t \to 0 on schedules reaching exact pure noise (so 'eps' requires VP with \alpha_1 \approx 0.007 > 0).
  • Well-conditioned velocity & \mathbf{v}-prediction: Linear velocity (\hat{\mathbf{x}}_0 = \mathbf{x}_t - t\hat{\mathbf{u}}) and cosine \mathbf{v}-prediction (\hat{\mathbf{x}}_0 = \alpha_t\mathbf{x}_t - \sigma_t\hat{\mathbf{v}}) reconstruct \hat{\mathbf{x}}_0 without dividing by \alpha_t.

DDPM’s Simple Loss vs. Score Matching Weighting

Historical Unification

Every milestone generative diffusion family corresponds to selecting one path, one target from the dictionary, and one time weighting:

Generative Model Family Forward Path Regression Target Relationship to Denoising Score Matching
NCSN (Song & Ermon, 2019) VE (\alpha_t = 1, \tilde\sigma_i) Score -\boldsymbol\epsilon/\tilde\sigma_i Weighted by \tilde\sigma_i^2, making the loss \mathbb{E}\|\tilde\sigma_i\mathbf{s}_{\boldsymbol\theta} + \boldsymbol\epsilon\|^2
DDPM (Ho et al., 2020) VP (\alpha_t^2 + \sigma_t^2 = 1) Noise \boldsymbol\epsilon L_{\textrm{simple}} = \mathbb{E}\|\boldsymbol\epsilon - \boldsymbol\epsilon_{\boldsymbol\theta}(\mathbf{x}_t, t)\|^2 = \mathbb{E}\big[\sigma_t^2\|\mathbf{s}_{\boldsymbol\theta} + \boldsymbol\epsilon/\sigma_t\|^2\big]
\mathbf{v}-Prediction (Salimans & Ho, 2022) Cosine VP (\cos\frac{\pi t}{2}) Angular velocity \mathbf{v} = \alpha_t\boldsymbol\epsilon - \sigma_t\mathbf{x}_0 Equal to (2/\pi)\,\mathbf{u}_t; well-conditioned at \alpha_1 = 0
Flow Matching (Lipman et al., 2022) Linear (1 - t, t) Velocity \boldsymbol\epsilon - \mathbf{x}_0 Equal to \frac{1}{(1-t)^2}\|\hat{\boldsymbol\epsilon} - \boldsymbol\epsilon\|^2; constant speed along straight paths

Analytical Loss Floors Across Targets and Times

Why Training Losses Never Reach Zero

\mathrm{floor}(t) = c_t^2\,\mathbb{E}\big[\operatorname{tr}\mathrm{Cov}[\mathbf{x}_0 \mid \mathbf{x}_t]\big]

  • Every target is c_t\mathbf{x}_0 + f(\mathbf{x}_t) at fixed \mathbf{x}_t: Thus every target’s irreducible loss floor is c_t^2 times the posterior covariance trace.
  • Explaining the 9\times plateau gap (4.91 vs. 0.54): Linear velocity (c_t = -1/t) plateaus at \approx 4.91 while VP noise (c_t = -\alpha_t/\sigma_t) plateaus at \approx 0.54: the targets are scaled by different c_t^2, and the two paths run on different clocks.

Measuring Excess Loss Above the Exact Oracle Floor

Verifying Cross-Path Equivalence

Using 10^6 Monte Carlo draws, we decompose the loss of our trained linear-velocity network (ema_v) and VP-noise network (ema_eps) into the exact oracle floor plus the network’s excess error \mathbb{E}\|\text{net} - \text{oracle}\|^2:

target, path      t=0.1  t=0.5  t=0.9  t~U(0,1)    s.e.  train loss   excess
noise, vp         1.368  0.477  0.002     0.540  0.0011       0.542   0.0002
velocity, linear  2.351  2.796  9.157     4.906  0.0070       4.899   0.0010
velocity net read as a noise model on vp: loss 0.540, excess 0.0002

Both networks learn the exact same posterior mean: Their excess errors over the oracle are \le 0.001 (smaller than Monte Carlo standard error), and querying the linear-path velocity network as a VP noise predictor via eps_from_velocity matches ema_eps to four decimal places (0.540 loss, 0.0002 excess).

Pitfall: Comparing Raw Training Losses Across Targets

Practical Diagnostics

Because the loss floor scales with c_t^2, raw training losses in diffusion and flow matching carry three counterintuitive diagnostic traps:

  • Trap 1: High plateau \neq underfitting: A velocity flow-matching loss plateauing at 4.9 and a DDPM noise loss plateauing at 0.54 are both within 0.001 of the Bayes-optimal oracle.
  • Trap 2: Lower raw loss \neq better model: The 9\times difference between 4.9 and 0.54 comes from the magnification factor c_t^2 (1/t^2 vs. \alpha_t^2/\sigma_t^2) and the different clocks of the two paths. Models trained on different targets or schedules must be compared in a common target unit (such as \mathbb{E}\|\hat{\mathbf{x}}_0 - \mathbf{x}_0\|^2 at matched log-SNR \lambda) or by sample quality.
  • Trap 3: Finite-dataset memorization: The empirical optimum on a small dataset of N points is the exact posterior mean of N Dirac delta masses, which memorizes training examples verbatim (Exercise 17.2.5); neural networks generalize because architectural inductive bias smooths the velocity field across space.

Concept Check: Log-SNR Clock & Target Conversions

Check Your Understanding

Test your mastery of Gaussian probability paths and the target dictionary:

  1. Half-signal, half-noise time (\lambda_t = 0): At what time t \in [0, 1] does signal variance equal noise variance (\alpha_t^2 = \sigma_t^2, so \lambda_t = 0) on the linear path versus the VP path with \log \bar\alpha_t = -(0.1t + 9.95t^2)?
  2. Cross-path rescaling: At t = 0.5, the VP path has \alpha_{0.5} = 0.28 and \sigma_{0.5} = 0.96. Which linear-path time t_{\textrm{lin}} has the same log-SNR, and by what scalar c must a VP point \mathbf{x}_{0.5} be multiplied to land on the linear path?
  3. Endpoint noise floors: On the 2D mixture (d = 2), why does the VP noise-prediction floor approach 2 as t \to 0 and 0 as t \to 1?

Answers:

  1. Linear: 1 - t = t \implies \mathbf{t = 0.50}. VP: \bar\alpha_t = 0.5 \implies 0.1t + 9.95t^2 = \log 2 \approx 0.693 \implies \mathbf{t \approx 0.26} (VP spends 74\% of its time in the noise-dominated regime).
  2. Matched linear time: t_{\textrm{lin}} = \frac{\sigma}{\alpha + \sigma} = \frac{0.96}{0.28 + 0.96} \approx \mathbf{0.773}, with rescaling factor c = \frac{1}{\alpha + \sigma} = \frac{1}{1.24} \approx \mathbf{0.806}.
  3. As t \to 1, \mathbf{x}_t \approx \boldsymbol\epsilon, so \boldsymbol\epsilon is known almost exactly (\text{floor} \to \mathbf{0}). As t \to 0, tiny noise \sigma_t\boldsymbol\epsilon is indistinguishable from within-mode spread, so \hat{\boldsymbol\epsilon} \to \mathbf{0} and \mathbb{E}\|\boldsymbol\epsilon - \mathbf{0}\|^2 = d = \mathbf{2}.

Summary: Gaussian Paths and Equivalent Targets

Key Takeaways

Concept / Path Mathematical Definition Key Property / Invariant Practical Role in Diffusion
Variance-Preserving (VP) \mathbf{x}_t = \sqrt{\bar\alpha_t}\mathbf{x}_0 + \sqrt{1 - \bar\alpha_t}\boldsymbol\epsilon \alpha_t^2 + \sigma_t^2 = 1; discrete DDPM chain on grid Keeps unit-variance inputs at unit variance; \alpha_1 \approx 0.007 > 0
Linear Path (Flow Matching) \mathbf{x}_t = (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon Straight conditional paths; velocity \boldsymbol\epsilon - \mathbf{x}_0 Reaches exact pure noise (\alpha_1 = 0, \sigma_1 = 1) at constant speed
Log-SNR Clock \lambda_t = \log(\alpha_t^2 / \sigma_t^2) Monotone decreasing from +\infty to -\infty Canonical clock aligning all Gaussian paths via c = 1/(\alpha_t + \sigma_t)
Conditional Flow Matching \mathbb{E}\big[\|\mathbf{u}_{\boldsymbol\theta}(\mathbf{x}_t, t) - (\dot\alpha_t\mathbf{x}_0 + \dot\sigma_t\boldsymbol\epsilon)\|^2\big] Equals marginal error \mathbb{E}\|\mathbf{u}_{\boldsymbol\theta} - \mathbf{u}_t\|^2 + C Learns marginal velocity \mathbf{u}_t(\mathbf{x}) from per-example pairs
Target Dictionary \hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon}, \nabla \log p_t, \hat{\mathbf{v}}, \mathbf{u}_t All affine in \mathbf{x}_t and \hat{\mathbf{x}}_0 = \mathbb{E}[\mathbf{x}_0 \mid \mathbf{x}_t] Converts any trained predictor across targets and schedules
Irreducible Loss Floor c_t^2\,\mathbb{E}[\operatorname{tr}\mathrm{Cov}(\mathbf{x}_0 \mid \mathbf{x}_t)] \approx 0.54 (VP noise) vs. \approx 4.9 (linear velocity) Explains high loss plateaus; rank models by excess over floor