JA EN
LearnGenerative Models
·★ MEMBER·PAPER·8 min read

CFG and Samplers — What the "Strength" Knob in Generative AI Really Does

What "CFG Scale" and "Sampling steps / method" actually do inside an image generator, explained from zero. CFG extrapolates along the difference between the conditional and unconditional prediction; the sampler is a numerical ODE solver. Both knobs trade something away.

ModalitytextTaskgeneration

Classifier-Free Diffusion Guidance

Primary source — what this article is built on

undefined2026-08-22

Classifier-Free Diffusion GuidancearXiv:2207.12598Paper page·PDF
Denoising Diffusion Implicit ModelsarXiv:2010.02502Paper page·PDF
Diffusion Models Beat GANs on Image SynthesisarXiv:2105.05233Paper page·PDF

The two knobs every generator has

Open any image-generation UI and you will find two kinds of knob under the prompt box: CFG Scale (guidance scale), and Sampling steps / Sampling method. Turn the first one up and the picture follows the prompt more closely — until the colors burn out. Turn the second one down and generation gets faster — until the picture falls apart. Most people settle on "about 7" and "about 25 steps" by feel and never learn why.

The two do completely different jobs. CFG is an extrapolation: it pushes the prediction further along the direction the condition is pulling. The sampler decides how many steps you take along a fixed trajectory. The first trades faithfulness against diversity; the second trades quality against time. And they are not independent — move one and the right value for the other shifts too.

Background: generation is repeated noise-guessing

The internals of diffusion are covered in Diffusion Models from Scratch. Only one fact is needed here. Hand the network a noisy image and it predicts "this is the noise mixed into it." Subtract a little of that prediction, repeat, and static turns into a picture. Call that prediction εθ\varepsilon_\theta.

For conditional generation a prompt cc joins the input. Now εθ(xt,c)\varepsilon_\theta(x_t, c) means "the noise in this static, given that we're making a picture of a cat." In principle that alone is enough, and it does work — but it is not faithful enough to the prompt. Ask for "a red cube on a blue table" and you tend to get something vaguely reddish, because the model is pulled toward the average of its training data.

The intuition: trust only the difference between two answers

So classifier-free guidance (CFG) asks the same network twice: once with the prompt shown, giving εcond\varepsilon_{\text{cond}}, and once with the prompt hidden — an empty string — giving εuncond\varepsilon_{\text{uncond}}.

Their difference εcondεuncond\varepsilon_{\text{cond}} - \varepsilon_{\text{uncond}} isolates exactly what changed because the model saw the prompt. Everything the model would have produced anyway cancels in the subtraction; only the direction the condition pushes survives. So why stop at pushing one unit along that direction?

ε~=εuncond+s(εcondεuncond)\tilde{\varepsilon} = \varepsilon_{\text{uncond}} + s\,(\varepsilon_{\text{cond}} - \varepsilon_{\text{uncond}})
(1)

In words: start from the unconditional answer and walk ss times as far toward the conditional one. At s=0s=0 the condition is ignored; at s=1s=1 the algebra collapses to plain εcond\varepsilon_{\text{cond}}, i.e. ordinary conditional generation; at s>1s>1 you overshoot the conditional answer and keep going. "CFG Scale 7.5" in the UI simply means s=7.5s = 7.5.

FIG 1Lower the temperature and the distribution sharpens until only the top candidates survive. Guidance does the same sharpening to a probability distribution. This figure is plain temperature-scaled softmax, not a diffusion computation

Why overshooting increases faithfulness

Equation (1) is, underneath, a sharpening operation. The predicted noise is tied (up to sign) to the gradient of the log density — the score — and rewriting the CFG combination through that correspondence shows it is equivalent to sampling from:

p~(xc)  p(xc)[p(cx)]s1\tilde{p}(x \mid c)\ \propto\ p(x \mid c)\,\bigl[\,p(c \mid x)\,\bigr]^{\,s-1}
(2)

In words: take the plain conditional distribution and multiply it by "how much this image looks like the prompt," raised to the power s1s-1. With an exponent above 1, prompt-like regions get lifted and everything else gets pushed down — exactly what lowering the temperature did in the figure above. The peak sharpens and the tails thin out.

Which means the gain in faithfulness and the loss of diversity are not cause and side effect — they are the same operation seen from two sides. "More faithful and more varied" is not something a single ss can give you.

The "classifier-free" in CFG is a contrast with classifier guidance, which came first. That method trains a separate model that can classify noisy images and adds its gradient into the prediction. It works, but you must train a dedicated noisy-image classifier, and inference needs a gradient computation on top.

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

References

  1. Classifier-Free Diffusion Guidance. arXiv:2207.12598Paper page·PDF
  2. Denoising Diffusion Implicit Models. arXiv:2010.02502Paper page·PDF
  3. Diffusion Models Beat GANs on Image Synthesis. arXiv:2105.05233Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Comments

Sign in to comment