The third installment. Having built the prerequisites (Part 1) and derived the closed-form forward/noising process (Part 2 — the "route"), we now tackle the reverse/denoising process: how to walk a noisy image backward, one step at a time, into the image we want. In the experienced-driver picture this is the car (车).
Loot from the previous levels
Clearing a level earns rewards you carry into the next. Here's our inventory of known conditions:
① The (human-defined) one-step noising formula: Don't ask why — the driver just picks a reasonable route.
② The closed-form jump from (Part 2's nesting-dolls result):
$$
q(x_t \mid x_0) = \mathcal{N}\big(x_t;\ \sqrt{\bar\alpha_t}, x_0,\ (1-\bar\alpha_t)\mathbf{I}\big)
\ \Longleftrightarrow
x_t = \sqrt{\bar\alpha_t}, x_0 + \sqrt{1-\bar\alpha_t},\varepsilon,\quad \varepsilon \sim \mathcal{N}(\mathbf{0}, \mathbf{I}).
$$
This is the reparameterized form; we'll run it in reverse to read off the underlying Gaussian.
③ The normal PDF, which we'll write in the "expanded exponent" form (this is the form that makes the template-matching trick work): $$ p(x) = \frac{1}{\sqrt{2\pi},\sigma}\exp!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right) = \frac{1}{\sqrt{2\pi},\sigma}\exp!\left[-\frac12\left(\frac{x^2}{\sigma^2} - \frac{2\mu x}{\sigma^2} + \frac{\mu^2}{\sigma^2}\right)\right]. $$
④ and ⑤ — the author's bookkeeping definitions: $$ \bar\alpha_t = \alpha_t,\alpha_{t-1}\cdots\alpha_1 = \prod_{i=1}^{t}\alpha_i, \qquad \alpha_t + \beta_t = 1. $$
Why we need a distribution, not a match
The goal is the reverse direction (reverse = backward in time): given , find . Specifically we want the distribution , then sample from it.
Why a distribution and not a direct mapping? Because this is a generative model — we want to create, including images outside the training set. If we learn a relationship between two distributions, we can sample one point from the prior and generate a corresponding point in the data distribution . A one-to-one sample matching could never work:
- There are infinitely many noise samples — you can't enumerate the pairing.
- Your finite training samples are tiny relative to the space. Sample a fresh noise vector that deviates from anything you've seen, and a match-based scheme produces garbage.
So we build a distribution-to-distribution relationship. That's what lets us generalize. This is a generation task, not a matching task.
Step 1: Bayes' rule to flip time
Look at the known conditions — they all run forward in time (, with ). We know forward; we're asked for reverse. The first instinct: flip time with Bayes' rule.
But this introduces a new problem: and are data distributions we don't know. (If we knew those, we wouldn't need any of this.) Dead end — as written.
Step 2: Add the condition
The fix: condition everything on .
Is adding legitimate? Two reasons it is:
- It makes the problem solvable — every term on the right becomes something we know (below).
- It matches the training setup. In (unconditional) training, our data is a set of original images . We add noise to and ask the model to restore it. The only thing we genuinely have in hand is — so it's exactly the condition we're allowed to add. You can only condition on what you can actually obtain, and we can obtain .
And conditions ① and ② quietly hint that conditioning on is the only way to make the distribution tractable.
The three terms are all known Gaussians
- — by the Markov property only adjacent timesteps interact, so vanishes. This is condition ①.
- — condition ② (at ).
- — condition ② (at ).
Explicitly:
⚠️ Watch the bars. Some terms use (cumulative product) and some use plain . The single most common derivation error is copying where you meant , or dropping a bar. Keep them straight.
Step 3: Plug in the PDFs and collect powers of
Substitute the three Gaussian densities (condition ③). The leading coefficients are constants and can be dropped — they don't affect the resulting mean/variance. (I checked this by carrying them through too; the final and come out identical, which is itself a confirmation that a product/quotient of Gaussians is again Gaussian.)
Multiplying/dividing exponentials just adds/subtracts exponents. The combined exponent is:
We're after a distribution over , so expand and collect by powers of :
Here collects everything independent of . It doesn't affect or — in fact, plugging the final back in reproduces exactly the "completing-the-square" remainder, another sanity check.
Step 4: "Trace the gourd to draw the ladle" (照葫芦画瓢)
Last time the keyword was nesting dolls. This time it's 照葫芦画瓢 — match the template. We line our exponent up against the standard form and read off and .
Variance — from the coefficient
Simplify the numerator using and :
Therefore:
This is the paper's .
Mean — from the coefficient
Matching to the linear coefficient:
Substituting and simplifying:
So the reverse posterior is:
The algebra to get is pure elementary manipulation (no trick) — just keep applying and , and don't miscopy a term. is the previous (known) step and is the original training image, so everything in is available at training time. Without conditioning on , you genuinely could not solve this.
Step 5: From to noise — why DDPM predicts
Here's the catch. needs . At training time we have it. At inference time we don't — we only have a noisy . So we let a model predict it.
Recall from condition ② that . Solve for :
This says and the noise are interchangeable as the unknown. The model has two equivalent options:
- Predict directly, or
- Predict the noise — and recover from the equation above.
DDPM chooses to predict the noise . Knowing gives , which gives , which lets us sample and iterate .
The loss
We want our predicted noise to match the true noise — minimize the gap between two tensors. The natural choices are MSE () or L1; DDPM (and most work) uses MSE. So the training objective collapses to: predict the injected noise accurately,
Interestingly, this same "predict with MSE" target also drops out of the principled route — maximizing the likelihood (the variational bound from Part 1). Think of it as two paths to the same technique: the "forward discipline" (likelihood / loss derivation) and the "reverse discipline" (this posterior derivation). Both land on noise prediction with MSE.
Summary
- Goal: the reverse posterior — but we only know forward conditionals.
- Bayes' rule flips time but introduces unknown data marginals .
- Condition on : . Legitimate because we have at training time, and the Markov property drops from the first term.
- All three terms are known Gaussians; plug in the PDFs, drop constants, and collect powers of .
- Template-match (照葫芦画瓢) against the standard Gaussian exponent to read off:
- At inference is unknown, so the model predicts it — equivalently predicts the noise via — trained with MSE.
That's the car. Next time: the driver — the principled likelihood/loss derivation ("forward discipline"), worked step by step.
Notes taken from a video tutorial on DDPM (Part 3 of the series).
References
- Ho, J., Jain, A., & Abbeel, P. (2020). Denoising Diffusion Probabilistic Models. NeurIPS 2020. arXiv:2006.11239