The Mathematics of Diffusion — Generation Seen Through Scores and SDEs
A layer beneath 'add noise, then subtract it': diffusion models restated in the language of the score, the gradient of log-density. Why denoising and score estimation are literally the same job, what the forward SDE, reverse SDE and probability flow ODE actually assert, and how those equations turn into the knobs you set at inference time.
Generative Modeling by Estimating Gradients of the Data Distribution
Primary source — what this article is built on
undefined2026-08-27
Generative Modeling by Estimating Gradients of the Data DistributionarXiv:1907.05600Paper page·PDFScore-Based Generative Modeling through Stochastic Differential EquationsarXiv:2011.13456Paper page·PDF
Elucidating the Design Space of Diffusion-Based Generative ModelsarXiv:2206.00364Paper page·PDF
Forget the altitude, remember the slope
Suppose you are somewhere in the mountains at night with no map and no GPS, trying to reach the summit. You have no way of knowing your altitude in metres. You can still climb, because knowing the slope under your feet is enough: step toward whichever direction goes up, repeat.
Generative modelling is in exactly that position. Try to learn the probability density of "plausible images" directly, and a normalising constant always gets in the way. Write the model as an energy function and the density looks like this:
is the number you divide by so that everything sums to one, and the integral runs over every image there could be. For a colour image that is an integral over roughly 200,000 dimensions. Nobody can compute it.
But take the logarithm of both sides and then differentiate with respect to , and vanishes — it does not depend on at all.
This is the score. The name is borrowed from the score function of classical statistics (the gradient of the log-likelihood), but the diffusion version differentiates with respect to the data rather than the parameters. In words: means "differentiate along every component of and stack the results", so the score has exactly the same shape as its input. For an image, picture a field of arrows with one arrow per pixel, each saying nudge me this way and the picture becomes slightly more plausible. You give up on knowing the altitude and settle for knowing the slope.
The overall machinery of diffusion — the forward process that adds noise and the reverse process that removes it — is covered in Diffusion Models from the Ground Up. This article goes one layer beneath it and asks why that procedure is correct at all, in the language of scores.
Turning a slope into samples
Suppose you had the score. The recipe for extracting samples from it is Langevin dynamics, and it is one line:
Here is the step size and is a fresh standard normal draw each iteration. In words: take half a step toward higher density, then stagger by however much the dice say, over and over. Make small enough and run long enough, and the distribution of approaches .
That second term is not decoration. Remove it and you are left with plain gradient ascent, which parks itself on the single most probable point and stops. That finds the mode; it does not draw from the distribution. The noise is what keeps the walker wandering the slope, lingering long where density is high and briefly where it is low — and that ratio of dwelling times is the probability.
A concrete case makes it tangible. For we have , so differentiating gives
which says the score is a spring pulling back toward the origin: the further out you are the harder the pull, and the tighter the distribution (small ) the stiffer the spring. So Langevin dynamics on a Gaussian is precisely a ball rolling in a parabolic valley with a random shove added at every step. And what happens when you crank the step size up is exactly what happens to that ball.
Why "denoising" and "score estimation" are the same job
There is an obvious problem. Nowhere do we have ground-truth labels for the score. If we knew the true , we would not need a generative model in the first place.
Plain score matching (Hyvärinen, 2005) solves this on paper. Integration by parts eliminates the unknown from the objective, leaving you to minimise the expectation of . The theory is airtight, but that second term is the trace of a Jacobian, which costs one backward pass per dimension. On a 200,000-dimensional image it is a non-starter.
The way through was to deliberately corrupt the data. We do not know the distribution of clean data, but the conditional distribution after adding Gaussian noise is something we built ourselves, so we know it exactly. Corrupt with where , and — whose score is the spring we just derived:
Comments
Sign in to comment