Complete derivation of the DDPM training loss: variational lower bound, simplification to noise prediction, loss weighting strategies, training algorithm, and connection to score matching.
Derive the variational lower bound (VLB) for diffusion models.
Show how the VLB decomposes into per-timestep KL divergence terms.
Prove the simplified noise prediction objective is equivalent.
Explain different loss weighting strategies and their effects.
Derive the learned variance parameterization (Improved DDPM).
Notation
βt — noise schedule at step t
αˉt=∏s=1t(1−βs) — cumulative signal retention
ϵθ(xt,t) — noise prediction network
Lsimple — simplified DDPM loss
Core Intuition
Training a diffusion model means learning to reverse the noise addition process. The model sees a noisy image xt at a random timestep t and must predict what noise was added. This simple objective — predicting ϵ — emerges naturally from the evidence lower bound (ELBO) on the log-likelihood.
DDPM Training Step
Timestep500
x₀ε (actual)ε̂ (predicted)
Explore: DDPM trains a network to predict the noise ε added at timestep t. The reparameterization xₜ = x₀ + ε√βₜ lets us sample xₜ directly without simulating all prior steps.
Each training step only evaluates one random timestep t.
Loss Weighting Strategies
Uniform weighting (Lsimple): All timesteps weighted equally. Emphasizes large t (high noise) where MSE is large.
SNR weighting: Weight by signal-to-noise ratio:
w(t)=1−αˉtαˉt=SNR(t).(7)
Min-SNR weighting (Hang et al., 2023): Clip the SNR weight:
w(t)=min(SNR(t),γ),γ=5.(8)
Prevents early timesteps (low noise, high SNR) from dominating the loss.
P2 weighting: Emphasize perceptually important timesteps (mid-range noise).
Variance Prediction (Improved DDPM)
Standard DDPM: Fixed variance σt2=βt or σt2=β~t=1−αˉt1−αˉt−1βt.
Improved DDPM (Nichol & Dhariwal, 2021): Learn the variance as interpolation in log-space:
Σθ(xt,t)=exp(vlogβt+(1−v)logβ~t),(9)
where v=sigmoid(vθ(xt,t)) is predicted by the network.
Training: Use a hybrid loss: Lsimple for the mean + LVLB for the variance (with stop-gradient on the mean prediction).
Result: Better log-likelihoods and improved sample quality, especially with fewer sampling steps.
Common Pitfalls
Pitfall 1. Using the VLB loss directly for training. The prefactors in Lt create highly non-uniform gradient magnitudes across timesteps. Lsimple (uniform weighting) trains better empirically.
Pitfall 2. Forgetting that t is sampled uniformly. Each training step only sees one timestep — the network must generalize across all T timesteps from random sampling.
Pitfall 3. Confusing x0-prediction with ϵ-prediction. They're equivalent but have different numerical properties: ϵ-prediction is better at high noise, x0-prediction at low noise.
Summary
DDPM training maximizes a variational lower bound on logp(x0).
The VLB decomposes into per-timestep KL terms between Gaussians.
Simplification: predict the added noise ϵ with an MSE loss.
Uniform loss weighting works well; min-SNR weighting improves convergence.
Learned variance (Improved DDPM) improves log-likelihood and few-step sampling.
Exercises
Exercise 1. Derive μ~t (equation 3) from q(xt−1∣xt,x0) using Bayes' rule on two Gaussians.
Exercise 2. Show that Lsimple (equation 6) differs from LVLB only by a time-dependent weighting factor.
Exercise 3. Prove that ϵ-prediction and x0-prediction are equivalent parameterizations.
Exercise 4. Compute the SNR at t=0,T/4,T/2,3T/4,T for a linear noise schedule with β1=10−4,βT=0.02.
Exercise 5. Explain why learning the variance requires a hybrid loss with stop-gradient.