Skip to content
module

Flow Matching

11 members
lucid.models.generative.flow_matching

Flow Matching family — Lipman et al., 2023 (simulation-free CNF training).

Image Generation
Paper

Lipman, Yaron, et al. "Flow Matching for Generative Modeling." International Conference on Learning Representations, 2023.

Overview

A continuous normalizing flow is defined by a vector field: push samples of a simple distribution along dx/dt=vt(x)d\mathbf{x}/dt = v_t(\mathbf{x}) and read off what arrives. Training one by maximum likelihood, as Neural ODE does, means solving that ODE on every gradient step — the cost that kept continuous flows off the scale diffusion models reached.

Flow Matching removes the solve. Suppose a probability path ptp_t interpolating noise and data were known, together with the field utu_t that generates it; then a regression would suffice,

LFM(θ)=Et,pt(x)∥vt(x;θ)−ut(x)∥2.\mathcal{L}_{\mathrm{FM}}(\theta) = \mathbb{E}_{t, p_t(x)} \bigl\| v_t(x; \theta) - u_t(x) \bigr\|^2 .

Neither ptp_t nor utu_t is available in closed form. The paper's key result — Theorem 2 — is that they need not be. Build the path per data point, as a mixture of conditional paths pt(x∣x1)p_t(x \mid x_1) each generated by a tractable ut(x∣x1)u_t(x \mid x_1), and regress against the conditional field instead:

LCFM(θ)=Et,q(x1),pt(x∣x1)∥vt(x;θ)−ut(x∣x1)∥2.\mathcal{L}_{\mathrm{CFM}}(\theta) = \mathbb{E}_{t, q(x_1), p_t(x \mid x_1)} \bigl\| v_t(x; \theta) - u_t(x \mid x_1) \bigr\|^2 .

The two objectives differ by a constant, so ∇θLFM=∇θLCFM\nabla_\theta \mathcal{L}_{\mathrm{FM}} = \nabla_\theta \mathcal{L}_{\mathrm{CFM}}. Training is now a regression against a target with a closed form: simulation-free.

For Gaussian conditional paths pt(x∣x1)=N(x∣μt(x1),σt(x1)2I)p_t(x \mid x_1) = \mathcal{N}(x \mid \mu_t(x_1), \sigma_t(x_1)^2 I), Theorem 3 names the unique generating field,

ut(x∣x1)=σt′(x1)σt(x1)(x−μt(x1))+μt′(x1),u_t(x \mid x_1) = \frac{\sigma_t'(x_1)}{\sigma_t(x_1)} \bigl(x - \mu_t(x_1)\bigr) + \mu_t'(x_1),

so a path is fully specified by two scalar schedules and their derivatives. Two instances matter. The diffusion path recovers the variance-preserving process score-based models use — the probability path they were already implicitly training, now reachable by regression. The optimal-transport path takes the schedules straight,

μt(x1)=t x1,σt(x1)=1−(1−σmin⁡) t,\mu_t(x_1) = t\,x_1, \qquad \sigma_t(x_1) = 1 - (1 - \sigma_{\min})\,t,

which makes each conditional flow a constant-speed straight line between a noise sample and a data point, and collapses the regression target to something that does not depend on tt at all:

LCFM(θ)=Et,q(x1),p(x0)∥vt(ψt(x0);θ)−(x1−(1−σmin⁡) x0)∥2,ψt(x0)=(1−(1−σmin⁡)t)x0+t x1.\mathcal{L}_{\mathrm{CFM}}(\theta) = \mathbb{E}_{t, q(x_1), p(x_0)} \bigl\| v_t(\psi_t(x_0); \theta) - \bigl(x_1 - (1 - \sigma_{\min})\,x_0\bigr) \bigr\|^2, \qquad \psi_t(x_0) = \bigl(1 - (1 - \sigma_{\min})t\bigr) x_0 + t\,x_1 .

Diffusion paths bend; these do not, and the particles never overshoot the target they are heading for. Straighter trajectories are cheaper for a solver to follow, which is why sampling needs fewer function evaluations and why the same solver reaches a better FID.

Time runs from noise to data: p0=N(0,I)p_0 = \mathcal{N}(0, I) and p1≈qp_1 \approx q. Sampling integrates vtv_t from t=0t = 0 to t=1t = 1; likelihood integrates the same field backwards while accumulating −tr⁡(∂v/∂x)-\operatorname{tr}(\partial v / \partial x), exactly as any continuous flow does.

Classes

Functions