Classifier-Free Guidance: Theory and Practice
Module: Generative AI | Difficulty: Advanced
Guidance Formula
where is the guidance scale.
Theory: Trade-off
- : Standard conditional generation
- : Amplifies conditioning (sharper but less diverse)
- : Deterministic, mode-seeking
Negative Prompt Guidance
Distillation of Guidance
def cfg_forward(model, x_t, t, cond, uncond, w=7.5):
eps_cond = model(x_t, t, cond)
eps_uncond = model(x_t, t, uncond)
return eps_uncond + w * (eps_cond - eps_uncond)
| Guidance | FID | Recall | Diversity | |----------|-----|--------|-----------| | w=1.0 | 4.2 | 0.62 | High | | w=3.0 | 3.1 | 0.58 | Medium | | w=7.5 | 2.8 | 0.51 | Low | | w=15.0 | 3.5 | 0.42 | Very Low |
Research Insight: Optimal guidance scale is task-dependent. Text-to-image works best at w=7-12, while class-conditional works at w=1-3.