Applied AI Vol. 2

Classifier-Free Guidance: Steering a Diffusion Model Without a Classifier

A single extra knob trades diversity for prompt adherence. Here is the formula and its failure modes.

Applied AI Vol. 2 · 4 min read

When you give a text prompt to an image generator, a guidance scale controls how strongly the output follows it. That scale comes from classifier-free guidance.

Two predictions in one model

During training, the condition, such as the text prompt, is randomly dropped some of the time. The same network thus learns both a conditional prediction and an unconditional one.

The combination

At sampling time, compute both noise predictions. The guided prediction is the unconditional one plus a scale w times the difference between the conditional and unconditional predictions. When w is one, you get the plain conditional model. Larger values push samples further in the direction that the condition adds.

The trade-off

  • Higher guidance typically improves how well samples match the prompt and often their apparent quality.
  • It also reduces diversity, since samples concentrate around the most prompt-typical modes.
  • Very high values can cause oversaturated colors and artifacts.
  • Each step needs two network evaluations, which doubles sampling cost unless the two are batched.

Evaluate more than one scale

Report results across a sweep of guidance scales rather than a single value, and measure both fidelity and diversity. A scale that wins on one metric may lose on the other, and the best choice depends on the application.

More guides from this book