Skip to main content
Open In Colab

Why DDIM

In the DDPM tutorial you trained a noise predictor ϵθ(xt,t)\epsilon_\theta(x_t, t) and used the stochastic DDPM reverse chain to generate samples. Two practical pain points come up immediately:
  1. It is slow. DDPM samples by stepping through every timestep TT11T \to T-1 \to \dots \to 1. With T=500T=500 or T=1000T=1000 that is hundreds of network calls per sample.
  2. It is non-deterministic. Even with a fixed initial noise xTx_T, the reverse chain injects fresh noise at each step, so you cannot reproduce a specific sample or do clean latent interpolation.
DDIM (Song, Meng, Ermon, 2020) addresses both with a single trick: a non-Markovian forward process that has the same per-step marginals q(xtx0)q(x_t \mid x_0) as DDPM. That means the same trained model ϵθ\epsilon_\theta can be reused, but with a different sampler that:
  • Lets you skip timesteps (e.g. take 50 steps instead of 500, a 10× speedup).
  • Has a tunable noise level η[0,1]\eta \in [0, 1] where η=1\eta = 1 recovers DDPM and η=0\eta = 0 is fully deterministic.
The deterministic case turns the diffusion model into an invertible map between Gaussian noise and data, which is what makes things like latent-space arithmetic and image editing possible.

Same target distribution as the DDPM tutorial

The 3-cluster MoG, seed 42, 300 points. We then train the same MLP noise predictor with the same DDPM objective.
Output from cell 2

Forward (noising) process

Same fixed Markov noising chain as DDPM: q(xtx0)=N ⁣(xt;αˉtx0,(1αˉt)I)q(x_t \mid x_0) = \mathcal{N}\!\left(x_t;\sqrt{\bar\alpha_t}\,x_0,(1-\bar\alpha_t)I\right). We visualize a few specific timesteps so the noise schedule is concrete before training.
Output from cell 4

Train the noise predictor (same architecture and objective as DDPM)

DDIM and DDPM share the training step, only the sampler differs.

The DDIM update rule

Given the trained ϵθ\epsilon_\theta, define a strictly increasing sub-sequence τ=(τ1<τ2<<τS){1,,T}\tau = (\tau_1 < \tau_2 < \dots < \tau_S) \subseteq \{1, \dots, T\}. The DDIM reverse step from xτix_{\tau_i} to xτi1x_{\tau_{i-1}} is xτi1=αˉτi1x^0  +  1αˉτi1στi2  ϵθ(xτi,τi)  +  στizτi,zτiN(0,I)x_{\tau_{i-1}} = \sqrt{\bar\alpha_{\tau_{i-1}}} \,\hat x_0 \;+\; \sqrt{1 - \bar\alpha_{\tau_{i-1}} - \sigma_{\tau_i}^2}\; \epsilon_\theta(x_{\tau_i}, \tau_i) \;+\; \sigma_{\tau_i}\, z_{\tau_i}, \quad z_{\tau_i} \sim \mathcal{N}(0, I) with the predicted clean sample x^0=xτi1αˉτiϵθ(xτi,τi)αˉτi\hat x_0 = \frac{x_{\tau_i} - \sqrt{1-\bar\alpha_{\tau_i}}\, \epsilon_\theta(x_{\tau_i}, \tau_i)}{\sqrt{\bar\alpha_{\tau_i}}} and the per-step noise scale στi  =  η1αˉτi11αˉτi1αˉτiαˉτi1\sigma_{\tau_i} \;=\; \eta \, \sqrt{\frac{1-\bar\alpha_{\tau_{i-1}}}{1-\bar\alpha_{\tau_i}}} \, \sqrt{1 - \frac{\bar\alpha_{\tau_i}}{\bar\alpha_{\tau_{i-1}}}} Two regimes:
  • η=1\eta = 1, full noise. The sampler becomes equivalent to DDPM (after accounting for sub-sequence corrections).
  • η=0\eta = 0, deterministic. The reverse step is a pure ODE-like update, zτiz_{\tau_i} disappears, and the same xTx_T always produces the same x0x_0.
Because the model was trained on the marginals q(xtx0)q(x_t \mid x_0) (not the chain transitions), it does not care which sampler we use at inference time.

DDIM in 50 steps versus DDPM-equivalent in 500 steps

Three samplers, same model, 1000 generated points each:
  • DDIM η=0, 50 steps, fast, deterministic.
  • DDIM η=1, 500 steps, equivalent to DDPM, sanity check.
  • DDIM η=0, 500 steps, deterministic with the full timestep grid.
Output from cell 8

Determinism: same noise, same sample

With η=0\eta = 0 the sampler is a deterministic function of the initial noise xTx_T. Run it twice with the same xTx_T and you get bit-identical outputs, regardless of how many steps you take.
Output from cell 10

Latent interpolation: slerp on xTx_T

Because η=0\eta = 0 DDIM is a deterministic invertible map, you can pick two endpoints in noise space and walk a path between them; each intermediate noise decodes to a coherent point in data space. The right path on the unit sphere is spherical linear interpolation (slerp), which preserves the Gaussian magnitude.
Output from cell 12

Connections to other concepts

  • Sampler decoupling. Training trains; sampling samples. DDIM proves you can swap samplers freely as long as marginals are preserved. Modern stacks ship many samplers (DDIM, DPM-Solver, Euler, Heun, …) on top of the same DDPM-trained network.
  • Step count is a knob, not a constant. Image-generation pipelines routinely use 20-50 DDIM steps in production where DDPM would take 1000.
  • Deterministic = invertible. η=0\eta = 0 DDIM gives you a noise-to-data map you can run forwards and backwards, enabling editing and interpolation.
  • Bridge to flows and ODEs. Deterministic DDIM is the discretization of a probability-flow ODE. That connection underlies most of the recent diffusion-model speedup work (consistency models, rectified flow, …).
  • Score-based unification. The Score MoG Tutorial makes that ODE bridge concrete: train sθ(x,σ)s_\theta(x, \sigma) on the same MoG, then sample via annealed Langevin or the reverse-time SDE. Deterministic DDIM is the probability-flow ODE limit of that score-SDE.

References

  1. Song, Meng, Ermon. Denoising Diffusion Implicit Models. ICLR 2021. arxiv.org/abs/2010.02502
  2. Ho, Jain, Abbeel. Denoising Diffusion Probabilistic Models. NeurIPS 2020. arxiv.org/abs/2006.11239
  3. Song et al. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021. arxiv.org/abs/2011.13456

PyTorch reference