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)

Intuition & Key Idea

ELI5 Guide

Why this model was invented and how it transforms generation

The 30-Second Core Idea

"Moves random noise particles straight into realistic images or audio along smooth, optimal straight-line paths, cutting generation steps down by 80%."

Real-World Metaphor

A high-speed bullet train traveling along a straight, direct railway track — compared to standard diffusion which wanders down a random zigzagging mountain path.

Key Superpowers & Values
Trajectory GeometryOptimal Transport
Straight Lines

Constant velocity vector fields minimize transport cost.

Inference StepsUltra Fast
10 – 20 Steps

Fast numerical ODE solvers (Euler, Midpoint, RK4) advance rapidly.

Distillation TargetReal-Time Ready
1 – 4 Steps

Straight lines make 1-step student distillation trivially accurate.

Industry AdoptionModern SOTA
Flux.1, SD3, Voicebox

The dominant modern standard for state-of-the-art visual generation.

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

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

Key Insight:

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

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)
Hardware & Weights InspectorStep 1: Initialize Initial Condition x(0) ~ 𝒩(0, I)
Execution Bottleneck
Communication-Bound
Calculated via Arithmetic Intensity
Arithmetic Intensity
Dynamic per batch
Ratio of math operations (FLOPs) to memory traffic (Bytes)
Dominant GPU Kernel
FlashAttention-2 / CuBLAS GEMM
Optimized CUDA / Triton kernel launched

GPU Memory Hierarchy & HBM Traffic for this Step

HBM ↔ SRAM on-chip

Weights are loaded from High-Bandwidth Memory (HBM) into Streaming Multiprocessor (SM) registers and SRAM cache for computation.

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)