Classifier-Free Guidance
Volume III, Chapter 10 — Part III. Conditioning diffusion models without a classifier: joint training, guided score derivation, guidance scale effects, and the quality-diversity tradeoff.
Prerequisites
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- Classifier Guidance: Background
- Classifier-Free Guidance: Formulation
- Joint Training Procedure
- Score Function Derivation
- The Guidance Scale
- Quality-Diversity Tradeoff
- Computational Cost
- Worked Examples
- Connection to the Broader Curriculum
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- State classifier guidance via Bayes' rule on the score function.
- Derive classifier-free guidance (CFG) as implicit classifier amplification without a separate model.
- Explain joint training with random condition dropout.
- Prove the equivalence between guided noise prediction and modified score .
- Analyze the quality-diversity tradeoff as a function of guidance scale .
- Compute the 2× inference overhead of CFG.
Prerequisites
- Reverse Process — , score connection
- Forward Diffusion
Notation
- — Conditioning variable (class, text, etc.)
- — Conditional noise prediction
- — Unconditional prediction
- — Guidance scale
- — Null / dropped condition
Core Intuition
Conditional generation requires sampling from — e.g., images given text prompts. Classifier guidance (Dhariwal & Nichol, 2021) modifies the score using a separately trained classifier at every noise level — expensive and limited to tasks with classifiers.
Classifier-free guidance (Ho & Salimans, 2022) trains a single noise predictor in both conditional and unconditional modes, then extrapolates between them at inference. No separate classifier needed — yet equivalent to amplifying an implicit classifier gradient.
CFG is the standard technique in Stable Diffusion, DALL·E 2, and Imagen, enabling high-fidelity text-to-image generation.
Series context. Volume III, Chapter 10, Part III.
Classifier-Free Guidance
Classifier Guidance: Background
Theorem 1 (Bayesian Score Decomposition).
Definition 1 (Classifier-Guided Score).
where amplifies conditioning.
Limitation. Requires training on noisy inputs at all — cumbersome for text conditioning.
Classifier-Free Guidance: Formulation
Definition 2 (CFG Noise Prediction).
equivalently:
is the guidance scale; is null condition (empty prompt).
Joint Training Procedure
Definition 3 (Condition Dropout). During training, with probability (typically 0.1–0.2), replace condition with :
Proposition 1. The same network learns:
- — conditional denoising
- — unconditional denoising
Using standard Reverse Process loss (13).
Score Function Derivation
From Reverse Process: .
Proposition 2 (Implicit Classifier Gradient).
In noise form:
Theorem 2 (CFG as Amplified Classifier Guidance). CFG (3) corresponds to modified score:
Equivalent to classifier guidance with scale without explicit classifier.
Proof. Substitute (6) into guided score; rearrange to (3).
The Guidance Scale
- 0 — Standard conditional sampling
- 1–4 — Moderate enhancement
- 7.5 — Stable Diffusion default
- — High fidelity, low diversity, artifacts
Proposition 3. At : — pure conditional.
Quality-Diversity Tradeoff
Theorem 3 (Sharpened Distribution). CFG samples from effective distribution:
Proof sketch. From (8): .
Consequences:
- High : concentrates on high regions — sharp, mode-collapsed
- Low : closer to true conditional — diverse but less aligned
- CLIP score increases with ; FID has optimal
Computational Cost
Proposition 4. Each sampling step requires two forward passes: conditional and unconditional. Total inference cost baseline.
Both passes can be batched: stack with conditions .
Worked Examples
Example 1:
— strong push toward conditional.
Example 2: Identical Predictions
If , CFG has no effect regardless of .
Connection to the Broader Curriculum
- Reverse Process — base sampling
- Bayes' Theorem — score decomposition
- Text conditioning via cross-attention (future article)
- RAG — conditioning in LLM domain
Common Pitfalls and Misconceptions
Pitfall 1: is not unconditional — it's conditional without guidance.
Pitfall 2: Too-high causes oversaturation and artifacts.
Pitfall 3: Forgetting condition dropout during training makes undefined.
Pitfall 4: Confusing in (3) vs. in (2) — related by offset.
Research Perspective
CFG (Ho & Salimans, 2022). Applied at scale in Stable Diffusion, Imagen. Research: guidance distillation (single-pass), autoguidance, negative prompting as .
Summary of Takeaways
- CFG —
- Implicit classifier —
- Effective distribution —
- Training — Drop condition with prob.
- Cost — 2× forward passes
Next: Tokenization (Volume III, LLMs)
Exercises
Exercise 1. Derive (8) from (3) using score–noise identity.
Exercise 2. Prove (9) from modified score.
Exercise 3. What happens as ?
Exercise 4. Design training schedule for .
Exercise 5. Compare CFG to Logistic Regression classifier guidance conceptually.
Exercise 6. Batch CFG: write combined forward pass dimensions.
Exercise 7. Negative prompting as alternative condition.
Exercise 8. Why does CFG improve CLIP score but harm diversity?