Generative Modeling Theory

classifier-free guidance (CFG)

When a diffusion model is asked to draw a corgi, you often want it to draw an unmistakable corgi rather than a vague dog. Classifier-free guidance is the knob that sharpens how strongly each sample obeys its condition. It works by training one network to play two roles, conditional and unconditional, then at sampling time extrapolating away from the unconditional prediction in the direction of the conditional one, amplifying whatever the condition adds.

Concretely, the condition is randomly dropped during training so the same network learns both the conditional score and the unconditional score. At sampling the guided score is the unconditional score plus a guidance weight times the difference between the two. By Bayes' rule that difference is the gradient of the log-likelihood of the condition given the data, so guidance is implicitly steering by an implied classifier without ever training a separate one, which is the origin of the name. A weight of one recovers ordinary conditional sampling; larger weights push samples toward higher condition-likelihood.

Guidance is the central lever behind the visual punch of text-to-image systems, but it is a trade, not a free lunch: raising the weight improves prompt fidelity and sample sharpness while shrinking diversity and, at high values, oversaturating colors and distorting structure.

\tilde\epsilon_\theta(x,c)=\epsilon_\theta(x,\varnothing)+w\big(\epsilon_\theta(x,c)-\epsilon_\theta(x,\varnothing)\big)

Extrapolate from the unconditional prediction toward the conditional one; the weight w controls fidelity versus diversity.

CFG biases the sampler toward the high-density tails of the conditional, so it improves perceived quality and prompt alignment but no longer samples the true conditional distribution.

Also called
CFG無分類器引導