atong01/conditional-flow-matching

TorchCFM: a Conditional Flow Matching library

What it solves

TorchCFM provides a fast, simulation-free training objective for Continuous Normalizing Flows (CNFs). It bridges the performance gap between CNFs and diffusion models, enabling faster training and inference for generative modeling across various data types.

How it works

The library implements Conditional Flow Matching (CFM) methods that learn to map a simple distribution (like a Gaussian) to a complex data distribution. It abstracts the choice of conditional distributions $q(z)$ through several loss functions, including:

  • ConditionalFlowMatcher: Standard CFM.
  • ExactOptimalTransportConditionalFlowMatcher: Uses exact optimal transport to approximate dynamic OT.
  • TargetConditionalFlowMatcher: Learns a flow from a standard normal Gaussian to data.
  • SchrodingerBridgeConditionalFlowMatcher: Approximates Schrödinger bridges via entropically regularized OT plans.
  • VariancePreservingConditionalFlowMatcher: Uses trigonometric interpolation to preserve variance over time.

Who it’s for

Researchers and developers working on generative AI, specifically those interested in continuous normalizing flows, optimal transport, and simulation-free training for image generation, single-cell dynamics, and tabular data.

Highlights

  • Implements multiple CFM variants including OT-CFM and SF2M.
  • Supports image generation (e.g., MNIST, CIFAR-10 with FID 3.5).
  • Compatible with PyTorch, PyTorch Lightning, and Hydra.
  • Provides a wide range of examples and Jupyter notebooks for 2D tutorials and image tasks.

Related

  • Project
  • Project
  • Project
  • Project
  • Project