Flow Matching Fundamentals

Overview

Master the conceptual foundation of flow matching and continuous normalizing flows. Understand how to learn a trajectory from noise to data by training a vector field.

Goal: Build intuition for the ODE perspective on generative modeling and understand why flow matching is often simpler than diffusion.

Key Concepts

📋 Concepts

0 / 5 mastered
0%

The ODE Trajectory Mental Model

Core idea: Generative modeling as learning a continuous path from noise z0N(0,I)z_0 \sim \mathcal{N}(0, I) to data z1pdataz_1 \sim p_{\text{data}}.

Define an ODE:

dztdt=vθ(zt,t)\frac{dz_t}{dt} = v_\theta(z_t, t)

Where vθv_\theta is a learned vector field.

Forward process: z0z1z_0 \to z_1 (noise to data)
Sampling: Solve ODE forward from z0z_0 to get z1z_1

Intuition: Instead of learning to denoise (diffusion), learn the velocity at each point along the path.

Flow Matching Objective

Goal: Train vθv_\theta to match the true vector field vtv_t.

Conditional flow matching loss:

L(θ)=Et,z1,zt[vθ(zt,t)ut(ztz1)2]\mathcal{L}(\theta) = \mathbb{E}_{t, z_1, z_t} \left[ \| v_\theta(z_t, t) - u_t(z_t | z_1) \|^2 \right]

Where:

  • z1pdataz_1 \sim p_{\text{data}}: Real data sample
  • zt=αtz1+σtϵz_t = \alpha_t z_1 + \sigma_t \epsilon: Interpolated sample at time tt
  • ut(ztz1)u_t(z_t | z_1): Target vector field (analytically computable!)

Key insight: Unlike diffusion (which requires score matching), flow matching has a simple regression objective.

Flow Matching vs Diffusion Models

AspectDiffusion ModelsFlow Matching
Forward processStochastic (SDE)Deterministic (ODE)
Training objectiveScore matching (Γêç log p)Vector field regression
SamplingSDE/ODE solversODE solvers only
SimplicityMore complexSimpler math
FlexibilityFixed noise scheduleFlexible paths

When to use flow matching:

  • You want a simpler training objective
  • You want to design custom interpolation paths
  • You prefer deterministic generation

When to use diffusion:

  • You want stochasticity for diversity
  • You’re using existing diffusion codebases (Stable Diffusion, etc.)

ODE Solvers for Sampling

Euler method (simplest):

zt+Δt=zt+Δtvθ(zt,t)z_{t+\Delta t} = z_t + \Delta t \cdot v_\theta(z_t, t)

Runge-Kutta 4 (RK4) (more accurate, fewer steps): More complex multi-stage method, but allows larger Δt\Delta t.

DPM-Solver (optimized for generative models): Exploits structure of learned vector fields for fast sampling.

Trade-off: Accuracy vs speed. Euler needs ~100 steps, RK4 ~50 steps, DPM-Solver ~20 steps.

Training Flow Matching Models

Algorithm

  1. Sample data z1pdataz_1 \sim p_{\text{data}}
  2. Sample noise ϵN(0,I)\epsilon \sim \mathcal{N}(0, I)
  3. Sample time tU(0,1)t \sim U(0, 1)
  4. Interpolate: zt=αtz1+σtϵz_t = \alpha_t z_1 + \sigma_t \epsilon
  5. Compute target: ut=ddt(αtz1+σtϵ)u_t = \frac{d}{dt}(\alpha_t z_1 + \sigma_t \epsilon)
  6. Loss: vθ(zt,t)ut2\| v_\theta(z_t, t) - u_t \|^2

Key: The target utu_t is analytically known (no score estimation needed).

Interpolation Schedule

Linear interpolation:

zt=(1t)z0+tz1z_t = (1-t) z_0 + t z_1

Variance-preserving (VP):

zt=1σt2z1+σtϵz_t = \sqrt{1-\sigma_t^2} z_1 + \sigma_t \epsilon

Choice matters: Affects sample quality and training stability.

Key Resources

📚 Essential Reading

Flow Matching for Generative Modeling (arXiv:2510.21890)
https://www.arxiv.org/abs/2510.21890

Comprehensive tutorial on flow matching for diffusion modeling. Explains the connection between diffusion and flows, and why flow matching often leads to simpler training. Start here.

MIT Diffusion Course 2025
https://diffusion.csail.mit.edu/2025/

MIT course covering diffusion models and flow matching with lectures, notes, and code. Excellent for structured learning.

Learning Path

Phase 1: Theory (5 hours)

  1. Read flow matching arXiv paper (2510.21890)
  2. Work through ODE trajectory derivations
  3. Compare to diffusion formulation

Phase 2: Implementation (5 hours)

  1. Implement flow matching on 2D toy data (moons, circles)
  2. Visualize learned vector fields
  3. Experiment with different interpolation schedules
  4. Compare Euler vs RK4 sampling

Phase 3: Deep Dive (2 hours)

  1. Watch MIT Diffusion Course lectures on flow matching
  2. Read original Conditional Flow Matching paper (Lipman et al.)
  3. Understand Rectified Flow (next node prerequisite)

Common Pitfalls

❌ Confusing forward/backward: Sampling goes forward in time (0to1), not backward like diffusion.

❌ Wrong target vector: Make sure to use the conditional target (u_t(z_t | z_1)), not the marginal.

❌ Too few sampling steps: Euler method needs ~100 steps. Use adaptive solvers for faster sampling.

❌ Ignoring interpolation schedule: Linear interpolation works but VP schedules often train faster.

Next Steps

  • to Rectified Flow / Consistency Toolkit: Modern training and distillation methods
  • to Conditioning & Control: Add T2V, I2V, camera control to flow models

Assessment Criteria

✅ You understand this node when you can:

  • Explain the ODE trajectory view of generative modeling
  • Derive the flow matching loss from scratch
  • Implement flow matching on toy datasets
  • Articulate the difference from diffusion models
  • Choose appropriate ODE solvers for sampling