Skip to content
module

Rectified Flow

13 members
lucid.models.generative.rectified_flow

Rectified Flow family — Liu, Gong & Liu, 2023 (straight paths, reflow).

Image Generation
Paper

Liu, Xingchao, Chengyue Gong, and Qiang Liu. "Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow." International Conference on Learning Representations, 2023.

Overview

Given any coupling of two distributions — in the generative case X0∼π0X_0 \sim \pi_0 noise and X1∼π1X_1 \sim \pi_1 data, drawn independently — the rectified flow induced by that pair is the ODE

dZt=v(Zt,t) dt,Z0∼π0,\mathrm{d}Z_t = v(Z_t, t)\,\mathrm{d}t, \qquad Z_0 \sim \pi_0,

whose field is fitted along the straight line between the endpoints,

min⁡v∫01E[∥(X1−X0)−v(Xt,t)∥2] dt,Xt=tX1+(1−t)X0.\min_v \int_0^1 \mathbb{E}\Bigl[ \bigl\| (X_1 - X_0) - v(X_t, t) \bigr\|^2 \Bigr]\,\mathrm{d}t, \qquad X_t = t X_1 + (1 - t) X_0 .

This is the paper's eq. (1), and its minimiser is the conditional expectation vX(x,t)=E[X1−X0∣Xt=x]v^X(x, t) = \mathbb{E}[X_1 - X_0 \mid X_t = x].

Relation to what came before. The objective is exactly Flow Matching's optimal-transport path at σmin⁡=0\sigma_{\min} = 0: the interpolation is the same, and the regression target X1−X0X_1 - X_0 is the same and equally independent of tt. What Rectified Flow adds is not a different loss but what is done with the trained model.

Marginal preservation (Theorem 3.3). The solve is not merely a sampler that happens to work — Law(Zt)=Law(Xt)\mathrm{Law}(Z_t) = \mathrm{Law}(X_t) at every tt, so Z1Z_1 is distributed as the data while (Z0,Z1)(Z_0, Z_1) is a different, non-independent coupling of the same two marginals. That is what makes the next step legitimate.

Reflow. Because the endpoints of the solve are themselves a valid coupling, the whole procedure can be applied to its own output:

Zk+1=RectFlow((Z0k,Z1k)),(Z00,Z10)=(X0,X1).\mathbf{Z}^{k+1} = \mathtt{RectFlow}\bigl((Z_0^k, Z_1^k)\bigr), \qquad (Z_0^0, Z_1^0) = (X_0, X_1).

Each round trains on the previous model's (noise, sample) pairs instead of independent draws. The marginals never move — every Zk\mathbf{Z}^k generates the same data distribution — but the transport cost never increases and the paths get straighter.

Straightness is what improves, and it is measurable:

S(Z)=∫01E[∥(Z1−Z0)−Z˙t∥2] dt,S(\mathbf{Z}) = \int_0^1 \mathbb{E}\Bigl[ \bigl\| (Z_1 - Z_0) - \dot{Z}_t \bigr\|^2 \Bigr]\,\mathrm{d}t ,

zero exactly when every trajectory is a straight line traversed at constant speed. A straight flow is one the forward Euler method integrates without discretisation error, so S→0S \to 0 is precisely the statement that one step suffices — which is why the paper reports a state-of-the-art one-step FID of 4.85 on CIFAR-10.

Distillation is the same loss with tt pinned rather than drawn: regressing v(⋅,0)v(\cdot, 0) onto Z1−Z0Z_1 - Z_0 over the reflow pairs makes z0+v(z0,0)z_0 + v(z_0, 0) a direct one-step map. Reflow is what makes that regression easy — it is fitting an already nearly-straight path, not shortcutting a curved one.

Time runs from noise to data: t=0t = 0 is π0\pi_0 and t=1t = 1 is π1\pi_1.

Classes

Functions