Key ideas
- Forward process (fixed). DDPM corrupts data over steps with . Each is a variance (the added noise has standard deviation ), and the schedule is a set of constants, so this "encoder" has no trainable parameters1. Shrinking by keeps unit-variance data at unit variance.
- Closed form. With and , one can jump straight from to any , so training never simulates the chain1. DDPM uses and a linear schedule from to , which leaves : is almost, but not exactly, pure noise1.
- Reverse process (learned). A network , usually a U-Net with a time embedding, is trained to predict the noise that produced 1. The latents have the same dimension as the data.
- Training (Algorithm 1): pick , and , build in closed form, take a gradient step on . This drops the per-step weights of the variational bound, which down-weights the easy small- terms and improved sample quality1.
- Sampling (Algorithm 2): start from and apply the learned denoising step for , adding fresh noise except at the last step: network evaluations in sequence1.
- Schedules. For and images the linear schedule destroys information too early: the end of the forward process is so noisy that skipping up to 20% of the reverse process barely hurts. The cosine schedule changes slowly near and 2.
- Score view. The score points uphill in density; for it is . In continuous time the forward process is an SDE, and running the reverse-time SDE or the deterministic probability-flow ODE from to 0 passes through the same marginals ; both need only the score, which a network learns by denoising3. A noise predictor is a scaled score: since , the optimal 7.
- DDIM uses non-Markovian forward processes with the same training objective, so a model trained as a DDPM can be reused unchanged. Its sampler can skip steps, and with (all ) it is deterministic, mapping each to one 4.
- Classifier-free guidance. One network learns both and the unconditional by replacing the condition with a null token with probability during training; sampling extrapolates away from the unconditional prediction5.
- Latent diffusion (LDM). An autoencoder is trained first and can be reused; it downsamples an image by a factor to a latent that keeps its 2-D layout. A time-conditional U-Net runs the whole diffusion in latent space, prompts enter through cross-attention (queries from U-Net features, keys and values from the encoded prompt ), and decodes once at the end6.
Formulas
- Forward posterior: with 1.
- Clean-data estimate: .
- Reverse-time SDE and probability-flow ODE for 3: and . Stepping backwards by therefore adds .
- Classifier-free guidance5: ; is plain conditional sampling.
- LDM with factor and latent channels: times fewer values, e.g. 48 for , 6.
Worked example
Schedule , so . Take and noise :
- ; given , has mean 0.805 and variance 0.352.
- A perfect noise predictor () recovers ; a prediction of 0.8 would give .
- Posterior variance of given and : , much smaller than , because is known too.
- Guidance with , , : , pushed beyond the conditional prediction.
In code
import torch
T = 1000
betas = torch.linspace(1e-4, 0.02, T) # DDPM linear schedule
alphas_bar = torch.cumprod(1 - betas, dim=0) # index i holds alpha_bar_{i+1}
print(round(alphas_bar[-1].sqrt().item(), 4)) # 0.0064
x0 = torch.randn(8, 3, 32, 32) # a batch of "images"
t = torch.randint(0, T, (8,)) # one random step per example
eps = torch.randn_like(x0)
ab = alphas_bar[t].view(-1, 1, 1, 1) # broadcast over C, H, W
xt = ab.sqrt() * x0 + (1 - ab).sqrt() * eps # jump straight to x_t
eps_model = lambda x, t: torch.zeros_like(x) # stand-in for the U-Net
loss = ((eps - eps_model(xt, t)) ** 2).mean() # L_simple
print(xt.shape, round(loss.item(), 1)) # torch.Size([8, 3, 32, 32]) 1.0
Common pitfalls
- is the variance of the added noise, not its standard deviation; the noise is scaled by 1.
- The forward process is not learned and is not simulated step by step during training; comes from the closed form1.
- The network's target in is the noise , not and not , although can be computed from it.
- Undoing one step divides by ; is the estimate of , not of .
- DDPM sampling needs one network call per step, in sequence; unlike a VAE decoder it is not a single pass. DDIM cuts the number of steps without retraining4.
- in classifier-free guidance gives the ordinary conditional model, not an unconditional one; the unconditional prediction comes from the null token5.
- Moving with score in the reverse SDE walks downhill in density, away from the data; the sign is when stepping backwards in time3.
- An LDM runs its decoder once at the end, not at every denoising step, and its latent is a small image-shaped tensor, not a flat vector6.
References
- Ho, Jain & Abbeel (2020), Denoising Diffusion Probabilistic Models, arXiv:2006.11239 — Sec. 2 Background (Eqs. 2, 4, 6–7); Sec. 3.1 Forward process and L_T; Sec. 3.2 (Eq. 11, Algorithms 1–2); Sec. 3.4 Simplified training objective; Sec. 4 Experiments
- Nichol & Dhariwal (2021), Improved Denoising Diffusion Probabilistic Models, arXiv:2102.09672 — Sec. 3.2 Improving the Noise Schedule
- Song et al. (2021), Score-Based Generative Modeling through Stochastic Differential Equations, arXiv:2011.13456 — Sec. 3.2 Generating samples by reversing the SDE; Sec. 3.3 Estimating scores for the SDE; Sec. 4.3 Probability flow and connection to neural ODEs
- Song, Meng & Ermon (2021), Denoising Diffusion Implicit Models, arXiv:2010.02502 — Sec. 3 Variational inference for non-Markovian forward processes; Sec. 4 Sampling from Generalized Generative Processes (4.1–4.2); Sec. 5 Experiments (Eq. 16, η)
- Ho & Salimans (2022), Classifier-Free Diffusion Guidance, arXiv:2207.12598 — Sec. 3.2 Classifier-free guidance (Eq. 6, Algorithm 1)
- Rombach et al. (2022), High-Resolution Image Synthesis with Latent Diffusion Models, arXiv:2112.10752 — Sec. 1 Introduction (contributions); Sec. 3.1 Perceptual Image Compression; Sec. 3.2 Latent Diffusion Models; Sec. 3.3 Conditioning Mechanisms
- Wikipedia: Diffusion model — Score-based generative model › Their equivalence