DDIM & Accelerated Sampling
Denoising Diffusion Implicit Models: deterministic sampling, the DDIM update rule, connection to probability flow ODE, DPM-Solver, consistency models, and reducing sampling from 1000 to 4 steps.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- The DDPM Sampling Bottleneck
- DDIM: Deterministic Sampling
- The DDIM Update Rule
- Probability Flow ODE
- DPM-Solver: High-Order ODE Solvers
- Consistency Models
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive the DDIM update rule and show it's a non-Markovian generalization of DDPM.
- Prove that DDIM with is deterministic (same noise → same image).
- Connect DDIM to the probability flow ODE.
- Explain how DPM-Solver achieves high quality in 10-20 steps.
- Describe consistency models and single-step generation.
Notation
- — stochasticity parameter (DDIM)
- — subsequence of timesteps for accelerated sampling
- — number of sampling steps ()
Core Intuition
DDPM requires sequential denoising steps for high-quality samples — far too slow for practical use. DDIM shows that by making the process deterministic (removing stochasticity), we can skip timesteps without loss of quality. The key insight: the DDPM training objective is compatible with a broader family of reverse processes, including non-Markovian ones that allow arbitrary step sizes.
DDIM Deterministic Sampling
The DDPM Sampling Bottleneck
DDPM sampling: .
Problem: Must go through all steps sequentially. Each step requires one neural network evaluation. Total: 1000 forward passes for one image.
Naive subsampling (skip steps): Use every -th step. Quality degrades rapidly — the stochastic noise accumulates incorrectly.
DDIM: Deterministic Sampling
Key insight (Song et al., 2020): The DDPM training loss depends only on the marginals , not on the joint . We can define a different (non-Markovian) joint that has the same marginals but allows larger steps.
DDIM defines:
When : completely deterministic (no noise added). When : recovers DDPM.
The DDIM Update Rule
Setting as the interpolation parameter:
Interpretation:
- First predict from using the noise estimate.
- Then interpolate toward at the noise level of step .
- Optionally add noise for stochasticity.
Accelerated sampling: Choose a subsequence with . Apply the DDIM update only at these timesteps. Works because the formula is valid for any step size.
Probability Flow ODE
In the continuous-time limit, DDIM () corresponds to the probability flow ODE:
where define the forward SDE. This ODE has the same marginals as the stochastic process but is deterministic.
Consequence: Any ODE solver (Euler, Runge-Kutta, etc.) can be used for sampling. Higher-order solvers = fewer steps for same quality.
DPM-Solver: High-Order ODE Solvers
DPM-Solver (Lu et al., 2022): Apply high-order methods to the probability flow ODE.
DPM-Solver-2 (second-order): Uses two function evaluations per step (analogous to Heun's method):
DPM-Solver++ (third-order): Three evaluations per step, achieving excellent quality in 10–20 steps.
Result: DPM-Solver with 20 steps ≈ DDPM with 1000 steps in FID quality.
Consistency Models
Radical approach (Song et al., 2023): Learn a model that maps any noisy point directly to in a single step.
Consistency property: For any two points on the same ODE trajectory, the model should produce the same output:
Training: Distill from a pre-trained diffusion model or train from scratch with the consistency loss.
Result: Single-step generation (one forward pass → image). Quality below multi-step diffusion but dramatically faster.
Common Pitfalls
Pitfall 1. Using DDPM-trained models with DDIM sampling without any modification. It works (same training objective), but models trained with noise prediction may not be optimal for few-step DDIM — v-prediction parameterization works better.
Pitfall 2. Setting too small without adjusting the noise schedule. For steps, the effective noise schedule is very aggressive; requires schedule adjustment.
Pitfall 3. Assuming consistency models replace diffusion. They trade quality for speed — multi-step diffusion still produces better samples when latency allows.
Summary
- DDIM generalizes DDPM to non-Markovian reverse processes with tunable stochasticity.
- At : deterministic mapping from noise to image (invertible).
- Allows arbitrary step skipping: 50 steps ≈ 1000 steps in quality.
- Probability flow ODE connects to classical numerical methods.
- DPM-Solver (high-order ODE solver): 10–20 steps for excellent quality.
- Consistency models: single-step generation via trajectory consistency.
Exercises
Exercise 1. Derive the DDIM update (equation 2) from the non-Markovian forward process definition.
Exercise 2. Verify that DDIM with recovers the DDPM update.
Exercise 3. For a linear noise schedule, compute the effective noise levels when sampling with evenly-spaced steps from .
Exercise 4. Explain why DDIM is invertible (can encode images to noise and back) while DDPM is not.
Exercise 5. Derive the second-order DPM-Solver update rule from the midpoint method applied to the probability flow ODE.