4.5.14 · D2Generative Models

Visual walkthrough — Classifier-free guidance

2,471 words11 min readBack to topic

Step 1 — What is the model even predicting? An arrow.

WHAT. A diffusion model, at some noisy step, is handed a fuzzy image and must answer one question: "which way is the noise?" Its answer is a vector — a list of numbers, one per pixel-channel — that we can picture as a single arrow living in the space of images.

WHY an arrow. Because the only thing we ever do with the model's output is subtract it to get a cleaner image. Subtracting a vector = stepping in a direction. So the output is a direction, and directions are arrows. Nothing more mysterious than that.

PICTURE. Below, one dot is our noisy image . The arrow (magenta) is what the model predicts when it can read your prompt . Read "" as "epsilon", the Greek letter we use for noise.

Figure — Classifier-free guidance

Step 2 — Two arrows from the same starting dot

WHAT. We now draw both arrows from the same noisy image: (prompt-aware, magenta) and (prompt-blind, violet). Same start, different tips.

WHY two. A single denoising path can't tell us what the prompt contributed — maybe the arrow points that way for reasons that have nothing to do with your words. The only way to isolate "the prompt's effect" is to run the model a second time with the prompt removed and compare. That comparison is the whole trick.

PICTURE. The two tips land in different places. The gap between the tips is the star of the next step.

Figure — Classifier-free guidance

Step 3 — The difference arrow: what the prompt actually adds

WHAT. Subtract tip-to-tip. First, formally define the difference arrow: (read "" as is defined to be; , capital "delta", is the standard symbol for a change or difference). Now the same statement, annotated term by term:

We take the prompt-aware arrow and remove the part it shares with the prompt-blind arrow. What survives is purely the prompt's contribution.

WHY subtract. Vector subtraction draws the arrow from the tip of to the tip of . That is literally "the extra push the words gave us." Everything both arrows agreed on cancels; only the disagreement — the "cat-ness" — remains.

PICTURE. The orange arrow is , floating between the two tips. Notice it does not start at the origin dot; it starts where the violet arrow ends.

Figure — Classifier-free guidance

Step 4 — Rebuild the arrows: baseline + one hop of the difference

WHAT. Notice a fact that is true by pure algebra:

Term by term: start at the blind baseline , take one hop of the difference arrow , and you arrive exactly at . The coefficient in front of is .

WHY rewrite something we already knew. Because now the number is sitting alone, begging to be changed. If one hop lands on "normal cat," what does two hops do? That single question is classifier-free guidance.

PICTURE. The violet baseline, then the orange hop of length one, landing precisely on the magenta tip.

Figure — Classifier-free guidance

Step 5 — Turn the coefficient into a knob

WHAT. Replace the lonely with a dial called , the guidance scale. Keeping every argument in place so you never lose track of what the function depends on:

Term by term: the tilde ("epsilon-tilde") means guided noise — the doctored arrow we actually feed back into sampling. It still lives at the same noisy image and timestep ; only its length changed. multiplies only the difference arrow, so it stretches or shrinks how far past the baseline we hop.

WHY multiply the difference and not the whole thing. If we scaled the whole we'd also amplify the generic, prompt-irrelevant part. Scaling only amplifies exactly the prompt's contribution and nothing else. That's the entire point of splitting the arrows in Steps 2–3.

PICTURE. Same baseline, but now the orange hop is stretched to length , overshooting the magenta tip toward "extra-cat." This is the "prompt volume knob."

Figure — Classifier-free guidance

Step 6 — Read every value of the knob (all cases)

WHAT. Slide across its whole range — including negative values — and watch where the guided tip lands. This is the "cover every case" step — no value of , of either sign, should surprise you.

weight on is where the tip lands meaning
on the opposite side of the violet tip from the prompt anti-prompt / negative guidance — hop backwards along , pushing away from the prompt (do the opposite of what was asked)
on the violet tip pure blind — prompt ignored
positive, between and between violet and magenta tips muted / under-guidance — a blend that leans partly toward the prompt but not fully; a weighted interpolation of blind and normal conditional
on the magenta tip normal Conditional generation
negative past the magenta tip extrapolation — over-follow the prompt
very large very negative far past over-saturated, low diversity (mode collapse)

WHY the row exists. For these values both weights are positive and sum to one, so the guided arrow lands on the segment between the two tips — you get a genuine mixture of "generic image" and "prompt image," a softened version of the prompt effect. It never overshoots, because the hop is shorter than the full .

WHY the row exists. A negative multiplies by a negative number, so the hop runs the other way — starting from the blind baseline and moving directly away from the prompt tip. This is exactly the mechanism behind Negative prompting: you steer generation to avoid a concept by pointing in reverse. (In practice, the "negative prompt" trick usually swaps for a second prompt's prediction, but the sign idea is the same — subtract that direction rather than add it.)

WHY the negative weight matters (for ). When , the coefficient on flips negative. A negative weight pushes away from the generic prediction — the model is told "be less like a random image, more like the thing I asked for." That push-away is why high sharpens prompt adherence.

PICTURE. One line, dots on it: a anti-prompt point on the far side, , a muted point between the tips, , and two overshoot points — all lying on the same straight track through the two tips.

Figure — Classifier-free guidance

Step 7 — The degenerate case: where does come from?

WHAT. Everything above assumed we have a prompt-blind prediction. But a text-to-image model only ever saw prompts! The fix lives in training: on each training example we flip a biased coin, and with probability we erase the prompt and replace it with the null token .

WHAT is , exactly. It is a single training hyperparameter — a fixed number you choose before training (typically , i.e. ). Concretely: for every pair drawn in a minibatch, sample a uniform random number ; if , set for that example, otherwise keep the real prompt. Everything else (the loss, the optimizer) stays identical. So literally sets what fraction of gradient steps see a blank prompt.

WHY that value and not or . If , the model never sees , so is undefined and the Step 3 subtraction is meaningless — the degenerate case that breaks guidance. If , the model never sees prompts and can't do at all. A small-but-nonzero value () buys a competent blind prediction while spending most of the budget on the conditional one we care about most.

PICTURE. A training batch: most rows keep the prompt (magenta), a random fraction have it swapped for (violet). Same loss everywhere. Links to DDPM sampling where the two calls are made at inference.

Figure — Classifier-free guidance

The one-picture summary

WHAT. The entire derivation, compressed: one starting dot, two model arrows, their difference, and the knob that stretches that difference into the guided prediction — with the whole family of -values (including the negative anti-prompt side) drawn as one track.

Figure — Classifier-free guidance
Recall Feynman retelling — say it in plain words

Picture a foggy image at some noise level . Ask the model twice: once knowing what you want ("a cat"), once knowing nothing. Each answer is an arrow pointing "this way to clean up the noise." Lay both arrows from the same spot. Subtract tip-to-tip and you get a little arrow that means "here's the part that is about the cat." Now the trick: start from the clueless arrow, and instead of adding the cat-arrow once, add it several times. You overshoot toward "very cat." The multiplier is . Turn it to and you get a random picture; between and you get a muted blend; turn it to and you get an ordinary cat; turn it past and the cat gets bolder — until, cranked too high, every picture looks the same over-saturated cat. Turn it negative and you get the anti-cat: the hop runs backwards, actively avoiding what you named. And the only reason exists at all is that during training we sometimes hid the prompt (a fixed fraction of the time) so the model learned to guess blind. That's it — no classifier, just two calls and a knob.

Recall Check yourself

What does represent geometrically? ::: The arrow from the tip of the prompt-blind prediction to the tip of the prompt-aware one — the pure contribution of the prompt. What is the timestep ? ::: Which rung of the noising ladder we are on — large is very noisy, small is nearly clean; the model is called once per timestep. Why does go negative for ? ::: Because the guided arrow overshoots past , which means pushing away from the generic , i.e. subtracting it. What happens for ? ::: A muted (under-guided) blend: the tip lands between the blind and conditional tips, a weighted interpolation of the two. What happens at and ? ::: lands on (prompt ignored); lands on (ordinary conditional). What does do? ::: Anti-prompt / negative guidance — the hop runs backwards along , pushing the sample away from the prompt (the sign idea behind negative prompting). Why must we drop the prompt during training, and what sets how often? ::: So a single network learns the blind prediction ; the hyperparameter (typically 10–20%) fixes the fraction of training examples whose prompt is replaced by .

See also: Negative prompting, Prompt engineering, and the Hinglish version.