# Denoising diffusion implicit models (DDIM)

> DDIM (Song, Meng and Ermon, ICLR 2021) reuses a DDPM-trained network with non-Markovian processes that keep DDPM's marginals. Its η = 0 member is deterministic, skips steps (10–50× faster) and maps noise to images invertibly, which enables encoding and interpolation.

Source: https://www.mlfoundry.in/learn/denoising-diffusion-implicit-models-ddim  
Section: Deep Learning › Generative Deep Learning Algorithms  
Level: advanced · 14 min read · updated 2026-10-12

**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 $\varepsilon_\theta(x_t,t)$ trained exactly as in **Denoising diffusion probabilistic models (DDPM)**. Each step first predicts the clean sample $\hat x_0$, then re-noises it to the next, lower noise level along the predicted noise direction, plus a fresh noise term of size $\sigma_t$. A parameter $\eta\in[0,1]$ scales $\sigma_t$. $\eta=1$ recovers DDPM-style ancestral sampling, and $\eta=0$ gives a deterministic map from $x_T$ to $x_0$: an **implicit** generative model. Steps can skip along any increasing sub-sequence of noise levels.

DDPM needs one network evaluation for each of its $T=1000$ 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 $q(x_t\mid x_0)$, not on the joint forward process. Any forward process with the same marginals has a variational objective that $L_{\text{simple}}$ also minimises, so a trained DDPM network already serves all of them. They built a family of such processes, indexed by the noise level $\sigma$, 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

$$
q_\sigma(x_{t-1}\mid x_t,x_0)=\mathcal N\!\Big(\sqrt{\bar\alpha_{t-1}}\,x_0+\sqrt{1-\bar\alpha_{t-1}-\sigma_t^2}\cdot\frac{x_t-\sqrt{\bar\alpha_t}\,x_0}{\sqrt{1-\bar\alpha_t}},\ \sigma_t^2I\Big),\qquad q_\sigma(x_T\mid x_0)=\mathcal N\big(\sqrt{\bar\alpha_T}\,x_0,(1-\bar\alpha_T)I\big)
$$

- $\bar\alpha_t$: the DDPM cumulative product; the DDIM paper writes it $\alpha_t$
- $\frac{x_t-\sqrt{\bar\alpha_t}x_0}{\sqrt{1-\bar\alpha_t}}$: the noise $\varepsilon$ that produced $x_t$ from $x_0$
- $\sigma_t$: a free choice for each $t$; the mean is constructed so that $q_\sigma(x_t\mid x_0)=\mathcal N(\sqrt{\bar\alpha_t}x_0,(1-\bar\alpha_t)I)$ for **every** $t$, whatever $\sigma$ is

The forward process $q_\sigma(x_t\mid x_{t-1},x_0)$ that follows from Bayes' rule depends on $x_0$, 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 $J_\sigma$ of each member equals a weighted noise-prediction loss $L_\gamma$ plus a constant. If the network does not share parameters across $t$, the optimum of $L_{\text{simple}}$ is the optimum of every $J_\sigma$. In practice the shared-parameter DDPM network is simply reused.

## The sampling step

The generative process replaces the unknown $x_0$ by the network's prediction and the noise by $\varepsilon_\theta$:

$$
x_{t-1}=\sqrt{\bar\alpha_{t-1}}\underbrace{\Big(\frac{x_t-\sqrt{1-\bar\alpha_t}\,\varepsilon_\theta(x_t,t)}{\sqrt{\bar\alpha_t}}\Big)}_{\text{predicted }x_0}+\underbrace{\sqrt{1-\bar\alpha_{t-1}-\sigma_t^2}\;\varepsilon_\theta(x_t,t)}_{\text{direction pointing to }x_t}+\underbrace{\sigma_t\,z}_{\text{random noise}},\qquad z\sim\mathcal N(0,I)
$$

- $\text{predicted }x_0$: $\hat x_0$, the posterior-mean estimate of the clean sample
- $\text{direction}$: re-uses the predicted noise to place the sample at the right noise level for step $t-1$
- $\sigma_t z$: fresh noise; the deterministic part and the fresh part together have variance $1-\bar\alpha_{t-1}$

$$
\sigma_t(\eta)=\eta\,\sqrt{\frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}}\,\sqrt{1-\frac{\bar\alpha_t}{\bar\alpha_{t-1}}}\qquad\Longrightarrow\qquad \eta=1:\ \sigma_t^2=\tilde\beta_t\ \ (\text{DDPM}),\qquad \eta=0:\ \sigma_t=0\ \ (\text{DDIM})
$$

- $\eta$: interpolates between DDPM-style ancestral sampling and the deterministic sampler
- $\eta=1$: $\sigma_t^2$ equals the DDPM posterior variance $\tilde\beta_t$ for adjacent steps, and the forward process becomes Markovian again
- $\hat\sigma_t$: the paper also tests $\hat\sigma_t=\sqrt{1-\bar\alpha_t/\bar\alpha_{t-1}}$, DDPM's larger variance $\sigma_t^2=\beta_t$; 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 $\tau_1<\dots<\tau_S$ of $\{1,\dots,T\}$ with $\tau_S=T$, and define the forward process only on those indices. Its marginals are still $q(x_{\tau_i}\mid x_0)=\mathcal N(\sqrt{\bar\alpha_{\tau_i}}x_0,(1-\bar\alpha_{\tau_i})I)$, so the same network applies. Sampling replaces $t-1$ by $\tau_{i-1}$ and $t$ by $\tau_i$ in the update, giving $S$ network calls instead of $T$. 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 $S$ shrinks. With few steps each update is large, and fresh noise of size $\sigma$ that the next few steps cannot remove ends up in the sample. With $\eta=0$ the only error is the discretisation error of a smooth trajectory.

## The ODE behind η = 0

$$
\bar x=\frac{x}{\sqrt{\bar\alpha}},\qquad \lambda=\sqrt{\frac{1-\bar\alpha}{\bar\alpha}}:\qquad \bar x_{t-1}=\bar x_t+(\lambda_{t-1}-\lambda_t)\,\varepsilon_\theta(x_t,t)\quad\longleftrightarrow\quad \frac{d\bar x}{d\lambda}=\varepsilon_\theta\Big(\frac{\bar x}{\sqrt{\lambda^2+1}},\ t(\lambda)\Big)
$$

- $\bar x$: the sample rescaled so that it reads "data plus noise of std $\lambda$": $\bar x=x_0+\lambda\varepsilon$
- $\lambda$: noise-to-signal ratio, $1/\sqrt{\mathrm{SNR}}$; the paper writes $\sigma$
- $\text{left}$: the $\eta=0$ update divided by $\sqrt{\bar\alpha_{t-1}}$: exactly one Euler step in $\lambda$
- $\text{right}$: 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 $\lambda$ rather than in $t$, its error is smaller where $\varepsilon_\theta$ changes little with $\lambda$. 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 $\eta=0$ update upward, $x_{\tau_{i+1}}=\sqrt{\bar\alpha_{\tau_{i+1}}}\,\hat x_0(x_{\tau_i})+\sqrt{1-\bar\alpha_{\tau_{i+1}}}\,\varepsilon_\theta(x_{\tau_i},\tau_i)$, encodes a real image $x_0$ into a latent $x_T$ that decodes back to it. The paper shows the reconstruction error falls as $S$ grows. Inversion is the basis of most diffusion image-editing methods: invert, change the condition, decode. **Consistency.** With $\eta=0$ the same $x_T$ decoded with different $S$ gives images with the same high-level content, so $x_T$ acts as a latent code. **Interpolation.** Spherical interpolation between two latents, $x_T(u)=\frac{\sin((1-u)\theta)}{\sin\theta}x_T^{(0)}+\frac{\sin(u\theta)}{\sin\theta}x_T^{(1)}$, decodes to a smooth semantic morph. With $\eta>0$ fresh noise at every step makes both properties fail.

CIFAR-10 FID (lower is better) for the same DDPM-trained model, by number of sampling steps S (Song et al. 2021, Table 1)

| 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 |

> Figure: Two moons built from 20 Gaussians (std σ = 0.06), with the exact noise predictor of the mixture standing in for a perfectly trained DDPM network (linear β, T = 1000). Sample mode: 200 fixed noise vectors x_T are decoded with S evenly spaced steps, and 12 trajectories show one vertex per step. With η = 0 and S = 10 (the default) 68.5% of the samples are within 3σ of the moons, at a mean distance of 2.30σ (the data: 0.88σ). They lie on average 0.174 from where the 1000-step ODE puts the same x_T. With S = 20 the numbers are 91.0% and 0.086, with S = 50 100% and 0.029. S = 1 is a single jump to x̂₀ = E[x₀ | x_T]: every sample collapses near the centre (0% near the data). Raising η keeps the quality similar at each S (η = 1, S = 50: 99.5%) but the samples no longer follow x_T: with η = 1 they lie 1.1 to 1.3 from the ODE solution. Invert mode: 16 data points are encoded with the upward η = 0 update and decoded again. The mean reconstruction error is 0.109 (1.82σ) at S = 20, 0.031 at S = 100 and 0.0032 at S = 1000. Interpolate mode: three slerp paths of 41 points between pairs of x_T are decoded with η = 0. Nearby latents decode to nearby samples, so each path traces a continuous curve along a moon; at S = 50 one path jumps where it crosses from one moon's basin into the other's.

## Worked example: one step at three values of η

Step from t = 500 to s = 250 on the 1-D mixture 0.3·N(−1, 0.12²) + 0.7·N(0.9, 0.2²) at x_t = 0.2, with the exact ε* = 0.0980 and x̂₀ = 0.3778 (computed in Node)

| η | σ | √(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. $\bar\alpha_{500}=0.07859$ and $\bar\alpha_{250}=0.52409$. Predicted clean sample: $\hat x_0=(0.2-\sqrt{0.92141}\cdot0.0980)/\sqrt{0.07859}=0.3778$.
2. $\eta=0$: $x_{250}=0.7239\cdot0.3778+0.6899\cdot0.0980=0.3411$, with no randomness. The noise part has variance $0.6899^2=0.476=1-\bar\alpha_{250}$, the full noise variance at $s=250$, all of it carried over from $\varepsilon^*$.
3. $\eta=1$: $\sigma=0.6626$, so $\sigma^2=0.439$ of the $0.476$ noise variance is fresh noise and only $0.1920^2=0.037$ is carried over from $\varepsilon^*$. A 250-step jump with $\eta=1$ throws away almost all the information in $x_t$ about its own noise.
4. Deterministic decoding of $x_T=0.5$ with $S$ steps gives $x_0=0.3325$ for $S=1$, $0.4587$ for $S=2$, $0.8654$ for $S=5$, $0.9012$ for $S=10$, $0.9217$ for $S=50$ and $0.9289$ for $S=1000$. With $S=1$ the result is $\mathbb E[x_0\mid x_T]$, close to the data mean $0.33$. From about 10 steps on the trajectory has chosen the mode at $0.9$ and only refines.

```python
import torch

T = 1000
abar = torch.cumprod(1 - torch.linspace(1e-4, 0.02, T, dtype=torch.float64), 0)
A = lambda t: abar[t - 1] if t > 0 else torch.tensor(1.0, dtype=torch.float64)  # ᾱ_0 = 1

def ddim_step(eps_model, x, t, s, eta=0.0):
    """One generalised step from t to s < t (eta = 0: DDIM, eta = 1: DDPM-like)."""
    at, as_ = A(t), A(s)
    e = eps_model(x, t)
    x0 = (x - (1 - at).sqrt() * e) / at.sqrt()                       # predicted x0
    sig = eta * ((1 - as_) / (1 - at) * (1 - at / as_)).sqrt()
    return as_.sqrt() * x0 + (1 - as_ - sig**2).sqrt() * e + sig * torch.randn_like(x)

def ddim_sample(eps_model, xT, S=50, eta=0.0):
    taus = torch.linspace(0, T, S + 1).round().long().tolist()       # [0, 20, 40, ..., 1000] for S = 50
    x = xT
    for i in range(S, 0, -1):
        x = ddim_step(eps_model, x, taus[i], taus[i - 1], eta)
    return x

def ddim_invert(eps_model, x0, S=50):
    """Run the eta = 0 update upward (x0 -> x_T), using ε at the current, less noisy step."""
    taus = torch.linspace(0, T, S + 1).round().long().tolist()
    taus[0] = 1                                                      # ε is not defined at t = 0
    x = x0
    for i in range(S):
        t, s = taus[i], taus[i + 1]
        at, as_ = A(t), A(s)
        e = eps_model(x, t)
        x = as_.sqrt() * (x - (1 - at).sqrt() * e) / at.sqrt() + (1 - as_).sqrt() * e
    return x

# A model we can write down exactly: data x0 ~ N(m, s² I) gives ε*(x_t, t) = E[ε | x_t] in closed form.
m, s2 = torch.tensor([0.5, -1.0], dtype=torch.float64), 0.2**2
def eps_star(x, t):
    a = A(t)
    return (1 - a).sqrt() * (x - a.sqrt() * m) / (a * s2 + 1 - a)

torch.manual_seed(0)
xT = torch.randn(4096, 2, dtype=torch.float64)
x20, x1000 = ddim_sample(eps_star, xT, S=20), ddim_sample(eps_star, xT, S=1000)
print(x20.shape)                                           # torch.Size([4096, 2])
print(x20.std(0).tolist(), x1000.std(0).tolist())          # ≈ [0.140, 0.140] and ≈ [0.198, 0.199]; true std 0.2
print(torch.equal(x20, ddim_sample(eps_star, xT, S=20)))   # True: eta = 0 is deterministic given x_T
z = ddim_invert(eps_star, x1000[:8], S=1000)
rec = ddim_sample(eps_star, z, S=1000)
print((z - xT[:8]).abs().max().item() < 0.05, (rec - x1000[:8]).abs().max().item() < 0.01)   # True True
```

DDIM sampling with any η and sub-sequence, and DDIM inversion, checked against an exact noise predictor for Gaussian data

> **Few steps shrink the spread:** Even with a perfect noise predictor, a coarse deterministic schedule is biased. In the code above, Gaussian data with std 0.2 comes out with std 0.140 after 20 uniform steps on the linear schedule, 0.174 after 50 and 0.198 after 1000. In the figure, 50 steps give a mean distance to the moons of 0.58σ, tighter than the data's 0.88σ. Higher-order solvers and better step spacings (quadratic, or uniform in log-SNR) reduce the bias.

> **Inversion is only approximate:** The upward update uses $\varepsilon_\theta(x_{\tau_i},\tau_i)$ where the exact reverse of a step would need $\varepsilon_\theta$ at the destination. The error is small for many steps and an unguided model, but grows with few steps and with classifier-free guidance at high weight, where the reconstructed image visibly drifts. Editing methods such as null-text inversion (Mokady et al., CVPR 2023) optimise the unconditional embedding per step to close that gap.

> **A sampler, not a new model:** DDIM changes nothing about training. Any ε-, $x_0$- or v-prediction network trained on the DDPM marginals can be sampled with it, at any $S$ and $\eta$ chosen at inference time. That is why "DDIM, 50 steps" became the default in early latent diffusion code. It also makes DDIM the bridge from **Denoising diffusion probabilistic models (DDPM)** to the ODE view in **Diffusion models**, and to methods that straighten or shortcut the ODE, such as **Rectified flow** and **Consistency models**.

**Strengths**

- 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

**Limitations**

- 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

**Question:** Why can DDIM use a network trained with DDPM's L_simple, without retraining?

- A. Because DDIM's forward process is the same Markov chain as DDPM's
- B. Because L_simple depends only on the marginals q(x_t | x₀), which every DDIM process shares with DDPM
- C. Because DDIM fine-tunes the network for each step count S
- D. Because η = 0 removes the need for a noise predictor

**Answer:** B. Because L_simple depends only on the marginals q(x_t | x₀), which every DDIM process shares with DDPM — The family $q_\sigma$ is built so that $q_\sigma(x_t\mid x_0)=\mathcal N(\sqrt{\bar\alpha_t}x_0,(1-\bar\alpha_t)I)$ for every $\sigma$. The forward processes differ in their joint structure (they are non-Markovian), but each variational objective $J_\sigma$ equals a noise-prediction loss plus a constant (Theorem 1). The same holds for sub-sequences $\tau$, which is what permits skipping steps.

**Question:** A DDIM step goes from t = 500 to s = 250 with η = 1. Compared with η = 0, what changes?

- A. Nothing; η only matters when S = T
- B. Most of the noise variance at s comes from fresh noise σz instead of the predicted ε, so the result is random and depends little on the noise in x_t
- C. The predicted x̂₀ changes
- D. The step becomes the exact probability-flow ODE solution

**Answer:** B. Most of the noise variance at s comes from fresh noise σz instead of the predicted ε, so the result is random and depends little on the noise in x_t — $\hat x_0$ is the same; only the split of the noise variance $1-\bar\alpha_s=0.476$ changes. With $\eta=1$, $\sigma^2=0.439$ is fresh and $0.037$ is carried over. With $\eta=0$ all $0.476$ is carried over through $\varepsilon_\theta$, so the step is deterministic, and that is the Euler step of the ODE.

**Key points**

- DDIM step: $x_s=\sqrt{\bar\alpha_s}\,\hat x_0+\sqrt{1-\bar\alpha_s-\sigma^2}\,\varepsilon_\theta(x_t,t)+\sigma z$ with $\hat x_0=(x_t-\sqrt{1-\bar\alpha_t}\varepsilon_\theta)/\sqrt{\bar\alpha_t}$ and any $s<t$.
- $\sigma=\eta\sqrt{\frac{1-\bar\alpha_s}{1-\bar\alpha_t}}\sqrt{1-\frac{\bar\alpha_t}{\bar\alpha_s}}$: $\eta=1$ is DDPM-like ($\sigma^2=\tilde\beta_t$), $\eta=0$ 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.

---

From MLFoundry (https://www.mlfoundry.in). The web page adds interactive figures and diagrams.
