Skip to content

Pranav-A-04/Flow_Matching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌀 Flow Matching in Generative Modeling

This is a minimal repo demonstrating Flow Matching — a method to train generative models via supervised learning of ODE trajectories.


🌊 What is Flow Matching?

Flow Matching is a recently proposed method (Lipman et al., 2022) for training generative models by learning a vector field that transforms samples from a simple distribution (e.g., Gaussian noise) into samples from a complex data distribution (e.g., images, shapes, point clouds).


🚀 Core Idea

We define a linear interpolation between a pair of points:

  • x₀ is a sample from the prior distribution (e.g., Gaussian noise)
  • x₁ is a sample from the target distribution (e.g., real data)
  • xₜ is a point interpolated between the two
  • t ∈ [0, 1] is a random time step

We want to learn a time-dependent vector field v(xₜ, t) that matches the true constant velocity from x₀ to x₁, defined as:

This defines a trivial ODE where each point moves at constant velocity along a straight line.


🧠 Training Objective

We train a neural network v_θ(xₜ, t) to match this target velocity using an MSE loss:

Effectively, the model learns to predict the direction and magnitude each point should move in at any timestep t along its trajectory from x₀ to x₁.


🎯 Sampling

To generate new samples:

  1. Sample x₀ ∼ p₀ (e.g., standard normal distribution)
  2. Solve the ODE:

from t = 0 to t = 1, using an ODE solver (e.g., Euler, Runge-Kutta).

The resulting x₁ is a sample from the learned data distribution.


📊 Results

Final Reconstructed Data

Final Reconstructed Data

Initial Noise Distribution

Initial Noise


🎥 Visualization

Flow Matching in Action

This animation shows how points are moved from the prior (noise) distribution to the data distribution by integrating the learned flow field.


📄 Citation

This repo is based on the ideas from:

Y. Lipman, G. Batzolis, and S. Achlioptas.
"Flow Matching for Generative Modeling", NeurIPS 2022.
[arXiv:2210.02747]


🛠️ Acknowledgments

This repo is a fun and lightweight implementation for understanding the mechanics of flow matching. It is not optimized for performance or scale, but focuses on clarity and visual intuition.

About

This is a fun little repo to explore how flow matching works in the context of generative models

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages