Source-linked AI summary

CFG-Zero*: Improved Classifier-Free Guidance for Flow Matching Models

Weichen Fan, Amber Yijia Zheng, Raymond A. Yeh, Ziwei Liu

arXiv:2503.18886v2cs.CV

TL;DR

CFG is widely used to improve generation quality and controllability, but its conditional distribution may not match users’ intended prompts. The paper studies CFG under inaccurate flow estimates and proposes CFG-Zero⋆, which outperforms standard CFG across image and video generation models.

  • Problem

    CFG is widely used to improve sample quality and controllability, yet the learned conditional distribution may not match the user’s intended distribution.

    Source: §1 · p. 1
  • Method

    The paper analyzes CFG with Gaussian mixtures and proposes CFG-Zero⋆, combining an optimized scale with zeroing the first ODE-solver step.

    Source: §1 · p. 2
  • Results

    Across text-to-image and text-to-video models, CFG-Zero⋆ outperforms standard CFG with higher aesthetic scores, better text alignment, and fewer artifacts.

    Source: §6 · p. 9
  • Takeaways & Limitations

    The reported experiments support CFG-Zero⋆ as an alternative to CFG across discrete and continuous conditional-generation tasks.

    Source: §1 · p. 2

    The scale analysis uses a single-Gaussian source and target example, while access to the ground-truth flow is treated as hypothetical.

    Source: §3 · p. 3, §4.1 · p. 4

Abstract

from arXiv · show

Classifier-Free Guidance (CFG) is a widely adopted technique in diffusion/flow models to improve image fidelity and controllability. In this work, we first analytically study the effect of CFG on flow matching models trained on Gaussian mixtures where the ground-truth flow can be derived. We observe that in the early stages of training, when the flow estimation is inaccurate, CFG directs samples toward incorrect trajectories. Building on this observation, we propose CFG-Zero*, an improved CFG with two contributions: (a) optimized scale, where a scalar is optimized to correct for the inaccuracies in the estimated velocity, hence the * in the name; and (b) zero-init, which involves zeroing out the first few steps of the ODE solver. Experiments on both text-to-image (Lumina-Next, Stable Diffusion 3, and Flux) and text-to-video (Wan-2.1) generation demonstrate that CFG-Zero* consistently outperforms CFG, highlighting its effectiveness in guiding Flow Matching models. (Code is available at github.com/WeichenFan/CFG-Zero-star)

1. Introduction

Flow-matching models are increasingly used for image and video generation, and CFG is used to improve conditional quality and controllability. The paper links underfitted velocity errors to misleading early guidance and introduces CFG-Zero⋆.

  • CFG is used to improve prompt alignment, but the learned conditional distribution may differ from the user’s intended distribution.The paper identifies dataset limitations and learning limitations as possible sources of this mismatch.Source: §1 · p. 1
  • When the model is underfitted, CFG’s first-step velocity can deviate significantly from the optimal trajectory, motivating skipping that prediction.Source: §1 · p. 2
  • The paper compares learned and closed-form optimal velocities on Gaussian mixtures, then proposes optimized scale and zero init for CFG.Source: §1 · p. 2
  • Zeroing the first ODE-solver step improves sample quality when the model is underfitted, and CFG-Zero⋆ is competitive across discrete and continuous conditional-generation tasks.Source: §1 · p. 2

2. Related Work

Related work describes flow matching as an ODE-based alternative and reviews CFG’s guidance-scale challenges. This paper instead targets inaccurate CFG predictions under underfitting.

  • Flow matching models use ODEs to model sample trajectories, while CFG combines conditional and unconditional model outputs without an external classifier.Source: §2 · p. 2
  • CFG’s unbounded empirical guidance scale can produce oversaturation or weakened fidelity, and prior work has found its estimate may not give an optimal denoising direction.Source: §2 · p. 2
  • Prior approaches explore adaptive or dynamic scaling, smaller unconditional models, or restricting CFG to a sampling interval.Source: §2 · p. 2
  • Unlike those approaches, this work studies CFG prediction error under underfitting, derives an error bound, and adjusts the unconditional output for more stable guidance.Source: §2 · pp. 2–3

3. Preliminaries

The preliminaries define conditional flow matching as learning a velocity field along a source-to-target probability path, then describe CFG sampling and the paper’s Gaussian analysis setup.

  • Conditional flow matching defines a probability path from source p(x|y) to target q(x|y), with samples interpolated as x_t = (1 − t)x_0 + tx_1.A time-dependent neural velocity field governs the trajectory, and the model is trained by minimizing the CFM loss.Source: §3 · p. 3
  • At generation, an ODE solver uses a model trained to produce conditional and unconditional velocities, which CFG combines using guidance scale ω.The null condition ∅ carries no conditioning information; ω = 1 corresponds to using only the conditional velocity.Source: §3 · p. 3
  • For Gaussian mixtures, the optimal velocity has a closed form; the preliminaries illustrate this with source N(0, I) and target N(µ, I).Source: §3 · p. 3
  • CFG-Zero⋆ takes a trained velocity, noise sample, guidance weight, and zero-init step count K; it skips ODE updates for the first K steps, with K = 1 by default.It then solves the ODE and returns the generated sample.Source: §3 · p. 3
  • The analysis compares learned and optimal velocities during underfitting, where the closed-form optimum makes their gap measurable.Source: §3 · p. 3

4. Methodology

CFG-Zero⋆ adds an optimized scale and zero-init to CFG. The section evaluates these changes on Gaussian mixtures and ImageNet-256, including how zero-init behaves across training stages.

4. Methodology

  • CFG-Zero⋆ combines an optimized scale that compensates for learned-velocity inaccuracies with zero-init, which zeros the first ODE solver step.The paper describes both changes as additions to standard CFG with minimal additional computational cost.Source: §4 · p. 3

4.1. Optimizing an additional scaler in CFG

  • An optimizable scalar s compensates for learned-velocity inaccuracies; minimizing an upper bound on approximation loss yields s⋆, the projection of conditional velocity onto unconditional velocity.On Gaussian mixtures, CFG-Zero⋆ samples more closely match the target distribution than CFG.Source: §4.1 · pp. 3–4

4.2. Zero-init for ODE Solver

  • During early training, CFG and CFG-Zero⋆ velocity estimates at t = 0 can be less accurate than an all-zero velocity, motivating zero-init for the first few ODE solver steps.The analysis compares estimated velocities with the ground-truth velocity.Source: §4.2 · p. 4

4.3. Validation beyond Mixture of Gaussians

  • On ImageNet-256, zero-init outperforms standard CFG through 160 epochs, but standard CFG surpasses it beyond that point as the model becomes more accurate.The comparison uses a 400M-parameter DiT trained from scratch; the table caption identifies the turning point at 160 epochs.Source: §4.3 · p. 4, Table 1 · p. 5
  • 258.87 Inception Score, 2.10 FID, and 4.59 sFID make CFG-Zero⋆ the strongest overall method, outperforming CFG++ [2] and ADG [31] on key metrics.Its Precision is 0.80, comparable to CFG and ADG, and its Recall is highest at 0.61.Source: §4.3 · pp. 4–5, Table 2 · p. 5
  • The ImageNet-256 guidance-strategy comparison reports FID and Inception Score, with the conditional prediction alone as its baseline.Lower FID and higher Inception Score are better.Source: Table 2 · p. 5

5. Experiments

Experiments compare CFG-Zero⋆ with CFG across text-to-image and text-to-video models, then test its components and sampling choices. The reported results favor CFG-Zero⋆ on image quality and text alignment, with model-dependent effects from zeroing initial steps.

5.1. Text-to-Image Generation

  • CFG-Zero⋆ consistently achieves higher Aesthetic and CLIP Scores than CFG across the tested text-to-image models.The quantitative evaluation covers Lumina-Next, Stable Diffusion 3, Stable Diffusion 3.5, and Flux.Source: Table 3 · p. 5, §5.1 · p. 5
  • On T2I-CompBench, CFG-Zero⋆ improves Color, Shape, and Texture quality while Spatial performance remains comparable to CFG.The comparison covers Lumina-Next, SD3, and SD3.5.Source: Table 4 · p. 6, §5.1 · p. 6
  • 72.15% overall win ratio on SD3.5, with 82.33% for detail preservation and 81.45% for color fidelity in the user study.CFG-Zero⋆ also performs favorably on image-text alignment, surpassing CFG in most cases.Source: §5.1 · pp. 6–7, Figure 5 · p. 6

5.2. Text-to-Video Generation

  • On Wan-2.1, CFG-Zero⋆ raises Aesthetic Quality by 2.57, Imaging Quality by 2.73, Motion Smoothness by 0.92, and Spatial Relationship by 1.09, but lowers Temporal Style by 0.77.The authors attribute the Temporal Style decrease to the base model’s poor stylized-video generation capability.Source: §5.2 · p. 7

5.3. Ablation Studies

  • CFG-Zero⋆ improves both image quality and text matching across different sampling-step settings.The SD3.5 study reports robustness across varied sampling settings.Source: §5.3 · pp. 7–8, Figure 7 · p. 8
  • Across guidance scales, CFG-Zero⋆ achieves higher CLIP and Aesthetic scores than CFG.This SD3.5 ablation tests both image-text alignment and visual appeal.Source: Figure 8 · p. 8, §5.3 · p. 8
  • Combining zero-init and optimized scaling achieves the highest Aesthetic Score (7.10) and CLIP Score (34.68) among the tested variants.The authors report that the optimized scaler reduces the gap between predicted and true velocity, while zero-init improves performance by skipping the first step.Source: §5.3 · p. 8, Table 6 · p. 8
  • Lumina-Next and SD3 perform best when the first 2 steps are zeroed out, while SD3.5 performance declines as more initial steps are zeroed.The authors suggest SD3.5 is well-trained and approaching convergence; CFG-Zero⋆adds minimal computational cost.Source: §5.3 · p. 8, Table 7 · p. 8, Table 8 · p. 8

6. Conclusion

The conclusion presents CFG-Zero⋆ as an improved classifier-free guidance method for flow-matching diffusion models. It reports that theoretical analysis and experiments support gains over standard CFG across image and video generation, with ablations supporting both components and minimal added computational cost.

6. Conclusion

  • CFG-Zero⋆ combines an optimized scale factor for velocity estimation with zero-init to stabilize early sampling.The conclusion presents both as techniques addressing CFG’s limitations.Source: §6 · pp. 8–9
  • Across text-to-image and text-to-video models, the reported experiments show higher aesthetic scores, better text alignment, and fewer artifacts than standard CFG.Evaluated models include SD3.5, Lumina-Next, Flux, and Wan-2.1.Source: §6 · p. 9
  • Ablations support both CFG-Zero⋆ components, and the method improves sample quality without significant computational cost.Source: §6 · p. 9

A1.1. Experiments on Mixed Gaussian

The mixed-Gaussian experiments compare CFG, conditional-only guidance, and CFG-Zero⋆ trajectories, and examine how zero-init depth interacts with training progress. CFG-Zero⋆ guides samples toward the target distribution without the excessive variance reported for conditional-only sampling.

A1.1. Experiments on Mixed Gaussian

A2. Additional Visual Results

The appendix adds visual comparisons, implementation snippets, and evaluation-protocol details. It reports finer details, more vibrant colors, and smoother motion in CFG-Zero⋆ videos relative to CFG, while specifying prompt, image, and video evaluation settings.

A2. Additional Visual Results

A3. Implementation Details

  • The implementation computes an optimized scale from the dot product of conditional and unconditional predictions divided by the unconditional prediction’s squared norm, and zeroes the first-step prediction.The code reshapes the predictions before computing the scale and applies zero-init when sample_step is zero.Source: A3. Implementation Details · p. 12

A3.1. Text-to-Image Details

  • Text-to-image evaluation uses 200 diverse prompts and 10 images per prompt; the user study includes 76 participants answering 25 questions sampled from generated images.The model evaluations use default optimal settings, and the prompt set includes short and long prompts spanning objects, animals, and humans.Source: A3.1. Text-to-Image Details · pp. 12–13
  • The T2I-CompBench comparison uses Lumina-Next, SD3, and SD3.5, generating each image 10 times with different random seeds under optimal settings.Source: A3.1. Text-to-Image Details · p. 12

A3.2. Text-to-Video Details

Loading 2503.18886v2…