Conditional Generation Theory
Module: Generative AI | Difficulty: Advanced
Class-Conditional
Embedding: added to time embedding.
Text-Conditional
Cross-attention for conditioning.
Image-Conditional (Inpainting)
Classifier-Free vs Classifier Guidance
| Method | FID | Diversity | Control | |--------|-----|-----------|---------| | Unconditional | 4.5 | High | None | | Classifier guidance | 3.8 | Medium | Strong | | CFG (w=1) | 4.2 | High | Weak | | CFG (w=7) | 2.8 | Medium | Strong |
def conditional_forward(model, x_t, t, cond, guidance_scale=7.5):
eps_cond = model(x_t, t, cond)
eps_uncond = model(x_t, t, None)
return eps_uncond + guidance_scale * (eps_cond - eps_uncond)
Research Insight: CFG with amplifies the conditional signal, effectively sharpening the conditional distribution. This is equivalent to reducing the temperature in the softmax of the attention mechanism.