Classifier-free guidance (CFG) is a sampling technique for conditional diffusion models that combines a conditional and an unconditional prediction at every denoising step and extrapolates away from the unconditional one, so that generated images, audio or video follow the prompt more closely. In generative AI, it is the mechanism behind the familiar guidance scale or CFG scale setting in text-to-image tools.
The technique replaced earlier classifier guidance, which required a separately trained noise-aware classifier. CFG needs only one network trained with condition dropout, which made strong prompt adherence practical for latent diffusion models, video diffusion models and many flow matching systems.
How classifier-free guidance works
Classifier-free guidance starts during training. The model receives its conditioning signal, such as a text embedding, most of the time, but for a random 10 to 20 percent of training examples the condition is replaced by a null or empty token. The same network therefore learns both a conditional prediction and an unconditional prediction.
At sampling time, the model runs twice per step, once with the prompt and once with the null condition. The sampler then computes the guided prediction as the unconditional output plus the guidance scale w multiplied by the difference between the conditional and unconditional outputs. A scale of 1 reproduces the plain conditional model, and values above 1 push the sample further in the direction the prompt implies.
The steps below summarize one guided denoising step in a typical diffusion sampler.
- Predict the noise (or velocity) for the current latent with the prompt embedding.
- Predict the noise for the same latent with the null embedding or a negative prompt.
- Subtract the unconditional result from the conditional result to obtain the guidance direction.
- Scale that direction by w and add it back to the unconditional prediction.
- Pass the guided prediction to the scheduler to produce the next, less noisy latent.
Mathematically, the difference term approximates the gradient of an implicit classifier, the log probability of the condition given the noisy sample. This is why the method achieves the effect of classifier guidance without a separate classifier.
The guidance scale and its effects
The guidance scale controls the trade-off between prompt fidelity and sample diversity. Low values produce varied, natural images that may ignore parts of the prompt, while high values produce images that match the text closely but lose variety and can look harsh or oversaturated.
The table shows typical behavior for latent diffusion image models; exact ranges differ between model families, samplers and step counts.
| Guidance scale | Prompt adherence | Visual character | Common use |
|---|---|---|---|
| 1 | Weak, conditional only | Diverse, sometimes off-prompt | Distilled models, research baselines |
| 3 to 5 | Moderate | Natural color and texture | Photographic styles, newer models |
| 6 to 9 | Strong | Crisp, high contrast | General default for many image models |
| 10 to 15 | Very strong | Saturated, possible artifacts | Difficult or highly specific prompts |
| Above 15 | Excessive | Burned colors, distorted shapes | Rarely useful |
Distilled and consistency models are often trained to work at a scale of 1 or with guidance built in. Applying a high external scale to such models usually degrades the output instead of improving it.
Classifier-free guidance compared with related methods
CFG belongs to a broader set of controllable generation methods. It differs from structural conditioning tools because it amplifies an existing condition rather than adding new spatial or stylistic information.
| Method | What it requires | What it controls | Main limitation |
|---|---|---|---|
| Classifier guidance | Separate noise-aware classifier | Class or attribute adherence | Extra training, adversarial gradients |
| Classifier-free guidance | One model trained with condition dropout | Strength of any text or class condition | Doubles compute per step |
| Negative prompting | CFG with a negative embedding | Concepts to steer away from | Depends on CFG being active |
| ControlNet | Auxiliary network and control image | Pose, edges, depth, layout | Needs a suitable control input |
| Guidance distillation | Teacher model and training run | Bakes CFG into one pass | Fixed or limited scale range |
Negative prompts are a direct extension of CFG. The sampler substitutes the negative prompt embedding for the null embedding, so the guidance direction points away from the unwanted concept as well as toward the desired one.
Practical configuration and variants
Choosing the right setup depends on the model architecture, the sampler and the output goal. Practitioners usually begin with the default scale recommended for the model and adjust in small steps while keeping the random seed fixed.
| Situation | Recommended choice | Reason |
|---|---|---|
| Prompt details are being ignored | Raise scale by 1 to 2 | Strengthens the conditional direction |
| Colors look burned or plastic | Lower scale or use rescaling | Reduces overshoot of pixel statistics |
| Inference cost is too high | Use a guidance-distilled model | Avoids the second forward pass |
| Video frames flicker or drift | Moderate scale with fewer high-guidance steps | Balances adherence and temporal consistency |
Several refinements address the weaknesses of a constant scale. Guidance rescaling normalizes the guided prediction so its standard deviation matches the conditional prediction, which reduces overexposure. Dynamic or interval guidance applies strong guidance only in the middle of the noise schedule, where it shapes composition, and weaker guidance at the end, where it mainly harms fine detail.
Limitations and common mistakes
Classifier-free guidance is effective but not free. Its most visible costs are double computation per step and a systematic loss of diversity that grows with the scale.
- Oversaturation at high scales. Extrapolation pushes predictions outside the range seen in training, producing burned highlights and unnatural contrast.
- Reduced variety. Strong guidance concentrates samples near the most typical image for a prompt, a mild form of the effect seen in mode collapse.
- Scale values are not portable. A scale of 7 in one model or sampler can behave very differently in another.
- Guidance cannot add missing knowledge. If the model never learned a concept, a higher scale amplifies noise rather than inventing it.
- Interaction with denoising strength. In image-to-image and inpainting, high guidance combined with low denoising strength often produces abrupt, mismatched edits.
The simple explanation
An image generator using this method makes two guesses at every step. One guess follows your description, and the other guesses what a random picture would look like with no description at all. The method then leans further toward the described version by a chosen amount.
That amount is the guidance scale. A small number gives relaxed, varied pictures that may miss details. A large number gives pictures that follow the words very strictly but can look overcooked, a bit like turning up contrast on a photo too far.
How it is used in practice
A product designer generates concept images of a ceramic lamp with a latent diffusion model, using 30 sampling steps and a fixed seed. At a guidance scale of 3, the images look natural, but half of them omit the requested matte green glaze. At a scale of 14, every image shows the glaze, yet the colors look neon and the lamp edges have hard halos.
The designer settles on a scale of 7 with guidance rescaling and adds a negative prompt for glossy surfaces. Most images now show the correct glaze with realistic lighting. For a later batch of 200 variations, the team switches to a guidance-distilled version of the model and cuts generation time roughly in half, accepting a small loss in fine control.