Score Matching and Diffusion Models

Dive into Deep Learning · §38.6

Denoising Score Matching and Score-Based Diffusion Models
Hyvärinen & Vincent theorems · Tweedie’s formula · Langevin mixing · DDPM & DDIM · classifier-free guidance

How Can We Learn a Score Field We Cannot Evaluate?

Motivation

Both generative reverse processes, Anderson’s reverse-time SDE and the probability-flow ODE, require only one unknown quantity: the score \nabla_{\mathbf{x}}\log p_t(\mathbf{x}) of the noised data distribution.

  • Why Maximum Likelihood Stalls on Energy-Based Models: Parameterizing a flexible density p_{\boldsymbol{\theta}}(\mathbf{x}) = \frac{e^{-E_{\boldsymbol{\theta}}(\mathbf{x})}}{Z_{\boldsymbol{\theta}}} requires the normalizing constant Z_{\boldsymbol{\theta}} = \int_{\mathbb{R}^d} e^{-E_{\boldsymbol{\theta}}(\mathbf{x})}\,d\mathbf{x}, which is intractable in high dimensions.
  • Scores Eliminate the Normalizer: Differentiating \log p_{\boldsymbol{\theta}}(\mathbf{x}) with respect to the state \mathbf{x} makes \log Z_{\boldsymbol{\theta}} vanish: \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}) = \nabla_{\mathbf{x}}\log p_{\boldsymbol{\theta}}(\mathbf{x}) = -\nabla_{\mathbf{x}}E_{\boldsymbol{\theta}}(\mathbf{x})
  • The Training Paradox: We want to minimize the Explicit Score Matching (ESM) objective J_{\text{ESM}}(\boldsymbol{\theta}) = \frac{1}{2}\mathbb{E}_{\mathbf{x}\sim p}\big[\|\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}) - \nabla\log p(\mathbf{x})\|^2\big], but we only have n = 4{,}096 data samples \mathbf{x}_i \sim p and cannot evaluate \nabla\log p(\mathbf{x}_i) at even a single point.

Implicit Score Matching: Integration by Parts

Hyvärinen’s Identity (2005)

Expanding the square in J_{\text{ESM}}(\boldsymbol{\theta}) and integrating the cross term -\int \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}) \cdot (\nabla\log p(\mathbf{x}))\,p(\mathbf{x})\,d\mathbf{x} = -\int \mathbf{s}_{\boldsymbol{\theta}} \cdot \nabla p\,d\mathbf{x} by parts moves the derivative off the unknown data density p and onto the network \mathbf{s}_{\boldsymbol{\theta}}:

J_{\text{ESM}}(\boldsymbol{\theta}) = \mathbb{E}_{\mathbf{x} \sim p}\!\left[\frac{1}{2}\|\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})\|^2 + \nabla \cdot \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})\right] + C, \qquad C = \frac{1}{2}\mathbb{E}_p\|\nabla\log p(\mathbf{x})\|^2

  • Geometric Mechanism: Minimizing \nabla \cdot \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}) < 0 creates an inward sink (\nabla\cdot\mathbf{s}_{\boldsymbol{\theta}} negative) at the observed data samples, while the quadratic penalty \frac{1}{2}\|\mathbf{s}_{\boldsymbol{\theta}}\|^2 prevents the sink from growing infinitely steep.
  • The Computational Bottleneck: Evaluating the divergence \nabla \cdot \mathbf{s}_{\boldsymbol{\theta}} = \operatorname{tr}(\partial\mathbf{s}_{\boldsymbol{\theta}}/\partial\mathbf{x}) requires d backward passes per training example (millions of passes per image).

Verifying Implicit Score Matching on a 1D Gaussian

Sanity Check

For data x \sim \mathcal{N}(0, v) and linear score model s_w(x) = -x/w, the implicit objective is J(w) = \mathbb{E}[\frac{1}{2}s_w^2 + s_w'] = \frac{v}{2w^2} - \frac{1}{w}, whose derivative -\frac{v}{w^3} + \frac{1}{w^2} = 0 recovers w = v from samples alone:

implicit score matching picks w = 2.03  (v = 2.0)

The Regression Lemma: Least Squares Fits E[Y | X]

Foundational Identity

For any pair (X, Y) with conditional expectation \mathbf{m}(X) = \mathbb{E}[Y \mid X], the tower rule eliminates the cross term:

\mathbb{E}\!\left[\|\mathbf{v}(X) - Y\|^2\right] = \mathbb{E}\!\left[\|\mathbf{v}(X) - \mathbf{m}(X)\|^2\right] + \mathbb{E}\!\left[\|Y - \mathbf{m}(X)\|^2\right]

  • Trace-free consequence: Regressing \mathbf{v}(X) onto a noisy per-sample target Y has the exact same gradients and minimizer as regressing onto the intractable conditional mean \mathbf{m}(X) = \mathbb{E}[Y \mid X].

Denoising Score Matching and Vincent’s Theorem

Trace-Free Score Learning

Perturb each clean sample \mathbf{x} \sim p with Gaussian noise of scale \sigma: \tilde{\mathbf{x}} = \mathbf{x} + \sigma\boldsymbol{\epsilon} (\boldsymbol{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})), so p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x}) = \mathcal{N}(\tilde{\mathbf{x}}; \mathbf{x}, \sigma^2\mathbf{I}). While the marginal score \nabla\log p_\sigma(\tilde{\mathbf{x}}) is unknown, the conditional score is known in closed form for every training pair:

\nabla_{\tilde{\mathbf{x}}}\log p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x}) = \frac{\mathbf{x} - \tilde{\mathbf{x}}}{\sigma^2} = -\frac{\boldsymbol{\epsilon}}{\sigma}

  • Vincent’s Identity (Marginal Score = Posterior Mean of Conditional Scores): By Bayes’ rule, \mathbb{E}\!\left[\nabla_{\tilde{\mathbf{x}}}\log p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x}) \,\middle|\, \tilde{\mathbf{x}}\right] = \int \frac{\nabla_{\tilde{\mathbf{x}}}p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x})}{p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x})}\frac{p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x})p(\mathbf{x})}{p_\sigma(\tilde{\mathbf{x}})}\,d\mathbf{x} = \frac{\nabla_{\tilde{\mathbf{x}}}\int p_\sigma(\tilde{\mathbf{x}} \mid \mathbf{x})p(\mathbf{x})\,d\mathbf{x}}{p_\sigma(\tilde{\mathbf{x}})} = \nabla_{\tilde{\mathbf{x}}}\log p_\sigma(\tilde{\mathbf{x}})
  • Theorem (Vincent, 2011): By the Regression Lemma, the Denoising Score Matching (DSM) loss J_{\text{DSM}}(\boldsymbol{\theta}) = \frac{1}{2}\mathbb{E}_{\mathbf{x}, \boldsymbol{\epsilon}}\!\left[\left\|\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x} + \sigma\boldsymbol{\epsilon}) + \frac{\boldsymbol{\epsilon}}{\sigma}\right\|^2\right] = \frac{1}{2}\mathbb{E}_{\tilde{\mathbf{x}} \sim p_\sigma}\!\left[\left\|\mathbf{s}_{\boldsymbol{\theta}}(\tilde{\mathbf{x}}) - \nabla\log p_\sigma(\tilde{\mathbf{x}})\right\|^2\right] + C learns \nabla\log p_\sigma by ordinary least squares with zero Jacobian traces.

Tweedie’s Formula and the Non-Zero DSM Loss Floor

Optimal Denoising

Rearranging Vincent’s identity \nabla\log p_\sigma(\tilde{\mathbf{x}}) = \mathbb{E}\!\left[\frac{\mathbf{x} - \tilde{\mathbf{x}}}{\sigma^2} \,\middle|\, \tilde{\mathbf{x}}\right] gives Tweedie’s formula for the MMSE clean-point estimator \hat{\mathbf{x}}_0(\tilde{\mathbf{x}}) = \mathbb{E}[\mathbf{x} \mid \tilde{\mathbf{x}}]:

  • Tweedie’s Formula: \mathbb{E}[\mathbf{x} \mid \tilde{\mathbf{x}}] = \tilde{\mathbf{x}} + \sigma^2\,\nabla_{\tilde{\mathbf{x}}}\log p_\sigma(\tilde{\mathbf{x}})
  • Noise Prediction (\boldsymbol{\epsilon}_{\boldsymbol{\theta}}): Parameterizing \mathbf{s}_{\boldsymbol{\theta}}(\tilde{\mathbf{x}}) = -\boldsymbol{\epsilon}_{\boldsymbol{\theta}}(\tilde{\mathbf{x}})/\sigma makes score matching identical to predicting the added noise \boldsymbol{\epsilon}.
  • Irreducible DSM Loss Floor (2J_{\text{DSM}}^\star): Setting \mathbf{v} = \mathbf{0} in the Regression Lemma gives: \mathbb{E}\!\left[\left\|-\frac{\boldsymbol{\epsilon}}{\sigma} - \nabla\log p_\sigma(\tilde{\mathbf{x}})\right\|^2\right] = \frac{d}{\sigma^2} - \mathbb{E}_{p_\sigma}\|\nabla\log p_\sigma\|^2

Verifying the DSM Floor and Curvature Bound

Gaussian Check & Curvature

For Gaussian data x \sim \mathcal{N}(0, v) with v = 1 and noise \sigma = 0.5, the noised marginal is p_\sigma = \mathcal{N}(0, 1.25), Tweedie’s optimal denoiser shrinks by \frac{v}{v+\sigma^2}\tilde{x} = 0.8\,\tilde{x}, and the irreducible MSE floor is \frac{1}{\sigma^2} - \frac{1}{v+\sigma^2} = 4 - 0.8 = 3.2 > 0:

mean squared error of the conditional mean -xt/1.25: 3.215  (floor 3.2)
least-squares slope of x on xt: 0.801  (0.8)

Curvature Bound of Any Noised Density: Differentiating Tweedie’s formula once more with respect to \tilde{\mathbf{x}} proves: \nabla^2\log p_\sigma(\tilde{\mathbf{x}}) = -\frac{\mathbf{I}}{\sigma^2} + \frac{1}{\sigma^4}\operatorname{Cov}[\mathbf{x} \mid \tilde{\mathbf{x}}] \quad \Longrightarrow \quad -\nabla^2\log p_\sigma(\tilde{\mathbf{x}}) \preceq \frac{1}{\sigma^2}\mathbf{I} No peak of a \sigma-blurred density can ever curve more sharply than the Gaussian kernel \mathcal{N}(\mathbf{0}, \sigma^2\mathbf{I}) that blurred it.

Fitting a Curved Bimodal Score by Least Squares

1D Mixture Experiment

On 4{,}096 draws from p = \frac{1}{2}\mathcal{N}(-2, 0.5^2) + \frac{1}{2}\mathcal{N}(2, 0.5^2) noised four times each at \sigma = 0.5 (16{,}384 pairs), fitting 17 fixed basis functions by np.linalg.lstsq against y = -\epsilon/\sigma recovers the exact score 4\tanh(4\tilde{x}) - 2\tilde{x}:

mean squared error: fit 2.08, exact score 2.07, population floor 2.11
excess risk 0.009; fit at x = 8: -4.7, exact score -12 (no pairs there)

Fitting a Curved Bimodal Score by Least Squares (cont.)

1D Mixture Experiment

Although the cloud of targets -\epsilon/\sigma scatters vertically with variance \approx 2.11 (the population floor), its conditional mean is the exact score curve, and the least-squares fit achieves an excess risk of only 0.01.

Extrapolation Hazard Where No Training Pairs Land

Out-of-Support Variance

Repeating the least-squares fit across 20 independent draws of data and noise reveals a fundamental limitation of single-level score matching:

exact score over 20 draws: mean squared error 2.11, sd 0.037
fit at x = 1 over 20 draws: from +1.8 to +2.1 (exact score +2.0)
fit at x = 8 over 20 draws: from -15.6 to +17.1 (exact score -12.0)
  • Accurate Inside the Support (x = 1): Where noisy pairs are plentiful, all 20 fits stay within \pm 0.2 of the true score +2.0.
  • Arbitrary in the Far Tails (x = 8): Because no training pair lands beyond |\tilde{x}| \approx 5, the regression loss exercises zero control at x = 8—the fitted score swings wildly across tens of units and even flips sign (pointing away from the data).

Sampling With One Score: Langevin Dynamics

MCMC via the Score

Given a score field \nabla\log p(\mathbf{x}) at a single noise level, Langevin dynamics climbs the log-density while injecting unit Brownian noise to prevent collapse onto a mode:

d\mathbf{X}_t = \frac{1}{2}\nabla\log p(\mathbf{X}_t)\,dt + d\mathbf{W}_t \;\xrightarrow{\text{Euler–Maruyama, step } h}\; \mathbf{x}_{k+1} = \mathbf{x}_k + \frac{h}{2}\mathbf{s}(\mathbf{x}_k) + \sqrt{h}\,\boldsymbol{\xi}_k

  • Proposition (p Is the Stationary Distribution): Substituting drift \mathbf{b} = \frac{1}{2}\nabla\log p, unit diffusion g = 1, and q_t = p into the Fokker–Planck equation gives: \partial_t q_t = -\nabla \cdot \left(\frac{1}{2}p\,\nabla\log p\right) + \frac{1}{2}\Delta p = -\frac{1}{2}\nabla\cdot(\nabla p) + \frac{1}{2}\Delta p = 0
  • Step-Size Variance Bias: On p = \mathcal{N}(0, v), the discrete recursion x_{k+1} = (1 - \frac{h}{2v})x_k + \sqrt{h}\xi_k has stationary variance V = \frac{v}{1 - h/(4v)} \approx v + \frac{h}{4}, overstating the true variance by O(h).

Why Single-Level Langevin Fails on Multimodal Data

The Mode-Mixing Bottleneck

What happens when we run 10{,}000 Langevin chains for 2{,}000 steps (h = 0.01) using the exact score of the lopsided mixture p = 0.8\,\mathcal{N}(-2, 0.5^2) + 0.2\,\mathcal{N}(2, 0.5^2)?

broad start: P(X > 0) = 0.484, E[X^2] = 4.20  (truth 0.2, 4.25)
all chains at -2 (weight 0.8): 0.006 end on the other side
all chains at +2 (weight 0.2): 0.025 end on the other side
  • Exponential Valley Trapping: Crossing the low-density valley around x = 0 against the restoring pull requires an exponentially rare sequence of noise kicks (0.5\% transition rate out of the heavy mode, 2.5\% out of the light mode; mixing relaxation takes \sim 67{,}000 steps).
  • Wrong Mode Proportions (0.48 vs. 0.20): Chains started from symmetric \mathcal{N}(0, 3^2) simply slide into the nearest mode and stay trapped, preserving the 50/50 proportions of the initialization instead of the 80/20 data weights.

How Multi-Scale Noise Solves All Three Failures

Noise-Conditional Score Matching

Training a single time-conditioned score network \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) across a continuum of Gaussian noising levels \mathbf{x}_t = \alpha_t\mathbf{x}_0 + \sigma_t\boldsymbol{\epsilon} cures all three defects of single-level score matching:

  1. No Empty Regions at High Noise: At large \sigma_t, the noised density fills the entire space where the sampler starts.
  2. No Valley Barrier (\sigma \ge 1.94): Once component variance 0.25 + \sigma^2 \ge \mu^2 = 4, the bimodal valley disappears into a single unimodal bell curve.
  3. Correct Mode Proportions: As noise decreases during reverse sampling, the score’s watershed at intermediate \sigma_t allocates particles in exact proportion to the mixture weights (0.8, 0.2).

The Noise-Conditional DSM Loss and Level Weightings

Training Across All Levels

Averaging the DSM loss over noise levels t \sim \mathcal{U}[\varepsilon, T] with weight schedule w(t) > 0:

\mathcal{L}(\boldsymbol{\theta}) = \frac{1}{2}\mathbb{E}_{t}\!\left[w(t)\,\mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}}\!\left[\left\|\mathbf{s}_{\boldsymbol{\theta}}(\alpha_t\mathbf{x}_0 + \sigma_t\boldsymbol{\epsilon}, t) + \frac{\boldsymbol{\epsilon}}{\sigma_t}\right\|^2\right]\right]

  • Three weight schedules: Unweighted w(t) = 1 explodes as d/\sigma_t^2; DDPM Simple w(t) = \sigma_t^2 equalizes the floor to d = O(1) across all levels (\tfrac12\|\boldsymbol{\epsilon} - \boldsymbol{\epsilon}_{\boldsymbol{\theta}}\|^2); Likelihood w(t) = g(t)^2 bounds reverse-SDE KL.

DDPM Is the Variance-Preserving SDE in Discrete Time

Connecting Discrete & Continuous

The Denoising Diffusion Probabilistic Model (DDPM) runs an N = 1000-step Markov chain with schedule \beta_1, \ldots, \beta_N \in [10^{-4}, 0.02]:

\mathbf{x}_t = \sqrt{1 - \beta_t}\,\mathbf{x}_{t-1} + \sqrt{\beta_t}\,\boldsymbol{\epsilon}_t \quad \Longrightarrow \quad \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\,\mathbf{x}_0 + \sqrt{1 - \bar{\alpha}_t}\,\boldsymbol{\epsilon}, \qquad \bar{\alpha}_t = \prod_{s=1}^t (1 - \beta_s)

alpha_bar at t = 10, 100, 1000: 0.998, 0.897, 4e-05; sigma_bar from 0.01 to 157
  • Exact VP-SDE Transition: Each DDPM step is an exact transition of the VP-SDE d\mathbf{X} = -\frac{1}{2}\beta(s)\mathbf{X}\,ds + \sqrt{\beta(s)}\,d\mathbf{W} over an interval with \int \beta(s)\,ds = -\log(1 - \beta_t) \approx \beta_t.
  • Jump to Any Level in One Draw: Training never simulates the 1,000-step chain—it samples \mathbf{x}_t directly from \mathbf{x}_0 in O(1) time as noise-to-signal \bar{\sigma}_t = \sqrt{(1-\bar{\alpha}_t)/\bar{\alpha}_t} grows from 0.01 to 157.

DDPM Simple Loss and Ancestral Reverse-SDE Sampler

Noise Prediction & Sampling

Parameterizing the score model via a noise-prediction network \mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) = -\boldsymbol{\epsilon}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) / \sigma_t (\sigma_t = \sqrt{1 - \bar{\alpha}_t}) unifies DDPM training and sampling with score-based SDEs:

  • DDPM “Predict the Noise” Loss: Substituting \mathbf{s}_{\boldsymbol{\theta}} = -\boldsymbol{\epsilon}_{\boldsymbol{\theta}}/\sigma_t into the noise-conditional DSM loss with weight w(t) = \sigma_t^2 = 1 - \bar{\alpha}_t cancels the 1/\sigma_t^2 factor: \frac{1}{2}\sigma_t^2\left\|\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) + \frac{\boldsymbol{\epsilon}}{\sigma_t}\right\|^2 = \frac{1}{2}\left\|\boldsymbol{\epsilon} - \boldsymbol{\epsilon}_{\boldsymbol{\theta}}(\mathbf{x}_t, t)\right\|^2
  • Ancestral Sampling as Reverse Euler–Maruyama: Stepping from t = N down to 1 via \mathbf{x}_{t-1} = \frac{\mathbf{x}_t + \beta_t\,\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t)}{\sqrt{1 - \beta_t}} + \sqrt{\beta_t}\,\boldsymbol{\xi}_t \approx \mathbf{x}_t + \left(\frac{1}{2}\beta_t\mathbf{x}_t + \beta_t\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t)\right) + \sqrt{\beta_t}\,\boldsymbol{\xi}_t is to first order in \beta_t the Euler–Maruyama discretization of Anderson’s reverse VP-SDE (1{,}000 network evaluations per generated sample).

DDIM: Fast Deterministic Sampling as Forward Euler

Skipping Levels via the PF-ODE

DDIM predicts \hat{\mathbf{x}}_0 = (\mathbf{x}_t - \sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}_{\boldsymbol{\theta}})/\sqrt{\bar{\alpha}_t} and jumps directly to an earlier level t' < t. In rescaled coordinates \bar{\mathbf{x}}_t = \mathbf{x}_t/\sqrt{\bar{\alpha}_t} and \bar{\sigma}_t = \sqrt{(1-\bar{\alpha}_t)/\bar{\alpha}_t}:

\bar{\mathbf{x}}_{t'} = \bar{\mathbf{x}}_t + (\bar{\sigma}_{t'} - \bar{\sigma}_t)\,\boldsymbol{\epsilon}_{\boldsymbol{\theta}}(\mathbf{x}_t, t)

  • Exact forward-Euler step: DDIM is 1st-order forward Euler on the VP probability-flow ODE \frac{d\bar{\mathbf{x}}}{d\bar{\sigma}} = \mathbb{E}[\boldsymbol{\epsilon} \mid \mathbf{x}_t], enabling 20–50 deterministic strides.

DDIM Stride Error: Point Masses vs. Gaussian Shrinkage

Analyzing DDIM Truncation Error

Because DDIM is a first-order Euler solver in the \bar{\sigma} clock, its stride error depends on how much \hat{\boldsymbol{\epsilon}}(\mathbf{x}_t, t) = \mathbb{E}[\boldsymbol{\epsilon} \mid \mathbf{x}_t] curves along the probability-flow trajectory:

  • Exact on a Single Point Mass: When p_0 = \delta_{\mathbf{x}_0}, \hat{\boldsymbol{\epsilon}} = (\bar{\mathbf{x}} - \mathbf{x}_0)/\bar{\sigma} is constant along the exact ray, so one DDIM stride of any length is exact.
  • Contractive on \mathcal{N}(\mathbf{0}, \mathbf{I}) Data: The exact flow is the identity, but holding \hat{\boldsymbol{\epsilon}} = \sqrt{1-\bar{\alpha}_t}\mathbf{x}_t fixed across a stride shrinks every sample by: \sqrt{\bar{\alpha}_t\bar{\alpha}_{t'}} + \sqrt{(1-\bar{\alpha}_t)(1-\bar{\alpha}_{t'})} = \cos(\phi_t - \phi_{t'}) < 1 where \bar{\alpha}_t = \cos^2\phi_t (0.832\times over 10 strides, 0.964\times over 50 strides).

Measuring DDIM Stride Contraction and Convergence

10 vs. 50 vs. 1,000 Strides

Comparing 10, 50, and 1,000 equally spaced DDIM strides with the exact noise prediction \hat{\epsilon} = -\sqrt{1-\bar{\alpha}_t}\nabla\log p_t on \mathcal{N}(0, 1) data and on the standardized bimodal mixture:

N(0,1) data,   10 strides: every sample times 0.832
N(0,1) data,   50 strides: every sample times 0.964
N(0,1) data, 1000 strides: every sample times 0.998
mixture,  10 strides vs 1000: mean |gap| 0.083, KS 0.077
mixture,  50 strides vs 1000: mean |gap| 0.015, KS 0.016
  • First-Order Euler Convergence: Increasing from 10 to 50 strides (5\times finer step) cuts the Gaussian shrinkage error by 4.7\times (1 - 0.832 = 0.168 \to 1 - 0.964 = 0.036) and cuts the mixture endpoint gap from 0.080 to 0.017.

DDIM on Least-Squares Scores Recovers Mode Weights

End-to-End Multi-Level Learning

Fitting our 17-feature linear model by ridge least squares at each of the 50 noise levels visited by a 50-stride DDIM sampler on the lopsided 0.8 / 0.2 mixture:

exact  scores: light mode 0.195, means -0.96 +0.94, widths 0.228 0.244, KS to p0 0.03
fitted scores: light mode 0.202, means -0.97 +0.94, widths 0.226 0.274, KS to p0 0.02
truth: light mode 0.2, means -0.97 +0.97, widths 0.243; KS between the clouds 0.02

Multi-Level Regression Solves Mode Weighting: Where single-level Langevin with the exact score left 48\% of samples in the light mode, 50-stride DDIM on least-squares fitted scores recovers the true 20\% light-mode mass (0.197) and matches the exact-score DDIM trajectory to \text{KS} = 0.02.

Classifier and Classifier-Free Guidance via Bayes’ Rule

Conditional Steering

By Bayes’ rule, \nabla\log p_t(y \mid \mathbf{x}) = \mathbf{s}_y - \mathbf{s}_\varnothing. Classifier-Free Guidance (CFG) amplifies this class difference by guidance scale \gamma \ge 1:

\tilde{\mathbf{s}}_{\boldsymbol{\theta}}(\mathbf{x}, t, y) = \mathbf{s}_\varnothing + \gamma\big(\mathbf{s}_y - \mathbf{s}_\varnothing\big) = (1 - \gamma)\mathbf{s}_\varnothing + \gamma\mathbf{s}_y

  • Broken curvature bound (\gamma > 1): Once \gamma is large, -\nabla^2\log\tilde{p}_t exceeds the universal 1/\sigma_t^2 bound of any true noised density, sharpening and shifting the terminal mode outward.

Measuring Mode Shift Under High Guidance Scales

Guidance Experiment

Running the 1,000-step ancestral reverse chain toward the right mode (y = \mathcal{N}(+0.970, 0.243^2)) across guidance scales \gamma \in \{1, 3, 10\}:

gamma =  1.0: mass right of 0 1.000, mean 0.969, std 0.247
gamma =  3.0: mass right of 0 1.000, mean 1.031, std 0.231
gamma = 10.0: mass right of 0 1.000, mean 1.077, std 0.233
exact conditional: mean 0.970, std 0.243

At \gamma = 1 (exact Bayes’ rule), the chain recovers the exact class mean 0.970 and standard deviation 0.243. At \gamma = 3 and \gamma = 10, linear extrapolation pushes samples away from the opposing left mode, shifting the terminal mean outward to 1.03 and 1.08.

Concept Check: Score Matching, DDIM, and Guidance

Concept Check

Test your understanding of score matching and diffusion samplers:

  1. Non-Zero DSM Loss: You train a high-capacity score network on d = 100-dimensional data at noise level \sigma = 0.1, and the DSM loss 2J_{\text{DSM}} plateaus near 9{,}800. Does this large loss indicate underfitting?
  2. Tweedie’s Denoiser: Given a noisy observation \tilde{\mathbf{x}} at noise scale \sigma = 0.5 where the learned score evaluates to \mathbf{s}_{\boldsymbol{\theta}}(\tilde{\mathbf{x}}) = (+4, -2), what is the MMSE estimate \hat{\mathbf{x}}_0 = \mathbb{E}[\mathbf{x}_0 \mid \tilde{\mathbf{x}}]?
  3. CFG Linear Combination: In Classifier-Free Guidance with scale \gamma = 7.5, what weights are placed on the conditional score \mathbf{s}_y and the unconditional score \mathbf{s}_\varnothing?

Answers:

  1. No. By the Regression Lemma, the irreducible Bayes-risk floor is \frac{d}{\sigma^2} - \mathbb{E}\|\nabla\log p_\sigma\|^2 = \frac{100}{0.01} - \mathbb{E}\|\nabla\log p_\sigma\|^2 = 10{,}000 - \mathbb{E}\|\nabla\log p_\sigma\|^2. A loss of 9{,}800 can be a globally optimal fit.
  2. By Tweedie’s formula, \hat{\mathbf{x}}_0 = \tilde{\mathbf{x}} + \sigma^2 \mathbf{s}_{\boldsymbol{\theta}}(\tilde{\mathbf{x}}) = \tilde{\mathbf{x}} + 0.25\,(4, -2) = \tilde{\mathbf{x}} + (1, -0.5).
  3. \tilde{\mathbf{s}} = (1 - \gamma)\mathbf{s}_\varnothing + \gamma\mathbf{s}_y = -6.5\,\mathbf{s}_\varnothing + 7.5\,\mathbf{s}_y (a linear extrapolation beyond \mathbf{s}_y away from \mathbf{s}_\varnothing).

Summary: Score Matching and Diffusion Samplers

Key Takeaways

Method / Theorem Mathematical Formula Role & Practical Characteristics
Hyvärinen’s Identity (ISM) \mathbb{E}_p\big[\frac{1}{2}\|\mathbf{s}_{\boldsymbol{\theta}}\|^2 + \nabla\cdot\mathbf{s}_{\boldsymbol{\theta}}\big] + C Removes unknown \nabla\log p, but costs O(d) backward passes for \nabla\cdot\mathbf{s}_{\boldsymbol{\theta}}
Vincent’s Theorem (DSM) \frac{1}{2}\mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}}\big\|\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) + \boldsymbol{\epsilon}/\sigma_t\big\|^2 Trace-free regression onto -\boldsymbol{\epsilon}/\sigma_t; optimal floor is \frac{d}{\sigma_t^2} - \mathbb{E}\|\nabla\log p_t\|^2
Tweedie’s Formula \mathbb{E}[\mathbf{x}_0 \mid \tilde{\mathbf{x}}] = \tilde{\mathbf{x}} + \sigma^2\nabla\log p_\sigma(\tilde{\mathbf{x}}) Converts any score or noise predictor into the MMSE clean-point denoiser
DDPM Forward & Loss \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}, w(t) = \sigma_t^2 Exact discrete VP-SDE transitions; \sigma_t^2 weight cancels the 1/\sigma_t^2 floor
DDIM Deterministic Stride \bar{\mathbf{x}}_{t'} = \bar{\mathbf{x}}_t + (\bar{\sigma}_{t'} - \bar{\sigma}_t)\boldsymbol{\epsilon}_{\boldsymbol{\theta}}(\mathbf{x}_t, t) Forward Euler on the VP probability-flow ODE in (\bar{\sigma}, \bar{\mathbf{x}}) coordinates
Classifier-Free Guidance \tilde{\mathbf{s}} = (1 - \gamma)\mathbf{s}_\varnothing + \gamma\mathbf{s}_y Amplifies class direction via Bayes’ rule; \gamma > 1 breaks the 1/\sigma_t^2 curvature bound