Guidance Scales in Diffusion Models
Module: Generative AI | Difficulty: Advanced
Guidance Scale Theory
Effective Temperature
Higher = lower temperature = sharper attention.
Dynamic Guidance
Schedule guidance strength over time.
Negative Prompt Guidance
def dynamic_guidance(model, x_t, t, cond, uncond, w_min=3, w_max=12):
progress = t / 1000
w = w_min + (w_max - w_min) * progress
eps_cond = model(x_t, t, cond)
eps_uncond = model(x_t, t, uncond)
return eps_uncond + w * (eps_cond - eps_uncond)
Research Insight: The optimal guidance scale depends on the trade-off between quality and diversity. For text-to-image, w=7-12 is optimal. For class-conditional, w=1-3 is optimal. Dynamic scheduling can improve results by 5-10%.