Week 14 — Diffusion, reversal and thermodynamics
A decoder generates a sequence by selecting one token at a time. A diffusion model uses another construction: corrupt a complete observation with known noise, then learn a sequence of reverse transitions that can generate a new observation from noise. We will see why adding noise is easy and why reversing it requires knowledge of the data distribution.
Course: nn-llm-syllabus. Authorship and supervision: ai-authorship.
Learning goals and reading route
Compute a noisy observation at any level, distinguish a conditional from a marginal distribution, derive the noise-prediction target and its relation to the score, and check a reverse equation on a Gaussian example.
The two-hour lecture follows §§1–2, 4–6 below. Section 3, containing the posterior and variational bound, is independent study, as in Chapter 5 of the companion notes. The thermal work identity in §6 provides a specified comparison; it is not an extra assumption about every trained sampler. Primary references are Sohl-Dickstein, Ho, Song and Jarzynski in nn-llm-bibliography. Only Gaussian probability and the relative entropy of Week 1 are required for the entry calculation.
1. Add noise while controlling the signal
Let be a clean observation drawn from the data distribution . Choose a noise schedule, meaning fixed numbers , and set , . A forward step is
with independent noises. We use for this schedule, reserving for inverse-temperature or softmax parameters elsewhere in the course. Here is retained signal per step, not the load of Unit 1. For fixed , recursively substituting earlier steps adds independent Gaussians. The means multiply and the variances add, giving
This is a conditional distribution given the clean observation. It lets us sample at level directly, using one new standard Gaussian .
Example. For a scalar and , the first conditional mean and variance are and . At the second step they are and : the variance is , while the retained signal is .
If is itself random, the marginal distribution is
It is generally an unknown mixture of Gaussians, not a single Gaussian. Knowing the forward kernel does not mean knowing the data marginal.
Why a Gaussian starting point for generation can work
At fixed , the terminal divergence from a standard normal is explicit:
Convexity of relative entropy in its first argument gives
If the data have finite second moment, the bound tends to zero as . The conditional Gaussian formula and this mixture bound are different steps. Replacing the actual terminal marginal by a standard normal is an approximation at finite retained signal.
2. Reverse a transition, not a recorded noise sample
Bayes’ rule gives
We chose the forward kernel, but the marginals depend on the unknown data law. A noisy value near zero, for example, can arise from either of two groups of clean observations. The reverse conditional can then have several modes, even though every forward kernel was Gaussian. Negating the sampled noise would undo a particular known realization; it would not generate the correct reverse conditional from alone.
The physical intuition is the usual inverse problem for a diffusion: many initial possibilities contribute to one noisy observation. The reverse rule must weight those possibilities using their prior occurrence in the data.
3. Independent study: a tractable posterior and a bound
When the clean observation is also supplied, completing the square gives, for ,
For example, the two-step schedule above gives . This Gaussian posterior is not the reverse conditional in §2: it contains extra information, namely . At that posterior is concentrated exactly at , rather than having positive variance.
Define a generative chain . Its intermediate states are unobserved variables. With the known forward chain as a trial distribution, Jensen’s inequality gives
The gap is exactly . Factoring the forward path in reverse order gives
The three terms test the terminal prior, the learned reverse steps and the final reconstruction. The decomposition is exact. Minimizing the bound does not guarantee that the likelihood improves at each step, since its gap can also change.
Choose a Gaussian reverse transition with prescribed variance and parameterize its mean as
The -dependent part of its level- divergence is
We know the target because we sampled it ourselves. This is the practical benefit of the corruption construction. Setting all level weights equal gives a useful simplified loss, but changes the finite-model fitting problem; it is not the original likelihood bound.
4. What the noise predictor learns
For squared error at fixed , conditioning on splits the expected error into a conditional variance and a squared difference from the conditional mean. Hence the population optimum is
Define the score . This derivative is with respect to the data coordinates, not the network parameters; it is also different from a token score or logit. Differentiating the known conditional Gaussian gives
Differentiate and divide by . The normalized integrand is the posterior law of given , so
Thus the optimal predicted noise and the score are related by a minus sign and a noise-dependent factor; they are not the same vector. Positive noise, finite relevant moments and differentiation under the Gaussian integral give this identity. It also yields the optimal clean estimate, for :
A conditional mean can lie between two plausible clean observations. It is an estimator, not itself a random draw from their posterior.
A force that can point outward
For equally weighted scalar Gaussians with means and variance , the noisy marginal has means , with , and variance within each component . Direct differentiation gives
Its derivative at zero is . When , zero is a local density minimum and the score points away from it. At sufficiently large noise it points inward instead. For , the two cases occur at and , respectively. A fixed restoring force cannot describe both noise levels.
The figure plots the same analytic mixture at those two levels. Its lower panels show the score: the direction of increasing log probability.
5. Reverse stochastic evolution
For small steps the forward process has a continuous form
Here is a rate, with discrete . The noise level is unrelated to training step. For spatially constant , the density satisfies the Fokker–Planck equation .
Under the smoothness, nonexplosion and positive-density hypotheses of diffusion time reversal, define increasing reverse time and . Its reverse drift is
The noise is Brownian motion relative to the reverse-time information. The formula is a stated time-reversal theorem; checking its marginal equation is a useful verification, not a proof of the pathwise theorem.
Check. For stationary Ornstein–Uhlenbeck motion, , and , the score is . The reverse drift is , identical to the forward drift. Merely reversing its sign would give the wrong process. For a nonstationary scalar Gaussian with mean and variance , the reverse drift becomes .
An implemented generator replaces the score by an estimate, the terminal marginal by a prior, and continuous evolution by discrete steps. These give three separate errors: score fitting, prior mismatch and time discretization.
6. When thermodynamic quantities are defined
The formulas so far concern probabilities. A thermal interpretation also specifies an energy, bath temperature, mobility and their relation to noise. For example, can represent overdamped motion in a quadratic potential at unit temperature and appropriate mobility.
For this Ornstein–Uhlenbeck process, let . Integration by parts, with sufficient decay at infinity, gives
For a scalar Gaussian, the independent check is , with , . Therefore . In the specified thermal realization, is excess nonequilibrium free energy. A decreasing probability discrepancy in a different model does not by itself measure heat.
A finite-state work identity
Specify energies at inverse temperature , partition functions , and Gibbs laws . Start in . At each step switch to while holding fixed, with work ; then use a kernel preserving .
The key identity is . Applying the preserving kernel and repeating makes the factors telescope:
The last inequality is Jensen’s. The probability identity needs Gibbs preservation, which is weaker than detailed balance. Interpreting the protocol as a physical work experiment uses the specified energies and bath; it is not a consequence of fitting a denoising network.
Checkpoints with answers
1. Which distribution is Gaussian for arbitrary clean data? at a fixed clean observation. Averaging over the unknown generally gives a non-Gaussian marginal .
2. If and a predictor returns , what score does it imply? . The sign and scale are essential.
3. Does predicting the conditional mean produce a clean sample? Not generally. A mean between two modes can be atypical under the clean source. Sampling requires the specified reverse transitions.
4. What makes the work identity different from a generated path cost? It specifies energies, an equilibrium initial law, work during controlled switches and Gibbs-preserving transitions. A path’s negative log probability alone supplies none of these definitions.
What the week establishes
The conditional forward law and Gaussian posterior are exactly calculable. The variational bound has an explicit relative-entropy gap. At the population optimum, predicted noise determines the marginal score after the stated rescaling. The reverse equation then provides a generative route under its time-reversal hypotheses. Thermal interpretations apply to the separate specified physical constructions, with their additional assumptions.
The practical session — Laboratory 8
Varied: the time step, the terminal noise level and the training sample size — separately, never together, since the point is to attribute error to its source. Held fixed: the analytic model — Gaussian or two-Gaussian, for which the score is known in closed form — and the held-out set used for evaluation. Measured: moments and a stated distributional discrepancy on held-out samples, for a reverse sampler using the exact score and for one using a fitted predictor; and the relative-entropy decay against the closed-form Ornstein–Uhlenbeck expression, as a calibration.
Product: distributions, samples and errors with the three error sources separated and each attributed. Do not label the discrepancy of an arbitrary learned sampler as dissipated work: §6 states exactly what would have to be built first.
Connections to other parts of the wiki
- Week 1 supplies the relative entropy and its nonnegativity, which is what makes the variational bound a bound.
- Week 10 introduced a diffusion over parameters and a path cost distinct from entropy production; this week supplies the construction in which the thermal words are earned.
- Week 13 asked what a transition claim requires; this chapter asks the same question of a thermal claim, and answers it in §6.
- nn-llm-unit-4 — the block skeleton this note implements.
Start here · All weeks · Book and experiments · Previous week · Next week