DDPM Training & the Noise Prediction Objective

Complete derivation of the DDPM training loss: variational lower bound, simplification to noise prediction, loss weighting strategies, training algorithm, and connection to score matching.

Advanced

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. The Variational Lower Bound
  5. Simplification to L-simple
  6. The Noise Prediction Objective
  7. Training Algorithm
  8. Loss Weighting Strategies
  9. Variance Prediction (Improved DDPM)
  10. Common Pitfalls
  11. Summary
  12. Exercises

Learning Objectives

  1. Derive the variational lower bound (VLB) for diffusion models.
  2. Show how the VLB decomposes into per-timestep KL divergence terms.
  3. Prove the simplified noise prediction objective is equivalent.
  4. Explain different loss weighting strategies and their effects.
  5. Derive the learned variance parameterization (Improved DDPM).

Notation

  • βt\beta_t — noise schedule at step tt
  • αˉt=s=1t(1βs)\bar{\alpha}_t = \prod_{s=1}^t (1-\beta_s) — cumulative signal retention
  • ϵθ(xt,t)\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) — noise prediction network
  • Lsimple\mathcal{L}_{\text{simple}} — simplified DDPM loss

Core Intuition

Training a diffusion model means learning to reverse the noise addition process. The model sees a noisy image xt\mathbf{x}_t at a random timestep tt and must predict what noise was added. This simple objective — predicting ϵ\boldsymbol{\epsilon} — emerges naturally from the evidence lower bound (ELBO) on the log-likelihood.

DDPM Training Step

xₜ = x₀ + ε·√βₜx₀ = 0.60+ε = 0.00· √β = 0.1002xₜ = 0.600U-Netε̂ = 0.01L = ||ε − ε̂||² = 0.0000
Timestep
500
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.

The Variational Lower Bound

Start from the marginal log-likelihood:

logpθ(x0)Eq[logpθ(x0:T)q(x1:Tx0)]=LVLB.(1)\log p_\theta(\mathbf{x}_0) \geq \mathbb{E}_{q}\left[\log\frac{p_\theta(\mathbf{x}_{0:T})}{q(\mathbf{x}_{1:T}|\mathbf{x}_0)}\right] = -\mathcal{L}_{\text{VLB}}. \tag{1}

Decompose using the Markov structure:

LVLB=DKL(q(xTx0)p(xT))LT+t=2TDKL(q(xt1xt,x0)pθ(xt1xt))Lt1logpθ(x0x1)L0.(2)\mathcal{L}_{\text{VLB}} = \underbrace{D_{\text{KL}}(q(\mathbf{x}_T|\mathbf{x}_0) \| p(\mathbf{x}_T))}_{L_T} + \sum_{t=2}^T\underbrace{D_{\text{KL}}(q(\mathbf{x}_{t-1}|\mathbf{x}_t, \mathbf{x}_0) \| p_\theta(\mathbf{x}_{t-1}|\mathbf{x}_t))}_{L_{t-1}} - \underbrace{\log p_\theta(\mathbf{x}_0|\mathbf{x}_1)}_{L_0}. \tag{2}

Key insight: Both q(xt1xt,x0)q(\mathbf{x}_{t-1}|\mathbf{x}_t, \mathbf{x}_0) and pθ(xt1xt)p_\theta(\mathbf{x}_{t-1}|\mathbf{x}_t) are Gaussian, so each LtL_t is a KL between Gaussians (closed form).


Simplification to L-simple

The posterior q(xt1xt,x0)q(\mathbf{x}_{t-1}|\mathbf{x}_t, \mathbf{x}_0) is Gaussian with:

μ~t=αˉt1βt1αˉtx0+1βt(1αˉt1)1αˉtxt.(3)\tilde{\boldsymbol{\mu}}_t = \frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\mathbf{x}_0 + \frac{\sqrt{1-\beta_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t. \tag{3}

Parameterize the model mean as:

μθ(xt,t)=11βt(xtβt1αˉtϵθ(xt,t)).(4)\boldsymbol{\mu}_\theta(\mathbf{x}_t, t) = \frac{1}{\sqrt{1-\beta_t}}\left(\mathbf{x}_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}}\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)\right). \tag{4}

The KL divergence LtL_t reduces to:

Lt=βt22σt2(1βt)(1αˉt)E[ϵϵθ(xt,t)2].(5)L_t = \frac{\beta_t^2}{2\sigma_t^2(1-\beta_t)(1-\bar{\alpha}_t)}\mathbb{E}\left[\|\boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)\|^2\right]. \tag{5}

The Noise Prediction Objective

DDPM simplified loss (Ho et al., 2020): Drop the weighting prefactor:

Lsimple=Et,x0,ϵ[ϵϵθ(αˉtx0+1αˉtϵ,t)2].(6)\boxed{\mathcal{L}_{\text{simple}} = \mathbb{E}_{t, \mathbf{x}_0, \boldsymbol{\epsilon}}\left[\|\boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}, t)\|^2\right].} \tag{6}

Steps:

  1. Sample x0pdata\mathbf{x}_0 \sim p_{\text{data}}, tUniform(1,T)t \sim \text{Uniform}(1, T), ϵN(0,I)\boldsymbol{\epsilon} \sim \mathcal{N}(0, \mathbf{I}).
  2. Construct noisy input: xt=αˉtx0+1αˉtϵ\mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}.
  3. Predict noise: ϵ^=ϵθ(xt,t)\hat{\boldsymbol{\epsilon}} = \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t).
  4. Loss: ϵϵ^2\|\boldsymbol{\epsilon} - \hat{\boldsymbol{\epsilon}}\|^2.

Training Algorithm

Algorithm (DDPM Training):

Repeat until convergence:

  1. x0pdata(x)\mathbf{x}_0 \sim p_{\text{data}}(\mathbf{x})
  2. tUniform{1,,T}t \sim \text{Uniform}\{1, \ldots, T\}
  3. ϵN(0,I)\boldsymbol{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})
  4. Compute gradient of ϵϵθ(αˉtx0+1αˉtϵ,t)2\|\boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\boldsymbol{\epsilon}, t)\|^2
  5. Update θ\theta with optimizer step

Key properties:

  • No adversarial training (unlike GANs).
  • Stable optimization (simple MSE loss).
  • Each training step only evaluates one random timestep tt.

Loss Weighting Strategies

Uniform weighting (Lsimple\mathcal{L}_{\text{simple}}): All timesteps weighted equally. Emphasizes large tt (high noise) where MSE is large.

SNR weighting: Weight by signal-to-noise ratio:

w(t)=αˉt1αˉt=SNR(t).(7)w(t) = \frac{\bar{\alpha}_t}{1-\bar{\alpha}_t} = \text{SNR}(t). \tag{7}

Min-SNR weighting (Hang et al., 2023): Clip the SNR weight:

w(t)=min(SNR(t),γ),γ=5.(8)w(t) = \min(\text{SNR}(t), \gamma), \quad \gamma = 5. \tag{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\sigma_t^2 = \beta_t or σt2=β~t=1αˉt11αˉtβt\sigma_t^2 = \tilde{\beta}_t = \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t}\beta_t.

Improved DDPM (Nichol & Dhariwal, 2021): Learn the variance as interpolation in log-space:

Σθ(xt,t)=exp(vlogβt+(1v)logβ~t),(9)\Sigma_\theta(\mathbf{x}_t, t) = \exp(v \log\beta_t + (1-v)\log\tilde{\beta}_t), \tag{9}

where v=sigmoid(vθ(xt,t))v = \text{sigmoid}(\mathbf{v}_\theta(\mathbf{x}_t, t)) is predicted by the network.

Training: Use a hybrid loss: Lsimple\mathcal{L}_{\text{simple}} for the mean + LVLB\mathcal{L}_{\text{VLB}} 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 LtL_t create highly non-uniform gradient magnitudes across timesteps. Lsimple\mathcal{L}_{\text{simple}} (uniform weighting) trains better empirically.

Pitfall 2. Forgetting that tt is sampled uniformly. Each training step only sees one timestep — the network must generalize across all TT timesteps from random sampling.

Pitfall 3. Confusing x0\mathbf{x}_0-prediction with ϵ\boldsymbol{\epsilon}-prediction. They're equivalent but have different numerical properties: ϵ\boldsymbol{\epsilon}-prediction is better at high noise, x0\mathbf{x}_0-prediction at low noise.


Summary

  • DDPM training maximizes a variational lower bound on logp(x0)\log p(\mathbf{x}_0).
  • The VLB decomposes into per-timestep KL terms between Gaussians.
  • Simplification: predict the added noise ϵ\boldsymbol{\epsilon} 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\tilde{\boldsymbol{\mu}}_t (equation 3) from q(xt1xt,x0)q(\mathbf{x}_{t-1}|\mathbf{x}_t, \mathbf{x}_0) using Bayes' rule on two Gaussians.

Exercise 2. Show that Lsimple\mathcal{L}_{\text{simple}} (equation 6) differs from LVLB\mathcal{L}_{\text{VLB}} only by a time-dependent weighting factor.

Exercise 3. Prove that ϵ\boldsymbol{\epsilon}-prediction and x0\mathbf{x}_0-prediction are equivalent parameterizations.

Exercise 4. Compute the SNR at t=0,T/4,T/2,3T/4,Tt=0, T/4, T/2, 3T/4, T for a linear noise schedule with β1=104,βT=0.02\beta_1=10^{-4}, \beta_T=0.02.

Exercise 5. Explain why learning the variance requires a hybrid loss with stop-gradient.