Quant Memo
Advanced

Classifier-Free Guidance

To make a conditional diffusion model follow its prompt more strongly, classifier-free guidance trains one network to predict both conditioned and unconditioned noise, then extrapolates away from the unconditioned prediction at generation time instead of needing a separate classifier at all.

Prerequisites: Denoising Diffusion Probabilistic Models

A diffusion model conditioned on a prompt yy — "a photo of a cat," or in a finance setting, "a stressed-regime return path" — will follow yy only loosely by default, because the training objective rewards matching the conditional data distribution p(xy)p(x\mid y), and that distribution still has plenty of room for outputs that only weakly resemble yy. Earlier approaches used a separate trained classifier to push samples toward yy more forcefully, but that meant training and maintaining a second model, on noisy intermediate images the classifier had never seen clean. Classifier-free guidance gets the same forceful push using only the diffusion model itself, trained once.

The analogy: exaggerating the difference between two directions

Suppose you're giving driving directions and you know both "the route to the mall" and "the route to nowhere in particular" from the current junction. If someone follows "the mall route" only loosely, you can make the instruction more insistent not by hiring a separate guide, but by comparing the two routes and telling the driver to lean further in the direction the mall route diverges from the aimless one — exaggerating the difference between "going somewhere specific" and "going nowhere in particular" pushes them more decisively toward the mall.

The mechanics: train both, extrapolate at sampling time

During training, the same network predicts noise conditioned on yy some fraction of the time, and conditioned on nothing (a null label, \varnothing) the rest of the time — one network, two modes, achieved just by randomly dropping the conditioning during training. At sampling time, both predictions are computed for the same noisy point, and combined with a guidance scale w>1w > 1:

ϵ^w=ϵθ(xt,)+w[ϵθ(xt,y)ϵθ(xt,)]\hat{\epsilon}_w = \epsilon_\theta(x_t, \varnothing) + w \big[\epsilon_\theta(x_t, y) - \epsilon_\theta(x_t, \varnothing)\big]

In words: start from the unconditional prediction, take the difference the conditioning makes, and add back more than 100% of that difference (since w>1w>1). This exaggerates whatever the label yy was already nudging the prediction toward, at the cost of some diversity — the sample is pushed harder toward the specific mode yy implies, and correspondingly further from the variety of outputs the unconditional model would otherwise consider plausible.

Worked example 1: computing a guided prediction

Suppose at some diffusion step, the unconditional noise prediction is ϵθ(xt,)=0.20\epsilon_\theta(x_t,\varnothing) = 0.20 and the conditional one is ϵθ(xt,y)=0.35\epsilon_\theta(x_t,y) = 0.35 (a single scalar for simplicity). With guidance scale w=1w=1 (no guidance, plain conditional sampling): ϵ^=0.20+1(0.350.20)=0.35\hat\epsilon = 0.20 + 1(0.35-0.20) = 0.35 — just the conditional prediction. With w=3w=3: ϵ^=0.20+3(0.15)=0.20+0.45=0.65\hat\epsilon = 0.20 + 3(0.15) = 0.20+0.45=0.65 — nearly double the conditional prediction's deviation from the unconditional one, pushing the denoising step much more aggressively toward whatever yy favors.

Worked example 2: the diversity trade-off, in numbers

Generate 100 samples at w=1w=1: suppose 40 land in each of two plausible sub-styles consistent with yy, and 20 are more generic/off-prompt. At w=5w=5, the extrapolation collapses much of that spread: perhaps 85 land in the single dominant sub-style, 10 in the other, and only 5 generic — prompt-following goes up sharply (fewer off-prompt samples), but the model has effectively narrowed which of the two valid sub-styles it explores, which is the classic guidance trade-off: fidelity to yy rises, diversity within "things consistent with yy" falls.

Function explorer
-2260.1
x = 1.00f(x) = 2.718

Picture the guidance scale ww as this curve's steepness parameter: small ww gives a gentle nudge toward the prompt, while large ww sharpens the response into an aggressive, low-diversity extrapolation — the same shape of trade-off between responsiveness and stability that shows up whenever you scale up a control signal.

unconditional conditional (w=1) guided (w=3)
The guided prediction extends past the conditional one along the same direction the conditioning already pointed — a straight extrapolation, not a new destination.

Classifier-free guidance trains one diffusion model to predict noise both with and without conditioning, and at sampling time extrapolates past the conditional prediction, away from the unconditional one, by a guidance scale w>1w>1 — sharpening prompt-following without any separate classifier, at the cost of reduced sample diversity.

What this means in practice

Every modern text-to-image and text-to-audio diffusion system uses some form of classifier-free guidance, and the same mechanism applies to a finance-conditioned generator — e.g. pushing synthetic scenario generation harder toward a specific stress label at the cost of exploring fewer distinct ways that stress could manifest. The guidance scale ww is a genuine dial practitioners tune per use case, not a fixed constant.

Cranking ww up is not a free way to get "more correct" samples — past a moderate value, guided samples start to look oversaturated, artifact-ridden, or mode-collapsed onto a narrow slice of what's actually consistent with yy, because the linear extrapolation eventually pushes the prediction outside the region the network was ever trained to produce sensible outputs in. Guidance scale trades fidelity for diversity; it does not trade for free.

Related concepts

Practice in interviews

Further reading

  • Ho & Salimans, Classifier-Free Diffusion Guidance (2021)
ShareTwitterLinkedIn