SDE & MLE Prep

Diffusion Models in Depth

Q: How are diffusion models trained and sampled? What is classifier-free guidance?

  • Forward process: gradually add Gaussian noise; in closed form x_t = √ᾱ_t · x₀ + √(1 − ᾱ_t) · ε.
  • Training: sample an image, a timestep t and noise ε; the network (U-Net or transformer/DiT) predicts ε from (x_t, t, condition); loss = MSE between true and predicted noise. Simple and stable.
  • Sampling: start from pure noise and iteratively denoise. DDPM needs hundreds to ~1000 steps; DDIM and ODE solvers take 20–50; distillation / consistency models get to 1–4 steps.
  • Conditioning: text embeddings (CLIP/T5) injected via cross-attention. Classifier-free guidance: train with the condition randomly dropped, then sample with ε = ε_uncond + w·(ε_cond − ε_uncond); larger w = closer prompt adherence, less diversity.
  • Latent diffusion (Stable Diffusion): diffuse in a VAE's compressed latent space (e.g. 8× smaller per side) — far cheaper at high resolution.
  • Newer: flow matching / rectified flow (straight-line paths, fewer steps), transformer backbones (DiT), video diffusion with temporal attention.
  • Evaluation: FID (realism vs a reference set), CLIP score (prompt alignment), human preference ratings.