Diffusion Models
Source: CS1674 Ch.18 (Part B). DDPMs (Ho et al. 2020) learn to reverse a gradual noising process; they now rival/exceed GANs in image synthesis. Covers forward/reverse math, conditional & classifier-free guidance, latent diffusion (Stable Diffusion), DDIM, SDXL/SD3, progressive distillation, LCM.
1. DDPM Basics
A diffusion model has two processes:
- Forward (diffusion): gradually add Gaussian noise to a clean image
over steps until it becomes pure noise. - Reverse (denoising): train a network to iteratively remove noise, recovering a sample from the data distribution.
1.1 Forward process (fixed, no learning)
Each step adds a small amount of noise:
where
1.2 Reverse process (learned)
A U-Net
1.3 Training loss (simplified)
The variational bound reduces to a simple noise-prediction objective:
i.e., given a noisy image and its step
1.4 Sampling (reverse iteration)
Start from
Setting
1.5 Score-based view (Song & Ermon 2019)
The gradient of the log-density,
1.6 Implementation details
- Time encoding: sinusoidal positional embeddings or random Fourier features, injected into the U-Net via addition or adaptive (AdaGN) normalization.
- U-Net predicts the noise
(not the image directly).
1.7 GAN vs. Diffusion
| GAN | Diffusion | |
|---|---|---|
| Training | adversarial, unstable, mode collapse | stable, mode-covering |
| Sampling | one forward pass (fast) | many iterative steps (slow) |
| Quality | can be excellent | now matches/exceeds GANs |
Dhariwal & Nichol (2021): class-conditioned DDPMs beat GANs on ImageNet; can sample in as few as 25 steps with FID comparable to BigGAN.
2. Conditional Diffusion
2.1 Classifier guidance
Combine unconditional and conditional scores:
The classifier gradient
2.2 Classifier-free guidance (Ho & Salimans 2021)
Train the model to handle both conditional and unconditional cases (randomly drop the condition with some probability). At sampling, steer between them:
where guidance weight
2.3 Text-guided diffusion
Condition on text
2.4 CLIP (Radford et al. ICML 2021)
Contrastive language–image pre-training: in a batch of
3. Large-Scale Text-to-Image Models
DALL·E 2 (Ramesh et al. 2022)
- CLIP text encoding → generative model produces a CLIP image embedding → diffusion model (GLIDE) conditioned on that embedding + text.
- Cascade: generate 64×64 → upsample to 256×256 → upsample to 1024×1024.
Latent Diffusion Model / Stable Diffusion (Rombach et al. CVPR 2022)
Key idea: train a separate autoencoder to map images to/from a lower-dimensional latent space; run the diffusion model in latent space (far cheaper than pixel space). Conditioning (text, layout, etc.) is incorporated via cross-attention in the U-Net.
Google Imagen (Saharia et al. NeurIPS 2022)
- Text encoder is a large language model (4.6B params, text-only trained).
- Efficient U-Net (2B params); cascade 64→256→1024.
- Classifier-free guidance with dynamic thresholding enables high guidance weights without artifacts.
- Trained on 460M internal + 400M LAION pairs. Outperforms DALL·E 2 on DrawBench for correct attribute binding.
4. Recent Advances (Speed & Quality)
4.1 DDIM — Denoising Diffusion Implicit Models
- DDPM follows a stochastic reverse process; DDIM uses a deterministic one.
- Allows far fewer sampling steps (e.g., 20–50 instead of 1000) with minimal quality loss.
4.2 Stable Diffusion XL (SDXL)
- Separate refiner model; two text encoders; bigger U-Net with more attention blocks and parameters.
- Strongly preferred by users over SD v1.4/1.5/2.1.
4.3 Stable Diffusion 3 (SD3)
- Further architecture improvements for prompt adherence and quality.
4.4 Progressive Distillation (Salimans et al.)
- Distill a multi-step teacher into a student that needs half the steps; repeat to amortize sampling cost.
4.5 Latent Consistency Models (LCM)
- Combine consistency models (Song et al.) with latent diffusion (Luo et al.) → few-step (even 1–4 step) high-resolution generation.
5. Implementation & Ethics
- Fast-moving area; start from HuggingFace
diffusers; popular open models: Stable Diffusion, SDXL, SD3, DeepFloyd IF. - Ethical/legal: deepfakes & misinformation; dataset image rights; artists' rights; the nature of creativity. (See Getty Images lawsuit, NYer/Verge/BBC coverage.)
6. Summary
| Topic | Key formula / idea |
|---|---|
| Forward | |
| Training | |
| Sampling | |
| Guidance | classifier-free: |
| Latent diffusion | run DDPM in autoencoder latent space (Stable Diffusion) |
| Speedups | DDIM, progressive distillation, LCM |
Takeaway: diffusion = learn to reverse gradual noising; predict noise, iterate; condition via cross-attention/CLIP; Stable Diffusion runs it in latent space; DDIM/distillation/LCM make sampling fast.
7. More on the Math
ELBO sketch
The training objective is a variational lower bound on log-likelihood; after reparameterization it simplifies to the noise-prediction loss
Reverse-step parameterization
The reverse mean is parameterized as:
and the score is recovered as
Variance schedules
8. Latent Diffusion Math
Let encoder
This makes training ~an order of magnitude cheaper (lower spatial resolution in latent space) — the basis of Stable Diffusion.
Classifier guidance (math)
The second term is the gradient of a classifier; it pulls samples toward class
9. Consistency Models & Fast Sampling
Consistency models (Song et al.) learn a function
10. SDXL / SD3 Details
- SDXL: base model + a separate refiner; two text encoders (CLIP + OpenCLIP); larger U-Net with more attention; strong user-preference gains over SD v1.5/2.1.
- SD3: improves text rendering and prompt adherence via a better architecture (MM-DiT style) and longer prompts.
Diffusion quality now leads on FID/human preference, with the main drawback being sampling cost — addressed by DDIM, distillation, and LCM.