Course contentsShow
← Machine Learning and Deep Learning
Lesson 1586 of 3,53834. Diffusion ModelsFree lesson

Classifier-Free Guidance: Training

Training diffusion models with random condition dropout to enable both conditional and unconditional generation.

Classifier-Free Guidance: Training

What You'll Learn

You'll learn how to train a single diffusion model that can perform both conditional and unconditional generation, enabling classifier-free guidance without a separate classifier network.

The Core Idea

In the previous lesson, you learned why classifier-free guidance is desirable—it avoids needing a separate classifier network. But how do we actually train a model that can generate both conditionally (following a prompt) and unconditionally (ignoring it)?

The key insight is random condition dropout during training.

Training with Dropout

During training, you randomly replace the conditioning information (like text embeddings or class labels) with a special "null" or "empty" token some percentage of the time (typically 10-20%). This teaches the model two things simultaneously:

  1. With condition: How to denoise images according to the given prompt/class
  2. Without condition: How to denoise images unconditionally (no guidance)

Think of it like teaching a chef to cook both with and without a recipe. Sometimes you give them the recipe, sometimes you don't—they learn both skills in one training session.

Why This Works

When the model sees the null condition during training, it learns the unconditional score estimate ε_θ(x_t). When it sees real conditions, it learns the conditional score estimate ε_θ(x_t, c). At inference time, you can combine these using the guidance scale:

ε_guided = ε_uncond + w * (ε_cond - ε_uncond)

The same network produces both estimates depending on whether you pass the real condition or the null token.

Training Process

  1. Take a training sample with its condition (text, class, etc.)
  2. With probability p (e.g., 0.1-0.2), replace the condition with null
  3. Train the denoising network as usual
  4. The model learns to handle both scenarios

Key Takeaway: Classifier-free guidance training uses random condition dropout to teach a single model both conditional and unconditional generation, enabling flexible guidance at inference without separate networks.