Search

Search papers and lessons

Denoising Diffusion Implicit Models (DDIM)

Jiaming Song, Chenlin Meng, Stefano Ermon · 2020

DDIM shows that a diffusion model trained with the DDPM objective can be sampled along a deterministic path, so it gives good images in 10 to 100 steps instead of 1000 with no retraining.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Architectures
  • Generative models
  • Linear algebra
  • Neural network basics
  • Sign in to see your progress

TL;DR

Diffusion models generate images by running a learned denoising chain for many steps, and DDPM needed 1000 of them. DDIM shows that the same trained network can be sampled along a different, deterministic path, and that the path can skip most steps. The result is samples of close to full quality in 20 to 100 steps, a 10 to 50 times speed-up, and no change to training.

Where you'll see it: in the fast samplers used by image generators, and in the idea that a real image can be encoded to a noise vector and decoded again, which the paper uses for interpolation.

The problem

DDPM, from Ho and colleagues in 2020, produced image quality that rivalled GANs. Its cost was sampling. Generating one image meant running the network once for each of the 1000 steps of the chain, one after another, so a single batch took far longer than a GAN forward pass. That made diffusion models impractical for any task with a latency budget.

Two things were fixed in the design of DDPM. The forward noising chain was Markovian, so each step depended only on the step before. The reverse chain was therefore forced to match it step by step. Speeding up sampling by just taking fewer steps of the stochastic DDPM sampler gave poor images, because each big step adds randomness the model was not trained to correct. The question was whether the training could be kept and the sampler changed.

Key idea

The training objective of DDPM depends only on the marginal distributions q(xt∣x0)q(x_t \mid x_0), the noisy version of the data at each noise level. It does not depend on how the steps link together. Many different chains share the same marginals. The paper builds a family of non-Markovian forward chains, indexed by a vector σ\sigma, that all have those marginals. Each one leads to a different reverse sampler. Because the training objective is the same for all of them, one trained network works for every sampler in the family.

Among these samplers, one choice of σ\sigma makes the reverse path deterministic. The paper calls this the denoising diffusion implicit model, DDIM. Its sampler is the one described in the DDIM Sampler lesson. The picture to hold is simple: the network says where the clean image probably is, and the sampler moves the current point toward that guess along a fixed curve. Because the curve is fixed, the sampler can use a coarse set of steps and still follow it.

The method

Forward chains with the same marginals

The DDPM forward chain satisfies q(xt∣x0)=N(αt x0,(1−αt)I)q(x_t \mid x_0) = \mathcal{N}(\sqrt{\alpha_t}\, x_0, (1 - \alpha_t) I), where αt\alpha_t is the cumulative product of the per-step retention factors. The paper keeps this marginal but changes the joint distribution over the chain. For a parameter vector σ∈R≥0T\sigma \in \mathbb{R}^T_{\ge 0}, the reverse conditional of the new chain is

qσ(xt−1∣xt,x0)=N ⁣(αt−1 x0+1−αt−1−σt2⋅xt−αt x01−αt, σt2I).q_\sigma(x_{t-1} \mid x_t, x_0) = \mathcal{N}\!\left(\sqrt{\alpha_{t-1}}\, x_0 + \sqrt{1 - \alpha_{t-1} - \sigma_t^2}\cdot\frac{x_t - \sqrt{\alpha_t}\, x_0}{\sqrt{1 - \alpha_t}},\ \sigma_t^2 I\right).

The mean is chosen so that the marginals still match. The forward step from xt−1x_{t-1} to xtx_t is then implied by Bayes rule, and it is no longer Markovian. A large σ\sigma makes the chain noisy; a σ\sigma near zero makes xt−1x_{t-1} almost determined by xtx_t and x0x_0.

The objective is the same

The variational objective JσJ_\sigma for each σ\sigma differs from the DDPM objective only by terms that do not depend on the network, and the paper shows that JσJ_\sigma equals a weighted noise-prediction loss LγL_\gamma for some positive weights γ\gamma (Theorem 1). The simplified unweighted loss L1L_{\mathbf{1}}, which DDPM used, is therefore a valid surrogate for every σ\sigma. The network is trained once, with the familiar mean squared error on noise.

The generative update

Given a trained noise predictor εθ(t)\varepsilon_\theta^{(t)}, the paper writes the predicted clean image as fθ(xt)=(xt−1−αt εθ(t)(xt))/αtf_\theta(x_t) = (x_t - \sqrt{1-\alpha_t}\,\varepsilon_\theta^{(t)}(x_t))/\sqrt{\alpha_t}, and the sampling update as

xt−1=αt−1 fθ(xt)+1−αt−1−σt2 εθ(t)(xt)+σtεt,x_{t-1} = \sqrt{\alpha_{t-1}}\, f_\theta(x_t) + \sqrt{1 - \alpha_{t-1} - \sigma_t^2}\, \varepsilon_\theta^{(t)}(x_t) + \sigma_t \varepsilon_t,

with εt∼N(0,I)\varepsilon_t \sim \mathcal{N}(0, I). Choosing σt=0\sigma_t = 0 removes the last term. When σ\sigma takes the value that makes the forward chain Markovian, the update is exactly the DDPM sampler, so DDPM is one member of the family.

Skipping steps

The paper also allows the forward chain to be defined on a subsequence τ1<⋯<τS\tau_1 \lt \dots \lt \tau_S of the training steps. The same marginal argument applies to the subsequence, so the same network can be used, and sampling only visits the chosen steps. Training still uses all T=1000T = 1000 steps.

The ODE view

With σ=0\sigma = 0, the update is a discretised ODE. Rewriting it in the variables xˉ=x/α\bar{x} = x/\sqrt{\alpha} and σ(t)=(1−αt)/αt\sigma(t) = \sqrt{(1-\alpha_t)/\alpha_t} gives xˉs−xˉt=(σs−σt) εθ(⋅)\bar{x}_{s} - \bar{x}_t = (\sigma_s - \sigma_t)\,\varepsilon_\theta(\cdot), which is one Euler step for an Ordinary Differential Equation. The paper's Section 4.3 (Relevance to Neural ODEs) states this and notes that the same ODE can be run in reverse to encode an image into a latent xTx_T. Proposition 1 shows that, with the optimal network, this ODE is equivalent to the probability flow ODE of the score-based SDE work of Song and colleagues. The two Euler discretisations differ, though: the DDIM steps are taken in σ\sigma, the probability flow steps in tt, so the samplers are not identical at few steps.

Results

The experiments use one trained model per dataset, with T=1000T = 1000, and vary only the sampler: the subsequence length SS and the parameter η\eta, where η=0\eta = 0 is DDIM and η=1\eta = 1 is DDPM. Quality is measured by Fréchet Inception Distance (FID), where lower is better.

On CIFAR-10 with S=10S = 10, DDIM gives FID 13.36, and the stochastic DDPM (η=1\eta = 1) gives 41.07. At S=20S = 20 the numbers are 6.84 and 18.36. At S=100S = 100 they are 4.16 and 5.78. With the full S=1000S = 1000, DDIM gives 4.04 and DDPM 4.73.

On CelebA at 64×6464 \times 64, the 20-step DDIM gives FID 13.73, close to the 100-step DDPM at 13.93. The paper reports that DDIM reaches quality comparable to the 1000-step model within 20 to 100 steps, which it describes as a 10 to 50 times speed-up over DDPM. Figure 4 shows that sampling time scales linearly with the number of steps.

Two further results matter. First, DDIM samples from the same starting noise xTx_T keep their high-level features when the number of steps changes, so xTx_T acts as a latent code. Interpolating between two starting noises gives smooth changes in the images. Second, encoding a test image to xTx_T and decoding it again reconstructs it, with per-dimension mean squared error falling from 0.014 at 10 steps to 0.0001 at 500 steps. The paper notes that a stochastic DDPM sampler cannot do this, because its output varies with the random draws.

Why it mattered

DDIM showed that the quality of a diffusion model is not fixed by its sampler, and that the sampler could be chosen after training. That changed the practical cost of diffusion models: fast generation became a question of choosing a sampler and a step count, not retraining. Later work on faster ODE solvers and distilled one-step models builds on the same view of sampling as solving an ODE. The deterministic latent also made diffusion models usable for editing and interpolation, which the stochastic sampler could not support in the same way. The paper's non-Markovian framework also suggested that other forward processes, not only Gaussian ones, could be used, which the authors note in the discussion.

Reading guide

Read these in order. Each row lists the paper section and the prerequisites it depends on.

  1. Section 1, Introduction. Needs Diffusion Model for the idea of a noising chain with a learned reverse, and Denoising Diffusion Probabilistic Models (DDPM) for the baseline the paper improves on.
  2. Section 2, Background. Needs Markov Chain for the forward and reverse chains, Gaussian (Normal) Distribution for every step, and Variational Lower Bound (ELBO) for the objective in Equation 2.
  3. Section 2, Equations 3 to 5. Needs Reparameterization Trick for writing xtx_t as a mix of x0x_0 and noise, and Mean Squared Error for the simplified loss L1L_{\mathbf{1}}.
  4. Section 3, Variational inference for non-Markovian forward processes. Needs Conditional Probability for the reverse conditional and Bayes rule for the implied forward step. Theorem 1 needs no further prerequisites beyond the objective.
  5. Section 4.1, DDIM. Needs DDIM Sampler for the update in practice. The role of σ\sigma is clearest after reading the Gaussian (Normal) Distribution term again.
  6. Section 4.2, Accelerated generation. Needs the idea of a subsequence of steps. Nothing new beyond Section 4.1.
  7. Section 4.3, Relevance to Neural ODEs. Needs Ordinary Differential Equation and Euler Method. Needs Neural Ordinary Differential Equation for the continuous-depth comparison in the related work.
  8. Section 5, Experiments. Needs Generative Model for what FID measures against real images, and U-Net for the denoising network used in the image experiments.

Check yourself

QuestionRecall: what does the DDIM paper change, and what does it keep fixed?Show answer

It changes the sampler, by choosing a non-Markovian reverse process with σ=0\sigma = 0 for a deterministic path, and by allowing that path to skip steps. It keeps the trained network and its objective, which is the DDPM noise-prediction loss. The same network serves the whole family of samplers.

QuestionCompute: from the CIFAR-10 numbers in the paper, how many times fewer network calls does 20-step DDIM use than 1000-step DDPM, and how many FID points does the 20-step DDIM give up relative to the full 1000-step DDIM?Show answer

Network calls: 1000/20=501000 / 20 = 50 times fewer. FID cost: 6.84−4.04=2.806.84 - 4.04 = 2.80 points. These are the numbers reported in Table 1 of the paper, and the second comparison is between two DDIM settings, not DDPM and DDIM.

QuestionWhy: why does the paper's theorem matter for practice, rather than being an aside?Show answer

Theorem 1 says that every sampler in the family optimises an objective equal to the DDPM loss up to weights and a constant. So a practitioner does not need to retrain a model to try a different sampler. Without the theorem, each new σ\sigma would look like a new training problem, and the speed-up would cost a full training run per setting.

QuestionApplied: you want to encode a real image into a latent and decode it later from a different number of steps. Which sampler do you use, and what should you expect?Show answer

Use the deterministic DDIM sampler, run in the forward direction to encode and in the reverse direction to decode, with the same step subsequence on both sides. Expect reconstruction error that falls as the number of steps grows, from about 0.014 per dimension at 10 steps to about 0.0001 at 500 steps in the paper's CIFAR-10 test. A stochastic DDPM sampler cannot be used this way, because its output changes with the random draws.

Sources

Read the full paper

Jiaming Song, Chenlin Meng, Stefano Ermon, 2020. arXiv:2010.02502