FoundationsChecking saved investigationReading browser-local route memory before showing a continuation.

Foundation Lab

Classifier-Free Guidance in Diffusion

CFG is why Stable Diffusion/DALL-E/Midjourney produce high-quality, on-prompt images

Concept 42 of 100Generative ModelsPhase 9
#42CFGGenerative Models
key equation\tilde{\epsilon}_\theta = \epsilon_\theta(\emptyset) + w \cdot (\epsilon_\theta(c) - \epsilon_\theta(\emptyset))

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 42 of 100CFGGenerative Models / Phase 9: Advanced architectures & generation
Current question

CFG extrapolates beyond the data distribution—high guidance can produce unrealistic but more "prompt-adherent" images

\tilde{\epsilon}_\theta = \epsilon_\theta(\emptyset) + w \cdot (\epsilon_\theta(c) - \epsilon_\theta(\emptyset))
PredictionCommit before the demo.

Ask what should change when the equation is manipulated, then let the visualization test that expectation.

EvidenceCompare local witness and source.

Use the runnable panel, the key equation, and canonical papers as separate forms of evidence for the same object.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue through the atlas.

Use prerequisites, dependents, and semantic links to repair the next gap without leaving the object behind.

Why It Matters for Modern Models

  • CFG is why Stable Diffusion/DALL-E/Midjourney produce high-quality, on-prompt images
  • The guidance scale is the main user-facing knob for text-to-image quality vs diversity
  • Trains one model that handles both conditional and unconditional generation via dropout on conditioning

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • CFG extrapolates beyond the data distribution—high guidance can produce unrealistic but more "prompt-adherent" images
  • There is an optimal guidance scale: too low = ignores prompt, too high = artifacts and oversaturation
  • CFG relates to temperature in LLMs: both are post-hoc distribution shaping at inference time

Interactive Visualization

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation and the visualization. Come back here for the full walkthrough.

Key Equation
ϵ~θ=ϵθ()+w(ϵθ(c)ϵθ())\tilde{\epsilon}_\theta = \epsilon_\theta(\emptyset) + w \cdot (\epsilon_\theta(c) - \epsilon_\theta(\emptyset))

CFG interpolates between conditional and unconditional scores:

ϵ~θ(xt,c)=ϵθ(xt,)+w(ϵθ(xt,c)ϵθ(xt,))\tilde{\epsilon}_\theta(x_t, c) = \epsilon_\theta(x_t, \emptyset) + w \cdot (\epsilon_\theta(x_t, c) - \epsilon_\theta(x_t, \emptyset))

where ww is the guidance scale (typically 3-15 for text-to-image).

Equivalently in score space:

s~(xt,c)=s(xt)+wxtlogp(cxt)\tilde{s}(x_t, c) = s(x_t) + w \cdot \nabla_{x_t} \log p(c|x_t)

Higher ww amplifies the conditioning signal, trading diversity for fidelity.

Canonical Papers

Classifier-Free Diffusion Guidance

Ho & Salimans2022NeurIPS Workshop
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.