skip to content

Search

← From Noise to Image

Part II — The Diffusion Revolution (2015–2022)

Guidance

Classifier guidance, the classifier-free guidance formula, and the dial between fidelity and diversity.

2021–2022 13 min read 3 papers

It is May 2021. Diffusion models can already match the likelihoods of other generative approaches, and faster samplers have cut the cost of drawing from them, but on the benchmark that matters most for images — class-conditional synthesis on ImageNet — they still look soft and generic next to the sharpest GANs. Over the following fourteen months, two papers hand diffusion a dial: turn it one way for fidelity, the other for diversity, and for the first time a diffusion model beats a GAN on its own turf.

Where We Were

By mid-2020, diffusion had a working denoising objective. DDPM (Ho et al., 2020) trains a network ϵθ\epsilon_\theta to predict the noise added to an image at each step of a fixed forward corruption process, then runs that prediction in reverse to generate samples — the mechanism lives in Chapter 8. Sampling was slow, requiring on the order of a thousand steps, until DDIM and the score-based SDE view later that year showed the same trained models could be run with far fewer, better-chosen steps; that reformulation is Chapter 9’s subject. By early 2021, diffusion models were fast enough and theoretically grounded enough to be judged seriously against the field’s reigning architecture for high-fidelity image synthesis: the GAN.

The incumbent set a high bar. BigGAN-deep (Brock et al., September 2018) — a class-conditional GAN scaled up on ImageNet, covered in Chapter 6 — reached an FID of 6.02 at 128×128 resolution, 6.95 at 256×256, and 8.43 at 512×512. Its samples were the sharpest and most texturally detailed the field had produced, at the cost of the training instability and mode collapse that motivated Chapter 4. A plain class-conditional diffusion model, by contrast, was stable to train and covered the data distribution more completely, but its samples looked soft: given only a class label, the model did not lean on that label hard enough, drifting toward generic, low-detail images of the requested class rather than confident, specific ones. The gap was not really “diffusion versus GANs” — it was one narrower failure, and it had a name once someone went looking for it: conditioning that was too weak.

Diffusion spends three years closing the fidelity gap on GANs Each step is stable and covers the data well. None of them yet beats the sharpest GAN on ImageNet. Grey monospace text is the chapter's number or phrase for that moment. 2018-09 BigGAN-deep sets the fidelity bar FID 6.95 at 256x256 2020-06 DDPM a real likelihood generator predicts noise each step 2020-10 DDIM fast, deterministic steps fewer steps, same model 2020-11 Score-SDE unifies diffusion as a score score = noise, rescaled 2021-05 Still behind soft, generic class samples conditioning too weak the GAN incumbent diffusion's own progress the unresolved gap this chapter closes Guidance, the mechanism this chapter introduces, is what finally turns the last card sage.
Diffusion spends three years becoming stable and fast without yet becoming sharp. The gap the coral card names, weak conditioning, is exactly what guidance closes next. PNG ↓

The Breakthrough

“Diffusion Models Beat GANs on Image Synthesis” (Dhariwal & Nichol, 2021), submitted to arXiv in May 2021, closed the gap with two changes: an improved U-Net (more attention heads, timestep-conditioned normalization, and a handful of tuning choices this chapter does not need to re-derive) and a new sampling technique, classifier guidance. The insight behind it is that a diffusion model’s noise prediction is already equivalent to a score — a gradient of a log-density — at every step (Chapter 9 develops the score view in full), and gradients of different log-densities simply add. So train a second network, a classifier pϕ(y∣xt)p_\phi(y \mid x_t) that recognizes the target class yy from a partially noised image xtx_t at every noise level the diffusion process visits, and at each sampling step nudge the predicted noise in the direction that increases that classifier’s confidence — scaled by a hyperparameter ss.

Classifier guidance nudges every denoising step toward a class A second network scores the noisy image, and its gradient is subtracted from the predicted noise before the step is taken. Grey monospace text names the chapter's formula for that box. Noisy image x_t at diffusion step t one of 250 sampling steps Diffusion model predicts the noise eps_theta(x_t, t) Classifier gradient scores confidence in class y gradient scaled by s trained on noised x_t, all t Combine subtract gradient from noise scaled by guidance s Reverse diffusion step produces the next x_t-1 repeat until t = 0 the classifier is asked again at the next step the noisy image being denoised the diffusion model's own process the classifier's judgement
Every one of a few hundred sampling steps repeats this same loop: ask the classifier again, nudge the prediction, step once more. PNG ↓

The effect was decisive. Sampling 250 steps on ImageNet at a guidance scale of s=1.0s=1.0, FID at 256×256 fell from 10.94 unguided to 4.59 guided — enough to pass BigGAN-deep’s 6.95. At 128×128 the guided model reached 2.97 against BigGAN-deep’s 6.02, and at 512×512, 7.72 against 8.43. Pushing ss above 1.0 traded further: sharper, more class-typical images at some cost to how much of the class’s diversity any single sample showed — the paper describes this as trading recall for precision. Classifier guidance was diffusion’s first credible, quantified route past the GAN benchmark, and it made a second point that mattered as much as the numbers: guidance strength was now a knob a practitioner could turn at sampling time, not a property fixed when the model was trained.

The knob had a structural cost. Classifier guidance needed a second network trained from scratch on the diffusion process’s own noise schedule — an ordinary ImageNet classifier, trained only on clean images, has never seen anything as noisy as an early-step xtx_t. The paper builds this classifier cheaply, by reusing the diffusion U-Net’s own downsampling trunk and terminating it early with an attention-pooling head, but reuse of architecture did not mean reuse of training: the classifier still needed its own training run, on the same noised images, before it could be used. Every sampling step then paid for a classifier forward pass and a backward pass through it, on top of the diffusion model’s own forward pass. And the technique could only condition on whatever discrete labels the classifier had learned — a thousand ImageNet classes, not the open-ended text prompts the field wanted within the year.

“Classifier-Free Diffusion Guidance” (Ho & Salimans, 2022), submitted in July 2022, removed the second network by removing the classifier’s job rather than just its cost. During training, the diffusion model is shown its conditioning cc — a class label, or later a text embedding — with some probability, and shown a fixed null token with the remaining probability, so one network learns both a conditional prediction ϵθ(xt,c)\epsilon_\theta(x_t, c) and, for free, an unconditional prediction ϵθ(xt)\epsilon_\theta(x_t). At sampling time both predictions come from that same network, and the guided estimate is an extrapolation away from the unconditional prediction and toward the conditional one — no classifier, no second network, no extra labeled data.

One model, run twice, replaces the classifier and its gradient Conditioning dropout during training teaches a single network both a conditional and a null prediction. Grey monospace text is each box's actual prediction. CONDITIONED PASS NULL PASS Conditioning c a label, or text embedding seen 90% of training steps Conditional pass network told the caption eps_theta(x_t, c) Null conditioning a fixed placeholder token seen 10% of training steps Unconditional pass same network, no caption eps_theta(x_t) Extrapolate push past the conditional away from the unconditional weight w controls the push Guided noise estimate used for this sampling step feeds the reverse step the conditioning input the network's own pass the guidance dial Same fidelity for diversity trade as classifier guidance, no second network.
One set of weights learns both jobs through conditioning dropout, so sampling can extrapolate between them with no second network. PNG ↓

The Mathematics

Classifier guidance and classifier-free guidance both modify the same object: the noise, or score, the network predicts at each denoising step, developed in full in Chapter 8. They arrive there by different routes.

Both formulas below lean on a fact Chapter 9 establishes in full: a diffusion model’s noise prediction and the score of the noisy-data distribution are the same object up to a known rescaling, ϵθ(xt,t)≈−1−αˉt ∇xtlog⁡pθ(xt)\epsilon_\theta(x_t, t) \approx -\sqrt{1-\bar\alpha_t}\,\nabla_{x_t}\log p_\theta(x_t). That correspondence is what lets a gradient — something classifiers and score-based samplers speak fluently — be added directly to a noise prediction, rather than requiring the two formulas to be reconciled through some separate change of variables.

Classifier guidance rests on the fact that gradients of log-probabilities add when probabilities multiply, then substitutes that sum into the noise prediction the sampler actually uses:

∇xtlog⁡(pθ(xt) pϕ(y∣xt))=∇xtlog⁡pθ(xt)+∇xtlog⁡pϕ(y∣xt)ϵ^=ϵθ(xt,t)−s1−αˉt ∇xtlog⁡pϕ(y∣xt)\begin{aligned} \nabla_{x_t} \log\big(p_\theta(x_t)\,p_\phi(y \mid x_t)\big) &= \nabla_{x_t} \log p_\theta(x_t) + \nabla_{x_t} \log p_\phi(y \mid x_t) \\ \hat{\epsilon} &= \epsilon_\theta(x_t, t) - s\sqrt{1-\bar\alpha_t}\,\nabla_{x_t} \log p_\phi(y \mid x_t) \end{aligned}
SymbolMeaning
xtx_tthe noisy image at diffusion step tt
pθ(xt)p_\theta(x_t)the diffusion model’s implicit density over noisy images
pϕ(y∣xt)p_\phi(y \mid x_t)a classifier trained to recognize class yy from a noisy xtx_t
yythe target class label
ϵ^\hat{\epsilon}the guided noise prediction actually used to take the sampling step
ϵθ(xt,t)\epsilon_\theta(x_t, t)the diffusion model’s unguided noise prediction
ssthe guidance scale, a tunable hyperparameter
αˉt\bar\alpha_tthe cumulative signal-retention factor of the forward noising process at step tt

Classifier-free guidance keeps the same one-model-only setup and skips the classifier entirely, extrapolating between the network’s conditional and unconditional predictions:

ϵ~θ(xt,c)=(1+w) ϵθ(xt,c)−w ϵθ(xt)\tilde{\epsilon}_\theta(x_t, c) = (1+w)\,\epsilon_\theta(x_t, c) - w\,\epsilon_\theta(x_t)
SymbolMeaning
ϵ~θ\tilde{\epsilon}_\thetathe guided noise prediction used at sampling time
ϵθ(xt,c)\epsilon_\theta(x_t, c)the network’s prediction conditioned on cc
ϵθ(xt)\epsilon_\theta(x_t)the same network’s prediction with null conditioning
ccthe conditioning signal — a class label, later a text embedding
wwthe guidance weight, a tunable hyperparameter
xtx_tthe noisy image at diffusion step tt

The two formulas are the same idea in different clothing. The CFG paper shows that the difference between its conditional and unconditional predictions, ϵθ(xt,c)−ϵθ(xt)\epsilon_\theta(x_t, c) - \epsilon_\theta(x_t), plays the same role — up to the 1−αˉt\sqrt{1-\bar\alpha_t} scaling in the equation above — as ∇xtlog⁡p(c∣xt)\nabla_{x_t} \log p(c \mid x_t), the classifier gradient classifier guidance needed a trained network to supply. Classifier-free guidance did not remove that gradient from the math; it observed that a model trained both conditionally and unconditionally already contains it, for the price of one extra forward pass instead of one extra network.

The paper’s own ImageNet 64×64 ablation, with conditioning dropped 10% of the time during training (puncond=0.1p_{\text{uncond}}=0.1), shows the trade-off directly:

Guidance weight wwFIDInception Score
0.01.8053.71
0.11.5566.11
0.33.0392.8
1.012.6170.1

FID — Fréchet Inception Distance, the field’s standard distributional-similarity metric, introduced with the TTUR paper and covered in Chapter 21 — bottoms out around a modest guidance weight and then rises again, while Inception Score, a rougher proxy for how confidently classifiable and sharp individual samples look, keeps climbing. That crossing point is the guidance dial made numeric: somewhere past it, “more typical of the class” stops meaning “closer to the real data distribution” and starts meaning “less diverse.”

What It Enabled

The clearest before-and-after is the comparison the ADM paper set out to win:

Model128×128 FID256×256 FID512×512 FID
BigGAN-deep, 20186.026.958.43
Diffusion, unguided5.9110.9423.24
Diffusion, classifier guidance, s=1.0s=1.02.974.597.72

Guidance, not the architecture change alone, is what turned “roughly competitive” into “clearly ahead,” and it did so at every resolution tested, with the margin widening as resolution grew.

Classifier guidance itself saw limited further use once the classifier-free alternative existed: it needed a second network retrained for every new noise schedule or resolution, and it could only condition on a fixed, labeled vocabulary. Classifier-free guidance conditions on anything the base model already conditions on, which is what let it travel. GLIDE (December 2021) tested both a CLIP-based classifier and classifier-free guidance for text-to-image generation and found the classifier-free variant preferred by human raters — that comparison, and the text-conditioning setup itself, is Chapter 12’s subject. From GLIDE forward, conditioning dropout and a user-facing guidance-scale control became close to standard: DALL-E 2 and Imagen in 2022 (Chapter 14), Stable Diffusion the same year (Chapter 13), and the rectified-flow and diffusion-transformer models that followed (Chapter 19) all trained with conditioning dropout and exposed some form of the guidance weight to the people using them.

Classifier guidance, 2021Classifier-free guidance, 2022
Extra network at sampling timeyes, a noise-aware classifierno
Extra compute per stepclassifier forward and backward passone extra diffusion forward pass
Conditioning signalfixed label set the classifier was trained onanything the base model already conditions on
Change to diffusion trainingnoneconditioning dropout
Long-run adoptionlimited to labeled, class-conditional settingsGLIDE, DALL-E 2, Imagen, Stable Diffusion, and later models

The diversity cost is not a footnote. A guidance weight tuned for the sharpest-looking single sample is, by construction, a weight tuned to under-represent whatever modes of a class or prompt are less typical — a model guided hard toward “confident and class-typical” will sample the frequent, stereotypical version of a concept more often than the training data’s own variety would justify. That trade-off, first made explicit and measurable here, is an early instance of the representation and evaluation questions Chapter 21 takes up in full once guidance is standard equipment on production text-to-image systems rather than a research ablation.

Guidance became the default dial for text to image systems Classifier-free guidance's one-network trick propagated to every major model that followed it. Grey monospace text is the date or detail this book attaches to each system. Classifier guidance needs a second network Dhariwal and Nichol, 2021 Classifier-free one network, two passes Ho and Salimans, 2022 GLIDE text guided diffusion Dec 2021 Imagen large frozen text encoder 2022 Stable Diffusion open weights release Aug 2022 DALL-E 2 diffusion plus CLIP Chapter 14 Rectified flow, DiT later backbone shift Chapter 19 the guidance mechanism itself a shipped system that adopted it Classifier guidance itself saw little further use once the classifier-free version existed.
Once the classifier was removed, the same guidance dial travelled to every major text-to-image system that followed. PNG ↓

Key Papers

PaperAuthorsYearLinkWhy it matters
Denoising Diffusion Probabilistic ModelsHo et al.2020arXiv:2006.11239Establishes the noise-prediction network ϵθ\epsilon_\theta that both guidance formulas modify
Diffusion Models Beat GANs on Image SynthesisDhariwal & Nichol2021arXiv:2105.05233Introduces classifier guidance; first diffusion model to beat a strong GAN benchmark on ImageNet FID
Classifier-Free Diffusion GuidanceHo & Salimans2022arXiv:2207.12598Removes the auxiliary classifier via conditioning dropout; becomes the guidance mechanism behind nearly all later text-to-image diffusion models

PM Lens

Papers referenced