DL0104 Score-Based Diffusion

What is the score-based / score-matching interpretation of diffusion models, as used in systems like Stable Diffusion?

Answer

The score-based view says a diffusion model never learns a density; it learns the score, the gradient of the log density s(x) = \nabla_x \log p(x). This is attractive because the gradient annihilates the intractable normalizing constant: if p(x) = e^{-E(x)}/Z then \nabla_x \log p(x) = -\nabla_x E(x) with no Z anywhere, so an unnormalized energy model becomes trainable. Direct score matching still needs the intractable \nabla_x \log p_{\text{data}}(x), and the fix is denoising score matching: perturb the data with a known Gaussian kernel, and the score of the perturbed conditional is available in closed form, which reduces the loss to predicting the noise that was added. Because a single small noise level leaves the score undefined off the data manifold and unreliable in low-density regions, the model is trained over a continuum of noise levels, which turns into the forward SDE of Song et al. and makes sampling the simulation of a reverse-time SDE or its deterministic probability-flow ODE. The punchline is that DDPM’s noise-prediction network is the same object in different clothing: s_\theta(x_t,t) = -\epsilon_\theta(x_t,t)/\sigma_t, so the discrete-time denoising story and the continuous-time score story are two parameterizations of one model.

(1) Model The Gradient, Not The Density: learning \nabla_x \log p(x) removes the partition function, so the network output is an unconstrained vector field of the same shape as the data.
(2) Denoising Score Matching Makes It Tractable: Vincent’s identity shows that regressing onto \nabla_{x_t}\log p(x_t \mid x_0) has the same minimizer as matching the true marginal score, and that target is just the scaled added noise.
(3) Multiple Noise Scales Are Essential: real data lies near a low-dimensional manifold where the score is ill-defined, and large noise levels smooth the density so the vector field is informative everywhere and connects separated modes.
(4) Sampling Is Numerical Integration: annealed Langevin dynamics, the reverse SDE, and the probability-flow ODE all consume only the learned score; the ODE additionally gives exact likelihoods and deterministic, invertible latents.
(5) Unifies VE And VP Diffusions: NCSN’s variance-exploding noise ladder and DDPM’s variance-preserving chain are two discretizations of the same SDE family, differing in f, g, and the loss weighting \lambda_t.

The geometric picture is worth holding onto. The score at a point is the direction of steepest increase in log density, so the learned field points from wherever you are toward nearby high-probability regions, and its magnitude grows as you move into the tails. Sampling then means dropping a Gaussian sample somewhere in space and following that field while injecting just enough noise to keep the chain from collapsing onto a single mode. The reason this needs annealing is that a score trained only at tiny noise is accurate on the data manifold and near-arbitrary far from it, where every initial sample actually starts.

Contour plot of a two-mode density with an overlaid arrow field pointing toward the modes, and a jagged Langevin sampling path starting in the empty lower-left corner and ending inside the left mode

Figure 1: The learned score is a vector field pointing toward high-density regions; a Langevin chain follows it from a random start and ends up distributed according to p(x), never evaluating the density itself.

Mathematical Formulation:
s_\theta(x,t) \approx \nabla_x \log p_t(x)
x_t = \alpha_t x_0 + \sigma_t \epsilon
\nabla_{x_t} \log p(x_t \mid x_0) = -\frac{\epsilon}{\sigma_t}
\mathcal{L}(\theta) = \mathbb{E}\left[ \lambda_t \left\| s_\theta(x_t,t) + \frac{\epsilon}{\sigma_t} \right\|^2 \right]
dx = f(x,t)\,dt + g(t)\,dw
dx = \left[ f - g^2 s_\theta \right] dt + g\,d\bar{w}
dx = \left[ f - \tfrac{1}{2} g^2 s_\theta \right] dt
s_\theta(x_t,t) = -\frac{\epsilon_\theta(x_t,t)}{\sigma_t}

Where:

  • s_\theta(x,t) is the network output, a vector with the same shape as x, approximating the score of the perturbed marginal p_t.
  • x_0 is a clean data point, x_t its noisy version, and \epsilon \sim \mathcal{N}(0,I) the Gaussian draw.
  • \alpha_t and \sigma_t define the noise schedule; variance-preserving keeps \alpha_t^2 + \sigma_t^2 = 1, variance-exploding fixes \alpha_t = 1 and grows \sigma_t.
  • t \in [0,T] indexes the noise level, with p_T essentially pure Gaussian noise; \lambda_t is the loss weighting, and the choice \lambda_t = \sigma_t^2 turns the objective into the plain noise-prediction MSE.
  • f(x,t) is the drift and g(t) the diffusion coefficient of the forward SDE; w is a Wiener process and \bar{w} its reverse-time counterpart, so the second SDE is integrated from t = T down to t = 0.
  • The final line is the reparameterization identity linking the score view to DDPM’s \epsilon_\theta; required initial condition for sampling: x_T \sim \mathcal{N}(0, \sigma_T^2 I) for the VE case.
Three panels showing the same two-mode density smoothed by increasing Gaussian noise, with score arrows that are confined near the modes at small noise and fill the whole plane at large noise

Figure 2: Why a ladder of noise levels is required: at \sigma = 0.05 the score carries no usable signal away from the data, while at \sigma = 1.5 the smoothed field points inward from everywhere and bridges the two modes.

PropertyScore SDE (VE, NCSN)DDPM (VP, noise-pred)Flow matching
Network outputScore, magnitude scales like 1/sigma_tUnit-variance noise estimateVelocity field of a probability path
CorruptionAdd noise, variance grows to data scaleShrink signal, keep total variance at 1Straight interpolation between data and noise
LossWeighted denoising score matchingSame loss with weighting sigma_t squaredRegression onto the conditional velocity
SamplerAnnealed Langevin or predictor-correctorAncestral chain, or DDIM as an ODEODE solver on a near-straight path
Exact likelihoodYes, via the probability-flow ODEOnly an ELBO in discrete timeYes, continuous normalizing flow change of variables

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *