mlgenerate.comVisual Generative ML
All Models/image/Flow Matching

Flow Matching / Rectified Flow

Flow Matching2023 · Meta AI / FAIR & UT Austin

Straight-line ODE probability transport between Gaussian noise and data

Execution Paradigm:Deterministic ODE Integration (Euler / Heun Solver)
Straight-Line Numerical ODE Integration (10–25 Steps)
Interactive Stage (INFERENCE)Initial point sits in the standard normal distribution space.
Continuous Flow Matching (ODE) vs DiffusionTime t = 0.00

Flow Matching transports probability mass along straight-line vector fields dx/dt = v_θ(x, t). Because the ODE path has zero curvature, simple numerical solvers (like Euler) reach the data distribution in far fewer steps.

Trajectory Phase Space: Noise x(0) → Data x(1)Curved Diffusion SDE PathStraight Flow Matching Chordt = 0 (Noise)t = 1 (Data)
Velocity Vector v_θ = x_1 - x_0Euler Step: x_{t+dt} = x_t + dt · v_θ(x_t, t)
Step 1 of 3

1. Initialize Initial Condition x(0) ~ 𝒩(0, I)

Draw sample x(0) from standard normal distribution at time t = 0.

💡 Takeaway: Unlike diffusion which counts backward from T to 0, Flow Matching integrates forward from 0 to 1.

Active Tensor Dimensions & Memory Shapes

x_0[B, C, H, W]
Initial ODE state at t=0
sample_flow_euler.py
1
def sample_flow_euler(model, shape, num_steps=16):
2
x = torch.randn(shape) # x(0) Gaussian noise
3
dt = 1.0 / num_steps
4
for step in range(num_steps):
5
t = step * dt
6
t_tensor = torch.full((shape[0],), t, device=x.device)
7
v = model(x, t_tensor) # Instantaneous velocity
8
x = x + v * dt # Straight Euler step
9
return x # x(1) clean image
Click code line to jump to corresponding stepPyTorch Reference
Why This Architecture Matters

The modern standard for state-of-the-art vision and audio generation (powers Stable Diffusion 3, Flux.1, and Voicebox), offering simpler mathematical foundations and faster sampling than classical diffusion.

Runtime Complexity & Bottlenecks

Training Objective:Conditional Flow Matching Loss: 𝔼_{t, x_0, x_1}[ ||v_θ(x_t, t) - (x_1 - x_0)||^2 ]

Inference Bottleneck:O(K) Euler/Heun ODE steps (as few as 4–20 steps)