Classifier-free guidance

Also known as: CFG

On this page 7

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.

  1. Predict the noise (or velocity) for the current latent with the prompt embedding.
  2. Predict the noise for the same latent with the null embedding or a negative prompt.
  3. Subtract the unconditional result from the conditional result to obtain the guidance direction.
  4. Scale that direction by w and add it back to the unconditional prediction.
  5. 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 scalePrompt adherenceVisual characterCommon use
1Weak, conditional onlyDiverse, sometimes off-promptDistilled models, research baselines
3 to 5ModerateNatural color and texturePhotographic styles, newer models
6 to 9StrongCrisp, high contrastGeneral default for many image models
10 to 15Very strongSaturated, possible artifactsDifficult or highly specific prompts
Above 15ExcessiveBurned colors, distorted shapesRarely useful
Typical guidance scale ranges for text-to-image models

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.

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.

MethodWhat it requiresWhat it controlsMain limitation
Classifier guidanceSeparate noise-aware classifierClass or attribute adherenceExtra training, adversarial gradients
Classifier-free guidanceOne model trained with condition dropoutStrength of any text or class conditionDoubles compute per step
Negative promptingCFG with a negative embeddingConcepts to steer away fromDepends on CFG being active
ControlNetAuxiliary network and control imagePose, edges, depth, layoutNeeds a suitable control input
Guidance distillationTeacher model and training runBakes CFG into one passFixed or limited scale range
How CFG relates to other guidance and control methods

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.

SituationRecommended choiceReason
Prompt details are being ignoredRaise scale by 1 to 2Strengthens the conditional direction
Colors look burned or plasticLower scale or use rescalingReduces overshoot of pixel statistics
Inference cost is too highUse a guidance-distilled modelAvoids the second forward pass
Video frames flicker or driftModerate scale with fewer high-guidance stepsBalances adherence and temporal consistency
Decision guide for guidance settings

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.