Exercises — Classifier-free guidance
This page is a self-testing ladder. Work each problem before opening its solution. The levels climb from recognising the CFG formula to synthesising it with Classifier guidance, DDPM sampling, and Negative prompting.

Level 1 — Recognition
Exercise 1.1 (L1)
State, in words, what each of the three quantities , , and represents, and which one requires two network calls to compute.
Recall Solution
- = the noise the model predicts when it is told nothing (empty prompt). One network call.
- = the noise predicted when it sees the prompt . One network call.
- = the direction the prompt adds. Because it is a difference, computing it needs both calls — so two network evaluations per denoising step.
Exercise 1.2 (L1)
Which value of recovers the ordinary conditional model (no guidance amplification)? Which value gives a purely unconditional sampler?
Recall Solution
Plug into the linear form .
- : → ordinary conditional.
- : → purely unconditional.
Level 2 — Application
Exercise 2.1 (L2)
Given and with , compute and then using the additive form.
Recall Solution
Step 1 — direction. Subtract component-by-component: Step 2 — scale & add.
Exercise 2.2 (L2)
Verify that the linear form gives the identical answer for Exercise 2.1. Why must it?
Recall Solution
With : . Why identical: the two forms are algebraically the same expression — Just factoring — nothing physical changes.
Level 3 — Analysis
Exercise 3.1 (L3)
For , the linear form has coefficients on and on . Explain geometrically why a negative coefficient on the unconditional term is exactly what "extrapolation beyond the prompt" means. Reference the figure.
Recall Solution
Look at the second figure. Place and as two points. The guided output lies on the line through them, at parameter :
- : sits between the two points (interpolation).
- : shoots past , on the far side, moving away from (extrapolation). The coefficient sum is always , so this is an affine combination — the point stays on the line. A negative weight on literally means "step in the direction opposite the generic guess," i.e. push away from bland/unconditional content toward the prompt.
Exercise 3.2 (L3)
Show that no matter what is, the coefficients on and always sum to 1. What breaks if they didn't?
Recall Solution
for every . This is why stays on the line through the two predictions. If the coefficients summed to something else, say , the guided noise would be scaled by roughly overall. In the DDPM sampling update, an over-scaled noise estimate would systematically over- or under-remove noise each step, drifting off the data manifold — you'd get blown-out or washed-out images independent of the prompt. The unit sum keeps the magnitude honest and lets control only direction.
Level 4 — Synthesis
Exercise 4.1 (L4)
Connect CFG to Classifier guidance. Starting from Bayes' rule for the conditional score, show that CFG's guided score is equivalent to a classifier-guided score with an implicit classifier of strength . Identify the implicit classifier gradient.
Recall Solution
Bayes gives . Gradient in kills : Substitute into CFG's guided score: This is exactly the Classifier guidance form (unconditional score + classifier gradient) — but the "classifier gradient" is not from a separately trained classifier; it is the implicit classifier obtained purely from the two noise predictions the single model already gives. That is the whole point: no extra classifier.
Exercise 4.2 (L4)
Negative prompting replaces the null condition with a disliked prompt (e.g. "blurry, deformed"). Write the guided noise and explain what changes geometrically.
Recall Solution
Swap in the additive form: Geometrically, the baseline point moves from "generic" to "the thing you hate," and now points from the disliked image toward the wanted one. Extrapolating along it () actively repels the sample from "blurry/deformed" while pulling toward . Ordinary CFG is the special case .
Level 5 — Mastery
Exercise 5.1 (L5)
Naive CFG needs two forward passes per step (one for , one for ). For a 50-step DDPM sampling run, how many forward passes does guided sampling cost versus unguided? Then propose why increasing does not increase this cost, but does eventually hurt sample quality (tie it to Example 3 in the parent).
Recall Solution
Count. Unguided: passes. Guided (naive CFG): passes — exactly double. Cost vs . is just a scalar multiplying an already-computed ; changing it is a cheap vector scale, no new forward pass. So compute is flat in . Why quality still degrades. As grows, extrapolates far past . In Score-based diffusion models this over-sharpens the score, concentrating probability mass onto a few high-likelihood modes → reduced diversity and, at extreme (≈15), over-saturated, unnatural colours (the parent's Example 3). Large also amplifies the magnitude of , over-removing noise per step and pushing off the manifold. The sweet spot is empirical: for Stable-Diffusion-style text-to-image.
Exercise 5.2 (L5)
Suppose you must implement CFG but can afford only a single forward pass per step. Design a scheme and quantify the tradeoff. (Batch trick.)
Recall Solution
Batch trick. Stack the conditional and unconditional inputs into one batch of size 2: feed with conditions . One batched forward call returns both and simultaneously. This is still "two evaluations of work" but a single kernel launch / single call, so wall-clock ≈ one large pass instead of two sequential ones. Tradeoff: memory doubles (batch ×2) but latency drops from sequential to ≈ (given hardware parallelism). If memory is the bottleneck you cannot use it and must pay the sequential time. Net: trade GPU memory for speed; you cannot get CFG for the math of one pass because intrinsically needs both predictions.
Recall One-line summary
CFG cost per step ::: two noise predictions ( and ), combined as an affine mix whose coefficients always sum to 1, with controlling extrapolation strength.