The second installment of the zero-barrier DDPM series. Here we derive the forward (noising) process in closed form — how to jump from the original image to any timestep in a single shot, instead of crawling there one noisy step at a time.
The "experienced driver" framing
There's a nice mental model for diffusion models — think of it as an experienced driver (老司机) theory. To master a diffusion model you need to nail down three things:
- The route (路线) — the noising trajectory.
- The car (车) — what's actually moving along it.
- The driver (司机) — who's steering.
We'll derive DDPM from all three angles across the series. This post tackles the route — the noising process. The next two will cover the car and the driver.
The per-step formula the paper just hands you
The paper, somewhat arbitrarily (you could say willfully), defines a single-step noising formula:
A few notes:
- This is defined, not derived — it's a reasonable, human-chosen construction.
- increases with time. Larger ⇒ more noise injected per step ⇒ the noising amplitude grows as grows. Intuitive enough.
Why this formula isn't good enough
The problem: starting from , this formula only lets you reach . To get you apply it again; to reach you apply it times. That's a step-by-step crawl — far too slow.
An experienced driver doesn't drive one step and look around, drive one more, look around again. We want to stand at the start () and jump to wherever we like — straight to , or , or any — in one move. So we need to push this formula further into a closed form.
This derivation is, in my opinion, the easiest of the route/car/driver trio: about 90% elementary math, with exactly one trick.
Setup: two definitions
To simplify the algebra, define:
and the cumulative product:
These are purely for notational convenience — the route designer chose them to make the math cleaner. With , note the per-step formula becomes:
The trick: nesting dolls (套娃)
We want to express in terms of , not . The whole derivation is captured by one idea: nesting dolls (套娃 / matryoshka) — repeatedly substitute the formula into itself until appears.
Since indices above 3 get annoying to write, let's work the example (the general case follows identically). Start:
Substitute (first nesting):
Substitute (second nesting — and finally appears 🎉):
Notice the pattern: the leading coefficients are products of 's, and the trailing terms are a sum of independent noise terms. Call the first term ① and the noise sum ②.
Collapsing term ①
By the definition of the cumulative product:
Clean. The mess is all in ②.
Collapsing term ②: a sum of Gaussians
Each . We need two facts from Part 1's prerequisites:
Scaling a Gaussian. If and we scale by :
Summing independent Gaussians. For two scaled terms:
The means are all zero, so the combined distribution depends only on the sum of the squared coefficients. The squared coefficients in ② are:
Call this sum . So term ② is distributed as .
The one trick: add an auxiliary term
Summing directly is awkward. The trick is to add a helper term and compute instead — because the relation , i.e. , makes everything telescope.
Compute by repeatedly factoring out common terms:
Group the terms (the auxiliary term was added precisely to complete ):
Factor from the first two:
So:
No squaring needed — the coefficients were already the squared values (they sit under the square roots, and variance uses their squares directly).
Term ② in closed form
Therefore term ② follows , and via the reparameterization trick we can write it as a single noise variable:
(We collapse three separate noise draws into one equivalent standard-normal draw.)
Putting it together
Adding ① + ②:
This is the route: from the starting point, jump anywhere you want in one step. Standing at , "eyes on all six roads, ears on all eight directions," we can pin down the whole noised state directly.
Generalizing 3 → T
Why is it legitimate to use just three terms? Because is a finite value. If you had the patience you could write — the pattern is identical (同理可得). So we simply swap the for :
This is exactly the closed-form forward sampling formula in the paper — and the one you actually use in code.
Summary
- DDPM defines an arbitrary one-step noising formula , but stepping one timestep at a time is too slow.
- We want to jump from to any directly. The method is nesting dolls (套娃): substitute the formula into itself, peeling .
- The result splits into a clean mean term and a sum of independent Gaussians.
- Using the Gaussian sum property, that noise sum has mean and variance equal to the sum of squared coefficients .
- The one trick: add the auxiliary term , use to telescope, and find , hence .
- We demonstrated with three terms because is finite; swapping gives the final closed-form:
That completes the route derivation. Next up: the car.
Notes taken from a video tutorial on DDPM (Part 2 of the series).
References
- Ho, J., Jain, A., & Abbeel, P. (2020). Denoising Diffusion Probabilistic Models. NeurIPS 2020. arXiv:2006.11239