Inferensys

Glossary

Classifier-Free Guidance (CFG) Scale

The Classifier-Free Guidance (CFG) scale is a critical hyperparameter in diffusion models that amplifies the influence of a text prompt on the generated image, trading off between sample diversity and prompt fidelity.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
DIFFUSION MODEL HYPERPARAMETER

What is Classifier-Free Guidance (CFG) Scale?

The Classifier-Free Guidance Scale is a critical hyperparameter in conditional diffusion models that controls the trade-off between sample diversity and prompt fidelity.

The Classifier-Free Guidance (CFG) Scale is a hyperparameter that amplifies the influence of a conditioning signal, such as a text prompt, during the iterative denoising process of a diffusion model. By adjusting a scalar value, typically between 1 and 20, it controls the strength of the guidance signal, steering the model away from unconditional generation and toward outputs that more closely adhere to the provided description. Higher values increase fidelity to the prompt but can reduce image diversity and quality.

Technically, the scale modifies the predicted noise at each denoising step by interpolating between a conditional prediction (guided by the prompt) and an unconditional prediction. This mechanism, introduced as an alternative to classifier guidance, eliminates the need for a separate trained classifier. Optimal CFG scale values are model-specific and must be tuned empirically, as excessively high values can lead to over-saturated colors, artifacts, or compromised compositional integrity in the generated image.

TEXT-TO-IMAGE GENERATION

Key Characteristics of the CFG Scale

The Classifier-Free Guidance (CFG) Scale is a critical hyperparameter in conditional diffusion models that controls the trade-off between sample quality and prompt adherence. Understanding its mechanics is essential for generating coherent, high-fidelity images.

01

Definition and Core Function

The Classifier-Free Guidance (CFG) Scale is a hyperparameter, typically denoted as a numerical value (e.g., 7.5), that amplifies the influence of a conditional input (like a text prompt) during the image denoising process. It works by extrapolating between a conditional and an unconditional noise prediction, steering the generation toward the prompt. A higher scale value increases adherence to the text description but can reduce image diversity and naturalness.

02

The Guidance Trade-Off

Adjusting the CFG scale involves a fundamental trade-off:

  • Low Scale (e.g., 1.0-4.0): Produces diverse, creative, and often more aesthetically "natural" images, but with weaker prompt adherence. The model has more freedom, which can lead to hallucination of unrelated elements.
  • High Scale (e.g., 10.0-20.0): Strongly enforces the prompt, improving fidelity and detail accuracy. However, it can cause oversaturated colors, unnatural contrast, and a reduction in sample variety, making outputs look "overcooked" or artificial.
03

Mathematical Mechanism

The CFG algorithm modifies the predicted noise at each denoising step. The final noise prediction is calculated as: ε_guided = ε_uncond + guidance_scale * (ε_cond - ε_uncond) Where:

  • ε_cond is the noise predicted using the text prompt.
  • ε_uncond is the noise predicted for an empty or null prompt.
  • guidance_scale is the CFG scale parameter. This extrapolation pushes the generation away from the unconditional prediction and toward the conditional one, effectively amplifying the signal from the text.
04

Typical Operating Range and Defaults

While model-dependent, common effective ranges are:

  • Stable Diffusion 1.x/2.x: A scale of 7.5 is a standard default, balancing detail and coherence. Values from 5.0 to 15.0 are commonly explored.
  • Very High Scales (>15.0): Often used for architectural or technical concepts requiring extreme precision, but risk artifacts.
  • Very Low Scales (<2.0): Used for more abstract, artistic, or dream-like generations where prompt is a loose inspiration. Optimal scale is found empirically per model checkpoint and desired output style.
05

Interaction with Negative Prompting

The CFG scale also amplifies the effect of negative prompts. A negative prompt provides ε_neg_cond, a noise prediction for what to avoid. The guided prediction becomes: ε_guided = ε_uncond + guidance_scale * (ε_cond - ε_neg_cond) A high CFG scale therefore strongly steers the generation away from the negative concepts (e.g., "blurry, deformed hands") as well as toward the positive prompt. This makes prompt engineering more precise but also more sensitive.

06

Impact on Inference and Samplers

The CFG scale directly affects computational cost and sampler behavior:

  • Increased Compute: Calculating both conditional and unconditional predictions doubles the forward passes per denoising step.
  • Sampler Sensitivity: Different samplers (e.g., DDIM, DPM++ 2M) have varying stability across CFG scales. Some samplers may become numerically unstable at very high scales.
  • Denoising Steps Relationship: The effect of the scale is cumulative over denoising steps. A high scale over many steps exerts maximal guidance but can also compound errors if the prompt is ambiguous.
BEHAVIORAL IMPACT

Effects of Different CFG Scale Values

This table compares the qualitative and quantitative effects of adjusting the Classifier-Free Guidance (CFG) scale, a critical hyperparameter for controlling text adherence in diffusion models like Stable Diffusion.

CharacteristicLow Scale (1.0 - 4.0)Moderate Scale (5.0 - 9.0)High Scale (10.0 - 20.0)Very High Scale (>20.0)

Primary Effect

Weak conditioning

Balanced fidelity & creativity

Strong prompt adherence

Over-conditioning

Image Fidelity to Prompt

Low. Images are creative but often ignore specific prompt details.

High. Good balance of following the prompt while maintaining natural image quality.

Very High. Strict adherence to the textual description.

Extreme. May over-interpret or distort elements to fit the prompt.

Visual Artifacts & Quality

Minimal artifacts, natural-looking outputs.

Few artifacts, high overall quality.

Increased risk of oversaturation, contrast issues, and minor distortions.

High probability of severe artifacts, color bleaching, and distorted anatomy.

Sample Diversity

High. Model explores latent space more freely.

Moderate. Guided exploration within prompt constraints.

Low. Converges to similar outputs for a given prompt.

Very Low. Outputs become deterministic and repetitive.

Recommended Use Case

Abstract art, mood-based generation, maximizing creativity.

General-purpose generation, photorealistic outputs, balanced control.

Technical illustrations, precise concept rendering, strict briefs.

Seldom recommended; can be used experimentally for extreme stylization.

Inference Time Impact

No impact. CFG scale is a weighting, not a step count.

No impact. CFG scale is a weighting, not a step count.

No impact. CFG scale is a weighting, not a step count.

No impact. CFG scale is a weighting, not a step count.

Typical Default Value

7.5 (Common in Stable Diffusion interfaces)

CLASSIFIER-FREE GUIDANCE (CFG) SCALE

Frequently Asked Questions

The Classifier-Free Guidance (CFG) scale is a critical hyperparameter in text-to-image diffusion models like Stable Diffusion. It controls the trade-off between image quality and adherence to the text prompt. This FAQ addresses common technical questions about its function, tuning, and impact on generation.

The Classifier-Free Guidance (CFG) scale is a hyperparameter that controls the strength of conditioning in a conditional diffusion model, amplifying the influence of a text prompt on the generated image to improve fidelity and adherence to the description.

It operates by computing a weighted combination of a conditional prediction (guided by the prompt) and an unconditional prediction (ignoring the prompt). The formula is: guided_prediction = unconditional_prediction + cfg_scale * (conditional_prediction - unconditional_prediction). A higher CFG scale pushes the generation further away from the unconditional 'average' image and closer to the specific concept described in the prompt.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.