Definition
Denoising diffusion implicit model (DDIM) is a sampler, and the generative process behind it, introduced by Jiaming Song, Chenlin Meng and Stefano Ermon, "Denoising Diffusion Implicit Models" (ICLR 2021). It uses a network trained exactly as in Denoising diffusion probabilistic models (DDPM). Each step first predicts the clean sample , then re-noises it to the next, lower noise level along the predicted noise direction, plus a fresh noise term of size . A parameter scales . recovers DDPM-style ancestral sampling, and gives a deterministic map from to : an implicit generative model. Steps can skip along any increasing sub-sequence of noise levels.
DDPM needs one network evaluation for each of its steps, because its reverse process inverts a Markov chain one small step at a time. The paper estimates about 20 hours to sample 50,000 images of size 32×32 from a DDPM on an Nvidia 2080 Ti GPU, against less than a minute for a GAN. Song, Meng and Ermon noticed that the DDPM loss depends only on the marginals , not on the joint forward process. Any forward process with the same marginals has a variational objective that also minimises, so a trained DDPM network already serves all of them. They built a family of such processes, indexed by the noise level , whose reverse steps can be taken with big jumps. On CIFAR-10, 50 deterministic steps reach FID 4.67, against 3.17 for DDPM's full 1000 steps. That is a 20× reduction in network calls without retraining.
A non-Markovian forward process with the same marginals
- the DDPM cumulative product; the DDIM paper writes it
- the noise that produced from
- a free choice for each ; the mean is constructed so that for every , whatever is
The forward process that follows from Bayes' rule depends on , so it is not Markovian. That does not matter, because only the marginals enter the loss. The paper's Theorem 1 states that the variational objective of each member equals a weighted noise-prediction loss plus a constant. If the network does not share parameters across , the optimum of is the optimum of every . In practice the shared-parameter DDPM network is simply reused.
The sampling step
The generative process replaces the unknown by the network's prediction and the noise by :
- , the posterior-mean estimate of the clean sample
- re-uses the predicted noise to place the sample at the right noise level for step
- fresh noise; the deterministic part and the fresh part together have variance
- interpolates between DDPM-style ancestral sampling and the deterministic sampler
- equals the DDPM posterior variance for adjacent steps, and the forward process becomes Markovian again
- the paper also tests , DDPM's larger variance ; it is the best choice at 1000 steps but very poor with few steps
Skipping steps
Nothing in the derivation requires the steps to be adjacent. Pick an increasing sub-sequence of with , and define the forward process only on those indices. Its marginals are still , so the same network applies. Sampling replaces by and by in the update, giving network calls instead of . The paper uses evenly spaced (linear) or quadratically spaced sub-sequences. Song et al. report that DDIM produces high-quality samples 10× to 50× faster in wall-clock time than DDPM.
The deterministic sampler degrades far more gracefully than the stochastic one as shrinks. With few steps each update is large, and fresh noise of size that the next few steps cannot remove ends up in the sample. With the only error is the discretisation error of a smooth trajectory.
The ODE behind η = 0
- the sample rescaled so that it reads "data plus noise of std ":
- noise-to-signal ratio, ; the paper writes
- the update divided by : exactly one Euler step in
- the ODE it discretises; it is the probability-flow ODE of the variance-exploding SDE of Song et al. (see Score-based generative models)
Because DDIM takes Euler steps in rather than in , its error is smaller where changes little with . DPM-Solver (Lu et al., NeurIPS 2022) shows that DDIM is its first-order case and adds higher-order steps, reaching good quality in about 10–20 evaluations. An ODE also defines an invertible map, which gives DDIM two abilities DDPM lacks.
Inversion, consistency and interpolation
Inversion. Running the update upward, , encodes a real image into a latent that decodes back to it. The paper shows the reconstruction error falls as grows. Inversion is the basis of most diffusion image-editing methods: invert, change the condition, decode. Consistency. With the same decoded with different gives images with the same high-level content, so acts as a latent code. Interpolation. Spherical interpolation between two latents, , decodes to a smooth semantic morph. With fresh noise at every step makes both properties fail.
| sampler | S = 10 | S = 20 | S = 50 | S = 100 | S = 1000 |
|---|---|---|---|---|---|
| η = 0 (DDIM) | 13.36 | 6.84 | 4.67 | 4.16 | 4.04 |
| η = 1 (σ² = β̃) | 41.07 | 18.36 | 8.01 | 5.78 | 4.73 |
| σ̂ (DDPM, σ² = β) | 367.43 | 133.37 | 32.72 | 9.99 | 3.17 |
Inversion and interpolation need the deterministic sampler, so they always use η = 0.
Worked example: one step at three values of η
| η | σ | √(1−ᾱ_s−σ²) | √ᾱ_s | deterministic part of x_s |
|---|---|---|---|---|
| 0 | 0 | 0.6899 | 0.7239 | 0.3411 |
| 0.5 | 0.3313 | 0.6051 | 0.7239 | 0.3328 |
| 1 | 0.6626 | 0.1920 | 0.7239 | 0.2923 |
Reading the table, then a full deterministic run
- 1 and . Predicted clean sample: .
- 2: , with no randomness. The noise part has variance , the full noise variance at , all of it carried over from .
- 3: , so of the noise variance is fresh noise and only is carried over from . A 250-step jump with throws away almost all the information in about its own noise.
- 4Deterministic decoding of with steps gives for , for , for , for , for and for . With the result is , close to the data mean . From about 10 steps on the trajectory has chosen the mode at and only refines.
1import torch23T = 10004abar = torch.cumprod(1 - torch.linspace(1e-4, 0.02, T, dtype=torch.float64), 0)5A = lambda t: abar[t - 1] if t > 0 else torch.tensor(1.0, dtype=torch.float64) # ᾱ_0 = 167def ddim_step(eps_model, x, t, s, eta=0.0):8 """One generalised step from t to s < t (eta = 0: DDIM, eta = 1: DDPM-like)."""9 at, as_ = A(t), A(s)10 e = eps_model(x, t)11 x0 = (x - (1 - at).sqrt() * e) / at.sqrt() # predicted x012 sig = eta * ((1 - as_) / (1 - at) * (1 - at / as_)).sqrt()13 return as_.sqrt() * x0 + (1 - as_ - sig**2).sqrt() * e + sig * torch.randn_like(x)1415def ddim_sample(eps_model, xT, S=50, eta=0.0):16 taus = torch.linspace(0, T, S + 1).round().long().tolist() # [0, 20, 40, ..., 1000] for S = 5017 x = xT18 for i in range(S, 0, -1):19 x = ddim_step(eps_model, x, taus[i], taus[i - 1], eta)20 return x2122def ddim_invert(eps_model, x0, S=50):23 """Run the eta = 0 update upward (x0 -> x_T), using ε at the current, less noisy step."""24 taus = torch.linspace(0, T, S + 1).round().long().tolist()25 taus[0] = 1 # ε is not defined at t = 026 x = x027 for i in range(S):28 t, s = taus[i], taus[i + 1]29 at, as_ = A(t), A(s)30 e = eps_model(x, t)31 x = as_.sqrt() * (x - (1 - at).sqrt() * e) / at.sqrt() + (1 - as_).sqrt() * e32 return x3334# A model we can write down exactly: data x0 ~ N(m, s² I) gives ε*(x_t, t) = E[ε | x_t] in closed form.35m, s2 = torch.tensor([0.5, -1.0], dtype=torch.float64), 0.2**236def eps_star(x, t):37 a = A(t)38 return (1 - a).sqrt() * (x - a.sqrt() * m) / (a * s2 + 1 - a)3940torch.manual_seed(0)41xT = torch.randn(4096, 2, dtype=torch.float64)42x20, x1000 = ddim_sample(eps_star, xT, S=20), ddim_sample(eps_star, xT, S=1000)43print(x20.shape) # torch.Size([4096, 2])44print(x20.std(0).tolist(), x1000.std(0).tolist()) # ≈ [0.140, 0.140] and ≈ [0.198, 0.199]; true std 0.245print(torch.equal(x20, ddim_sample(eps_star, xT, S=20))) # True: eta = 0 is deterministic given x_T46z = ddim_invert(eps_star, x1000[:8], S=1000)47rec = ddim_sample(eps_star, z, S=1000)48print((z - xT[:8]).abs().max().item() < 0.05, (rec - x1000[:8]).abs().max().item() < 0.01) # True TrueUse when
- +No retraining: reuses any DDPM-trained noise predictor
- +10–50× fewer network calls for similar quality; FID 4.67 at 50 steps on CIFAR-10
- +Deterministic (η = 0): the same x_T always gives the same image, at any step count
- +Invertible: encodes real images to latents for reconstruction, editing and interpolation
Avoid when
- −At the full 1000 steps it is slightly worse than DDPM with σ² = β (FID 4.04 against 3.17)
- −First-order: below about 10 steps quality drops quickly; higher-order solvers do better
- −Inversion is approximate and degrades with few steps and strong guidance
- −Deterministic sampling cannot correct its own errors with noise, unlike stochastic samplers
Check yourself
Why can DDIM use a network trained with DDPM's L_simple, without retraining?
Check yourself
A DDIM step goes from t = 500 to s = 250 with η = 1. Compared with η = 0, what changes?
Remember
- ✓DDIM step: with and any .
- ✓: is DDPM-like (), is deterministic.
- ✓Same marginals as DDPM, non-Markovian forward process, so the DDPM-trained network is reused unchanged on any step sub-sequence.
- ✓η = 0 is an Euler discretisation of the probability-flow ODE: it gives inversion x₀ → x_T, consistent latents, and slerp interpolation.
- ✓CIFAR-10 FID: 13.36 / 6.84 / 4.67 / 4.16 at 10 / 20 / 50 / 100 steps (η = 0), against 3.17 for DDPM at 1000 steps; 10–50× faster.