AI Wiki中文/EN

Rectified flow: changing the coupling, straightening the path

整流流

Use Gaussian transport to distinguish original regression, Euler error and reflow.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Straight training segments can produce curved generated paths

Draw a noise point and a data point, then connect them with a straight segment. Many such segments cross. At a crossing, their velocities disagree, so a model that sees only the current position and time cannot follow every pair’s original instruction. Least-squares regression averages those instructions and defines a new flow.

Rectified flow, introduced by Xingchao Liu, Chengyue Gong and Qiang Liu in September 2022, studies this change of coupling and the possibility of repeatedly straightening the resulting trajectories. We read the first preprint; the author’s repository identifies the work with ICLR 2023. Read flow matching first. Here the main question is what happens to paths and endpoint pairings, rather than how to construct arbitrary conditional probability paths.

Coupling costs, Euler errors and output variance show what reflow changes in this Gaussian construction.
Coupling costs, Euler errors and output variance show what reflow changes in this Gaussian construction.

Learn a velocity that does not need to know the endpoint

Let a coupling be a joint distribution of X0 and X1 with the desired source and target marginals. The initial coupling can be independent. Linear interpolation and its velocity are:

Xt=(1−t)X0+tX1,X˙t=X1−X0.X_t=(1-t)X_0+tX_1,\qquad \dot X_t=X_1-X_0.

Following the second equation directly would require knowing X1 in advance. Instead, regress that velocity on the current state and time:

L(v)=∫01E∥v(Xt,t)−(X1−X0)∥2 dt,v∗(x,t)=E[X1−X0∣Xt=x].L(v)=\int_0^1\mathbb E\|v(X_t,t)-(X_1-X_0)\|^2\,dt,\qquad v^*(x,t)=\mathbb E[X_1-X_0\mid X_t=x].

Generation follows an ODE from a new source point:

dZtdt=v∗(Zt,t),Z0∼π0.\frac{dZ_t}{dt}=v^*(Z_t,t),\qquad Z_0\sim\pi_0.

Under the paper’s rectifiability conditions—local boundedness and existence and uniqueness of the relevant ODE solution—the exact rectified process preserves the interpolation’s time marginals. In particular, the endpoint is distributed as π1. It need not preserve the original pairing (X0,X1). Deterministic ODE trajectories cannot cross at the same time when solutions are unique, whereas the original paired interpolation segments can.

The paper’s Theorem 3.5 gives a further property for rectifiable linear interpolations and well-defined expectations: convex displacement costs do not increase:

E[c(Z1−Z0)]≤E[c(X1−X0)]for convex c.\mathbb E[c(Z_1-Z_0)]\le\mathbb E[c(X_1-X_0)]\qquad\text{for convex }c.

This is a comparison with the supplied coupling, not a claim that one regression produces the global optimum among all couplings. Finite-capacity fitting and approximate ODE integration add errors outside the exact statement. Preserve those qualifications when interpreting a numerical result.

Use the generated pairing as new training data

After fitting a flow, sample source points and retain their generated endpoints as pairs. Refit the same regression objective on that new coupling. This is reflow:

(Z0k+1,Z1k+1)=Rectify⁡(Z0k,Z1k),(Z00,Z10)=(X0,X1).(Z_0^{k+1},Z_1^{k+1})=\operatorname{Rectify}(Z_0^k,Z_1^k),\qquad (Z_0^0,Z_1^0)=(X_0,X_1).

The input pairing changes; this is more than running the original numerical solver for additional steps. Perfectly straight, constant-velocity trajectories permit an exact single Euler step. A nearly straight flow may permit a useful coarse approximation, but one-step quality is not guaranteed for every learned flow. The paper’s asymptotic straightness result has rectifiability and finite-cost assumptions; we do not claim to have reproduced its full proof.

Reflow also differs from distillation. Reflow learns another time-dependent field from recoupled endpoints. Distillation can learn a direct map or a small-step student from a teacher. The author loss implementation explicitly distinguishes reflow pairs, time-sampling policies and optional distillation losses.

An exact example where one Euler step first fails

Take independent X0∼N(0,1) and X1∼N(2,.36). The interpolated distribution has mean 2t and variance vt. Its conditional-mean field and exact marginal flow are:

vt=(1−t)2+0.36t2,u(x,t)=2+0.36t−(1−t)vt(x−2t),Zt=2t+vtZ0.v_t=(1-t)^2+0.36t^2,\qquad u(x,t)=2+\frac{0.36t-(1-t)}{v_t}(x-2t),\qquad Z_t=2t+\sqrt{v_t}Z_0.

At t=0 the velocity is 2−Z0. A single Euler step therefore sends every point to 2: output variance becomes zero. Yet the exact endpoint is Z1=2+.6Z0, which has the correct .36 variance. An exact learned field can still be sampled badly.

Use that exact endpoint pairing for reflow. The new interpolant is (1−.4t)Z0+2t, so its field and trajectory are:

ureflow(x,t)=2−0.41−0.4t(x−2t),Z~t=(1−0.4t)Z0+2t.u_{\rm reflow}(x,t)=2-\frac{0.4}{1-0.4t}(x-2t),\qquad \widetilde Z_t=(1-0.4t)Z_0+2t.

Each trajectory has constant velocity 2−.4Z0. Now one Euler step is exact. Both flows have the same source and endpoint marginals, but different intermediate marginals because reflow changed the coupling used to construct the interpolation.

Compare pairings, costs and step errors

Save as rectified_flow.py with Python 3.12 and NumPy 1.26.4. This original Gaussian example solves the population regression analytically and independently checks it by weighted least squares on Gaussian quadrature pairs. It is not neural training. The reflow pairing is produced by the exact first flow; using approximate generated endpoints in a real pipeline would introduce another source of error.

The program implements forward Euler sampling and compares it with an independent closed-form trajectory. Its source-to-target time convention is zero to one. The fixed author’s Euler routine uses an epsilon-shifted network time; our analytical example uses the mathematical endpoint exactly, so it is not a byte-for-byte reproduction of that implementation.

For S steps and N scalar points, generation costs O(SN) with O(N) working storage. The independent regression check uses Q² pairs for the independent coupling and Q pairs for the deterministic reflow coupling. A neural implementation must also account for training the new field and generating the endpoint-pair dataset; reflow is not free inference acceleration.

"""Original Gaussian rectification/reflow example with population optimal fields."""
import json
import numpy as np

MU,STD=2.,.6

def field(x,time,reflow=False):
    if not np.isfinite(time) or not 0<=time<=1:raise ValueError('Time in[0,1] required.')
    x=np.asarray(x,float)
    if not np.all(np.isfinite(x)):raise ValueError('Finite state required.')
    if reflow:
        width=1+(STD-1)*time
        return MU+(STD-1)/width*(x-MU*time)
    var=(1-time)**2+(STD*time)**2
    return MU+(STD**2*time-(1-time))/var*(x-MU*time)

def exact(x,time=1.,reflow=False):
    if not 0<=time<=1:raise ValueError('Time in[0,1] required.')
    width=1+(STD-1)*time if reflow else np.sqrt((1-time)**2+(STD*time)**2)
    return MU*time+width*np.asarray(x)

def euler(x,steps,reflow=False):
    if type(steps) is not int or not 1<=steps<=2048:raise ValueError('Steps1..2048 required.')
    x=np.asarray(x,float).copy()
    for i in range(steps):x+=field(x,i/steps,reflow)/steps
    return x

def fitted_field(time,reflow=False):
    # Independent weighted regression from the endpoint coupling, not ODE outputs.
    z,w=np.polynomial.hermite.hermgauss(5);z=np.sqrt(2)*z;w/=np.sqrt(np.pi)
    if reflow:x0=z;x1=MU+STD*z;weight=w
    else:
        x0=np.broadcast_to(z[:,None],(5,5)).ravel();x1=np.broadcast_to(MU+STD*z[None,:],(5,5)).ravel();weight=(w[:,None]*w[None,:]).ravel()
    xt=(1-time)*x0+time*x1;u=x1-x0;design=np.column_stack([xt,np.ones_like(xt)])
    coef=np.linalg.solve(design.T@(weight[:,None]*design),design.T@(weight*u))
    residual=design@coef-u
    return coef,float(weight@(residual*residual))

def demo():
    probes=np.array([-2.,0.,2.]);reference=exact(probes)
    before=MU**2+1+STD**2;after=MU**2+(STD-1)**2
    result=dict(original_coupling_squared_cost=before,rectified_coupling_squared_cost=after,independent_pair_covariance=0.,rectified_pair_covariance=STD,one_step_original_variance=0.,one_step_reflow_variance=STD**2,endpoint_variance=STD**2,errors={str(n):dict(original=float(np.max(abs(euler(probes,n)-reference))),reflow=float(np.max(abs(euler(probes,n,True)-reference)))) for n in [1,4,16,64]},regression={str(t):dict(original=fitted_field(t)[1],reflow=fitted_field(t,True)[1]) for t in [0,.25,.5,.75,1]})
    return result

if __name__=='__main__':print(json.dumps(demo(),indent=2))

For quadratic cost, the independent coupling has expected cost 5.36. The rectified endpoint coupling has covariance .6 and cost 4.16. In this one-dimensional Gaussian case, the increasing affine endpoint map also agrees with the quantile transport map; this special calculation does not establish global optimality for arbitrary learned multidimensional flows.

For initial probes −2, 0 and 2, first-flow Euler errors at 1, 4, 16 and 64 steps are 1.2, .36093230, .10002796 and .02578650. Reflow errors are at floating-point scale even with one step. Independent-pair regression retains positive conditional residual variance; reflow-pair regression has essentially zero residual in this example because the pairing is deterministic and the paths are straight.

Recoupling cannot repair every model defect

Exact marginal preservation and nonincreasing convex costs are mathematical results under stated assumptions. Training on finite, possibly biased pairs does not inherit them automatically. Solver error can distort the endpoints used as the next training distribution; repeated reflow can then reinforce that distortion.

The analogy of uncrossing paths also needs the uniqueness condition. An arbitrary discontinuous fitted vector field may not define a unique flow. Straight conditional segments do not by themselves guarantee straight marginal trajectories, good sample quality, semantic preservation or a globally optimal transport plan.

This article covers the original rectification/reflow construction and a transparent Gaussian case. Later image systems can combine it with latent codecs, guidance, distillation and different couplings; their capabilities need their own evidence. No upstream code, weights or data are reused, and a root license for the inspected RectifiedFlow repository was not established.

Did you change the solver or the coupling?

  1. Conditioning. Why is the regression target X1−X0 not directly available to a generator at inference? Answer: The generator starts with a new source point and has no paired destination. It uses the learned conditional expectation given the current state and time.
  2. Hand calculation. Apply one Euler step to u(x,0)=2−x from z. What is the result? Answer: z+(2−z)=2, so all initial variability disappears despite the correct continuous field.
  3. Cost. Why does the example’s cost fall from 5.36 to 4.16? Answer: The mean displacement and marginal variances stay fixed, but endpoint covariance rises from zero to .6. Squared displacement cost decreases by 2·.6=1.2.
  4. Method choice. Is taking more Euler steps the same as reflow? Answer: No. More steps approximate the current field better. Reflow uses generated endpoint pairs to define and fit a new field, changing the coupling behind its interpolation.

Keep exact-flow claims separate from finite computation

Read Section 2.1, Algorithm 1 and Definitions 3.1–3.4/Theorems 3.3 and 3.5. The marginal-preservation argument and selected theorem conditions were inspected, including PDF page 13; this is not a full proof audit. Compare paired regression and reflow handling with the Euler routine. These references support the construction; the small model’s outcomes are independently calculated rather than borrowed image benchmarks.

Make a prediction, then check

What changes when applying reflow?

Choose one answer

Learning objectives

  • Define a coupling and its conditional velocity.
  • State marginal-preservation assumptions.
  • Separate reflow from extra solver steps.
  • Check convex cost and one-step behavior.

Prerequisites & connections

Explore related knowledge →

References

  1. Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow (v1)
    Xingchao Liu; Chengyue Gong; Qiang Liu · 2022
  2. rectified-losses method reference at 5a1fd4d
    gnobitab/RectifiedFlow contributors · 2024
  3. rectified-sde method reference at 5a1fd4d
    gnobitab/RectifiedFlow contributors · 2024

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-20 · Single AI author checked Rectified Flow v1 section2.1 and selected section3 definitions/theorems, plus fixed author loss and epsilon-shift Euler code. Seven paired equations and four explained exercises; analytic Gaussian marginal flow, independent weighted regression, coupling costs, Euler collapse and exact-pair reflow. One-step exactness restricted to this construction; not a neural reflow or global optimality claim.

  • Single AI author checked Rectified Flow v1 section2.1 and selected section3 definitions/theorems, plus fixed author loss and epsilon-shift Euler code. Seven paired equations and four explained exercises; analytic Gaussian marginal flow, independent weighted regression, coupling costs, Euler collapse and exact-pair reflow. One-step exactness restricted to this construction; not a neural reflow or global optimality claim.
  • Four computed SVG variants per topic. Eleven numeric/geometry tests and36 responsive cases passed; twelve final Chinese-mobile/English-desktop screenshots actually inspected. Mobile-title and cost-axis corrections preserved. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.