Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:Huggingface Diffusers Guidance Scale Defaults

From Leeroopedia
Knowledge Sources
Domains Diffusion_Models, Optimization
Last Updated 2026-02-13 21:00 GMT

Overview

Default classifier-free guidance (CFG) scale values and tuning rules: standard diffusion models use 7.5, Flux models use 3.5, and guidance scale comparisons use `math.isclose()` for floating-point safety.

Description

Classifier-free guidance (CFG) controls the trade-off between image quality/adherence to the prompt and image diversity. Higher values produce images more closely matching the prompt but can introduce artifacts. Different model architectures have different optimal guidance scales due to their training procedures. The Diffusers codebase implements multiple guidance strategies through the `guiders/` module, including standard CFG, zero-star guidance, adaptive projected guidance, and smoothed energy guidance. The code uses `math.isclose()` instead of `==` for floating-point comparisons of guidance scale values to avoid precision issues.

Usage

Relevant when tuning image generation quality, switching between model architectures (each has different optimal CFG ranges), or implementing custom guidance strategies.

The Insight (Rule of Thumb)

  • Standard Stable Diffusion (SD 1.5, SDXL): `guidance_scale = 7.5` (default)
  • Flux models: `guidance_scale = 3.5` (lower due to distilled guidance)
  • Adaptive Projected Guidance: `guidance_scale = 10.0` (higher default for adaptive method)
  • Smoothed Energy Guidance: `guidance_scale = 7.5`, `seg_guidance_scale = 2.8`
  • Scale = 1.0: Effectively disables CFG (unconditional generation)
  • Scale = 0.0: Pure unconditional (negative prompt only)
  • Comparison safety: Always use `math.isclose(guidance_scale, target)` not `guidance_scale == target`
  • Higher scales (10-20): More prompt adherence but risk oversaturation and artifacts
  • Lower scales (1-3): More diversity and creativity but less prompt fidelity
  • Training tip: Use `proportion_empty_prompts` to train unconditional guidance (enables CFG at inference)

Reasoning

The default of 7.5 was established empirically in the original Stable Diffusion paper as a good balance between quality and diversity. Flux models use lower scales because they were trained with a distillation-based guidance technique that bakes some guidance into the model itself.

The `math.isclose()` pattern in `classifier_free_zero_star_guidance.py` prevents subtle bugs: when users pass `guidance_scale=1.0` (intending to disable CFG), floating-point arithmetic might produce `0.9999999...` or `1.0000001...`, which would incorrectly enable/disable the guidance computation. This is a defensive programming pattern that prevents hard-to-debug generation quality issues.

The `proportion_empty_prompts` parameter in training scripts randomly replaces text conditioning with empty strings during training. This teaches the model the unconditional distribution, which is necessary for CFG to work at inference time.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment