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.

Advanced

Prerequisites

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. The DDPM Sampling Bottleneck
  5. DDIM: Deterministic Sampling
  6. The DDIM Update Rule
  7. Probability Flow ODE
  8. DPM-Solver: High-Order ODE Solvers
  9. Consistency Models
  10. Common Pitfalls
  11. Summary
  12. Exercises

Learning Objectives

  1. Derive the DDIM update rule and show it's a non-Markovian generalization of DDPM.
  2. Prove that DDIM with η=0\eta=0 is deterministic (same noise → same image).
  3. Connect DDIM to the probability flow ODE.
  4. Explain how DPM-Solver achieves high quality in 10-20 steps.
  5. Describe consistency models and single-step generation.

Notation

  • η[0,1]\eta \in [0, 1] — stochasticity parameter (DDIM)
  • τ=(t1,,tS)\tau = (t_1, \ldots, t_S) — subsequence of timesteps for accelerated sampling
  • SS — number of sampling steps (STS \ll T)

Core Intuition

DDPM requires T=1000T = 1000 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

η=0.0 · 20 steps
η (stoch.)
0.00
Steps
20
DDPM (stochastic)DDIM (η=0)
Explore: DDIM (η=0) takes straight deterministic paths, enabling 10–50 step sampling. η=1 recovers DDPM stochasticity. Fewer steps work because paths don't wander.

The DDPM Sampling Bottleneck

DDPM sampling: xt1=11βt(xtβt1αˉtϵθ(xt,t))+σtz\mathbf{x}_{t-1} = \frac{1}{\sqrt{1-\beta_t}}(\mathbf{x}_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}}\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)) + \sigma_t\mathbf{z}.

Problem: Must go through all T=1000T=1000 steps sequentially. Each step requires one neural network evaluation. Total: 1000 forward passes for one image.

Naive subsampling (skip steps): Use every kk-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 q(xtx0)q(\mathbf{x}_t|\mathbf{x}_0), not on the joint q(x1:Tx0)q(\mathbf{x}_{1:T}|\mathbf{x}_0). We can define a different (non-Markovian) joint that has the same marginals but allows larger steps.

DDIM defines:

qσ(xt1xt,x0)=N(αˉt1x0+1αˉt1σt2xtαˉtx01αˉt,  σt2I).(1)q_\sigma(\mathbf{x}_{t-1}|\mathbf{x}_t, \mathbf{x}_0) = \mathcal{N}\left(\sqrt{\bar{\alpha}_{t-1}}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_{t-1}-\sigma_t^2}\cdot\frac{\mathbf{x}_t - \sqrt{\bar{\alpha}_t}\mathbf{x}_0}{\sqrt{1-\bar{\alpha}_t}}, \; \sigma_t^2\mathbf{I}\right). \tag{1}

When σt=0\sigma_t = 0: completely deterministic (no noise added). When σt=(1αˉt1)/(1αˉt)βt\sigma_t = \sqrt{(1-\bar{\alpha}_{t-1})/(1-\bar{\alpha}_t)}\sqrt{\beta_t}: recovers DDPM.


The DDIM Update Rule

Setting η[0,1]\eta \in [0,1] as the interpolation parameter:

xt1=αˉt1(xt1αˉtϵθ(xt,t)αˉt)predicted x0+1αˉt1σt2ϵθ(xt,t)+σtϵt.(2)\boxed{\mathbf{x}_{t-1} = \sqrt{\bar{\alpha}_{t-1}}\underbrace{\left(\frac{\mathbf{x}_t - \sqrt{1-\bar{\alpha}_t}\,\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)}{\sqrt{\bar{\alpha}_t}}\right)}_{\text{predicted }\mathbf{x}_0} + \sqrt{1-\bar{\alpha}_{t-1}-\sigma_t^2}\cdot\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) + \sigma_t\boldsymbol{\epsilon}_t.} \tag{2}

Interpretation:

  • First predict x^0\hat{\mathbf{x}}_0 from xt\mathbf{x}_t using the noise estimate.
  • Then interpolate toward x^0\hat{\mathbf{x}}_0 at the noise level of step t1t-1.
  • Optionally add noise σt\sigma_t for stochasticity.

Accelerated sampling: Choose a subsequence τ=(t1,,tS)\tau = (t_1, \ldots, t_S) with STS \ll T. 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 (η=0\eta=0) corresponds to the probability flow ODE:

dx=[f(x,t)12g(t)2xlogpt(x)]dt,(3)d\mathbf{x} = \left[f(\mathbf{x}, t) - \frac{1}{2}g(t)^2\nabla_\mathbf{x}\log p_t(\mathbf{x})\right]dt, \tag{3}

where f,gf, g define the forward SDE. This ODE has the same marginals pt(x)p_t(\mathbf{x}) 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):

xt1=ExactUpdate(xt)+12[ϵθ(xt,t)ϵθ(x^t1/2,t1/2)]Δt.(4)\mathbf{x}_{t-1} = \text{ExactUpdate}(\mathbf{x}_t) + \frac{1}{2}\left[\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) - \boldsymbol{\epsilon}_\theta(\hat{\mathbf{x}}_{t-1/2}, t-1/2)\right] \cdot \Delta t. \tag{4}

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 xt\mathbf{x}_t directly to x0\mathbf{x}_0 in a single step.

Consistency property: For any two points on the same ODE trajectory, the model should produce the same output:

fθ(xt,t)=fθ(xt,t)t,t on the same trajectory.(5)f_\theta(\mathbf{x}_t, t) = f_\theta(\mathbf{x}_{t'}, t') \quad \forall t, t' \text{ on the same trajectory}. \tag{5}

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 SS too small without adjusting the noise schedule. For S<10S < 10 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 η=0\eta=0: 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 σt=(1αˉt1)/(1αˉt)βt\sigma_t = \sqrt{(1-\bar{\alpha}_{t-1})/(1-\bar{\alpha}_t)}\sqrt{\beta_t} recovers the DDPM update.

Exercise 3. For a linear noise schedule, compute the effective noise levels when sampling with S=10S=10 evenly-spaced steps from T=1000T=1000.

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.