VerifiedarXiv:2105.0523327 min
Diffusion · Generative models

Diffusion Models Beat GANs on Image Synthesis

A better U-Net and a classifier's gradient let a diffusion model beat BigGAN on ImageNet.

Dhariwal and Nichol tune the diffusion model's denoising network, then add classifier guidance: during sampling, each denoising step is shifted along the gradient of a classifier, and one scale parameter sets how far, trading sample variety for sample quality.

Explaining the paperDiffusion Models Beat GANs on Image SynthesisDhariwal, Nichol · OpenAI · NeurIPS 2021 · arXiv:2105.05233 ↗

In 2021 the best ImageNet samples came from GANs, which get them partly by leaving out parts of the data. This paper reaches a lower FID with a diffusion model that leaves out less.

GANs and diffusion models in 2021

Before this paper, the strongest class-conditional ImageNet generators were GANs (generative adversarial networks), in which a generator learns to produce images that a second network, the discriminator, cannot tell apart from real ones. BigGAN-deep was the state of the art at 256×256 with an FID of 6.956.95. FID is the standard sample-quality score, defined in a later section; lower is better. The paper names two weaknesses of GANs: they capture less of the data's diversity than the best likelihood-based models, and they are "often difficult to train, collapsing without carefully selected hyperparameters and regularizers".

Diffusion models are likelihood-based. They train with a plain regression loss and cover the data distribution well, but in 2021 their ImageNet samples still scored worse than a good GAN's. Prafulla Dhariwal and Alex Nichol, at OpenAI, hypothesize that the gap comes from at least two factors. GAN architectures had been explored and refined for years, while diffusion models still used the network from one 2020 paper. And a GAN can trade diversity for fidelity: BigGAN's truncation trick draws its input noise from a normal distribution cut off near the centre, which gives cleaner images from fewer modes of the data, and diffusion models had no equivalent control.

The paper answers each factor with one contribution. An architecture sweep produces a stronger denoising network, which the authors call ADM (ablated diffusion model). Classifier guidance adds the missing control: during sampling, the gradient of an image classifier shifts each denoising step toward a chosen class, and a scalar ss sets how hard. Guided ADM reaches FID 2.972.97 on ImageNet 128×128, 4.594.59 on 256×256 and 7.727.72 on 512×512, against BigGAN-deep's 6.026.02, 6.956.95 and 8.438.43. With only 25 sampling steps it scores 5.985.98, 5.445.44 and 8.418.41, still level with or better than BigGAN-deep at each resolution.

The page follows the paper's order: the diffusion model, reduced to the five equations guidance needs; the architecture changes; the metrics that measure fidelity and diversity separately; the derivation of classifier guidance and the one approximation in it; what the scale does, shown on a toy sampler you can run; the version for the fast DDIM sampler; and the measured results.

A diffusion model in five equations

The full construction is in the DDPM explainer; this section keeps the parts classifier guidance uses. A diffusion model generates images by reversing a fixed noising process. The forward process takes a clean image x0x_0 and mixes in Gaussian noise over T=1000T = 1000 steps until only noise is left. In the variance-preserving (VP) convention this paper uses, any noise level tt can be reached in one jump:

q(xt∣x0)=N ⁣(αˉt x0, (1−αˉt)I),xt=αˉt x0+1−αˉt ϵq(x_t \mid x_0) = \mathcal{N}\!\big(\sqrt{\bar\alpha_t}\,x_0,\ (1-\bar\alpha_t)\mathbf{I}\big),\qquad x_t = \sqrt{\bar\alpha_t}\,x_0 + \sqrt{1-\bar\alpha_t}\,\epsilonq(xt∣x0)=N ⁣(αˉt x0, (1−αˉt)I),xt=αˉt x0+1−αˉt ϵ\begin{gathered} q(x_t \mid x_0) = \mathcal{N}\!\big(\sqrt{\bar\alpha_t}\,x_0,\ (1-\bar\alpha_t)\mathbf{I}\big), \\ x_t = \sqrt{\bar\alpha_t}\,x_0 + \sqrt{1-\bar\alpha_t}\,\epsilon \end{gathered}
(1)

In (1), ϵ∼N(0,I)\epsilon \sim \mathcal{N}(0,\mathbf{I}) is the noise and αˉt\bar\alpha_t falls from near 1 at the first step to near 0 at the last. On ADM's linear schedule αˉt\bar\alpha_t is 0.99990.9999 at t=0t=0, 0.0790.079 halfway (t=499t=499) and 4×10−54\times10^{-5} at t=999t=999. Halfway, the image is scaled by 0.079=0.28\sqrt{0.079} = 0.28 and noise with standard deviation 0.960.96 is added. The signal variance αˉt\bar\alpha_t and the noise variance 1−αˉt1-\bar\alpha_t sum to one, so data scaled to unit variance keeps unit variance at every tt. (Variance-exploding papers leave the signal unscaled and grow only the noise; the formulas below are for the VP form.)

For a 256×256 RGB image, x0x_0, ϵ\epsilon and xtx_t are tensors of shape 3 × 256 × 256, with pixel values scaled to [−1,1][-1, 1]. Following Ho et al., a network ϵθ(xt,t)\epsilon_\theta(x_t, t) takes the noised image and the timestep and predicts the noise that was added, trained with a squared error:

Lsimple=Et, x0, ϵ[ ∥ϵ−ϵθ(xt,t)∥2 ]L_{\text{simple}} = \mathbb{E}_{t,\,x_0,\,\epsilon}\big[\,\lVert \epsilon - \epsilon_\theta(x_t,t)\rVert^2\,\big]
(2)

Each training step picks an image, a tt and an ϵ\epsilon, builds xtx_t with (1), and regresses the prediction onto the ϵ\epsilon it used. Sampling runs the chain backward. Each reverse step is a Gaussian pθ(xt−1∣xt)=N(μθ,Σθ)p_\theta(x_{t-1} \mid x_t) = \mathcal{N}(\mu_\theta, \Sigma_\theta) whose mean is computed from the noise prediction, with βt=1−αt\beta_t = 1-\alpha_t the forward process's per-step noise variance:

μθ(xt,t)=1αt(xt−1−αt1−αˉt ϵθ(xt,t))\mu_\theta(x_t,t) = \frac{1}{\sqrt{\alpha_t}}\Big(x_t - \frac{1-\alpha_t}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t,t)\Big)
(3)

From Improved DDPM, the authors' previous paper, ADM also learns the variance. The network outputs a vector vv, and the variance interpolates in log space between two bounds: βt\beta_t and the forward process's posterior variance β~t\tilde\beta_t. It is trained with a hybrid loss, LsimpleL_{\text{simple}} plus a small weight on the variational bound.

Σθ(xt,t)=exp⁡ ⁣(vlog⁡βt+(1−v)log⁡β~t)\Sigma_\theta(x_t,t) = \exp\!\big(v\log\beta_t + (1-v)\log\tilde\beta_t\big)
(4)

The two bounds differ by orders of magnitude near t=0t = 0, which is why the blend is done in log space. A fixed variance works when the number of sampling steps is large; learning it lets the sampler take fewer steps "without much drop in sample quality". ADM's ImageNet samples use 250 steps by default. Below 50 steps the paper switches to the deterministic DDIM sampler, and all its 25-step results use DDIM.

The last equation connects the noise predictor to the score, the gradient of the log-density with respect to the image. A classifier gradient will enter the sampler through it. Given x0x_0, the noised image in (1) is Gaussian around αˉt x0\sqrt{\bar\alpha_t}\,x_0 with variance 1−αˉt1-\bar\alpha_t, so its score is −(xt−αˉt x0)/(1−αˉt)-(x_t - \sqrt{\bar\alpha_t}\,x_0)/(1-\bar\alpha_t). The numerator equals 1−αˉt ϵ\sqrt{1-\bar\alpha_t}\,\epsilon, which leaves −ϵ/1−αˉt-\epsilon/\sqrt{1-\bar\alpha_t}. The network does not know x0x_0; its prediction estimates the average ϵ\epsilon over the images that could have produced xtx_t, and the same average turns this per-image score into the score of the noised data distribution:

∇xtlog⁡pθ(xt)=−11−αˉt ϵθ(xt)\nabla_{x_t}\log p_\theta(x_t) = -\frac{1}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t)
(5)

The divisor is the standard deviation 1−αˉt\sqrt{1-\bar\alpha_t}, not the variance, because one power cancels against the noise in the numerator. The minus sign says density increases in the direction opposite the predicted noise, which is toward the data. The score-matching line of work rests on the same equivalence, and Song et al.'s SDE paper states it in the form used here.

How ADM improves the U-Net

Ho et al.'s denoiser is a U-Net: residual blocks that downsample the image through coarser resolutions and upsample back, with skip connections between matching resolutions. It has one global self-attention layer, at 16×16, with a single head, and adds a projection of the timestep embedding into each residual block. Dhariwal and Nichol test five changes, each applied alone to a baseline with 160 channels and 2 residual blocks per resolution, on ImageNet 128×128 with batch size 256 and 250 sampling steps. FID is measured after 700K and 1200K training iterations; the baseline scores 15.3315.33 and 13.2113.21.

Figure 1 plots each change's FID difference from the baseline; bars to the left of the zero line are improvements.

Figure 1 · architecture ablation
all three kept

kept · The three keepers together (4 heads, multi-resolution attention, BigGAN up/down). The combined -3.14 beats the -2.46 they sum to: the gains compound.

FID change from each architecture change on ImageNet 128×128, against the baseline U-Net (FID 15.33 at 700K iterations). BigGAN up/downsampling is the largest single gain; rescaling residuals by 1/√2 is the only change that raises FID. Select a bar or drag the slider to read what each change does and whether the paper kept it; switch between the 700K and 1200K checkpoints.

Rescaling residuals raises FID by 0.160.16 at 700K and 0.250.25 at 1200K, and was dropped. Depth lowers FID (−0.21-0.21 and −0.48-0.48) but takes longer in wall-clock time to reach the same FID as a wider model, so it was dropped too. The other three combined give −3.14-3.14 at 700K, more than the −2.46-2.46 sum of their separate gains (−0.54-0.54, −0.72-0.72, −1.20-1.20); the paper describes the changes as having "a positive compounding effect".

A second sweep (Table 2, 128 base channels, 700K iterations, baseline FID 14.0814.08 with one head) sizes the attention two ways. Fixing the number of heads at 2, 4 or 8 lowers FID by 0.500.50, 0.970.97 and 1.171.17. Fixing the channels per head at 32, 64 or 128 gives −1.36-1.36, −1.03-1.03 and −1.08-1.08. At a given width, fewer channels per head means more heads, so both sweeps vary the same quantity. 32 channels per head has the best FID, but 64 is fastest in wall-clock time and matches how a Transformer sizes its heads, so ADM uses 64.

Injecting the timestep and class with AdaGN

Every residual block needs the noise level tt and, in a class-conditional model, the class yy. Each becomes an embedding vector and the two are summed, e=et+eclasse = e_t + e_{\text{class}} (an unconditional model has only ete_t). Ho et al. projected the embedding and added it to the block's activations. ADM uses adaptive group normalization (AdaGN). GroupNorm splits a block's channels into groups and normalizes each group to zero mean and unit variance using the activations' own statistics. AdaGN then scales and shifts each channel by amounts computed from the embedding:

AdaGN(h,y)=ys GroupNorm(h)+yb,[ys,yb]=Linear(e)\text{AdaGN}(h, y) = y_s\,\text{GroupNorm}(h) + y_b,\qquad [y_s, y_b] = \text{Linear}(e)AdaGN(h,y)=ys GroupNorm(h)+yb,[ys,yb]=Linear(e)\begin{gathered} \text{AdaGN}(h, y) = y_s\,\text{GroupNorm}(h) + y_b, \\ [y_s, y_b] = \text{Linear}(e) \end{gathered}
(6)

In (6), hh is the block's activation after its first convolution, and for a block with CC channels the linear layer outputs 2C2C numbers: a scale and a shift per channel. Only GroupNorm reads statistics from hh; the scale and shift depend only on the timestep and class. The official code computes out_norm(h) * (1 + scale) + shift, so a zero output means no rescaling. FiLM and StyleGAN's adaptive instance norm use the same scale-and-shift. Adding a vector to a normalized channel moves its mean; multiplying also changes its spread, so a block can amplify or damp a channel depending on the noise level. Toggle Figure 2 between the two and compare the widths of the coloured curves against the grey reference.

Figure 2 · AdaGN vs additive conditioning
Each channel is drawn as a bell curve; the grey reference is the group-normalized activation. AdaGN scales and shifts each channel from the timestep and class embedding, so the coloured bells widen or narrow as the timestep slider moves. Addition + GroupNorm can only shift them. In the paper's ablation AdaGN reaches FID 13.06 against 15.08 for addition.

Both models in that ablation use 128 channels, multi-resolution attention with 64 channels per head and BigGAN up/downsampling, trained for 700K iterations. The final default architecture has 2 residual blocks per resolution, a width that grows at coarser resolutions, 64 channels per head, attention at 32, 16 and 8, BigGAN up/downsampling, and AdaGN. The ImageNet 256×256 model built this way has 256 base channels, channel multipliers 1, 1, 2, 2, 4, 4 across six resolutions, and 554M parameters.

The architecture alone sets the state of the art on the three LSUN datasets (bedrooms, horses, cats) and on ImageNet 64×64, where ADM with dropout reaches FID 2.072.07 against BigGAN-deep's 4.064.06. On ImageNet 128×128 unguided ADM scores 5.915.91, slightly better than BigGAN-deep's 6.026.02 but behind LOGAN's 3.363.36. At 256 and 512 it is far behind: 10.9410.94 against 6.956.95, and 23.2423.24 against 8.438.43. These are the resolutions where guidance changes the result: guided, the same architecture reaches 4.594.59 and 7.727.72.

Measuring fidelity and diversity: FID, precision and recall

Guidance raises one property of a set of samples at the expense of another, so the paper needs metrics that measure them separately. All of them work on features from an Inception-V3 network, which compares images by what an ImageNet classifier extracts from them.

FID (Fréchet Inception Distance, Heusel et al.) fits a Gaussian to the features of real images, with mean μr\mu_r and covariance Σr\Sigma_r, and another to the features of generated images (μg\mu_g, Σg\Sigma_g), then computes

FID=∥μr−μg∥22+Tr ⁣(Σr+Σg−2(ΣrΣg)1/2)\text{FID} = \lVert\mu_r - \mu_g\rVert_2^2 + \text{Tr}\!\big(\Sigma_r + \Sigma_g - 2(\Sigma_r\Sigma_g)^{1/2}\big)FID=∥μr−μg∥22+Tr ⁣(Σr+Σg−2(ΣrΣg)1/2)\begin{aligned} \text{FID} &= \lVert\mu_r - \mu_g\rVert_2^2 \\ &\quad + \text{Tr}\!\big(\Sigma_r + \Sigma_g - 2(\Sigma_r\Sigma_g)^{1/2}\big) \end{aligned}
(7)

This is the squared 2-Wasserstein distance between the two Gaussian fits, the least average squared distance that one Gaussian's probability mass must travel to become the other. It compares the fits, not the actual feature distributions, so differences the Gaussians do not capture do not count. FID goes up when samples look wrong (μg\mu_g moves) and when they lack variety (Σg\Sigma_g shrinks), which is why the paper uses it as its overall score. sFID computes the same quantity on spatial feature maps instead of pooled features, to catch errors in layout. Inception Score (IS) rewards samples that an ImageNet classifier labels confidently and that spread across the classes. It does not reward variety within a class, so a model that memorizes a small subset of the dataset still scores high.

Precision and recall (Kynkäänniemi et al., 2019) measure the two properties separately. Each set of feature vectors defines a manifold estimate: around every point, a sphere that reaches its third-nearest neighbour in the same set, and the manifold is the union of those spheres. Precision is the fraction of generated samples that fall inside the real-data manifold, a measure of fidelity. Recall is the fraction of real images that fall inside the generated-sample manifold, a measure of coverage. The two tests run in opposite directions. A model that puts every sample inside one dense region of the real data scores high precision, while recall drops because most real images have no generated sample near them. Drag the concentration slider in Figure 3 to pull the model's samples onto one mode.

Figure 3 · precision and recall
full
Real data sits in four modes; model samples start spread over all four. The shaded region is one set's manifold, a union of nearest-neighbour spheres; the buttons switch which set. Precision counts teal samples inside the amber manifold; recall counts amber data inside the teal manifold. As the samples concentrate, precision stays high and recall falls.

A truncated GAN sits toward the high-precision end: BigGAN-deep at 256×256 has precision 0.870.87 and recall 0.280.28. Classifier guidance gives a diffusion model a control that moves it along the same axis.

How classifier guidance works: the exact part

GANs for class-conditional synthesis use labels heavily, through class-conditional normalization and discriminators with classifier-like heads. Classifier guidance brings the label in from a separate model: train a classifier pϕ(y∣xt,t)p_\phi(y \mid x_t, t) on noised images, and during sampling use its gradient with respect to the image. The paper takes the method from Sohl-Dickstein et al. (2015) and Song et al., and writes pϕ(y∣xt)p_\phi(y \mid x_t) with the timestep left implicit.

The classifier is the downsampling half of the ADM U-Net, with an attention pool (the pooling layer from CLIP) at the 8×8 resolution producing the output. It is trained on the same noising distribution as the diffusion model, with random crops to reduce overfitting. The classifiers have 43M to 65M parameters, against 296M to 559M for the diffusion models. At each reverse step it takes the current noisy image xtx_t and the timestep and returns logits over the 1,000 ImageNet classes.

Start from a trained diffusion model whose reverse step pθ(xt∣xt+1)p_\theta(x_t \mid x_{t+1}) knows nothing about yy. To condition that step on yy, it is enough to multiply it by the classifier and renormalize:

pθ,ϕ(xt∣xt+1,y)=Z pθ(xt∣xt+1) pϕ(y∣xt)p_{\theta,\phi}(x_t \mid x_{t+1}, y) = Z\,p_\theta(x_t \mid x_{t+1})\,p_\phi(y \mid x_t)
(8)

with ZZ a normalizing constant. The appendix proves the fact that (8) relies on: if the forward process is redefined to also carry the label, its noising steps are unchanged, q^(xt+1∣xt)=q(xt+1∣xt)\hat q(x_{t+1} \mid x_t) = q(x_{t+1} \mid x_t), so the unconditional reverse model the network learned is the correct first factor. Both statements are exact. The chain also has to start from xTx_T conditioned on yy; the paper notes that a noisy enough forward process makes xTx_T nearly Gaussian for every class, so every class starts from N(0,I)\mathcal{N}(0, \mathbf{I}). On the linear schedule the image's contribution to xTx_T is scaled by 4×10−5=0.006\sqrt{4\times10^{-5}} = 0.006. Sampling from (8) exactly is still intractable, because it is a Gaussian multiplied by an arbitrary function computed by a neural network, so the paper approximates it.

The mean shift and its Taylor approximation

Write the model's reverse step as N(μ,Σ)\mathcal{N}(\mu, \Sigma), so its log-density is a quadratic in xtx_t. Over the region that Gaussian covers, replace log⁡pϕ(y∣xt)\log p_\phi(y \mid x_t) by its first-order Taylor expansion around μ\mu: a constant plus (xt−μ)⊤g(x_t-\mu)^\top g, where gg is the classifier's log-probability gradient at μ\mu. The log of the product in (8) becomes a quadratic plus a linear term, and completing the square turns it into another Gaussian with the same covariance and a moved mean:

log⁡(pθ pϕ)≈−12(xt−μ−Σg)⊤Σ−1(xt−μ−Σg)+C  ⟹  xt∼N(μ+Σg, Σ)\log\big(p_\theta\,p_\phi\big) \approx -\tfrac12(x_t-\mu-\Sigma g)^\top\Sigma^{-1}(x_t-\mu-\Sigma g) + C \;\Longrightarrow\; x_t \sim \mathcal{N}(\mu + \Sigma g,\ \Sigma)log⁡(pθ pϕ)≈−12(xt−μ−Σg)⊤Σ−1(xt−μ−Σg)+C⟹  xt∼N(μ+Σg, Σ)\begin{gathered} \log\big(p_\theta\,p_\phi\big) \approx -\tfrac12(x_t-\mu-\Sigma g)^\top\Sigma^{-1}(x_t-\mu-\Sigma g) + C \\ \Longrightarrow\; x_t \sim \mathcal{N}(\mu + \Sigma g,\ \Sigma) \end{gathered}
(9)

where g=∇xtlog⁡pϕ(y∣xt)∣xt=μg = \nabla_{x_t}\log p_\phi(y \mid x_t)\big|_{x_t=\mu}. The constant 12g⊤Σg\tfrac12 g^\top\Sigma g left over from completing the square is absorbed into ZZ. The mean moves by Σg\Sigma g, the gradient multiplied by the step's covariance. The covariance lies between βt\beta_t and β~t\tilde\beta_t, which on the 250-step schedule are within 8% of each other at the points below, so the same gradient moves the mean by about 0.039 g0.039\,g halfway through sampling and 0.0076 g0.0076\,g near the end (t=99t = 99). Guidance pushes hard while the image is mostly noise and lightly once it has formed. Algorithm 1 of the paper adds a scale ss to the gradient:

xt−1∼N ⁣(μθ+s Σθ ∇xtlog⁡pϕ(y∣xt), Σθ)x_{t-1} \sim \mathcal{N}\!\big(\mu_\theta + s\,\Sigma_\theta\,\nabla_{x_t}\log p_\phi(y \mid x_t),\ \Sigma_\theta\big)xt−1∼N ⁣(μθ+s Σθ ∇xtlog⁡pϕ(y∣xt),Σθ)\begin{gathered} x_{t-1} \sim \mathcal{N}\!\big(\mu_\theta + s\,\Sigma_\theta\,\nabla_{x_t}\log p_\phi(y \mid x_t), \\ \Sigma_\theta\big) \end{gathered}
(10)

In Algorithm 1 and in the official code, the gradient is taken at the current noisy image xtx_t with the timestep-tt classifier, not at the mean μ\mu as in the derivation: guided-diffusion's condition_mean returns the model mean plus variance * gradient, with the gradient computed from x. One sampling step on a 256×256 image, with the scale applied:

# Algorithm 1: classifier-guided ancestral sampling, gradient scale s
x = randn(3, 256, 256)                  # x_T ~ N(0, I), same start for every class
for t in reversed(range(T)):            # T-1 .. 0
    mu, var = model(x, t)               # unconditional reverse step N(mu, var)
    logp = log_softmax(classifier(x, t))[y]   # noised classifier, at the CURRENT x_t
    g = grad(logp, x)                   # same shape as x
    x = mu + s * var * g + sqrt(var) * randn_like(x)   # var is diagonal
return x                                # x_0, values in [-1, 1]

Figure 4 shows the shift in two dimensions with a two-class classifier. Drag the mean μ\mu and raise ss: the arrow is sΣgs\Sigma g, and the readout gives the target class's probability at μ\mu and at the shifted mean. Place μ\mu near the other class, where an unguided sample would be ambiguous, and watch the shift carry the mean back across the boundary.

Figure 4 · classifier guidance as a mean shift
s = 3.0
Two classes; a Bayes classifier plays the role of pϕp_\phi. At the draggable mean μ the unguided step would sample from N(μ,Σ)\mathcal{N}(\mu,\Sigma) (dashed ring). Guidance shifts the mean by s Σgs\,\Sigma g toward the target class (bright ring); the A/B buttons choose the target. Raising s moves the mean further and raises the target probability at the shifted mean.

The linearization needs the classifier's log-probability to be close to a straight line across the width of the step. The paper's condition is low curvature compared with Σ−1\Sigma^{-1}, "reasonable in the limit of infinite diffusion steps, where ∥Σ∥→0\lVert\Sigma\rVert \to 0". Figure 5 tests it in one dimension, where both sides can be computed. One step N(μ,Σ)\mathcal{N}(\mu, \Sigma) meets a logistic classifier p(y∣x)=1/(1+e−3x)p(y \mid x) = 1/(1+e^{-3x}). The amber curve is the exact guided step, the Gaussian times p(y∣x)sp(y \mid x)^s normalized numerically (the next section shows why a scaled gradient corresponds to this power); the teal curve is the shifted Gaussian from (10).

Figure 5 · exact guided step vs the shifted Gaussian
0.50
1.0
-0.60
One reverse step in one dimension. Amber: the exact product of the unguided step (dashed) and the classifier raised to ss, normalized. Teal: the paper's approximation, the unguided step shifted by sΣgs\Sigma g with gg taken at μ\mu. Violet: the classifier probability. Narrow the step and the two agree; widen it with μ\mu on the far side of the boundary and the shifted Gaussian overshoots.

At the default step (μ=−0.6\mu = -0.6, step standard deviation 0.50.5, s=1s = 1) the exact mean is −0.16-0.16 and the shifted mean +0.04+0.04. Narrow the step to 0.10.1 and they agree to three decimals (−0.575-0.575 and −0.574-0.574). Widen it to 1.01.0 and the shifted mean lands at 1.971.97 against an exact 0.400.40: the linearization keeps using the steep gradient it measured at μ\mu, while the real log-probability flattens out once xx is inside the class.

Fewer sampling steps make each step wider. With the linear schedule, the reverse-step variance halfway through sampling is 0.0100.010 with all 1000 steps, 0.0390.039 with 250 and 0.310.31 with 25, standard deviations of 0.100.10, 0.200.20 and 0.560.56. The toy classifier is not in image units, but the ratio carries over: cutting the step count tenfold roughly triples the width of each step, and the linear approximation gets worse. The paper's tuned scales for 25-step DDIM (1.251.25, 2.52.5, 9.09.0 at 128, 256, 512) are above its 250-step ones (0.50.5, 1.01.0, 4.04.0).

Why the gradient scale goes above 1

The derivation gives s=1s = 1: (8) is the exact conditional, and (10) at s=1s = 1 approximates it. On unconditional ImageNet models s=1s = 1 did not work. The classifier assigned the intended class about 50% probability on the finished samples, and the samples did not look like that class. Raising the scale brought the classifier's probabilities to nearly 100% and fixed the samples. The paper's corgi figure, from the unconditional 256×256 model, shows the effect: scale 1.01.0 gives FID 33.033.0, worse than the unguided model's 26.2126.21, and scale 10.010.0 gives FID 12.012.0 and recognizable corgis.

A larger scale can be read as a sharper classifier. Multiplying a log-gradient by ss gives the gradient of the classifier raised to the power ss:

s ∇xlog⁡pϕ(y∣x)=∇xlog⁡ ⁣(1Z pϕ(y∣x)s)s\,\nabla_x\log p_\phi(y \mid x) = \nabla_x\log\!\Big(\tfrac{1}{Z}\,p_\phi(y \mid x)^{s}\Big)
(11)

Raising p(y∣x)p(y \mid x) to a power s>1s > 1 amplifies values that are already large relative to small ones, so sampling concentrates on the inputs the classifier is most confident about: higher fidelity, less diversity. The identity holds for any constant ZZ that does not depend on xx. A classifier renormalized per input, p(y∣x)s/∑y′p(y′∣x)sp(y \mid x)^s / \sum_{y'} p(y' \mid x)^s, has a normalizer Z(x)Z(x) that does depend on xx, and its gradient would include an extra −∇xlog⁡Z(x)-\nabla_x\log Z(x) term. The paper says the process "is still theoretically grounded in a re-normalized classifier distribution proportional to p(y∣x)sp(y|x)^s"; read that as a description of what the scale does, a temperature of 1/s1/s on the classifier, not as a claim that the sampler draws from a renormalized classifier.

Figure 6 runs guided sampling end to end on a one-dimensional toy where every quantity is exact. Class A is two equal bumps at −1.6-1.6 and −0.55-0.55; class B is one bump at +1.1+1.1 holding half the data. For a mixture of Gaussians the noised density, its score and the noised classifier p(A∣xt)p(A \mid x_t) all have closed forms, so the only approximations are the paper's: a finite number of steps and the mean shift (10), with the gradient taken at xtx_t. The schedule is ADM's linear one, respaced to the chosen step count. Paths start from N(0,1)\mathcal{N}(0,1) at the top; the histogram shows 3,000 samples at the scrubbed step against the true class-A density at that noise level.

Figure 6 · guided sampling on a 1-D toy
step 250/250
1.0
steps
Press Play to run the sampler from noise (top) to data (bottom), or drag the scrubber. Paths are teal if they end in class A and amber if they end in class B. Set s=0s = 0 for unguided sampling, s=1s = 1 for the exact conditional, and higher to watch the class-A bump nearer class B empty out. The step buttons change how many steps the sampler takes.

At s=0s = 0 the sampler is unconditional and half the samples end in class B. At s=1s = 1 with 250 steps, 99.9% end in class A and the bump nearer class B holds 51% of them, against 50% in the true p(x∣A)p(x \mid A), so the sampler draws from the correct conditional. At s=3s = 3 that bump holds 27% of the class-A samples, and at s=10s = 10, 14%. The samples stay in class A, which is what precision measures, while the part of class A that looks most like class B empties, which is what recall measures. With 25 steps at s=1s = 1, only 92% of samples land in class A, and with 10 steps 77%: coarse steps under-apply the guidance, and a larger ss makes up for it.

Multiplying a classifier's gradient by 10 is also how adversarial examples are made: small changes to an input that drive a classifier to high confidence without changing what a person sees. Guidance at s=10s = 10 produces corgis instead. The paper reports that the scale can be raised "by an order of magnitude without obtaining adversarial examples", and separately that the classifier is trained on noised images. Connecting the two is this page's interpretation, not the paper's argument: a classifier that must work on heavily noised inputs cannot rely on the fine, high-frequency patterns that adversarial perturbations exploit, so its gradients point toward coarse, class-level structure. Tsipras et al. (2019) found that adversarially robust classifiers learn features that align better with human perception, which is consistent with this reading.

This ss is not the weight ww of classifier-free guidance, the follow-up that removes the separate classifier. Classifier-free guidance at weight ww corresponds to a classifier-guidance scale of s=w+1s = w + 1, so its w=0w = 0 is plain conditional sampling.

Guiding the deterministic DDIM sampler

The 25-step results use DDIM, which maps noise to an image deterministically, with no Gaussian sampled at each step, so (10) has no covariance to shift. The paper instead adapts the score-based route from Song et al. The score of the joint pθ(xt) pϕ(y∣xt)p_\theta(x_t)\,p_\phi(y \mid x_t) is a sum, because the log of a product is the sum of the logs, and (5) supplies the first term:

∇xtlog⁡(pθ(xt) pϕ(y∣xt))=−11−αˉt ϵθ(xt)+∇xtlog⁡pϕ(y∣xt)\nabla_{x_t}\log\big(p_\theta(x_t)\,p_\phi(y \mid x_t)\big) = -\frac{1}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t) + \nabla_{x_t}\log p_\phi(y \mid x_t)∇xtlog⁡(pθ(xt) pϕ(y∣xt))=−11−αˉt ϵθ(xt)+∇xtlog⁡pϕ(y∣xt)\begin{aligned} &\nabla_{x_t}\log\big(p_\theta(x_t)\,p_\phi(y \mid x_t)\big) \\ &\quad = -\frac{1}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t) + \nabla_{x_t}\log p_\phi(y \mid x_t) \end{aligned}
(12)

Define a new noise prediction ϵ^\hat\epsilon whose score, through (5), is this joint score: multiply (12) by −1−αˉt-\sqrt{1-\bar\alpha_t}. With the scale on the classifier term,

ϵ^(xt)=ϵθ(xt)−s 1−αˉt ∇xtlog⁡pϕ(y∣xt)\hat\epsilon(x_t) = \epsilon_\theta(x_t) - s\,\sqrt{1-\bar\alpha_t}\,\nabla_{x_t}\log p_\phi(y \mid x_t)
(13)

Adding the classifier gradient to the score subtracts it from the noise, since the score is the noise times −1/1−αˉt-1/\sqrt{1-\bar\alpha_t}. DDIM then runs unchanged with ϵ^\hat\epsilon in place of ϵθ\epsilon_\theta. The paper prints its version of (13), and the matching line of Algorithm 2, without ss, although Algorithm 2 takes "gradient scale ss" as an input; the official code multiplies the classifier gradient by classifier_scale before condition_score subtracts it. The DDIM loop, with the scale where the code applies it:

# Algorithm 2: classifier-guided DDIM (deterministic), gradient scale s
x = randn(3, 256, 256)
for t in reversed(range(T)):            # 25 strided steps in the paper's fast runs
    eps = eps_model(x, t)
    g = grad(log_softmax(classifier(x, t))[y], x)
    eps_hat = eps - s * sqrt(1 - abar[t]) * g     # Eq. (13): subtract from the noise
    x0_pred = (x - sqrt(1 - abar[t]) * eps_hat) / sqrt(abar[t])
    x = sqrt(abar_prev[t]) * x0_pred + sqrt(1 - abar_prev[t]) * eps_hat
return x

Results: the trade-off curve and beating BigGAN

On ImageNet 256×256 the paper measures guidance at s=0s = 0, 1 and 10 on a conditional and an unconditional diffusion model, both trained for 2M iterations with batch size 256 (Table 4). Figure 7 places those points on the precision/recall plane with BigGAN-deep for reference.

Figure 7 · the measured trade-off
s = 1
Precision against recall on ImageNet 256×256; guided points from Table 4, BigGAN-deep from Table 5. Each point is a gradient scale ss, and raising it trades recall for precision. FID is best at the middle point (s=1s=1, FID 4.59). BigGAN-deep sits at high precision and low recall. Switch between the conditional and unconditional models; select a point or drag the slider to read its numbers.

The unguided conditional model has FID 10.9410.94, precision 0.690.69 and recall 0.630.63. At s=1s = 1: FID 4.594.59, precision 0.820.82, recall 0.520.52, and Inception Score up from 100.98100.98 to 186.70186.70. At s=10s = 10: precision 0.880.88, recall 0.320.32, FID 9.119.11. FID responds to both fidelity and diversity, so its best value is at an intermediate scale. The unconditional model gets worse at s=1s = 1 (FID 33.0333.03) and reaches 12.0012.00 at s=10s = 10, close to the unguided conditional model's 10.9410.94; the paper adds that "training directly with the class labels still helps", and guiding the conditional model gives the best result. The headline numbers all come from guided class-conditional models (ADM-G), with scales tuned per setting between 0.50.5 (ImageNet 128, 250 steps) and 9.09.0 (ImageNet 512, 25-step DDIM).

BigGAN-deep sits at precision 0.870.87 and recall 0.280.28. At s=1s = 1 the guided model gives up a little precision (0.820.82) for much more recall (0.520.52); at s=10s = 10 it matches the GAN's precision with recall 0.320.32. On ImageNet 128 the paper finds guidance "strictly better than BigGAN-deep when trading off FID for Inception Score", but on precision and recall it is better only up to a precision threshold, beyond which it "cannot achieve better precision".

The headline FIDs (Table 5) use 250 steps: 2.972.97 at 128×128, 4.594.59 at 256×256 and 7.727.72 at 512×512, against BigGAN-deep's 6.026.02, 6.956.95 and 8.438.43. With 25 DDIM steps ADM-G scores 5.985.98, 5.445.44 and 8.418.41, so 25 diffusion-model passes per sample, plus 25 classifier gradients, match BigGAN-deep at every resolution. A two-stage stack, a guided low-resolution model (64×64 for the 256 result, 128×128 for 512) followed by an upsampling diffusion model called ADM-U, reaches 3.943.94 at 256 and 3.853.85 at 512. Only the low-resolution model is guided. ADM-U on top of an unguided base gives 7.497.49 and 9.969.96, so guidance and upsampling each contribute.

Diffusion still costs more. In training compute (Table 10, in V100-days), the full ImageNet 256 ADM-G took 916 for the diffusion model plus 46 for the classifier, against an estimated 128 to 256 for BigGAN-deep. Stopping at 750K iterations, 393 V100-days in total, already gives FID 6.496.49, under BigGAN-deep's 6.956.95. At sampling time a GAN needs one network pass per image and ADM-G needs 25 to 250. A nearest-neighbour search in Inception-V3 feature space on a handful of guided samples found no copies of training images.

Limitations and what came next

The paper names two limitations. Sampling is still slower than a GAN's single pass; the authors point to Luhman and Luhman's distillation of DDIM into a one-step model as a direction, noting its samples were not yet competitive with GANs. And classifier guidance needs labels: the paper offers no way to trade diversity for fidelity on an unlabeled dataset. It suggests guiding an image generator with a noised CLIP model to condition on text captions.

Both directions were taken up within a year. Classifier-free guidance trains one diffusion model with and without the label and combines its two predictions, so no separate classifier is needed. GLIDE and then unCLIP (DALL-E 2) guided text-to-image diffusion models, and latent diffusion moved the process into an autoencoder's latent space, the basis of Stable Diffusion. DiT replaced the U-Net with a Transformer on the same ImageNet benchmarks, conditioning it with adaptive layer norm, the same scale-and-shift that AdaGN applies after group norm.

Provenance Verified against primary literatureHow we verify
DDPM (Ho et al. 2020)The VP forward process, epsilon-prediction and L_simple, and the baseline U-Net: one global attention layer at 16x16 with a single head, with the timestep embedding added into each residual block.
Improved DDPM (Nichol & Dhariwal 2021)The learned reverse variance and the hybrid objective. It also introduced the cosine schedule, which ADM uses only for ImageNet 64x64 (and its classifier); the LSUN and ImageNet 128/256/512 models use the linear schedule (Table 11).
DDIM (Song et al. 2020)The deterministic sampler the paper uses below 50 steps, including all 25-step results.
Score SDE (Song et al. 2021)The score view and the classifier-gradient conditioning the paper adapts for DDIM (Eqs. 12 and 13 here).
Sohl-Dickstein et al. (2015)Conditioning a reverse step by multiplying in a classifier, and the perturbed-Gaussian approximation (Eqs. 8 to 10 here).
BigGAN (Brock et al. 2018)The truncation trick, the residual up/downsampling block ADM adopts (following Song et al. 2020b), and the GAN baseline.
Kynkäänniemi et al. (2019)Improved precision and recall: each manifold is the union of hyperspheres reaching the k-th nearest neighbour, k = 3 (guided-diffusion evaluations/evaluator.py, nhood_sizes=(3,)).
guided-diffusion (official code)gaussian_diffusion.py:356-369 condition_mean adds variance * gradient, with the gradient evaluated at the current x_t; :371-393 condition_score subtracts sqrt(1 - alpha_bar) * gradient from eps; scripts/classifier_sample.py:54-61 multiplies the gradient by classifier_scale; unet.py:251 applies AdaGN as out_norm(h) * (1 + scale) + shift.
correctionTwo points. (1) The guided step N(μ + sΣg, Σ) is a first-order Taylor approximation of the classifier's log-probability around the step mean. The paper justifies it by assuming low curvature compared with Σ⁻¹, "reasonable in the limit of infinite diffusion steps, where ||Σ|| → 0". What it approximates is exact: the reverse step times the classifier with a normalizing constant (the paper's Eq. 2), and the appendix proof that adding a label leaves the forward process unchanged. With coarse steps the approximation degrades, which is why few-step guided sampling needs a larger, hand-tuned scale (1.25, 2.5 and 9.0 for 25-step DDIM against 0.5, 1.0 and 4.0 for 250 steps). (2) The paper's Eq. 14 and the ε̂ line of Algorithm 2 print no gradient scale, although Algorithm 2 lists "gradient scale s" as an input and the DDIM results use s up to 9.0. The official code multiplies the classifier gradient by classifier_scale before subtracting it from ε, so this page writes ε̂ = ε_θ − s√(1−ᾱ_t)∇log p_φ(y|x_t).

Questions you might still have

?

Is classifier guidance the same as classifier-free guidance?
No. Classifier guidance uses a separate classifier trained on noised images, and its gradient shifts each reverse step toward the class. Classifier-free guidance (Ho and Salimans, covered in our Classifier-Free Diffusion Guidance explainer) drops the separate classifier and combines the diffusion model's own conditional and unconditional predictions. The two parameterize the strength differently: this paper's s multiplies the classifier gradient, while classifier-free guidance at weight w corresponds to a scale of s = w + 1.

?

Does classifier guidance require retraining the diffusion model?
No. The diffusion model is used as trained; guidance needs only a classifier trained on the same noised images, which costs much less (43M to 65M parameters against 296M to 559M for the diffusion models). The paper's best results guide a class-conditional diffusion model, though: guiding an unconditional model at s = 10 gets FID 12.00 on ImageNet 256, close to the unguided conditional model's 10.94, and guiding the conditional model reaches 4.59.

?

Why not use an ordinary pretrained ImageNet classifier?
At every step the classifier sees the current noisy image x_t, not a clean one. Halfway through sampling on ADM's schedule, x_t is 0.28 times an image plus noise of standard deviation 0.96, an input a clean-image classifier never saw. The paper trains its classifiers on the same noising distribution as the diffusion model and gives them the timestep as an input.

?

Why does amplifying the classifier gradient not produce adversarial noise?
The paper reports that the scale can be raised by an order of magnitude without obtaining adversarial examples, and that its classifiers are trained on noised images. Linking the two is an interpretation: a classifier that must work on heavily noised inputs cannot depend on the fine high-frequency patterns adversarial perturbations exploit, so its gradients point toward coarse class structure. The paper does not make that argument itself.

?

Is the guided reverse step exact?
Partly. Multiplying the reverse step by the classifier and renormalizing is exact, as is the proof that adding a label leaves the forward process unchanged. The single Gaussian with its mean shifted by s times Sigma times g is a first-order Taylor approximation of the classifier, accurate when the step is narrow. With few, wide steps it under-applies or misplaces the guidance, which is why 25-step sampling uses larger scales.

?

Why is FID lowest at an intermediate gradient scale?
FID compares the whole feature distribution, so it penalizes both bad samples and missing variety. A large scale makes samples more class-typical but removes coverage, which FID also punishes. On conditional ImageNet 256 the best of the measured points is s = 1 (FID 4.59); s = 10 gives 9.11.

?

Does strong guidance make the model copy training images?
The paper checks a handful of guided samples by finding their nearest neighbours in Inception-V3 feature space, at scale 1 with 250 steps and scale 2.5 with 25 DDIM steps, and finds they are not copies of training images. Guidance concentrates samples on class-typical regions, but the samples are still new images.

?

How much extra work does guidance add per sampling step?
One classifier forward pass and one backward pass to get the gradient with respect to the image, on top of the diffusion model's forward pass. The classifier is the downsampling half of a U-Net, so this is smaller than the diffusion model's pass.

Footnotes & further reading

  1. The paper: Dhariwal & Nichol, Diffusion Models Beat GANs on Image Synthesis (OpenAI, NeurIPS 2021). Official code (guided-diffusion).
  2. The diffusion foundations: Ho et al., Denoising Diffusion Probabilistic Models (our explainer), and Nichol & Dhariwal, Improved Denoising Diffusion Probabilistic Models (learned variance, hybrid loss, cosine schedule).
  3. The score view and the score-based conditioning: Song et al., Score-Based Generative Modeling through SDEs (our explainer), building on score matching with Langevin dynamics. The deterministic sampler is DDIM.
  4. The original classifier-conditioned diffusion step: Sohl-Dickstein et al., Deep Unsupervised Learning using Nonequilibrium Thermodynamics (our explainer).
  5. The GAN baselines and the truncation trick: Brock et al., Large Scale GAN Training (BigGAN), and the original GAN. Precision and recall: Kynkäänniemi et al., Improved Precision and Recall Metric; FID: Heusel et al.
  6. Feature-wise modulation, the lineage of AdaGN: FiLM and adaptive instance norm. Robust classifiers and perceptually aligned features: Tsipras et al., Robustness May Be at Odds with Accuracy.
  7. The follow-up that removes the separate classifier: Ho & Salimans, Classifier-Free Diffusion Guidance (our explainer).