research30 min studyLesson 784 in Engineering

Classifier-free guidance cost and bias

Account for conditional branches and altered sampling fields without equating a fused invocation or stronger guidance with free or exact improvement.

On this page

What you’ll understand

  • State the pipeline guidance convention and its relation to conditional prediction.
  • Count logical branch evaluations independently of batched invocations.
  • Explain why guidance changes distributional behavior and needs quality/diversity evaluation.

Classifier-free guidance combines predictions from differently conditioned evaluations of a denoiser. It can strengthen conditional adherence, but it also changes the field that the sampler follows and usually increases neural work. Serving analysis must specify the guidance convention, branch implementation, memory effect, and evaluation objective. A larger guidance number is neither a universal quality order nor an exactness certificate.

Fix the guidance convention before interpreting its scale

Use ε_u for the null-conditioned prediction and ε_c for the conditional prediction, evaluated at the same latent and noise coordinate. The common pipeline convention adds w times their difference to ε_u. Here w=1 gives the conditional prediction and w=0 the null prediction; w greater than one extrapolates beyond the conditional value. The original classifier-free guidance paper expresses its coefficient relative to the conditional baseline, so its named weight can differ by one. Record the actual formula rather than comparing naked guidance numbers across implementations.

A negative prompt can replace the null branch with another condition, which is not literally the unconditional data distribution. Noise prediction, score prediction, and clean-data prediction must be combined and converted consistently with the algorithm. Diffusers v0.35.1’s classic StableDiffusionPipeline demonstrates the ε_u+w(ε_c−ε_u) convention in its pinned implementation. These endpoint identities describe the formula. Without timestep-guidance embeddings, the classic pipeline enables two-branch CFG only for guidance_scale greater than one; at values at most one it normally follows its conditional-only path, so passing zero is not an unconditional request. Other model families can use distilled guidance embeddings or different conditioning mechanisms; their cost and scale semantics should not be inferred from this two-branch example.

ϵguided=ϵu+w(ϵc−ϵu)\epsilon_{\rm guided}=\epsilon_u+w(\epsilon_c-\epsilon_u)
Both predictions have the same noise-prediction units, latent input, and time; w is dimensionless. This is the stated null-baseline convention, with w=1 conditional. It is not a claim that every model uses two branches or that the original paper names its coefficient identically.↔ Scroll wide equations horizontally.

Count work, invocations, and memory separately

Two logical branches per image per evaluation can be run sequentially or concatenated into a larger batch. Concatenation can reduce launch overhead and improve utilization, but one call over twice the batch still performs both branches and needs their intermediate storage. Actual latency is not necessarily exactly doubled because kernels, occupancy, memory pressure, and overhead vary with batch. Measure the implementation at the intended resolution and precision rather than counting host calls as though they were fixed-cost units.

Guidance can be enabled for only part of a trajectory or changed by callbacks, but that changes the executed sampler policy and can affect a multistep history. Record the schedule of guidance values and corresponding branch batch shapes. A comparison that reduces guidance work while also changing adherence or diversity is a tradeoff, not a pure implementation speedup. Include conditioning encoders, scheduler work, latent decoding, and queueing when translating denoiser branch counts into request latency.

Nbranch=2BNN_{\rm branch}=2BN
This accounting assumes B images, N denoiser evaluation points, and two branches for every image at every point. It counts single-image branch equivalents, not GPU invocations, FLOP equality, or wall-clock seconds. Models with single-branch or partial-trajectory guidance have different accounting.↔ Scroll wide equations horizontally.

Guidance changes the field rather than merely solving it faster

With exact conditional and unconditional scores at a fixed noise level, their linear combination is the gradient of a corresponding weighted log-density expression when that expression is normalizable. That instantaneous identity does not prove the guided family is the marginals of the same forward diffusion or that a finite reverse solver exactly samples a simple terminal tempered law. Learned score fields add further approximation. Measure adherence, diversity, saturation, artifacts, and coverage under the guidance policy instead of presenting increased scale as a universally unbiased improvement.

The vector instrument illustrates linear magnitude amplification only. Reset, set both angle=0° and magnitude=1, predict x-component one and y-component zero, then Play or Step. Separately Reset, set both angle=0° and magnitude=3, predict x-component three and y-component zero, then Play or Step. These supported controls show a threefold component scale without predicting whether that direction is desirable. The lab does not contain conditional denoisers, their difference field, guidance batching, or image quality. Stronger field magnitude alone is not evidence of better generated samples.

Price a two-branch guided evaluation budget

A hypothetical pipeline uses four images, thirty denoiser evaluation points, and both guidance branches at each point. For one scalar component, ε_u=0.2, ε_c=0.5, and the null-baseline guidance scale is 7.5.

  1. The component difference is 0.5−0.2=0.3. The guided prediction is 0.2+7.5×0.3=2.45, outside the interval between the two branch predictions.

  2. The logical neural budget is 2×4×30=240 single-image branch evaluations. A concatenated implementation can make thirty invocations with effective branch batch eight, while still doing those two branches.

  3. Neither 240 branch equivalents nor thirty invocations directly gives milliseconds. Resolution, kernel efficiency, memory, decoding, and the measured quality/diversity tradeoff still determine whether this policy fits a serving objective.

The result

Guidance extrapolation and branch accounting are explicit mechanisms. Fused batching changes execution efficiency, not the existence of conditional and baseline work.

Explore the model

Interactive lab

Interactive lab · vectors

A larger field component does not define a better objective

Reset, set both angle=0° and magnitude=1, predict vector components (1,0), then Play or Step. Separately Reset, set both angle=0° and magnitude=3, predict (3,0), then Play or Step. This single-vector projection model has no guidance branches, denoising trajectory, or generated-quality metric.

A larger field component does not define a better objectivePlayback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Current readings: x component: 1.393; y component: 0.975; Magnitude: 1.7. All parameters are adjustable with the labeled controls below.−7.46−3.7303.737.46−3.5−1.7501.753.5xyvvₓ = 1.39
Vectorx / y projectionsTrace marker
x component
1.393
y component
0.975
Magnitude
1.7
t = 0 s

Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAmplification, computational work, and conditional-generation quality are different quantities.

Check your understanding

Two guidance branches are concatenated into one denoiser call. What is justified?

Try it yourself

A two-branch policy uses B=3 images and N=20 evaluation points. Count branch equivalents. For ε_u=1, ε_c=2, and w=2, compute the guided scalar prediction.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Count two branches per image and apply the declared null-baseline formula.

Compare with the solution

There are 2×3×20=120 single-image branch equivalents. The scalar guided prediction is 1+2×(2−1)=3. These calculations do not establish actual GPU latency or whether the stronger conditional extrapolation improves adherence, diversity, or perceptual quality.

Take it with you

  • Record the exact guidance formula and conditioning baseline.
  • Separate branch equivalents, batched calls, memory, and measured latency.
  • Treat guidance as a changed sampling policy with empirical quality/diversity tradeoffs.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.