Classifier-Free Guidance (CFG) Mechanics & Negative Prompting
Classifier-Free Guidance (CFG) is the mathematical bedrock of controllable text-to-image synthesis. Understanding how guidance vectors interact with negative conditioning enables precise steering without destroying image dynamic range.
1. Mathematical Formulation of CFG
During diffusion sampling, the model computes an unconditional score prediction $\mathbf{\epsilon}_\theta(\mathbf{x}_t, \emptyset)$ and a conditional score prediction $\mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c})$.
The guidance step extrapolates between these predictions using scalar guidance scale $s$:
$$\mathbf{\tilde{\epsilon}} = \mathbf{\epsilon}_\theta(\mathbf{x}_t, \emptyset) + s \cdot \left(\mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}) - \mathbf{\epsilon}_\theta(\mathbf{x}_t, \emptyset)\right)$$
When a negative prompt $\mathbf{c}_{\text{neg}}$ is introduced, it substitutes for the null unconditional embedding $\emptyset$:
$$\mathbf{\tilde{\epsilon}}_{\text{guided}} = \mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}_{\text{neg}}) + s \cdot \left(\mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}) - \mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}_{\text{neg}})\right)$$
The vector difference $\left(\mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}) - \mathbf{\epsilon}_\theta(\mathbf{x}_t, \mathbf{c}_{\text{neg}})\right)$ defines an explicit trajectory pointing away from negative concepts and towards the positive prompt.
2. Optimal CFG Scale Selection
- CFG 1.0 – 3.0: Under-guided. Low prompt adherence, soft painterly blending, but high creative diversity.
- CFG 4.5 – 7.0: Optimal zone for SDXL and SD 1.5. Clean subject adherence, natural skin tones, and rich dynamic lighting range.
- CFG > 9.0: Over-guided. Latent values saturate beyond normal distribution boundaries. Results in severe burnt halos, unnatural contrast, neon skin tones, and blocky textures.
3. Why Flux and SD 3 Diverge
Modern flow-matching models like Flux.1 use guidance distillation or operate with native CFG 1.0 (no negative guidance). In Flux, negative prompting is neither supported nor required: the T5-XXL language model directly responds to precise positive phrasing instead of noise subtraction.