Search

Search papers and lessons

Improved Denoising Diffusion Probabilistic Models

Alex Nichol, Prafulla Dhariwal · 2021

Nichol and Dhariwal (2021) make diffusion models competitive on likelihood and usable in tens of steps, using a learned variance, a cosine noise schedule and importance sampling.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Architectures
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

Alex Nichol and Prafulla Dhariwal show that a diffusion model trained with the 2020 DDPM recipe can be made much better at two things it was weak on: log-likelihood, which measures how well the model covers the data, and sampling speed. Three changes do most of the work: the model learns the variance of each reverse step, the noise schedule is changed to a cosine curve, and the likelihood term is estimated with importance sampling. The result is competitive likelihood, near-optimal samples with about 100 sampling steps instead of the 4,000 used in training, and higher recall than the GAN BigGAN-deep at comparable sample quality.

Builds on: Denoising Diffusion Probabilistic Models (DDPM), Importance Sampling, Cosine Noise Schedule · Leads to: DDIM Sampler as the other fast-sampling method the paper compares against

Why it mattered

The paper turned DDPMs from a striking image generator into a serious likelihood model. Before it, diffusion models had excellent FID and Inception scores but poor log-likelihood, and the field believed that a weak likelihood meant the model missed parts of the data distribution. The paper's experiments show the gap can be closed on ImageNet 64 by 64 and CIFAR-10 without changing the core idea of the model.

Its sampling result is what made diffusion practical. The authors trained with 4,000 diffusion steps, and a single sample took several minutes at that length. They show that a trained model reaches near-optimal FID with 100 sampling steps. The abstract describes the saving as an order of magnitude fewer forward passes, with a negligible difference in sample quality. The cosine schedule, learned variance and strided sampler from this paper are used widely in later image-diffusion systems, and the paper's code is public.

The problem

Ho and colleagues' DDPM trained a network to predict the noise in an image at a random step, and that objective gives good samples measured by FID. But the same model was poor on log-likelihood. The paper asks three questions. Can DDPMs match the likelihood of autoregressive models and VAEs? Do they cover the modes of a diverse dataset such as ImageNet? And can they sample in far fewer steps?

Each question has a concrete obstacle. The likelihood is a sum of terms, and optimising it directly was noisy in practice. The variance of each reverse step was fixed, not learned. The linear noise schedule destroyed information too fast at the end of the process, which wasted steps. And sampling used the full chain of steps, which is slow. The paper addresses each in turn.

How it works

Take a toy process with T=10T = 10 training steps and ask for a sampler with K=4K = 4 steps. The pipeline has four changes, and each is traced below on the toy numbers.

  1. Choose the noise schedule. The cosine schedule defines the fraction of signal that survives at each step through αˉt\bar{\alpha}_t, and it drops smoothly in the middle of the process. The paper's schedule is designed so that very little changes at the two ends of the chain.
  2. Predict the noise and the variance together. The network outputs the noise estimate ϵθ\epsilon_\theta and a vector vv that sets the variance of each reverse step. The variance is an interpolation, in the log domain, between two bounds, so it is always in the right range. Check: with βt=0.04\beta_t = 0.04 and β~t=0.02\tilde{\beta}_t = 0.02, the variance is 0.040.04 when v=1v = 1, 0.020.02 when v=0v = 0, and 0.04⋅0.02≈0.0283\sqrt{0.04 \cdot 0.02} \approx 0.0283 when v=0.5v = 0.5.
  3. Train on a hybrid loss. The objective adds the simple noise loss to a small multiple of the full likelihood bound, with a stop-gradient on the mean, so that the bound only moves the variance. Check: the simple term sets the samples, and the bound term only adds a small correction.
  4. Sample with fewer steps. Choose KK evenly spaced steps from the original TT steps, round them, and run the reverse chain on that subsequence. For T=10T = 10 and K=4K = 4 the steps are 1,4,7,101, 4, 7, 10, which are already integers. Check: the variance formula is recomputed for the shorter gap between steps, so the learned variance keeps its range.

The likelihood bound in step 3 is estimated by sampling a random step tt for each training example. Importance sampling, in section 3.3 of the paper, samples the steps in proportion to the root mean square of their loss terms, which removes most of the gradient noise.

flowchart LR
  A[Cosine schedule] --> B[Predict noise and variance]
  B --> C[Hybrid loss: simple plus small VLB term]
  C --> D[Importance-sampled VLB for likelihood]
  D --> E[Trained model]
  E --> F[Strided sampling with K steps]
  F --> G[Image]

The math

The forward and reverse chains (step 2 in symbols)

The forward process adds Gaussian noise with variance βt\beta_t at each step, and αt=1−βt\alpha_t = 1 - \beta_t and αˉt=∏s≤tαs\bar{\alpha}_t = \prod_{s \le t} \alpha_s. The noisy image at step tt has a closed form:

xt=αˉt x0+1−αˉt ϵ,ϵ∼N(0,I)x_t = \sqrt{\bar{\alpha}_t}\, x_0 + \sqrt{1 - \bar{\alpha}_t}\, \epsilon, \qquad \epsilon \sim \mathcal{N}(0, \mathbf{I})

The reverse step is pθ(xt−1∣xt)=N(μθ(xt,t),Σθ(xt,t))p_\theta(x_{t-1} \mid x_t) = \mathcal{N}(\mu_\theta(x_t, t), \Sigma_\theta(x_t, t)). The variational lower bound is a sum of KL terms, Lvlb=L0+∑tLt−1+LTL_{\text{vlb}} = L_0 + \sum_{t} L_{t-1} + L_T, each a KL divergence between two Gaussians.

The learned variance (step 2 in symbols)

The paper parameterises the variance by an interpolation between the two bounds βt\beta_t and β~t\tilde{\beta}_t, where β~t=1−αˉt−11−αˉtβt\tilde{\beta}_t = \frac{1 - \bar{\alpha}_{t-1}}{1 - \bar{\alpha}_t}\beta_t is the variance of the true posterior:

Σθ(xt,t)=exp⁡(vlog⁡βt+(1−v)log⁡β~t)\Sigma_\theta(x_t, t) = \exp\bigl(v \log \beta_t + (1 - v) \log \tilde{\beta}_t\bigr)

Here vv is the network's output, with one value per dimension. Working in the log domain keeps the variance positive, and the bounds keep it in a range that a network can learn easily.

The hybrid loss (step 3 in symbols)

Lhybrid=Lsimple+λ Lvlb,λ=0.001L_{\text{hybrid}} = L_{\text{simple}} + \lambda\, L_{\text{vlb}}, \qquad \lambda = 0.001

where Lsimple=E[∥ϵ−ϵθ(xt,t)∥2]L_{\text{simple}} = \mathbb{E}\bigl[\lVert \epsilon - \epsilon_\theta(x_t, t) \rVert^2\bigr] is the noise-prediction loss from DDPM. A stop-gradient on μθ\mu_\theta inside LvlbL_{\text{vlb}} means that the bound trains Σθ\Sigma_\theta while LsimpleL_{\text{simple}} trains the mean.

The cosine schedule (step 1 in symbols)

αˉt=f(t)f(0),f(t)=cos⁡2 ⁣(t/T+s1+s⋅π2),s=0.008\bar{\alpha}_t = \frac{f(t)}{f(0)}, \qquad f(t) = \cos^2\!\left(\frac{t/T + s}{1 + s} \cdot \frac{\pi}{2}\right), \qquad s = 0.008

The offset ss keeps βt\beta_t from being too small at the start, and βt\beta_t is clipped at 0.9990.999 near the end.

Importance sampling (step 3 in symbols)

Lvlb=Et∼pt ⁣[Ltpt],pt∝E[Lt2],∑tpt=1L_{\text{vlb}} = \mathbb{E}_{t \sim p_t}\!\left[\frac{L_t}{p_t}\right], \qquad p_t \propto \sqrt{\mathbb{E}[L_t^2]}, \qquad \sum_t p_t = 1

The second moments are estimated from the last 10 values of each term, which the paper updates during training. Sampling steps in proportion to E[Lt2]\sqrt{\mathbb{E}[L_t^2]} gives a much lower-variance estimate of the bound.

Strided sampling (step 4 in symbols)

For a subsequence SS of the original steps, the sampling schedule is βSt=1−αˉSt/αˉSt−1\beta_{S_t} = 1 - \bar{\alpha}_{S_t} / \bar{\alpha}_{S_{t-1}}, and the variance β~St\tilde{\beta}_{S_t} is computed from it in the same way. The learned vv then interpolates inside the new, wider gaps.

Results

Likelihood and FID on ImageNet 64 by 64. Table 1 of the paper ablates the changes. With 4,000 steps and the linear schedule, the simple loss gives NLL 3.77 bits per dimension and FID 31.3. Switching to the cosine schedule with the simple loss gives NLL 3.68 and FID 27.0. Adding the hybrid loss and learned variance at the same schedule gives NLL 3.62 and FID 28.0. Optimising the bound directly with importance sampling gives the best likelihood, NLL 3.57 at 200,000 iterations, but a worse FID of 56.7. At 1.5 million iterations, the hybrid model reaches NLL 3.57 with FID 19.2. The paper says that the hybrid objective is generally preferred because it gives a likelihood gain without losing sample quality.

CIFAR-10. The same pattern holds. The linear schedule with the simple loss gives NLL 3.37 and FID 2.90 at 4,000 steps. The cosine bound-only model reaches NLL 2.94, which is the best of the table, but its FID is 11.47.

Comparison with other likelihood models. In Table 3 the improved model reaches 3.53 bits per dimension on ImageNet 64 and 2.94 on CIFAR-10. The original DDPM had 3.77 and 3.70. The paper says this makes it competitive with the best convolutional models on ImageNet 64, though fully transformer-based models were still better.

Sampling speed. Figure 8 and the text report that the hybrid model keeps its sample quality as steps are removed, while fixed-variance models degrade. At 100 steps it reaches near-optimal FID on the fully trained models. DDIM is better with fewer than 50 steps, and the hybrid model is better at 50 or more.

GAN comparison. On class-conditional ImageNet 64 with 250 steps, the large diffusion model has FID 2.92, precision 0.82 and recall 0.71. BigGAN-deep has FID 4.06, precision 0.86 and recall 0.59. The paper reads the recall gap as evidence that diffusion models cover more of the target distribution, even though the GAN has the higher precision.

Limits. The scaling study uses four model sizes and is labelled preliminary. Validation NLL does not fit a power law as cleanly as FID does, and the paper names a possible irreducible loss or overfitting as causes. The two-stage ImageNet 256 result, FID 12.3, is still well behind BigGAN at 7.7 in the paper's table.

Reading guide

Check yourself

QuestionWith T=10T = 10 training steps, a sampler uses K=4K = 4 evenly spaced steps. Which steps does it run, and by what factor is the number of network evaluations reduced?Show answer

The steps are 1,4,7,101, 4, 7, 10, since they are evenly spaced with gap 3 and are already integers. The model runs 4 evaluations instead of 10, a reduction by a factor of 10/4=2.510 / 4 = 2.5. For the paper's T=4000T = 4000 and a 100-step sampler, the same arithmetic gives a factor of 4040, which is consistent with the order-of-magnitude speed-up the abstract claims.

QuestionWith βt=0.04\beta_t = 0.04 and β~t=0.02\tilde{\beta}_t = 0.02, what variance does the learned interpolation give at v=0.25v = 0.25?Show answer

The log-domain interpolation gives exp⁡(0.25log⁡0.04+0.75log⁡0.02)\exp(0.25 \log 0.04 + 0.75 \log 0.02). Compute the exponent: log⁡0.04≈−3.219\log 0.04 \approx -3.219 and log⁡0.02≈−3.912\log 0.02 \approx -3.912, so the exponent is 0.25×(−3.219)+0.75×(−3.912)≈−3.7390.25 \times (-3.219) + 0.75 \times (-3.912) \approx -3.739. The variance is e−3.739≈0.0238e^{-3.739} \approx 0.0238. This lies between the two bounds, as it must, and is closer to β~t\tilde{\beta}_t because vv is closer to 00.

QuestionWhy does the paper use LhybridL_{\text{hybrid}} with λ=0.001\lambda = 0.001 instead of optimising LvlbL_{\text{vlb}} directly, given that the bound is the quantity that measures likelihood?Show answer

Optimising LvlbL_{\text{vlb}} directly gives the best likelihood but a much worse FID, 56.7 against 28.0 for the hybrid at 200,000 iterations, so sample quality suffers. The simple loss is what trains the mean and gives good samples. The small weight λ\lambda stops the bound from overwhelming it, while still letting the bound train the variance. The paper says the hybrid gives a likelihood gain without sacrificing sample quality.

QuestionA team says their diffusion model has FID close to a GAN's, so their samples cover the data as well as the GAN's. What does the paper's precision and recall comparison say about that claim?Show answer

FID alone does not establish coverage. The paper finds that its large diffusion model has FID 2.92 against BigGAN-deep's 4.06, but recall 0.71 against 0.59 and precision 0.82 against 0.86. Precision measures how many samples look like the data, and recall measures how much of the data the samples cover. So the diffusion model covers more of the distribution, with slightly lower precision. The team should report precision and recall, not FID alone, before claiming equal coverage.

Sources

Read the full paper

Alex Nichol, Prafulla Dhariwal, 2021. arXiv:2102.09672