How DDPM learns to run the noising chain backwards: a likelihood bound split into one KL term per step, a Gaussian posterior known in closed form, and the noise-prediction loss with its training and sampling algorithms.
The basic DDPM training objective fits in one line: take an image, add Gaussian noise of a random strength, and ask the network to say what noise was added. The loss is the squared error of that guess. Nothing in it mentions likelihoods, chains or posteriors, yet the network it trains generates images by running the forward process backwards. Why is this the right regression, and what does it give up?
The answer comes from treating the noisy images x1,…,xT as latent variables, as in the VAE. The encoder is the fixed forward chain, the decoder is the learned reverse chain, and the loss starts as the VAE’s bound on the likelihood. Every simplification from that bound to the one-line loss can be derived, and one of them is a deliberate change of objective.
We keep the notation of the forward process: βt∈(0,1) is the noise variance of step t, and
Generation starts from p(xT)=N(0,I), a fixed distribution with no parameters, and applies a learned step pθ(xt−1∣xt) for t=T,…,1. The complete forward and reverse processes are
The forward step is known; the backward step must be learned
Tiles show marginal noising of a local pattern at ᾱ = 1, 0.6, 0.42 and 0. Shared noise aids comparison; this is not a Markov trajectory. The last tile is the pure-noise limit. Arrows indicate the directions of fixed q and learned pθ.
What family should pθ(xt−1∣xt) belong to? The step it imitates is the true reverse step, by Bayes’ theorem
q(xt−1∣xt)∝q(xt∣xt−1)q(xt−1),
which involves the unknown marginal q(xt−1). For a smooth positive marginal and a sufficiently small step, a local Gaussian approximation is useful. In one coordinate it is
where q in the score means the marginal of xt−1. The Taylor argument below controls the log-density locally when its curvature is bounded; turning that into an approximation of the whole conditional distribution also needs its mass to concentrate in that neighbourhood. It does not cover an atomic data distribution at the final step. Sohl-Dickstein et al. (2015), §2.2, motivate small-step reverse diffusions using Feller’s result; Isachenko (2025), lecture 7, gives the same motivation.
Why a small reverse step is nearly Gaussian
As a function of xt−1, the first factor is a Gaussian centred at y with the tiny variance v; its exponent is −αt(xt−1−y)2/(2βt). Over a width of order v around y, the smooth function logq(xt−1) is close to its first-order Taylor expansion, logq(y)+(xt−1−y)∇logq(y). A Gaussian multiplied by the exponential of a linear function is a Gaussian with the same variance and its mean moved by the variance times the slope (complete the square). That gives the display above.
The error comes from the neglected quadratic term of the Taylor expansion. If the second derivative of logq stays within ±K near y, that term is at most 21K(xt−1−y)2, which is of order Kv over the width v and goes to 0 with v.
This motivates many small steps and the Gaussian family used for the intermediate reverse steps, t≥2:
pθ(xt−1∣xt)=N(μθ(xt,t),σt2I),
a Gaussian whose mean a network computes from xt and t, and whose variance σt2 is a fixed number for each step. The gradient ∇logq in the mean is the score of the noised data; the score matching note returns to it.
We want real images to be likely under the model: minimize Eq(x0)[−logpθ(x0)]. The likelihood of one image integrates the reverse process over all intermediate states, every path from noise to the image:
pθ(x0)=∫pθ(x0:T)dx1:T.
For a general nonlinear network the composed reverse steps need not be Gaussian, and this integral has no tractable closed form. Numerically it runs over T times the number of pixels dimensions.
Figure
The likelihood integral sums over every path from noise to the image
The exact likelihood integrates the joint reverse density over all states x₁, …, x_T. Each value of these states is one path from a noise sample to the image x₀; paths start anywhere in the noise. The drawn curves are schematic random bridges with a fixed seed, not trajectories of a trained model.
The way out is the one of the VAE. Multiply and divide by the forward process, which is positive everywhere and easy to sample, then apply Jensen’s inequality to the concave logarithm, logE[Y]≥E[logY]:
L is the negative ELBO, an upper bound on the negative log-likelihood. The gap is DKL(q(x1:T∣x0)∥pθ(x1:T∣x0)), by the same decomposition as in variational inference. Training minimizes Eq(x0)[L(x0)]. As written, L is still an expectation over all T noisy states at once. A one-sample estimate draws a whole path and adds T random log-ratios, so the randomness of every step enters it. The next two sections rewrite L as a sum of terms that each involve one step, and replace the average over each step by its closed form; Ho, Jain and Abbeel (2020, §2) introduce this rewriting as variance reduction.
The lemma: the reversed chain is Markov given the image#
The bound pairs the reverse steps pθ(xt−1∣xt) with forward steps q(xt∣xt−1), which are densities of different variables. To compare like with like we need the forward process written backwards. The tool is a lemma. The proof, bound decomposition and image-to-noise route below adapt BMML lecture 5, §5.4 and Lemma 1, under the MIT license and copyright notice; notation and explanation are expanded here. The underlying DDPM equations are credited to Ho, Jain and Abbeel.
Lemma. If q(x1:T∣x0)=∏t=1Tq(xt∣xt−1), then for every t<T
q(xt∣xt+1,…,xT,x0)=q(xt∣xt+1,x0).
Reversed in time and with x0 held fixed, the chain is still Markov: once xt+1 and the image are known, the later, noisier states say nothing more about xt.
Proof of the lemma
Fix t. Integrating x1,…,xt−1 out of the forward product turns its first t factors into the marginal q(xt∣x0):
Now rewrite the first two factors of (1). The chain is Markov, so q(xt+1∣xt)=q(xt+1∣xt,x0), and Bayes’ theorem for the pair (xt,xt+1) given x0 gives
Substituted into (1), the factors left after q(xt∣xt+1,x0) are q(xt+1∣x0)∏s=t+2Tq(xs∣xs−1), which is (1) written for t+1, that is q(xt+1:T∣x0):
q(xt,…,xT∣x0)=q(xt∣xt+1,x0)q(xt+1:T∣x0).
Comparing with (2) and dividing by q(xt+1:T∣x0)>0 proves the lemma.
The chain rule of probability, applied from the last state backwards, and then the lemma, give the factorization the bound needs:
Put the two factorizations into the ratio inside L. In the numerator, peel off the last reverse step pθ(x0∣x1); in the denominator, shift the index of the product by one, so that both products run over t=2,…,T and pair a reverse step with a backward forward step of the same variables:
Each term involves at most two states, so its expectation over all of x1:T reduces to those two. For the term with (xt−1,xt), apply the definition of a conditional density twice:
The last factor integrates to 1 over the other states. What remains is an average over xt∼q(xt∣x0) of an inner average over xt−1∼q(xt−1∣xt,x0), and the inner average of log(q/pθ) is by definition a KL divergence (lecture notes, lecture 5). Changing the sign, the bound splits into
LT compares the end of the forward chain with the fixed prior. Neither contains a trainable parameter, so LT is a constant during training; for DDPM’s schedule it is small for order-one pixels, with its exact value depending on x0 (forward process).
L0 is the decoder’s reconstruction term. It is not a constant: even with the family of pθ(x0∣x1) fixed, its mean μθ(x1,1) is the network’s output, so L0 changes with θ.
Lt−1 for t=2,…,T does the main work. Each compares the model’s step with q(xt−1∣xt,x0), the forward step reversed with the image known. Both are Gaussians, as the next section shows, so every KL has a closed form instead of a noisy Monte Carlo estimate.
The decoder at t = 1 and bits per dimension
Pixels are integers 0,…,255 scaled linearly to [−1,1], so neighbouring values are 2/255 apart. DDPM’s last step gives each value the probability mass of its bin under the Gaussian of the reverse step (Ho, Jain and Abbeel, 2020, Eq. 13), one factor per pixel value i=1,…,D:
with the outer edges δ+(1)=+∞ and δ−(−1)=−∞, so that the 256 probabilities sum to 1. Each factor is a difference of two values of the standard normal CDF Φ. For an interior bin, with σ1=β1=0.01 and the mean exactly on its pixel value, the bin ±1/255 spans ±0.392 standard deviations, so its probability is 2Φ(0.392)−1=0.305, or −log20.305=1.71 bits.
Likelihoods are reported in bits per dimension: the bound in nats divided by Dln2 (definition). For CIFAR-10, D=32⋅32⋅3=3072, so 3.75 bits per dimension mean 11,520 bits per image.
The forward step q(xₜ | xₜ₋₁) adds noise. The model's step pθ(xₜ₋₁ | xₜ) sees only xₜ. The true posterior q(xₜ₋₁ | xₜ, x₀) also goes back to xₜ₋₁ but conditions on the image x₀ as well (dotted group); it has a closed form but needs an image.
The forward step reversed with the image known, q(xt−1∣xt,x0), is the “true posterior” that each Lt−1 compares with. Bayes’ theorem conditioned on x0, followed by the Markov property q(xt∣xt−1,x0)=q(xt∣xt−1), gives
Both factors of the numerator are Gaussian in xt−1, and the denominator does not depend on xt−1. Take logarithms, per coordinate, and collect the terms in xt−1; every term without xt−1 goes into a constant c:
Completing the square, Ax2−2Bx=A(x−B/A)2−B2/A, so the posterior is Gaussian with variance 1/A and mean B/A. Over a common denominator, and with αtαˉt−1=αˉt and αt+βt=1,
This is DDPM’s Eq. 6–7, and the same computation as the normal–normal conjugate update: the precisions add, and the mean is a precision-weighted average. Toy example:β1=0.1 and β2=0.2, so αˉ1=0.9 and αˉ2=0.72. Then q(x1∣x2,x0) has variance β~2=0.1/0.28⋅0.2=0.0714 and mean 0.678x0+0.319x2; the Code section recovers these numbers by simulation. At t=1, αˉ0=1 gives β~1=0 and μ~1=x0: given the image, there is nothing left to guess, which is why that step is handled by the decoder term L0.
The posterior needs x0, and at generation time there is no image. The network must imitate it from xt alone.
DDPM does not learn the variance of the reverse step: σt2 is fixed in advance. With pθ=N(μθ,σt2I), the KL divergence between two 1-D Gaussians, summed over the d coordinates, is
Ct does not depend on θ, and it is 0 when σt2=β~t. So each Lt−1 is a squared error between means, plus a constant (Ho, Jain and Abbeel, 2020, Eq. 8).
Figure
With equal variances, the KL divergence is an L2 loss on the means
The model's step pθ = N(μθ, σₜ²) against the true posterior q for one pair (xₜ, x₀), with σₜ² equal to the posterior variance β̃ₜ = 1. The KL is then (gap)² / (2σₜ²), the parabola on the right: a gap of 2.7 gives 3.645 nats. Training moves μθ down the parabola.
Which σt2? Ho, Jain and Abbeel tried βt and β~t and found similar results (§3.2). They are the right variance in two extreme cases. If the data are a single point, the true reverse step is the posterior itself, with variance β~t. If the data are N(0,I), every xt is N(0,I) and Cov(xt−1,xt)=αtI, so the Gaussian conditional has variance 1−αt=βt.
What does the network learn? The target μ~t depends on x0, which it does not see, and many images are compatible with the same xt. Since the conditional mean minimizes the expected squared error, the optimum is the average of μ~t over the images compatible with xt, and by the tower property that is the mean of the true reverse step:
μθ∗(xt,t)=E[μ~t(xt,x0)∣xt]=E[xt−1∣xt].
In general the KL terms remain nonzero at this optimum. What remains of the squared error is the variance of μ~t(xt,x0) given xt. Since μ~t is linear in x0, that is the square of its coefficient of x0 times Var(x0∣xt), summed over pixels: it is zero only when xt determines the image.
The network could output μθ directly. The lecture notes take a route through the image first. Since μ~t is linear in x0 with coefficient ct=αˉt−1βt/(1−αˉt), let a network x^θ(xt,t) guess the image and plug the guess into the posterior mean, μθ=μ~t(xt,x^θ). Then the means differ only through the images:
Training is regression of the clean image on the noisy one: a denoiser.
DDPM goes one step further and predicts the noise (Ho, Jain and Abbeel, 2020, §3.2). The one-draw jump xt=αˉtx0+1−αˉtε can be solved for the image:
x0=αˉt1(xt−1−αˉtε).
Substitute this into μ~t and use αˉt−1/αˉt=1/αt, from αˉt=αtαˉt−1. The coefficient of xt collects two terms, which add up by βt+αt=1:
Here x0 is fixed, as in L(x0); the training objective additionally averages over data images. The three parameterizations describe the same model with the same bound. Define the image guess from the noise guess by the same solved jump, x^θ=(xt−1−αˉtεθ)/αˉt; subtracting it from the expression for x0 gives x0−x^θ=−(1−αˉt)/αˉt(ε−εθ), and ct2(1−αˉt)/αˉt=2σt2wt. They differ in what the network finds easy to output, and in what the unweighted losses below emphasize. Ho, Jain and Abbeel found that predicting x0 gave worse samples early in their experiments, and that predicting μ~ trained well only with the true weights (§3.2, §4.2). The optimal noise predictor is εθ∗=E[ε∣xt], the average noise consistent with xt. Up to the factor −1−αˉt it is the score of q(xt), the gradient that appeared in the small-step mean of the reverse process (score matching).
Final simplification: a random timestep per sample#
The bound now reads
L(x0)=const+t=2∑TwtEε∥ε−εθ(xt,t)∥2+L0.
Summing all T−1 terms for every image would cost T−1 network evaluations per image. Instead we draw one timestep per image. For any f, ∑t=2Tf(t)=(T−1)Et∼Uniform{2,…,T}f(t), so (T−1)f(t) is an unbiased estimate of that sum. Omitting the constant preserves the minimizer of the sum alone; to retain the full bound, keep its scale relative to the separate decoder term L0. Because xt comes from x0 in one draw, no chain is ever simulated during training.
Ho, Jain and Abbeel then drop the weight (Eq. 14):
with t uniform on {1,…,T}. The t=1 term stands in for L0: the decoder’s bin probability approximated by the Gaussian density times the bin width, ignoring σ12 and the edge bins (§3.4).
Dropping wt changes the objective. With DDPM’s linear schedule and σt2=βt, the weight simplifies to wt=βt/(2αt(1−αˉt)). It is 0.273 at t=2, falls to a minimum of 0.0050 at t=349 and ends at 0.0102 at t=T: the bound puts 55 times more weight on the nearly clean step t=2 than at the minimum. Lsimple weights every step equally, so relative to the bound it down-weights the small-t steps, which describe tiny pixel-level corrections, and shifts relative weight toward noisier steps. This does not mean that predicting the added noise is always harder at a higher noise level. With unlimited capacity the weights would not matter: each step’s term is minimized separately by εθ∗=E[ε∣xt], whatever its positive weight. They matter because one network serves all steps and trades errors at one step against another, so minimizing Lsimple no longer minimizes the bound; Ho, Jain and Abbeel call it a weighted variational bound (§3.4). In the authors’ CIFAR-10 experiment it gave FID 3.17 against 13.51 for the true-bound objective, evaluated against training-set statistics, and a slightly worse negative-log-likelihood upper bound, 3.75 against 3.70 bits per dimension (their Table 1). These are cited research results, not measurements of our local examples.
Figure
The bound's weight favours the nearly clean steps
The bound's weight wₜ = βₜ² / (2σₜ² αₜ (1 − ᾱₜ)) for the linear schedule (T = 1000), on logarithmic axes. With σₜ² = βₜ: 0.273 at t = 2, minimum 0.0050 at t = 349, 0.0102 at t = T. Dashed: σₜ² = β̃ₜ (0.600 at t = 2). L_simple uses wₜ = 1.
The training loop is DDPM’s Algorithm 1:
Draw an image x0 from the data.
Draw a timestep t uniformly from {1,…,T} and noise ε∼N(0,I).
Form xt=αˉtx0+1−αˉtε.
Take a gradient step on ∥ε−εθ(xt,t)∥2, and repeat until converged.
Figure
One training step: draw, jump, predict the noise
One training step: draw an image x₀, a timestep t and a noise ε, jump straight to xₜ, ask the network for its estimate εθ(xₜ, t), and step on the unweighted squared error. This is L_simple: t from 1 to T, unit weight. The KL sum for t ≥ 2 uses wₜ; the decoder term is separate.
Generation does run the chain. DDPM’s Algorithm 2 samples each reverse step pθ(xt−1∣xt)=N(μθ(xt,t),σt2I) with the noise form of the mean:
Draw xT∼N(0,I).
For t=T,…,1, draw z∼N(0,I) if t>1, else set z=0, and compute
xt−1=αt1(xt−1−αˉtβtεθ(xt,t))+σtz.
Return x0.
Each step removes the network’s estimate of the noise, rescales, and adds a little fresh noise of variance σt2, either βt or β~t.
The last step, with z=0, returns the decoder’s mean μθ(x1,1), not a draw from pθ(x0∣x1); Ho, Jain and Abbeel display this mean (§3.3). Setting σ12=β~1=0 instead defines a deterministic continuous endpoint, not a nondegenerate Gaussian density or the discrete decoder above. With σ12=β1, an exact continuous draw adds σ1z; the discrete decoder then maps that draw to the appropriate pixel bin. Returning the mean suppresses this final randomness, but in general it is not a sample from the specified decoder.
How far an exact last step moves a pixel
Take a mean exactly on an interior pixel value, with at least two bins on either side, and σ1=β1=0.01. The bins have half-width 1/255=0.39σ1, so the draw stays in the mean’s bin with probability 2Φ(0.392)−1=0.305, moves one level up or down with probability 2(Φ(1.176)−Φ(0.392))=0.456, and moves further with probability 0.239.
Generation costs T=1000 network evaluations, one per step, against one for training on an image; this is the main practical cost of DDPM. Samplers that reuse the trained network with far fewer steps are in the latent diffusion note.
For general data the Gaussian reverse-step approximation relies on sufficiently small steps; Gaussian data are a special case where it can be exact at larger steps too. Take data that are two points, x0∈{−1,+1} with equal weights. For this data the optimal noise predictor is known exactly: E[x0∣xt]=tanh(αˉtxt/(1−αˉt)), from Bayes’ theorem with two Gaussian likelihoods, and E[ε∣xt] follows from the one-draw jump. Run Algorithm 2 with this perfect network and σt2=β~t, for two schedules that end at the same αˉT=4.0×10−5:
chain
samples within 0.05 of ±1
samples with ∣x∣<0.5
T=1000, DDPM’s linear schedule
1.0
0.0
T=10, constant β=0.636
0.03
0.47
With a thousand small steps all 20,000 samples in this seeded run land near one of the two data points; this tolerance check does not establish equality of distributions. With ten large steps it fails although every step has the exact optimal mean E[xt−1∣xt]. The true reverse step averages the two posteriors over the image, by the law of total probability:
The two Gaussians have the same variance β~t, and their means differ by 2αˉt−1βt/(1−αˉt), the coefficient of x0 in μ~t times the distance between the images. The mixture is far from one Gaussian only where both weights P(x0∣xt) are substantial and this gap is large next to the standard deviation β~t. In the thousand-step chain the numerical criterion below finds no substantially populated, widely separated pair. In the ten-step chain they do at the last steps. At t=1, where β~1=0, the true step goes to −1 or +1, while the sampler returns their weighted average, which lies between −0.8 and 0.8 for 74% of the x1 of the forward process. Almost half the samples end near 0, where the data have none.
The gap in numbers
Divided by the standard deviation, the gap is
rt=(1−αˉt)(1−αˉt−1)2αˉt−1βt,
which shrinks like βt at fixed noise levels. In the thousand-step chain, both weights first exceed 0.1 for at least 1% of the xt at t=110, where rt=0.74, and rt only falls after that. The early steps, where rt is large (148 at t=2), see an xt that still identifies the image, so one weight is close to 1. In the ten-step chain r2=1.29 with almost every x2 ambiguous, and r1 is infinite.
The derivation treats εθ(xt,t) as a function of two arguments. In practice it is one network for all steps, a U-Net, that receives the timestep as an embedding added inside every block.
Figure
The DDPM denoiser: a U-Net that receives the step t
All 5 steps · press ▶ to go one at a time
Schematic from Ho et al. (2020), Appendix B. Each box condenses a resolution stage: 32 → 16 → 8 → 4 and back. Skip connections join matching sizes; the timestep embedding enters residual blocks. This depicts the architecture, not an executed model.
Neighbouring steps solve almost the same problem, so DDPM shares the parameters across time instead of training a thousand networks, and tells the network which step it is at (§4). The same input calls for different outputs at different noise levels: the noise in a given xt is a small part of it when t is small and almost all of it when t is large.
An example: one input, two noise levels
For 1-D data N(0,0.52), ε and xt are jointly Gaussian with covariance 1−αˉt, so the Gaussian conditional mean is
E[ε∣xt]=0.25αˉt+1−αˉt1−αˉtxt.
With the linear schedule and xt=1 it is 0.17 at t=10 (αˉt=0.998), where xt is mostly image, and 1.02 at t=500 (αˉt=0.079), where xt is mostly noise.
The output has the shape of the input, one noise value per pixel: a dense prediction problem that needs context from far away and precision at the pixel itself. A U-Net, built in the segmentation note of the Deep Learning course, provides both: an encoder halves the resolution level by level, a decoder doubles it back, and skip connections bring the encoder’s features of each size to the decoder. DDPM’s network follows the PixelCNN++ backbone, a U-Net of Wide ResNet blocks, with group normalization and self-attention at the 16×16 resolution (§4 and Appendix B).
A small MLP turns the code into a feature vector m(t), and every residual block k adds its own linear projection Akm(t) to its feature maps, one bias per channel. A raw number t would give the MLP one input running up to 1000, from which it would have to build every function of t it needs. The sinusoidal code supplies them ready-made: its components turn at rates from ω0=1 down to ωd/2−1≈10−4 radians per step, periods from about 6 to about 60,000 steps, so linear combinations of it can follow both fast and slow changes in t. Alternatives set a scale and a shift of each channel after group normalization from the embedding (Murphy, 2023, §25.2), and text enters through cross-attention.
DDPM maps pixel values 0,…,255 linearly to [−1,1] (§3.3). The chain removes the image only by shrinking it, and with αˉT=0.0064 the leftover is negligible only for values of order 1 (forward process). By the variance recursion Var(xt)=αˉtVar(x0)+1−αˉt, every step then sees inputs of similar size, and the decoder’s bins of width 2/255 end at ±1.
To display an image, x is clipped to [−1,1] and mapped back by 255(x+1)/2, because noisy states leave the interval routinely.
How often, and what goes wrong without the clip
A pixel with x0=0.9 at a step with αˉt=0.5 has xt∼N(0.64,0.5), which falls outside [−1,1] with probability 0.31. An unchecked NumPy cast to unsigned 8-bit integers can wrap out-of-range values into wrong colours; other image libraries may saturate or reject them. Clipping explicitly makes the intended display conversion clear.
Training in practice: averaged weights and clipped gradients#
An exponential moving average of the weights. Keep a second copy θˉ of the parameters and update it after every optimizer step:
θˉ←μθˉ+(1−μ)θ.
Unrolled over n steps, θˉ is a weighted average of the past iterates with weights (1−μ)μn−k, plus μn times its starting value: roughly an average over the last 1/(1−μ) steps, which carry the weight 1−μ1/(1−μ)≈1−1/e=0.63. Training continues with θ; samples are drawn with θˉ. Every example brings its own image, timestep and noise, so the iterates jitter around a good region. By the triangle inequality, its distance to any fixed point is bounded by the same weighted average of distances. This can smooth cancelling fluctuations, but does not guarantee a lower loss or better samples for a nonlinear network. DDPM uses μ=0.9999 (Appendix B), a window of about 10,000 steps, and Nichol and Dhariwal (2021) found 0.9999 and 0.99995 best in a sweep.
How long the initialization remains influential
The starting value keeps the weight μn: 0.999910000=0.37 and 0.999950000=0.0067, so a large window retains substantial initialization weight for a long time. Whether early EMA samples are useful depends on initialization and training; choose the checkpoint using validation, rather than treating this arithmetic as a universal warm-up rule.
Gradient clipping. Before each step, rescale the gradient g when its norm exceeds a threshold c, g←g⋅min(1,c/∥g∥) (training background). For a zero gradient leave it unchanged. This caps the raw gradient norm and preserves its direction; clipping may occur frequently if c is too small. It bounds a plain SGD update by the learning rate times c, but does not directly bound an adaptive optimizer’s full update.
The bound splits into LT (constant), Lt−1=EDKL(q(xt−1∣xt,x0)∥pθ) and the decoder term L0, which depends on θ.
Given x0 the reversed chain is Markov, and q(xt−1∣xt,x0)=N(μ~t,β~tI) by Bayes and completing the square.
With fixed variances each KL is ∥μ~t−μθ∥2/(2σt2) plus a constant.
μθ=(xt−βtεθ/1−αˉt)/αt turns it into wt∥ε−εθ∥2.
Lsimple sets wt=1 and changes the trade-off across steps. The original paper reports better FID and a slightly worse NLL bound in its comparison; this is not a universal guarantee.
Training jumps straight to xt; sampling takes T steps, which must be small for the Gaussian step to hold.
The posterior of the toy example checked by simulation, the weights of the bound for DDPM’s schedule, and Algorithm 2 with the exact noise predictor for two-point data, with many small steps and with ten large ones. It uses NumPy and runs in a few seconds.
import numpy as nprng = np.random.default_rng(0)# 1. the posterior q(x1 | x2, x0) for beta1 = 0.1, beta2 = 0.2, by regression on simulated pairsb1, b2 = 0.1, 0.2ab1, ab2 = 1 - b1, (1 - b1) * (1 - b2)x0 = 1.0x1 = np.sqrt(ab1) * x0 + np.sqrt(1 - ab1) * rng.standard_normal(1_000_000)x2 = np.sqrt(1 - b2) * x1 + np.sqrt(b2) * rng.standard_normal(x1.size)slope, icpt = np.polyfit(x2, x1, 1) # for fixed x0, E[x1 | x2] is linear in x2resid = (x1 - slope * x2 - icpt).var()print(np.round([slope, icpt, resid], 4)) # simulatedprint(np.round([np.sqrt(1 - b2) * (1 - ab1) / (1 - ab2), # formula: coefficient of x_t, np.sqrt(ab1) * b2 / (1 - ab2) * x0, # coefficient of x0 times x0, (1 - ab1) / (1 - ab2) * b2], 4)) # and the variance tilde beta# [0.3202 0.6771 0.0715]# [0.3194 0.6776 0.0714]# 2. the bound's weight on ||eps - eps_theta||^2 for DDPM's linear schedule, sigma_t^2 = beta_tT = 1000beta = np.linspace(1e-4, 0.02, T); alpha = 1 - beta; abar = np.cumprod(alpha)w = beta / (2 * alpha * (1 - abar)) # beta^2 / (2 sigma^2 alpha (1 - abar)) with sigma^2 = betat_min = np.argmin(w[1:]) + 2 # steps t = 2..Tprint(round(w[1], 4), round(w.min(), 4), t_min, round(w[-1], 4), round(w[1] / w.min(), 1))# 0.2727 0.005 349 0.0102 54.9# 3. sampling (Algorithm 2) with the exact optimal noise predictor for data x0 in {-1, +1}def sample(beta, n=20_000): alpha = 1 - beta; abar = np.cumprod(alpha) abar_prev = np.concatenate([[1.0], abar[:-1]]) x = rng.standard_normal(n) for t in range(len(beta) - 1, -1, -1): x0_hat = np.tanh(np.sqrt(abar[t]) * x / (1 - abar[t])) # E[x0 | x_t] for two equal points eps = (x - np.sqrt(abar[t]) * x0_hat) / np.sqrt(1 - abar[t]) # E[eps | x_t] mean = (x - beta[t] / np.sqrt(1 - abar[t]) * eps) / np.sqrt(alpha[t]) var = (1 - abar_prev[t]) / (1 - abar[t]) * beta[t] # sigma_t^2 = tilde beta_t x = mean + np.sqrt(var) * rng.standard_normal(n) if t > 0 else mean return xfew = np.full(10, 1 - abar[-1] ** 0.1) # 10 steps with the same abar_T as the 1000-step chainfor b in (beta, few): x = sample(b) print(len(b), round(np.prod(1 - b), 7), round(np.mean(np.abs(np.abs(x) - 1) < 0.05), 3), round(np.mean(np.abs(x) < 0.5), 3))# 1000 4.04e-05 1.0 0.0# 10 4.04e-05 0.03 0.47
For optional practice, run python3 scripts/notes/generative-practice.py ddpm-training-objective. The standard-library experiment creates 256 grayscale 8×8 signals from a fixed cosine background m and a sinusoidal stripe p with random amplitude a∼N(0,0.36):
x0=m+ap,xt=0.55x0+0.45ε.
Here ∥p∥2=32. Subtract the known background and project onto p. This leaves a one-dimensional Gaussian inference problem. Its posterior variance and mean are
Use x^0=m+a^p to obtain the noise estimate from the rearranged forward equation. The saved run has noise-prediction MSE 0.014848, compared with 0.995149 for always predicting zero noise; signal MSE is 0.012148. The script checks that signal MSE equals noise MSE times (1−αˉ)/αˉ.
Change the signal prior variance or noise strength and rerun both the posterior calculation and the check. Which part of the observation identifies the stripe amplitude? Why can the estimator remove noise orthogonal to the stripe particularly well? The signal family is deliberately only one random degree of freedom; these errors are not image-generation quality scores. This exercise performs one forward step and exact conditional denoising, not U-Net training or a reverse chain. The signals and code were authored for this project with Codex assistance, with no external dataset or checkpoint. Gaussian signal amplitudes are unbounded; clipping for display would change the statistical model.
DDPM reaches its loss through a likelihood bound. The next note reaches the same loss without one: it learns the gradient of the log-density of noised data, samples by following it, and shows that the noise predictor is that gradient up to a known scale.
J. Ho, A. Jain, P. Abbeel. Denoising diffusion probabilistic models. NeurIPS, 2020. §2 and Eq. 5–14 (the bound, the posterior and the parameterizations), §3.3–3.4 (the decoder and Lsimple), Algorithms 1 and 2, §4 and Table 1, Appendix B (architecture and training settings).
Конспект курса «Байесовские методы в анализе данных», 2026, BMML lecture 5, лекция 5 (the ELBO of the chain, Lemma 1, the split into L0, Lt, LT, the parameterizations and the algorithms).
R. Isachenko. Deep Generative Models, MIPT and Yandex School of Data Analysis, 2025. Course repository; lecture 7 (the reverse process and the small-step result), lecture 8 (Gaussian diffusion as a VAE, the ELBO and its reparameterization).