Score Matching and the SDE View: DDPM as One Discretisation Among Many
Published:
Why the score, and not the density
Fitting a density means dealing with \(p_\theta(\mathbf{x}) = \tilde{p}_\theta(\mathbf{x})/Z_\theta\), and the partition function \(Z_\theta = \int \tilde{p}_\theta\) is an intractable integral over pixel space. The score sidesteps it entirely, because \(Z_\theta\) does not depend on \(\mathbf{x}\):
The score is a vector field pointing towards higher density — locally, the direction in which the image becomes more plausible. Knowing it everywhere is enough to sample, via Langevin dynamics:
Gradient ascent on log-density, with injected noise that stops the chain from collapsing onto a mode; as \(\delta\to0\) and \(k\to\infty\) the iterates are distributed according to \(p\).
Run naively this fails badly. Real data sits near a low-dimensional manifold, so \(\nabla\log p\) is undefined off it and the estimate is unreliable anywhere the training data was sparse — which is almost everywhere the chain starts. Song & Ermon’s fix was to estimate the score of noised versions of the data at many noise levels, and anneal from high noise to low. That is the same annealing structure as diffusion, arrived at from the other direction.
The identity that connects the two views
Score matching in its plain form needs \(\nabla\log p\) of the data, which we do not have. Denoising score matching replaces it with the score of a known perturbation kernel. For the diffusion kernel \(q(\mathbf{x}_t\mid\mathbf{x}_0) = \mathcal{N}(\sqrt{\bar{\alpha}_t}\mathbf{x}_0,\,(1-\bar{\alpha}_t)\mathbf{I})\), that score is available in closed form:
using \(\mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0+\sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}\) from the forward process. Vincent’s theorem says that minimising \(\mathbb{E}\lVert s_\theta(\mathbf{x}_t) - \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)\rVert^2\) over \(\mathbf{x}_0\) as well as \(\mathbf{x}_t\) yields the score of the marginal, because a squared-error minimiser is a conditional expectation: \(s_\theta^\star(\mathbf{x}_t) = \mathbb{E}\big[\nabla\log q(\mathbf{x}_t\mid\mathbf{x}_0)\ \big\vert\ \mathbf{x}_t\big] = \nabla_{\mathbf{x}_t}\log p_t(\mathbf{x}_t)\).
The DDPM objective is exactly this minimisation, in different units: \(\boldsymbol{\epsilon}_\theta^\star(\mathbf{x}_t,t) = \mathbb{E}[\boldsymbol{\epsilon}\mid\mathbf{x}_t]\). Dividing by the constant \(-\sqrt{1-\bar{\alpha}_t}\) gives
Not an analogy, an equality: a trained DDPM is a score network with a per-timestep rescaling folded into the loss weighting.
Taking the step size to zero
Write \(\beta_i = \beta(t)\Delta t\) with \(\Delta t = 1/N\) and expand \(\sqrt{1-\beta_i}\approx 1-\beta_i/2\). The forward update \(\mathbf{x}_i = \sqrt{1-\beta_i}\mathbf{x}_{i-1}+\sqrt{\beta_i}\mathbf{z}\) becomes \(\mathbf{x}_i - \mathbf{x}_{i-1} \approx -\tfrac12\beta(t)\Delta t\,\mathbf{x}_{i-1} + \sqrt{\beta(t)\Delta t}\,\mathbf{z}\), which is the Euler–Maruyama discretisation of
Variance preserving because the drift’s contraction exactly cancels the injected noise, holding the marginal variance at 1 — the continuous statement of why the shrink factor is needed. DDPM’s linear schedule with \(T=1000\) corresponds to \(\beta(t) = 0.1 + t(20-0.1)\) for \(t\in[0,1]\), since \(1000\times10^{-4}=0.1\) and \(1000\times0.02=20\).
The VE-SDE has no drift at all: \(\mathbf{x}_t = \mathbf{x}_0 + \sigma(t)\mathbf{z}\), with \(\sigma\) growing geometrically over several orders of magnitude. This is the continuous limit of Song & Ermon’s noise-conditional score networks, and it is where the two lineages meet — the same reverse-time machinery covers both.
Reversing time, and the ODE hiding inside
Anderson’s 1982 result gives the reverse-time process of any diffusion in closed form, and the only unknown in it is the score:
Substituting our estimator makes this simulable, and the DDPM sampler is one particular discretisation of it. But there is a second object with the same marginals — the probability-flow ODE, obtained by halving the score coefficient and deleting the noise:
The distributions \(p_t\) match those of the SDE at every \(t\); only the individual trajectories differ. Three things follow. Sampling becomes deterministic, so a latent \(\mathbf{x}_T\) names one image and the map is invertible — the property DDIM exploits. Any black-box ODE solver applies, so adaptive higher-order methods can cut the step count. And because it is a continuous normalising flow, the instantaneous change-of-variables formula gives the exact likelihood, up to the divergence estimate:
with the divergence estimated by Hutchinson’s trace trick. Unlike the ELBO this is not a bound.
References
- Hyvärinen, A. Estimation of Non-Normalized Statistical Models by Score Matching. JMLR 2005.
- Vincent, P. A Connection Between Score Matching and Denoising Autoencoders. Neural Computation, 23(7), 2011.
- Song, Y., & Ermon, S. Generative Modeling by Estimating Gradients of the Data Distribution. NeurIPS 2019.
- Song, Y., Sohl-Dickstein, J., Kingma, D. P., Kumar, A., Ermon, S., & Poole, B. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021.
- Anderson, B. D. O. Reverse-Time Diffusion Equation Models. Stochastic Processes and their Applications, 12(3), 1982.
