Classifier-free guidance (CFG) is a technique for steering a conditional generative model during sampling without using a separate classifier. Most closely associated with diffusion models, it combines a model’s prediction under a specified condition with its prediction when that condition is absent. Amplifying the difference generally increases adherence to the condition, often at the cost of reduced sample diversity and, at high strengths, visible artifacts. CFG is widely used in generative artificial intelligence, including text-conditioned image, audio, and video generation.
Background and motivation
A conditional generative model produces samples associated with some input, such as a class label, text description, reference image, or audio signal. In a diffusion model, generation typically proceeds through a sequence of denoising steps, beginning with random noise and progressively constructing a sample.
A model trained to generate conditionally does not necessarily follow its condition as strongly as a user or application requires. Guidance modifies the sampling process to increase the influence of that condition.
Earlier classifier guidance methods achieve this by using a separate classifier trained to recognize the requested class from noisy inputs. The gradient of the classifier’s log probability steers generation toward samples that it associates more strongly with that class. This requires a suitable noise-aware classifier and additional gradient computation during sampling.
Classifier-free guidance, introduced by Jonathan Ho and Tim Salimans, replaces that external classifier gradient with a difference between conditional and unconditional predictions from the generative model itself. The term classifier-free refers to the absence of a separate guidance classifier; the model may still contain text encoders or other conditioning components.
Training with and without conditioning
The usual implementation trains a single neural network to operate both conditionally and unconditionally. During training, the conditioning input is randomly replaced with a null condition for some examples. This procedure is often called conditioning dropout.
Let denote a clean training sample and its condition. A common diffusion formulation constructs a noisy sample as
where is the noise level and and define the noise schedule.
For a model trained to predict the added noise, a representative loss function is
where
The null condition may be implemented as a learned embedding, an encoded empty text string, or another representation used consistently during training and sampling. It does not necessarily mean a zero vector.
Conditioning dropout differs from ordinary neural-network dropout: it removes or replaces conditioning information rather than randomly suppressing internal activations. The dropout probability is a training hyperparameter that affects how well the model learns its conditional and unconditional behaviors.
Guidance during sampling
At each guided sampling step, the model evaluates the same noisy state under two conditions:
A common guidance convention combines them as
where is the guidance scale. The sampling algorithm uses in place of the ordinary noise prediction.
Under this convention:
- gives the unconditional prediction.
- gives the ordinary conditional prediction.
- extrapolates beyond the conditional prediction, strengthening the conditioning signal.
Another common convention writes
The conventions are equivalent when . Consequently, a reported “guidance scale” is meaningful only together with its defining equation or software convention.
CFG is not restricted to noise prediction. Related combinations can be applied to compatible score, clean-sample, or velocity predictions. Their interpretation depends on the model parameterization and sampler; intervening nonlinear operations such as clipping can break otherwise straightforward equivalences.
Score-based interpretation
A score is the gradient of a log probability density with respect to the sample. Let
be the conditional score and
the unconditional score. Here, describes the data distribution at noise level .
By Bayes’ rule,
Thus, the conditional–unconditional score difference has the same mathematical form as the classifier gradient used in classifier guidance. CFG estimates this direction implicitly through the generative model rather than through an independently trained classifier.
The guided score is
For exact scores at a fixed noise level, this is the gradient of the log of an unnormalized density
where such a density can be normalized. Equivalently,
This explains why stronger guidance favors samples that are especially associated with the condition rather than merely plausible overall.
The interpretation has an important limitation: these reweighted densities at different noise levels do not generally form the forward-noising marginals of a single clean-data distribution. Guided sampling therefore should not be described as exactly sampling from a simple powered version of the original conditional probability distribution. Approximate model predictions and numerical sampling introduce further differences.
Applications and implementation
Text-conditioned generation
In text-to-image systems, the condition is usually an encoded prompt, often supplied through cross-attention. CFG increases the influence of that prompt during denoising.
The method also works in latent diffusion models, where denoising takes place in a compressed latent space rather than directly in pixel space. Its equations operate on the model’s predictions regardless of the eventual output modality.
Negative prompts
Some implementations replace the null condition with a negative prompt, producing
The reference branch is then no longer unconditional: it is conditioned on the negative prompt. Generation is steered toward the positive condition and away from the negative one in the model’s prediction space.
Negative prompting is not a hard exclusion rule. It does not guarantee that an object, attribute, or visual defect will be absent, especially when the positive and negative conditions overlap semantically.
Computational cost
Standard CFG requires two model evaluations per guided denoising step rather than one. These can often be combined into a single batched execution, improving hardware utilization but increasing memory demand. Actual runtime overhead depends on the model, batching strategy, and implementation.
The extra cost occurs during inference. The two branches usually share the same trained weights rather than requiring two separately stored models.
Trade-offs and limitations
Condition adherence versus diversity. Stronger guidance often improves prompt or class alignment while concentrating generation on a narrower range of outcomes. Different random seeds may produce more similar compositions or features.
Artifacts at high scales. Excessive guidance can cause oversaturated colors, exaggerated contrast, distorted structures, or other modality-dependent defects. Increasing guidance is not equivalent to improving model quality.
Dependence on both predictions. Guidance relies on the difference between two learned outputs. Errors in either branch can be amplified, especially when extrapolating far beyond the ordinary conditional prediction.
No guarantee of compositional correctness. Strong guidance does not ensure accurate counting, spatial relationships, text rendering, or faithful handling of every instruction. It can strengthen dominant features without resolving weaker or conflicting requirements.
Sensitivity to the sampling setup. Effective guidance depends on the model, noise schedule, prediction parameterization, numerical solver, and number of sampling steps. A scale that works well in one system may not transfer to another.
Extensions
Guidance need not remain constant throughout sampling. Guidance schedules vary its strength with noise level or apply it only over selected intervals, changing the balance between early structural decisions and later detail formation.
Other modifications rescale guided predictions or constrain predicted clean samples to reduce instability. Such methods alter the practical sampling procedure and do not all have the same mathematical interpretation.
Distillation can train a model to approximate a guided teacher’s predictions or trajectories, reducing or eliminating the need for two evaluations at inference. In that case, the guidance behavior is learned into the student rather than explicitly computed at every sampling step.
Related conditional–unconditional combinations also appear outside conventional diffusion systems. Their applicability depends on the model’s probability or vector-field formulation; the diffusion noise-prediction equation cannot be transferred unchanged to every generative architecture.