Classifier Guidance Steers Diffusion
Classifier guidance steers a diffusion sampler with gradients from a noisy image classifier, pushing each step toward the requested class.
Why Does This Exist?
Unconditional diffusion draws from the whole data distribution at once. Asking it for a golden retriever means hoping one appears, and retraining a conditional model per control is prohibitively expensive. Classifier guidance bolts steering onto a frozen model: one big unconditional sampler plus a small classifier per control. This page covers the gradient-steered original; the successor that drops the extra classifier lives in classifier-free guidance, and the sampler loop it plugs into in diffusion samplers.
The one idea you need first
A reverse diffusion step cleans a noisy sample slightly, predicting a mean for the cleaner sample. Run that loop from pure noise and an image emerges. Guidance intervenes inside each single step: before sampling, shift the mean a little toward whatever scores higher under a classifier for the target class. Small shifts compound over dozens of steps into a different image.
Think of It Like This
A bloodhound leading a painter
A painter works half-blind, sketching whatever emerges. A bloodhound beside them sniffs each stroke and tugs the brush toward the scent of retriever. A gentle leash lets the painter compose freely with a nudge; a yanked leash drags every stroke onto the same canonical dog pose.
The guidance scale is the leash tension, and the analogy stops at training: a real bloodhound arrives pre-trained, while this one must learn every noise level or its tugs point nowhere.
How It Actually Works
At reverse step with current sample , the unconditional model predicts mean . A noise-aware classifier scores the target class . The guided step shifts the mean along the classifier gradient:
is the guidance scale, the step covariance. At sampling is unconditional; follows the classifier's natural slope; production values often land near to for crisp class features at visible diversity cost. The classifier must train on the same noise schedule, because a clean-image classifier's gradients point meaninglessly on heavy noise.
Worked example
Mid-sampling, the classifier gives target probability with gradient in the class direction, and scales steps by . At the nudge is per step, gentle pressure that compounds over fifty steps. At the nudge is per step, enough to drag marginal samples onto canonical class features within a dozen steps, and enough to collapse variety if every sample takes the same ride.
Code
Guided mean update, the arithmetic inside one reverse step:
def guided_mean(mu: float, grad: float, sigma: float = 0.02, s: float = 1.0) -> float: """Shift the predicted mean along the classifier gradient.""" return mu + s * sigma * grad
print(round(guided_mean(0.5, 0.4, s=1.0), 3)) # -> 0.508 gentle pressureprint(round(guided_mean(0.5, 0.4, s=8.0), 3)) # -> 0.564 firm steeringWatch Out For
Guiding with a clean-image classifier
A classifier trained on pristine photos has never seen noise, so its gradients on at high noise are arbitrary directions that shred composition. Samples degenerate into adversarial textures that maximise classifier score while looking like static. Always train or fine-tune the classifier across the diffusion noise schedule.
Cranking scale until diversity dies
High prints the classifier's favourite exemplar repeatedly. Benchmarks scored at flatter fidelity metrics while coverage collapses. Sweep and plot fidelity against diversity, then ship the knee of the curve rather than the fidelity maximum.
The Quick Version
- Classifier guidance adds to each denoising mean.
- The classifier must train on the same noise schedule as the diffusion model.
- A worked step moves 0.508 at versus 0.564 at .
- The scale knob trades class crispness against sample variety.
- Clean-image classifiers and maxed-out scales are the two standard failures.