NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Contrastive Flow Matching

George Stoica, Vivek Ramanujan, Xiang Fan, Ali Farhadi, Ranjay Krishna, Judy Hoffman

TL;DR

This paper introduces Contrastive Flow Matching (AFM), a novel objective that enhances conditional generative models by enforcing distinct generative trajectories for different conditions. AFM significantly improves image quality, training speed, and inference efficiency compared to standard flow matching, making it a valuable tool for high-fidelity generative tasks.

What Problem Does This Paper Address?

Generative models like diffusion models and flow matching are powerful tools for creating realistic images. However, when these models are conditioned on specific attributes (e.g., class labels for image generation), they can sometimes produce outputs that are an "average" of the possible images for that condition, lacking specificity and diversity. This is because the learned "flows" (paths through latent space) for different conditions can overlap, leading to ambiguous generations. Existing methods like classifier-free guidance (CFG) can help but often come with increased computational costs. The paper aims to address this challenge by developing a method that encourages distinct and class-specific generative flows without the overhead of CFG.

Methods

The core contribution of this paper is Contrastive Flow Matching (AFM). It builds upon the existing flow matching objective, which trains models to learn probability flow fields between a base noise distribution and a target data distribution. AFM augments this by adding a contrastive learning objective.

Here's how it works:

  • Standard Flow Matching: Aims to regress the ideal probability flow field, essentially learning a "velocity" vector that guides a sample from noise to data.
  • Contrastive Augmentation: AFM introduces a pairwise loss term. For a given sample and its corresponding flow, it also considers a different sample from the batch (with a potentially different condition) and its associated flow. The contrastive loss then penalizes the model if the predicted flow for the first sample is too similar to the predicted flow for the second, unrelated sample. This encourages the model to learn flows that are discriminative across different conditions.
  • "Plug-and-Play" Integration: AFM is designed to be easily integrated into existing flow matching training loops with minimal computational overhead. It can also be combined with other techniques like Representation Alignment (REPA) and classifier-free guidance.

Datasets

The paper uses the following datasets for training and evaluation:

  • ImageNet-1k: Used for class-conditioned image generation experiments, processed at both 256x256 and 512x512 resolutions.
  • Conceptual Captions 3M (CC3M): Used for text-to-image generation experiments, processed at 256x256 resolution.

Key Insights and Ideas

  • Flow Overlap is the Root of Ambiguity: The paper clearly articulates that the overlap of generative trajectories (flows) between different conditions is a primary cause of suboptimal conditional generation quality.
  • Contrastive Learning for Flow Uniqueness: Applying contrastive learning principles not to image features but to the flow vectors themselves is a novel and effective way to enforce distinctiveness.
  • Efficiency Gains are Substantial: The improvements in training speed and inference steps are not marginal; they are significant enough to make generative models much more practical.
  • Complementarity is Key: AFM's ability to seamlessly integrate with and enhance other state-of-the-art techniques like REPA and CFG highlights its versatility and broad applicability.

Key Results

  • Improved Image Quality: AFM consistently outperforms standard flow matching across various metrics like FID, IS, SFID, Precision, and Recall. For example, it achieved up to an 8.9-point reduction in FID-50K on ImageNet.
  • Faster Training: AFM can improve training speed by a factor of up to 9x, reaching the same performance level with significantly fewer training iterations.
  • Faster Inference: Models trained with AFM require up to 5x fewer de-noising steps for inference, leading to much faster generation times.
  • Enhanced Class Separation: Visualizations (Figure 3) clearly show that AFM produces more distinct and class-coherent flows compared to standard flow matching, leading to more representative samples.
  • Compatibility with Other Methods: AFM significantly boosts performance when combined with REPA and also works well with CFG, further improving results.

Limitations and Future Work

  • Hyperparameter Tuning (λ): While AFM is robust, the paper notes that the contrastive weight (λ) needs careful tuning. Too high a value can lead to degenerate distributions and difficulty capturing class structure, while too low a value makes it similar to standard flow matching. The paper identifies λ=0.05 as a stable and effective choice.
  • Potential for Conflicts with CFG: While AFM and CFG can be combined, the paper acknowledges that their signals might not always align perfectly, and suggests that further work could explore more sophisticated ways to combine them to avoid potential conflicts and achieve even better results.
  • Future Work: The authors suggest exploring other ways to combine CFG with AFM beyond the proposed method, indicating that there's still room for optimization in their integration. They also hint at the broader implication that deviating from perfect distribution modeling might lead to better image generation, opening up new research avenues.

Summary updated

BibTeX
@inproceedings{stoica2025contrastive,
  author = {George Stoica and Vivek Ramanujan and Xiang Fan and Ali Farhadi and Ranjay Krishna and Judy Hoffman},
  title = {{Contrastive Flow Matching}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure