Search

Search papers and lessons

Rectified Flow

Level 4 · 13 min read

Rectified flow trains a generative model to follow straight-line paths from noise to data, and reflow retrains it on its own outputs so the paths become straighter and fewer sampling steps are needed.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Generative models
  • Losses & regularization
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Rectified flow is a way to train a generative model so that its sampling paths are as close to straight lines as possible. It takes a random noise sample and a real data sample, joins them with a straight line, and trains a network to predict the velocity along that line. The training target is simply the difference between the two endpoints. Sampling then follows the learned velocity field with a few steps of an ODE solver, and a second training round called reflow makes the paths straighter still, so fewer steps are needed.

Builds on: Flow Matching, Ordinary Differential Equation, Vector Field · Leads to: the Rectified Flow paper

Where it's used

Text-to-image models. The 2024 Stable Diffusion 3 image generator was trained with a rectified-flow objective instead of the older curved-path diffusion objective. The network is still asked for a velocity at each time, but the path it has to match is a straight line between noise and an image, which makes the regression target simple.

Fast samplers. Sampling a standard diffusion model takes dozens of network evaluations, because the paths curve and a coarse step lands in the wrong place. InstaFlow (2023) used reflow together with distillation to build a text-to-image model that produces an image in a single step. The gain comes from the straightness: when the path is straight, one step can reach the end.

Moving data between two distributions. Because the recipe only needs two sets of samples, it can connect any two distributions, not just noise and images. The original paper applies it to transferring samples from one data set to another, for example from one style of picture to another, by starting from a source sample instead of from noise.

How it works

We trace one tiny example in one dimension. The noise sample is x0=−1x_0 = -1 and the data sample is x1=3x_1 = 3.

  1. Draw a noise sample. Take x0x_0 from a standard Gaussian. Here x0=−1x_0 = -1. Check: the noise is just a number near zero, so −1-1 is a plausible draw.
  2. Draw a data sample. Take x1x_1 from the training set. Here x1=3x_1 = 3. Check: x1x_1 is a point the model should learn to produce.
  3. Pick a random time. Choose tt between 0 and 1. Say t=0.5t = 0.5. Check: t=0t = 0 is the noise end and t=1t = 1 is the data end.
  4. Place the point on the straight line. The point at time tt is the weighted average xt=(1−t) x0+t x1x_t = (1 - t)\,x_0 + t\,x_1. With the numbers: 0.5×(−1)+0.5×3=10.5 \times (-1) + 0.5 \times 3 = 1. Check: xtx_t is halfway between −1-1 and 33, which is 11.
  5. Compute the target velocity. Along a straight line the speed never changes, so the velocity is the difference x1−x0=3−(−1)=4x_1 - x_0 = 3 - (-1) = 4. It is the same at every time tt. Check: moving from −1-1 to 33 is a distance of 44, and the line takes one unit of time, so the speed is 44.
  6. Ask the network for a velocity and compare. The network reads xtx_t and tt and outputs a number vv. Training pushes vv toward the target 44. If the network outputs 33, the squared error is (3−4)2=1(3 - 4)^2 = 1, and gradient descent moves the weights to reduce that error. Check: a perfect network outputs 44 at this point, so the error is 00.
  7. Sample. Start from fresh noise at t=0t = 0, for example −1-1. Take Euler steps: each step adds the predicted velocity times the step size to the current point. If the field is perfectly straight, one step of size 11 gives −1+4×1=3-1 + 4 \times 1 = 3. Check: one step lands on the data, because the path has no bend.
  8. Reflow. Run the trained sampler from many noise samples to get pairs (z0,z1)(z_0, z_1), where z1z_1 is the model's output for z0z_0. Train again on these pairs exactly as in steps 4 to 6. The new pairs are better matched, so the paths bend less. Check: after reflow the same few-step sampler is more accurate.
flowchart LR
  A[Train on random noise-data pairs] --> B[Sample many noise points with the ODE]
  B --> C[Form new pairs: noise, generated sample]
  C --> D[Retrain on the new pairs]
  D --> E[Straighter paths: fewer steps needed]
00.20.40.60.81−10123time tposition x
  • straight path
  • curved path
Both paths start at -1 and end at 3. The straight path is the one rectified flow trains on; a curved path needs more steps to follow accurately.

The math

Definition: Rectified flow

Given a noise distribution π0\pi_0 (usually N(0,I)\mathcal{N}(0, I), the standard Gaussian, where II is the identity matrix, so each coordinate has mean 00 and variance 11) and a data distribution π1\pi_1, rectified flow is the Flow Matching model whose conditional paths are straight lines. A pair (X0,X1)(X_0, X_1) is drawn with X0∼π0X_0 \sim \pi_0 and X1∼π1X_1 \sim \pi_1, and the path is Xt=(1−t) X0+t X1X_t = (1 - t)\,X_0 + t\,X_1 for t∈[0,1]t \in [0, 1].

Step 4 in symbols: the straight path

For fixed endpoints, the path is

Xt=(1−t) X0+t X1,t∈[0,1].X_t = (1 - t)\,X_0 + t\,X_1, \qquad t \in [0, 1].

At t=0t = 0 this is X0X_0, and at t=1t = 1 it is X1X_1. This is the straight-line choice of conditional path in Flow Matching, with no noise spread around the line, so its conditional field is the simplest one available.

Step 5 in symbols: the constant velocity

Differentiate the path with respect to tt. Each term is linear in tt, so

dXtdt=−X0+X1=X1−X0.\frac{d X_t}{dt} = -X_0 + X_1 = X_1 - X_0.

The derivative does not contain tt, so the velocity is the same at every point of the path. The worked example used x1−x0=4x_1 - x_0 = 4 at every time, and this is why.

Step 6 in symbols: the loss

The network vθ(x,t)v_\theta(x, t) is trained to match the velocity along the path:

L(θ)=EX0∼π0,  X1∼π1,  t∼U[0,1]∥vθ(Xt,t)−(X1−X0)∥2.\mathcal{L}(\theta) = \mathbb{E}_{X_0 \sim \pi_0,\; X_1 \sim \pi_1,\; t \sim \mathcal{U}[0, 1]}\left\| v_\theta(X_t, t) - (X_1 - X_0) \right\|^2.

Here E\mathbb{E} is the Expected Value over random noise, data and time, U[0,1]\mathcal{U}[0, 1] is the uniform distribution on the interval from 00 to 11 (a random time chosen with equal chance anywhere on it), and ∥⋅∥2\|\cdot\|^2 is the squared length of a vector, the Mean Squared Error applied to vectors. Because the paths are the conditional paths of flow matching, minimising this loss trains the same marginal field as the flow-matching theory describes.

Step 7 in symbols: sampling with Euler steps

With KK steps, where KK is the number of steps and Δt=1/K\Delta t = 1/K is the time covered by each step, start from Z0∼π0Z_0 \sim \pi_0 and update

Zk+1=Zk+Δt  vθ(Zk,tk),tk=k Δt.Z_{k+1} = Z_k + \Delta t\; v_\theta(Z_k, t_k), \qquad t_k = k\,\Delta t.

This is the Euler Method applied to the ODE dZ/dt=vθ(Z,t)dZ/dt = v_\theta(Z, t). In the one-dimensional example, K=1K = 1, Z0=−1Z_0 = -1 and vθ=4v_\theta = 4 give Z1=−1+1×4=3Z_1 = -1 + 1 \times 4 = 3.

Step 8 in symbols: reflow

Let Φ\Phi be the map from noise to output given by the sampler above. Build new pairs (Z0,Φ(Z0))(Z_0, \Phi(Z_0)) with Z0∼π0Z_0 \sim \pi_0, then train with the same loss as step 6, but with X0=Z0X_0 = Z_0 and X1=Φ(Z0)X_1 = \Phi(Z_0). Each round gives a new model whose paths are straighter, because the coupling between noise and data has become more deterministic and the crossings of paths have been reduced.

Worked examples

Example
Example 1: one dimension, by hand

Start with x0=−1x_0 = -1 and x1=3x_1 = 3. Find the point at t=0.25t = 0.25 and the velocity.

  1. The path is xt=(1−t)(−1)+t(3)x_t = (1 - t)(-1) + t(3).
  2. Substitute t=0.25t = 0.25: x0.25=0.75×(−1)+0.25×3x_{0.25} = 0.75 \times (-1) + 0.25 \times 3.
  3. Evaluate: −0.75+0.75=0-0.75 + 0.75 = 0.
  4. The velocity is x1−x0=3−(−1)=4x_1 - x_0 = 3 - (-1) = 4.
  5. Interpretation: at a quarter of the way through the time, the point sits at 00, and it moves right at speed 44. Since 0+4×0.75=30 + 4 \times 0.75 = 3, the point reaches the data after the remaining three quarters of the time.
Example
Example 2: two dimensions, with two Euler steps

Start with x0=(1,−1)x_0 = (1, -1) and x1=(3,3)x_1 = (3, 3). Check that a perfect model is recovered by two Euler steps.

  1. The velocity is x1−x0=(3−1,  3−(−1))=(2,4)x_1 - x_0 = (3 - 1,\; 3 - (-1)) = (2, 4).
  2. The midpoint at t=0.5t = 0.5 is 0.5×(1,−1)+0.5×(3,3)=(0.5+1.5,  −0.5+1.5)=(2,1)0.5 \times (1, -1) + 0.5 \times (3, 3) = (0.5 + 1.5,\; -0.5 + 1.5) = (2, 1).
  3. Take the first Euler step with Δt=0.5\Delta t = 0.5: Z1=(1,−1)+0.5×(2,4)=(2,1)Z_1 = (1, -1) + 0.5 \times (2, 4) = (2, 1).
  4. This is the midpoint from step 2, as it should be.
  5. Take the second step: Z2=(2,1)+0.5×(2,4)=(3,3)Z_2 = (2, 1) + 0.5 \times (2, 4) = (3, 3).
  6. Interpretation: Z2=x1Z_2 = x_1. A perfect constant field makes any number of Euler steps exact, and a field that bends would make the two-step result miss x1x_1.
Example
Example 3: one training step on a two-pixel image

A training pair has noise x0=(0.5,1.0)x_0 = (0.5, 1.0) and data x1=(0.8,−0.2)x_1 = (0.8, -0.2). The sampled time is t=0.3t = 0.3. The network predicts vθ=(0.1,−0.9)v_\theta = (0.1, -0.9). Find the loss for this sample.

  1. Compute the point on the path: xt=0.7 (0.5,1.0)+0.3 (0.8,−0.2)x_t = 0.7\,(0.5, 1.0) + 0.3\,(0.8, -0.2).
  2. First component: 0.7×0.5+0.3×0.8=0.35+0.24=0.590.7 \times 0.5 + 0.3 \times 0.8 = 0.35 + 0.24 = 0.59.
  3. Second component: 0.7×1.0+0.3×(−0.2)=0.70−0.06=0.640.7 \times 1.0 + 0.3 \times (-0.2) = 0.70 - 0.06 = 0.64. So xt=(0.59,0.64)x_t = (0.59, 0.64).
  4. The target velocity is x1−x0=(0.8−0.5,  −0.2−1.0)=(0.3,−1.2)x_1 - x_0 = (0.8 - 0.5,\; -0.2 - 1.0) = (0.3, -1.2).
  5. The error is vθ−target=(0.1−0.3,  −0.9−(−1.2))=(−0.2,0.3)v_\theta - \text{target} = (0.1 - 0.3,\; -0.9 - (-1.2)) = (-0.2, 0.3).
  6. The squared length is (−0.2)2+0.32=0.04+0.09=0.13(-0.2)^2 + 0.3^2 = 0.04 + 0.09 = 0.13.
  7. Interpretation: this sample contributes 0.130.13 to the loss. A training batch averages this quantity over many samples, and gradient descent lowers the average.

Try it: keep x0=(0.5,1.0)x_0 = (0.5, 1.0) and x1=(0.8,−0.2)x_1 = (0.8, -0.2), but take t=0.6t = 0.6. Find xtx_t and the target velocity, and say why the target does not change.

Answer: xt=0.4 (0.5,1.0)+0.6 (0.8,−0.2)=(0.2+0.48,  0.4−0.12)=(0.68,0.28)x_t = 0.4\,(0.5, 1.0) + 0.6\,(0.8, -0.2) = (0.2 + 0.48,\; 0.4 - 0.12) = (0.68, 0.28). The target is still (0.3,−1.2)(0.3, -1.2), because the straight path has the same slope at every time.

Common mistakes and tradeoffs

It is tempting to think that a straight line for each pair means the sampling path is straight too. In fact the network learns one velocity field for all pairs at once. Paths that start at different noise points cross each other, and at a crossing the field must give one velocity, so the learned field bends. Reflow reduces the crossings by replacing random pairs with pairs the model itself produces, which is why it straightens the paths.

It is tempting to think that one sampling step is always enough. In fact one step is exact only when the learned field is constant along each path. With a bent field, one step lands on an average of several possible images, and the result is blurry. Fewer steps trade quality for speed, and you measure that trade on your own data.

It is tempting to think that rectified flow is a different family from flow matching. In fact it is flow matching with the straight-line path, plus the reflow procedure. The difference lies in the choice of path and in how the noise-data pairs are formed.

When to use it: when you want a simple regression target, a path that a coarse ODE solver can follow, and a route to very few sampling steps through reflow.

When not to use it: reflow means training the model again on its own samples, which is a costly extra stage. If you cannot afford that, a curved diffusion schedule with a good high-order solver may give better quality at the same cost.

Alternatives: diffusion models with a noise schedule, which have a long track record but curved paths; consistency models, which learn to jump to the end of the path in one or few steps by distillation; and continuous normalizing flows, which give exact likelihoods but are harder to scale.

History

By 2020 diffusion models had reached high image quality, after a line of work that began with nonequilibrium thermodynamics ideas in 2015. Their sampling was slow, because the reverse process needed many small steps. Continuous-time models had been explored earlier: neural ODEs (2018) defined a network as an ODE, and continuous normalizing flows were trained by solving the ODE for every training example, which is expensive.

In 2022 two groups published the simulation-free idea almost together. Lipman and colleagues introduced Flow Matching, and Liu, Gong and Liu introduced rectified flow, with the straight-line path and the reflow procedure. Rectified flow caught on because the straight paths made few-step sampling plausible. In 2023 InstaFlow used reflow and distillation to make a fast text-to-image model, and in 2024 Stable Diffusion 3 was trained with a rectified-flow objective.

Recap

  • A straight line joins each noise sample to a data sample, and its velocity is the constant difference x1−x0x_1 - x_0.
  • The network regresses the velocity at a random point on the line, which is the Flow Matching loss with straight paths.
  • Sampling follows the learned field with Euler steps from noise to data.
  • Reflow retrains on the model's own noise-to-sample pairs, which straightens the paths and lowers the step count.
  • Read next: the Rectified Flow paper for the full theory and experiments, and consistency models for another route to few-step sampling.

Check yourself

QuestionRecall: what is the velocity target for a training pair with noise x0x_0 and data x1x_1 under rectified flow?Show answer

The target is x1−x0x_1 - x_0. The straight path (1−t) x0+t x1(1 - t)\,x_0 + t\,x_1 has derivative x1−x0x_1 - x_0 with respect to tt, and this does not depend on tt, so the same target is used at every time.

QuestionComputation: x0=2x_0 = 2 and x1=−4x_1 = -4. Find the point on the path at t=0.25t = 0.25, and the target velocity.Show answer

The point is 0.75×2+0.25×(−4)=1.5−1=0.50.75 \times 2 + 0.25 \times (-4) = 1.5 - 1 = 0.5. The target velocity is x1−x0=−4−2=−6x_1 - x_0 = -4 - 2 = -6.

QuestionWhy: if the learned field were exact and every path straight, why would a single Euler step of size 1 reach the data exactly?Show answer

With a straight path, the velocity is the same at every point and time, so the position after time 1 is x0+1×(x1−x0)=x1x_0 + 1 \times (x_1 - x_0) = x_1. A single step of size 1 with the correct constant velocity therefore reaches x1x_1 with no error.

QuestionApplied: a team's sampler uses 50 steps and is slow. They ask why one reflow round might let them cut the number of steps. What do you tell them?Show answer

Reflow trains on pairs of noise and the model's own outputs. These pairs are better matched than random pairs, so the paths cross less and bend less. A field that bends less has a smaller Euler error for a given step size, so fewer steps reach a similar result. The cost is the extra training round, and the team should measure image quality at each step count before choosing.

Sources