TL;DR
Classifier-free guidance makes a conditional diffusion model follow its condition more strongly, such as a text prompt. At each denoising step the model makes two predictions, one with the condition and one without. The sampler then moves past the conditional prediction, in the direction that the condition adds. A single number, the guidance weight, controls how far it moves.
The method needs no separate classifier. One network learns both the conditional and the unconditional behaviour, which is why it is simple to train and to scale.
Where you'll see it: in text-to-image generators such as Stable Diffusion, where the "guidance scale" slider is this weight, and in most text-conditioned image and video models built since 2022.
Intuition
Turning up the accent
Suppose you ask a painter for "a red barn" and they paint from a loose memory of barns. The result is plausible but vague. Now suppose you could ask the painter two things: draw a barn in general, and draw a barn that is specifically red. The difference between those two drawings is exactly what "red" adds. If you then push the painting further in that direction, the red becomes more pronounced than the painter would normally let it be.
That is the whole idea. A conditional model and an unconditional model disagree about the image, and the disagreement points toward the condition. Classifier-free guidance takes a step in that direction and overshoots a little on purpose.
Why overshoot? A diffusion model trained on a condition is trained to match the data distribution, and that distribution is broad. Samples from it are faithful to the whole distribution but not always to the prompt. Sharpening the sampling toward the condition gives up some diversity to get closer to what was asked for. This trade is the source of both the benefit and most of the failure modes below.
flowchart LR
Z[noisy image z_t] --> U[unconditional prediction]
Z --> C[conditional prediction given prompt]
U --> D[difference: what the prompt adds]
C --> D
D --> G[push past conditional by weight w]
U --> G
G --> S[next denoising step]
Both predictions come from the same network. The "unconditional" branch is the same model run with the condition switched off.
- unconditional, mean 0
- conditional, mean 1
- guided, w = 2, mean 3
The math
Two predictions from one network
Diffusion models predict a quantity at each noise level from the noisy input . The common choice is the noise , where is the condition, such as a text embedding. The same network can be run with the condition removed. During training, the condition is dropped at random for a fraction of examples, so the network learns both behaviours. The original paper compares dropout rates of 0.1, 0.2 and 0.5 and finds that 0.5 is consistently worse than 0.1 or 0.2, which perform about equally. The unconditional prediction is written .
Here is a null token that stands for "no condition".
The guided prediction
The guided prediction is
Here is the guidance weight. Setting gives the plain conditional model. Larger moves further from the unconditional prediction and past the conditional one.
Rearranged, this is the conditional prediction plus times the difference:
The bracketed difference is the direction the condition adds. The weight scales it.
Why this is a classifier in disguise
The first form of the method came from classifier guidance, where a separate classifier is trained on noisy images and its gradient steers sampling. Bayes' rule, from Bayes' Rule, gives the posterior as . Taking logarithms and gradients and raising the classifier term to a power gives a sampling score of the form
The gradient of the log classifier equals the difference of the two scores, . Substituting it in gives . This is the score form of the same rule. Because the diffusion network already estimates the scores, a separate classifier is not needed. The conversion from score to noise is the step-by-step relation described in Score Matching and Diffusion Model.
Guided sampling
Each denoising step computes and uses it in place of the usual prediction in the reverse update. Two network passes are needed per step, one conditional and one unconditional. In practice the two inputs are batched together, so the cost is roughly double the cost of plain sampling.
Worked examples
Take a single number, with conditional prediction and unconditional prediction .
- With : . This is the plain conditional prediction.
- With : .
- With : .
- Check the rearranged form at : . It agrees.
- Interpretation: the gap between the two predictions is . Each unit of weight adds one more gap to the conditional prediction. With the guided value is above the unconditional prediction, four times the original gap of (in general times the gap), which is the sharpening effect in action.
Let the conditional distribution be and the unconditional distribution be . Their scores are and .
- Apply the guided rule with : .
- Expand: .
- Write this as . A score of the form belongs to , so the guided distribution is .
- Interpretation: the conditional mean was and the unconditional mean was . Guidance with moved the centre to , which is the conditional mean plus times the gap. The spread stays at . Sampling from the guided distribution gives samples that sit further toward the condition than the conditional distribution itself does.
Tradeoffs and failure modes
Guidance buys prompt adherence at the cost of diversity and, past a point, image quality. The weight is a single knob with a sweet spot.
| Situation | Problem | Better choice |
|---|---|---|
| Weight too low | Output ignores the prompt or drifts from it | Raise toward the usual range |
| Weight too high | Oversaturated colours, harsh contrast, repeated textures | Lower , or use dynamic thresholding |
| Diversity matters more than fidelity | Every sample looks alike at high | Keep small, or sample with |
| Real-time generation | Two passes per step double the cost | Distilled or few-step samplers, or guidance distillation |
| Unconditional quality matters | The null-condition branch is undertrained | Tune the condition dropout rate |
The most common failure is over-saturation. Because the step overshoots, pixel values can leave their normal range, and the output looks burnt. Practitioners clip the predicted image, or use dynamic thresholding that rescales it per sample, to keep the overshoot under control.
Guidance also assumes that the difference between the two predictions means something. When the condition is weak or ambiguous, the difference is mostly noise, and high weights amplify the noise.
History
In 2021, Dhariwal and Nichol introduced classifier guidance for diffusion models. They trained a classifier on noisy images and used its gradient, which gave a clear quality gain on class-conditional ImageNet generation. Its drawback was that the classifier had to be trained on noisy inputs, which added a second model and training pipeline.
Ho and Salimans (arXiv, 2022) showed that the classifier could be dropped. A single conditional model, trained with the condition sometimes removed, gives both predictions the rule needs. Their paper framed the method as classifier-free guidance and reported that it trades off sample fidelity (Inception score) against diversity and FID in a manner similar to classifier guidance, on class-conditional ImageNet at 64x64 and 128x128, without the extra model.
It caught on because it was simple, it worked for any condition that could be fed to the network, and it suited text. Later text-to-image systems adopted it as a default, with guidance scales that users could adjust directly. Its use in text-conditioned models is the reason the term is now standard.
Check yourself
QuestionRecall: what does the guidance weight reduce the guided prediction to?Show answer
With the formula is . The guided prediction is just the plain conditional prediction. No extra guidance is applied, and the sampler behaves like an ordinary conditional diffusion model.
QuestionComputation: with conditional prediction , unconditional prediction , and , what is the guided prediction?Show answer
Use . Check with the rearranged form: . The answer is .
QuestionWhy: why does the method need the condition to be dropped sometimes during training?Show answer
The method needs a prediction without the condition at sampling time. If the network had only ever seen conditioned inputs, it would have no learned unconditional behaviour, and the second prediction would be meaningless. Randomly dropping the condition for a fraction of training examples teaches one network both behaviours, so no separate model is required.
QuestionApplied: a product team's images look correct but are washed out at a high weight, and they want a faster sampler for a mobile app. What should they check first?Show answer
They should first check the weight, because high values overshoot and push pixel values out of range, which can look oversaturated or harsh. They can lower or use clipping or dynamic thresholding. For speed, guidance costs two passes per step, so a distilled model that folds the guidance into one pass, or a few-step sampler, is the usual route. The two problems have different fixes, so they should be diagnosed separately.
Sources
- Ho, J., and Salimans, T. (2022). Classifier-Free Diffusion Guidance. https://arxiv.org/abs/2207.12598
- Dhariwal, P., and Nichol, A. (2021). Diffusion Models Beat GANs on Image Synthesis. https://arxiv.org/abs/2105.05233
- Ho, J., Jain, A., and Abbeel, P. (2020). Denoising Diffusion Probabilistic Models. https://arxiv.org/abs/2006.11239