This article is devoted almost entirely to derivations. For a conceptual introduction to DDPM itself, see the previous post. Looking back, I am not sure I understood every part perfectly when I wrote that one either. The DDPM paper is here. It is hard to believe this difficult paper is already three years old.
Forward and Reverse Processes
Repeatedly add a tiny Gaussian perturbation with small variance β to image x0 for T steps. The final output xT approaches a Gaussian distribution with the same spatial dimensions as x0. The paper schedules the variance at each step and treats those values as fixed.
Forward Process q(xt∣xt−1)
q(xt∣xt−1)=N(xt;1−βtxt−1,βtI).
Direct stochastic sampling is not differentiable with respect to the distribution parameters, so training uses the reparameterization trick. At every step, the previous output is scaled by 1−βt before adding noise. The two coefficients preserve unit variance when the signal and noise each have unit variance:
The independent Gaussian noise terms combine into another Gaussian whose variance is the sum of their variances:
αt1−αt−1ϵt−2+1−αtϵt−1∼1−αtαt−1ϵ.
Repeating this argument and defining αˉt=∏s=1tαs yields
q(xt∣x0)=N(xt;αˉtx0,(1−αˉt)I).
Reparameterizing this marginal gives the formula used throughout the loss derivation:
xt:=αˉtx0+1−αˉtϵ,ϵ∼N(0,I).
Reverse Process pθ(xt−1∣xt)
The learned reverse process imitates the posterior of the forward process. This is distribution prediction. Wanting the reverse direction to match the forward one should sound familiar: the approach resembles a VAE and therefore optimizes a variational lower bound.
The reverse joint from xT to x0 factors as
pθ(x0:T):=p(xT)t=1∏Tpθ(xt−1∣xt),
with each transition modeled as
pθ(xt−1∣xt):=N(xt−1;μθ(xt,t),Σθ(xt,t)).
The forward process adds a very small Gaussian at each step, so the reverse removes a very small Gaussian. The network can sample backward by predicting the noise at each point and subtracting it.
The loss should therefore make the learned reverse process match the known forward process.
Loss Function
Evidence Lower Bound in DDPM
A VAE negative-log-likelihood bound can be written
The first term trains the decoder to reconstruct x0 from z. The second is a KL-divergence term that makes encoder posterior qϕ(z∣x0) resemble a predefined latent prior such as Gaussian pθ(z).
Rearranging the same log ratio to emphasize the generative joint,
Why arrange the VAE terms differently? Intuitively, we want the forward and reverse processes to match. More precisely, a VAE decoder learns an implicit conditional distributionpθ(x0∣z), whereas a diffusion decoder learns the stepwise dynamics that reverse the diffusion process.
The problem is that although the forward transition q(xt∣xt−1) is known, its reverse posterior q(xt−1∣xt) is intractable:
q(xt−1∣xt)=q(xt)q(xt∣xt−1)q(xt−1).
An intuitive explanation: because we know the noise added to xt−1, the conditional distribution of xt given xt−1 is explicitly Gaussian. But we do not know the marginal distributions of noisy states q(xt) and q(xt−1), leaving two intractable terms in Bayes' rule.
Conditioning every term on the original sample x0 makes the posterior tractable because accumulated Gaussian noise from x0 has the closed form derived above:
Adding x0 may appear to make this a different target from pθ(xt−1∣xt). During training, however, x0 is known and the Markov property provides the tractable posterior whose conditional mean the model can learn from xt.
The expression above is still abstract. The implemented objective follows after substituting the Gaussian distributions. The ELBO has three pieces.
The first KL term is naturally satisfied by the forward diffusion schedule, which drives xT toward the chosen Gaussian prior, and it contains no learned reverse parameters in the usual setup:
DKL(q(xT∣x0)∥pθ(xT)).
In a VAE, a similar term regularizes a learned encoder. Diffusion does not learn q, so this term is normally omitted from the trainable loss.
The final log-likelihood term is less intuitive:
Eq[logpθ(x0∣x1)].
It assigns likelihood to reconstructing clean x0 from slightly noised x1. The middle terms compare Gaussian distributions via KL divergence and do not require mapping the density into a discrete pixel probability. This endpoint term does.
Consider only
pθ(x0∣x1).
The reverse network predicts a Gaussian distribution over every component of x0:
pθ(x0∣x1)∼N(x0;μθ(x1,1),σ12).
To obtain the likelihood of a discrete image, integrate this Gaussian over the quantization bin for every pixel. Assume images are normalized to [−1,1]. Values below −1 map to the boundary pixel −1, values above 1 map to 1, and intermediate 8-bit values occupy bins of width approximately 2/255.
Suppose the ground-truth component should be zero when mapping x1 back to x0.
Then pθ(x0∣x1) assigns the area of the predicted density around that quantized value—the yellow region below.
Multiplying over D image components gives the joint probability:
The discussion above says that LT requires no learned optimization and that L0 can be evaluated through discretized Gaussian likelihood. What about the intermediate denoising terms?
t>1∑DKL(q(xt−1∣xt,x0)∥pθ(xt−1∣xt)).
We first show that q(xt−1∣xt,x0) is Gaussian. The tractable posterior is
The DDPM paper moves past this algebra quickly, which is why I wanted to leave the full derivation here.
The model distribution is
pθ(xt−1∣xt)=N(xt−1;μθ(xt,t),Σθ(xt,t)).
In the original simplified setup, its variance is fixed rather than learned, often to βt or β~t. The experiments report little difference between those choices. The network therefore needs to predict only μθ(xt,t).
With equal fixed covariance, KL divergence between the two Gaussians reduces, up to parameter-independent constant C, to squared error between their means:
At time t, xt is already the network input. The unknown part of the forward construction is the added noise ϵ, so parameterize the model mean through a noise predictor ϵθ:
μθ(xt,t)=αt1(xt−1−αˉtβtϵθ(xt,t)).
Sampling xt−1 uses this predicted mean plus the fixed variance term: