Classifier guidance

On this page 7

Classifier guidance is a sampling technique for diffusion models in which the gradient of a separately trained noise-aware classifier is added to each denoising step, pushing the sample toward images the classifier assigns to a chosen class. In generative AI, it was the first method that let diffusion models trade diversity for fidelity in a controlled way, and it helped diffusion models overtake GANs on class-conditional image benchmarks.

The method was introduced in 2021 in the work that presented the ablated diffusion model (ADM). A single number, the guidance scale, controls how strongly the classifier influences sampling. Low values keep the variety of the original model, while high values produce sharper, more recognizable class examples at the cost of reduced sample diversity.

How classifier guidance modifies the sampling step

Classifier guidance works by adding a class-specific gradient to the score that the diffusion model already estimates. A diffusion model learns the score of the noisy data distribution, written as the gradient of log p(x_t) with respect to the noisy sample x_t. Bayes’ rule shows that the conditional score equals this unconditional score plus the gradient of log p(y | x_t), where y is the desired class label.

The classifier supplies that second term. At each timestep, the current noisy sample is passed through the classifier, the log-probability of the target class is computed, and backpropagation returns its gradient with respect to the input pixels or latents. This gradient is multiplied by the guidance scale s and added to the model’s prediction, so the guided score becomes the unconditional score plus s times the classifier gradient.

In ancestral DDPM sampling, the shift is applied to the mean of the reverse transition, scaled by its variance. In deterministic DDIM sampling, the same idea is expressed through the predicted noise: the classifier gradient, multiplied by the noise level and the scale, is subtracted from the noise prediction. Both forms move the trajectory toward regions the classifier rates as more typical of the class.

The table below lists the components that take part in one guided step.

ComponentRoleTrained on
Diffusion modelPredicts noise or score for x_tClean data with added noise
Noisy classifierEstimates p(y | x_t, t)Noisy samples at all timesteps
Guidance scale sWeights the classifier gradientChosen by hand, not trained
Timestep embeddingTells the classifier the noise levelShared schedule with the model
Components of a guided sampling step

Why the classifier must be noise-aware

An ordinary image classifier cannot provide useful guidance, because intermediate diffusion samples are heavily corrupted. Early in sampling, x_t is almost pure Gaussian noise, and a classifier trained only on clean photographs produces gradients that are meaningless or adversarial at that stage.

The original implementation therefore trained a classifier on noised versions of the training images, using the same noise schedule as the diffusion model and receiving the timestep as an input. In ADM, this classifier reused the downsampling half of the U-Net with attention pooling at the output. Training it requires labeled data and a full extra training run, which is a significant practical cost for every new dataset or label set.

Because the classifier sees the timestep, it learns how confident it can reasonably be at each noise level. At high noise levels its gradient mostly shapes coarse layout and color, while at low noise levels it refines textures and class-specific details.

The guidance scale and its effect

The guidance scale effectively samples from a sharpened conditional distribution proportional to p(x) times p(y | x) raised to the power s. A scale above 1 concentrates probability mass on inputs that the classifier labels with high confidence, which raises precision and Inception Score while lowering recall.

The original experiments used scales near 1 for class-conditional models and up to about 10 for unconditional models, because an unconditional model needs a stronger push to produce class-specific content. Optimal values depend on the dataset, resolution and evaluation metric, so they are found by sweeping the scale and measuring results.

Scale rangeFidelityDiversityTypical risk
0 (no guidance)BaselineFull model diversityWeak class identity
About 1 to 3Clearly improvedModerately reducedSmall FID changes
About 4 to 10High precisionStrongly reducedRepetitive samples
Above 10Exaggerated featuresCollapsedSaturated, artifact-heavy images
Typical behavior across guidance scales

The best FID score usually appears at a moderate scale, while the best Inception Score appears at a higher one. This divergence is the clearest illustration of the fidelity-diversity trade-off that guidance introduces.

Classifier guidance belongs to a family of methods that steer a pretrained generative model at sampling time. Its closest successor, classifier-free guidance, removed the external classifier, and that change explains why most current text-to-image systems no longer use the original approach.

MethodSource of guidance signalExtra model neededMain limitation
Classifier guidanceGradient of a noisy classifierYes, noise-aware classifierFixed label set, extra training
Classifier-free guidanceDifference between conditional and unconditional predictionsNoDoubles network evaluations per step
CLIP guidanceGradient of image-text similarityYes, ideally a noised CLIPProne to adversarial artifacts
Truncation trickRestricting the GAN latent distributionNoApplies to GANs, not diffusion
Classifier guidance and neighboring techniques

Classifier-free guidance trains one network both with and without the condition by randomly dropping labels, then extrapolates between the two predictions. It achieves a similar trade-off, works with free-form text prompts, and avoids classifier gradients that can exploit non-robust features. In practice it also produced better perceptual quality in large text-to-image comparisons.

Limitations and common mistakes

Classifier guidance is powerful but brittle, and most failures trace back to the classifier rather than to the diffusion model. The gradient can be adversarial: it may raise the classifier’s confidence by adding subtle patterns instead of genuinely improving the class content.

SymptomLikely causeRemedy
Noisy, textured artifactsClassifier trained only on clean imagesTrain on noised inputs with timestep input
Near-identical outputsGuidance scale set too highLower the scale and sweep FID
Wrong or mixed classesWeak or poorly calibrated classifierImprove classifier accuracy at high noise
Slow samplingBackpropagation through the classifier each stepUse classifier-free guidance instead
Frequent problems and their remedies
  • The label set is fixed at classifier training time, so new concepts require a new classifier.
  • Each step needs a forward and backward pass through the classifier, which adds memory and latency.
  • Higher Inception Score does not mean better images: strong guidance can inflate metrics while reducing realism.

Put simply

A diffusion model makes a picture by cleaning up noise step by step. On its own, it may drift toward any kind of image. Classifier guidance adds a second opinion. A separate model looks at the half-finished picture and says how much it resembles, for example, a dog.

At every step, the picture is nudged in the direction that makes it look more like a dog. A dial sets how hard that nudge is. A gentle setting keeps variety, while a strong setting gives clear but similar dogs. Push too hard, and the images start to look strange.

In practice

A research team trains an unconditional diffusion model on a large dataset of bird photographs covering 200 species. A field guide project then asks for clear example images of specific species. Rather than retraining the generator, the team trains a noise-aware species classifier on noised versions of the same photographs, with the timestep as an extra input.

During sampling, the team sweeps the guidance scale from 1 to 10 and scores each setting with FID and a separate expert review. At a scale of about 1, many samples show blurred plumage that experts cannot identify. Around a scale of 4, species identification by reviewers rises sharply, while pose and background still vary. At a scale of 10, birds look nearly identical and show oversaturated colors.

The team settles on a moderate scale of about 4 for the field guide images. Later, when the project expands to new species, the team must retrain the classifier, which leads it to evaluate classifier-free guidance for the next version.