---
title: 'Zero-CFG: Optimized Guidance for Flow Models'
url: https://www.emergentmind.com/topics/zero-cfg
type: topic
---

# Zero-CFG: Optimized Guidance for Flow Models

Zero-CFG (CFG-Zero*) is an enhanced classifier-free guidance (CFG) method for conditional generative models using flow matching. By addressing limitations in the original CFG approach, Zero-CFG introduces “optimized scale” and “zero-init” mechanisms to improve both sample fidelity and controllability—especially during early generation stages where standard CFG can degrade performance. The method demonstrates significant quantitative and qualitative improvements across image and video generation benchmarks, with negligible computational overhead [2503.18886].

## 1. Classifier-Free Guidance in Flow Matching Models

Classifier-free guidance (CFG) is a widely used inference-time strategy in diffusion and flow-based generative models. In this setting, generative sampling is formulated as a time-indexed ODE (or SDE) trajectory $x_t$ ($t\in[0,1]$) transforming samples from a simple prior $p_0$ to a structured data distribution $p_1$. The model is trained to estimate a velocity field $v_t^\theta(x|y)$ via

$$
\frac{dx_t}{dt} = v_t^\theta(x_t|y)\,,
$$

where $y$ denotes a condition such as a text prompt or class label. Learning proceeds by minimizing

$$
L_\mathrm{CFM}(\theta) = \mathbb{E}_{t,x_0,x_1}\, \| v_t^\theta(x_t|y) - (x_1-x_0) \|^2\,.
$$

CFG extends this framework by jointly learning a conditional branch $v_t(x|y)$ and an unconditional branch $v_t(x|\emptyset)$ within the same network. At inference, a guidance-weighted blend constructs

$$
\hat v_t(x|y) = (1-\omega)\,v_t(x|\emptyset) + \omega\,v_t(x|y)\,,
$$

with $\omega>1$ amplifying the influence of the condition $y$. This increases alignment to the condition while risking out-of-distribution artifacts.

## 2. Analysis: Limitations of Standard CFG

When the velocity model is underfitted, especially during early training or at the initial steps in the ODE solver ($t\approx 0$), CFG can exacerbate estimation error. For target distributions where ground-truth velocity $v_t^*(x)$ is available (e.g., Gaussian mixtures), empirical analysis shows

$$
\| \hat v_0^\theta - v_0^* \|^2 \geq \| 0 - v_0^* \|^2\,,
$$

meaning that even a zero velocity would outperform the CFG-blended estimate in these early steps. Therefore, standard CFG not only fails to improve guidance but can actively worsen the sample trajectory relative to a naïve baseline.

## 3. Optimized Scale Mechanism

Zero-CFG introduces an “optimized scale” scalar $s>0$ to reweight the unconditional branch prior to blending. The new guided velocity is

$$
\tilde v_t^\theta = (1-\omega)\, (s\,v_t^\theta(x|\emptyset)) + \omega\, v_t^\theta(x|y)\,,
$$

with $s$ chosen to minimize

$$
\min_s \| v_t^\theta(x|y) - s\,v_t^\theta(x|\emptyset) \|^2\,.
$$

By closed-form projection,

$$
s^* = \frac{ \langle v_t^\theta(x|y),\, v_t^\theta(x|\emptyset) \rangle }{ \| v_t^\theta(x|\emptyset) \|^2 }
$$

and the final guided velocity can be reparametrized as

$$
v_\mathrm{zero}(x_t, t) = (1 + \omega') v_\mathrm{cond}(x_t, t) - \omega' \, \alpha^* v_\mathrm{uncond}(x_t, t)
$$

where $\omega' = \omega - 1$ and $\alpha^* = s^*$.

This mechanism actively projects the conditional velocity toward the unconditional vector direction, ensuring the guidance optimally corrects the model’s estimation error, especially in underfitted regimes.

## 4. Zero-Init: Early Step Correction

The “zero-init” strategy is motivated by the observation that, for initial timesteps $(t \lesssim 0)$, even the optimized guided velocity is inferior to simply zero. Thus, Zero-CFG zeros out the velocity in the first $K$ ODE steps:

```python
for t in range(T):
    if t < K:
        x[t+1] = x[t]  # zero velocity update
    else:
        x[t+1] = ODEStep(v_zero(x[t]), x[t])
```

Default $K=1$ is typically sufficient. This procedure guarantees that the model's generated trajectory is not misdirected by severely erroneous velocity estimates in early timesteps, limiting the compounding of error over the full integration.

## 5. Key Mathematical Formulations

Comparison between standard CFG and Zero-CFG is summarized by the velocity update formulas:

| Variant         | Guided Velocity Formula                                                      |
|-----------------|----------------------------------------------------------------------------|
| Standard CFG    | $v_\mathrm{cfg}(x_t, t) = (1-w) v_\mathrm{uncond}(x_t, t) + w v_\mathrm{cond}(x_t, t)$     |
| Zero-CFG        | $v_\mathrm{zero}(x_t, t) = (1 + w') v_\mathrm{cond}(x_t, t) - w' \alpha^* v_\mathrm{uncond}(x_t, t)$ |

where $w' = w-1$.

The “optimized scale” $\alpha^*$ is a closed-form projection factor computed at each step.

## 6. Empirical Performance and Benchmarks

CFG-Zero* exhibits accelerated and more accurate convergence on toy targets (e.g., 2D Gaussian mixtures), with reduced error norms at $t=0$ compared to standard CFG. On real-world tasks:

- **ImageNet-256 with pre-trained SiT-XL (700M parameters)**:
  - Baseline conditional: IS=125.1, FID=9.41
  - Standard CFG: IS=257.0, FID=2.23
  - ADG: IS=257.9, FID=2.37
  - CFG++: IS=257.0, FID=2.25
  - Zero-CFG: IS=258.87, FID=2.10, sFID=4.59, Precision=0.80, Recall=0.61

- **Text-to-image synthesis:** Four leading models (Lumina-Next, SD3, SD3.5, Flux) demonstrate consistent improvements in both Aesthetic and CLIP scores:
  - Example (Lumina-Next): Aesthetic 6.85→7.03, CLIP 34.09→34.37

- **Compositional and qualitative benchmarks:** On T2I-CompBench++ and user studies, Zero-CFG yields $\approx$+0.02–0.04 gains in compositional fidelity, and 72% average user preference over standard CFG (82% on SD3.5 for detail preservation).

- **Text-to-video generation (Wan-2.1):** On VBench, total score moves from 83.99 (CFG) to 84.06 (Zero-CFG), with increased motion smoothness (+0.92) and spatial relationship accuracy (+1.09).

In all settings, the addition of optimized scaling and zero-init incurs negligible overhead—one dot-product per step and a trivial conditional branch.

## 7. Implications in Other Modalities and Limitations

CFG variants successful in image generation, including Zero-CFG, do not universally improve synthesis in other modalities such as zero-shot text-to-speech (TTS). Empirical evaluation establishes that techniques like zero-init and advanced reweighting do not yield consistent benefit for TTS, where modality- and text-embedding-specific factors dominate performance. In those domains, selective timestep-dependent CFG is preferred and efficacy is model × language dependent [2509.19668].

A plausible implication is that projection-based and initialization corrections like those in Zero-CFG are highly effective for flow-matching image and video models but require modality-specific adaptation for domains with more complex conditional structures or training dynamics.

## 8. Future Directions

Potential future research directions include:
- Extending optimized projection and initialization techniques to other conditional generative modalities (e.g., audio, molecular generation), with careful calibration to condition representation.
- Unifying Zero-CFG with separated-condition, timestep-adaptive CFG in multimodal settings.
- Systematic analysis of error propagation under various data and model regimes to refine initialization and scaling schedules.

The class of CFG improvements typified by Zero-CFG continues to be a key area for boosting fidelity and controllability in conditional generative modeling. Further innovation will require detailed analysis of both the guidance mechanism and the underlying model’s error profile at each generative timestep [2503.18886][2509.19668].

Source: https://www.emergentmind.com/topics/zero-cfg