ResearchGenerative Networks

Flow Matching (FM)

It learns the velocity field of an ordinary differential equation that carries the noise distribution to the data distribution, by regressing directly on the velocities of simple probability paths (such as straight lines between noise and data), without simulating the equation during training.

Overview

NameFlow Matching
Year introduced2023
ResearchersYaron Lipman, Ricky T. Q. Chen, Heli Ben-Hamu, Maximilian Nickel, Matt Le
InstitutionMeta AI / Weizmann Institute
Original paperFlow matching for generative modeling arXiv
Data typeImages, Tabular data, Sequences and time series
DomainsScientific computing, Generative AI, Computer vision, Audio and speech
Computational costOne pass for training; tens of evaluations for generation.
Data sizeAs for diffusion.

Problem it solves

Training continuous normalising flows (CNF) by maximum likelihood requires costly ODE simulation, and diffusion models need many generation steps because their paths are curved.

Background and evolution

What came before: Diffusion Models, Score-Based Generative Models, Neural ordinary differential equations

  1. 2018

    Neural ODE and continuous flows. [ref]

  2. 2023

    Flow Matching (ICLR 2023). [ref]

  3. 2023

    Rectified Flow: straight paths and "rectification". [ref]

Core idea

We choose a simple conditional path between a noise sample $x_0$ and a data sample $x_1$, such as $x_t=(1-t)x_0+tx_1$, whose velocity is $x_1-x_0$. We train $v_\theta(x_t,t)$ by MSE regression on this velocity. The authors proved that the gradient of this conditional loss equals the gradient of the loss for the unknown marginal field. To generate, we solve $dx/dt=v_\theta$ from $t=0$ to 1.

Example: Generating audio or images with few solver steps because the paths are closer to straight.

Interactive diagram

A simplified illustrative diagram with the dimensions of a small example, not a drawing matching every detail of the original implementation. Click any layer to see its role, dimensions and mathematical operation.

Select a layer in the diagram.

Components

ComponentRole
Probability path p_tLinear/OT or diffusion
Conditional velocity u_tx₁ − x₀ for the linear path
Velocity network v_θ(x, t)
ODE solverEuler/RK at generation

Equations

1. Conditional flow matching loss

$$\mathcal{L}_{CFM}=\mathbb{E}_{t,x_0,x_1}\left\lVert v_\theta(x_t,t)-u_t(x_t\mid x_1)\right\rVert^2$$

Symbols
$u_t$Conditional velocity of the path
Dimensions
A scalar
Numerical example
$x_0=(0,0)$, $x_1=(2,0)$, $t=0.5$ ⇒ $x_t=(1,0)$ and the target is $(2,0)$.
Relation to the architecture
Its gradient equals the gradient of the marginal loss.

2. The optimal-transport (OT) path in the paper

$$x_t=\big(1-(1-\sigma_{min})t\big)x_0+t\,x_1,\qquad u_t=x_1-(1-\sigma_{min})x_0$$

Symbols
$\sigma_{min}$A small deviation at t=1
Dimensions
Same shape as x
Numerical example
With $\sigma_{min}=0$ the path becomes exactly linear and the velocity is $x_1-x_0$.
Relation to the architecture
Straight paths make it easy to solve in few steps.

3. Generation by solving the ODE

$$\frac{dx}{dt}=v_\theta(x,t),\quad x(0)\sim\mathcal N(0,I)\;\Rightarrow\;x(1)\approx\text{sample}$$

Symbols
$v_\theta$Learned velocity field
$t$Time from 0 (noise) to 1 (data)
$x(t)$Position of the sample on the path
Dimensions
Path
Numerical example
Euler with a step $h=0.1$: $x\leftarrow x+0.1\,v_\theta(x,t)$ ten times.
Relation to the architecture
Deterministic, and the likelihood can be computed with the change-of-variables formula.

How it works, step by step

  1. Draw noise, data and t.
  2. Compute the point on the path and its velocity.
  3. Regress $v_\theta$ on the velocity.
  4. Generate by solving the ODE.

Strengths and limitations

Strengths

  • Simple, simulation-free training.
  • Often fewer generation steps than diffusion.
  • A flexible framework for different paths.

Limitations

  • The marginal paths are not perfectly straight even with linear conditioning.
  • A newer framework whose practices are still evolving.

When to use it, and when not?

Good for

  • An alternative to diffusion with faster generation.
  • Transport between two general distributions.

Not suited for

  • When ready-made diffusion tools are sufficient and required.

Applications

DomainUse
Generative AIImage and video generation.
Audio and speechSpeech generation.
Scientific computingGenerating molecules and proteins.
Computer visionDistribution translation.

PyTorch code

A simplified teaching code sample that runs on small synthetic data, covering: imports, model definition, data, forward pass, loss, optimizer, training loop, evaluation and inference. It is not the paper's full implementation.

Evaluation here uses two simple metrics computed inside the example: the share of samples close to one of the eight modes, and the number of modes covered. FID is not used because it is specific to images. The example compares 5 and 50 Euler steps.

Python (PyTorch)
# Flow Matching with a linear path and an Euler ODE solve
# A simplified educational example in PyTorch (not the paper's full original implementation): small synthetic data,
# runs on the CPU in seconds. The numbers it prints belong to this example only.
# 1) Import the libraries
import torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

# 2) Define the model
class VelocityNet(nn.Module):
    """v_θ(x_t, t): a velocity field that carries noise to data along a straight path."""
    def __init__(self, h=128):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(3, h), nn.SiLU(), nn.Linear(h, h), nn.SiLU(), nn.Linear(h, h), nn.SiLU(), nn.Linear(h, 2))
    def forward(self, x, t):
        return self.net(torch.cat([x, t[:, None]], 1))
model = VelocityNet()

# 3) Prepare the data
# Target distribution: a mixture of 8 Gaussians on a circle of radius 2 (a classic test of mode collapse)
CENTERS = torch.stack([torch.tensor([2 * torch.cos(torch.tensor(k * torch.pi / 4)), 2 * torch.sin(torch.tensor(k * torch.pi / 4))]) for k in range(8)])
def sample_ring(n, std=0.1):
    k = torch.randint(0, 8, (n,))
    return CENTERS[k] + std * torch.randn(n, 2), k

def ring_metrics(x):
    """Quality: share of samples close (<0.3) to one of the centres. Coverage: number of modes that received ≥5% of the good samples."""
    d = torch.cdist(x, CENTERS)
    near, k = d.min(1)
    good = near < 0.3
    counts = torch.bincount(k[good], minlength=8).float()
    covered = int((counts >= 0.05 * max(1, good.sum().item())).sum())
    return good.float().mean().item(), covered

# 4) Conditional flow matching loss (linear path, σ_min = 0): || v_θ(x_t, t) − (x_1 − x_0) ||²
opt = torch.optim.Adam(model.parameters(), lr=2e-3)

# 5) Training loop: no ODE simulation during training, just regression on the target velocity
STEPS, BATCH = 4000, 256
for step in range(STEPS):
    x1, _ = sample_ring(BATCH)                         # data
    x0 = torch.randn_like(x1)                           # noise
    t = torch.rand(BATCH)
    xt = (1 - t[:, None]) * x0 + t[:, None] * x1        # a point on the straight path
    loss = F.mse_loss(model(xt, t), x1 - x0)            # Forward Pass
    opt.zero_grad(); loss.backward(); opt.step()
    if step % 1000 == 0 or step == STEPS - 1:
        print(f"step {step:4d}  loss={loss.item():.4f}")

# 6) Evaluation: solve dx/dt = v_θ(x, t) with Euler's method from t=0 to 1
@torch.no_grad()
def sample(n, steps=50):
    x = torch.randn(n, 2)
    for k in range(steps):
        t = torch.full((n,), k / steps)
        x = x + model(x, t) / steps
    return x
for s in (5, 50):
    q, cov = ring_metrics(sample(4000, s))
    print(f"Euler steps={s:2d}: sample quality (near a mode) = {q:.3f} ; modes covered = {cov}/8")

# 7) Inference
print("generated point:", [round(v, 3) for v in sample(1)[0].tolist()])

This code was run on 2026-11-20 in 9.5 seconds (PyTorch (CPU), Python 3 – local build machine).

Sample output:

Euler steps= 5: sample quality (near a mode) = 0.754 ; modes covered = 8/8
Euler steps=50: sample quality (near a mode) = 0.936 ; modes covered = 8/8

Trainable parameters in the example: model = 33,794.

These results are for small synthetic data and few epochs, and only prove that the code runs; do not compare them with published results.

Try it and go deeper

Related architectures

Advanced2020

Diffusion Models

Diffusion Models (DDPM)

They gradually corrupt the data by adding Gaussian noise over T steps, then a network learns to reverse this process by predicting the added noise, so a new example is g…

Generative Networks

Research2019

Score-Based Generative Models

Score-Based Generative Models (SGM)

They learn a "score" network _x p(x) at multiple noise levels, then generate samples with Langevin dynamics that follow the score from noise towards high-density regions…

Generative Networks

Advanced2018

Neural ordinary differential equations

Neural Ordinary Differential Equations (Neural ODE)

The hidden state is defined by a continuous differential equation whose derivative is given by a neural network, and the output is computed with a numerical solver, so t…

Temporal and Sequential NetworksPhysics-Informed Neural Networks

Advanced2022

Latent Diffusion Models

Latent Diffusion Models (LDM)

They apply diffusion in a compressed latent space from a pretrained autoencoder instead of pixel space, with a cross-attention mechanism for feeding in conditions (text,…

Generative NetworksHybrid Architectures

Research ideas

  • Flow matching for generating synthetic medical time series, with an evaluation of privacy and utility.

Starting suggestions, not confirmed research gaps; review the recent literature before adopting them.

Test your understanding

  1. Concept

    What target does the network regress on in flow matching with a linear path?

  2. Concept

    Does training require simulating the differential equation?

  3. Mathematical

    With $x_0=(1,1)$, $x_1=(3,1)$ and $t=0.25$, what is $x_t$?

References

  1. Lipman, Y., Chen, R. T. Q., Ben-Hamu, H., Nickel, M., & Le, M. (2023). Flow matching for generative modeling. International Conference on Learning Representations (ICLR). https://arxiv.org/abs/2210.02747

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20

  2. Liu, X., Gong, C., & Liu, Q. (2023). Flow straight and fast: Learning to generate and transfer data with rectified flow. International Conference on Learning Representations (ICLR). https://arxiv.org/abs/2209.03003

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20

  3. Chen, R. T. Q., Rubanova, Y., Bettencourt, J., & Duvenaud, D. (2018). Neural ordinary differential equations. Advances in Neural Information Processing Systems (NeurIPS) 31. https://arxiv.org/abs/1806.07366

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20

  4. Song, Y., Sohl-Dickstein, J., Kingma, D. P., Kumar, A., Ermon, S., & Poole, B. (2021). Score-based generative modeling through stochastic differential equations. International Conference on Learning Representations (ICLR). https://arxiv.org/abs/2011.13456

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20

  5. Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems (NeurIPS) 33. https://arxiv.org/abs/2006.11239

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20