Foundations to Frontier
Tests
H. Generative Models › H7 Diffusion Models

Rectified flow and reflow

Rectified flow (Liu, Gong and Liu, 2023) learns an ODE that moves noise to data along paths that are as straight as possible, because a straight path can be followed in one step. Training starts like flow matching: join random noise and data points with straight lines and regress the velocity. The resulting flow does not cross itself, but its paths bend. Reflow then generates new pairs by running the flow from noise to its endpoint and trains again on straight lines between those pairs. Each round makes the paths straighter and never increases transport cost. This page covers the theory (non-crossing, cost reduction, straightness), the recipe used by Stable Diffusion 3 and InstaFlow, and its limits. In the exercises you measure straightness and transport cost, then run one reflow round with a small MLP on an 8-mode ring. Reflow cut the straightness measure from 1.46 to 0.014 and the squared distance travelled from 6.31 to 0.87. One-step sampling went from 100% off-mode (every sample at the data mean) to 13.6%. With 16 steps the reflowed model still left 5.2% of samples between modes, against 0.1% for the exact first flow: its own fitting error does not go away with more steps.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Straightening the road

If the road from noise to a picture is curvy, you need many small steps to follow it. If it is straight, one big step gets you there. Rectified flow first learns a road, then rides it from many noise points to see where each one ends. It then trains a new road that goes straight from each start to its end. The demo compares the curvy first road with the straightened one.

Diffusion lab 3: video, flows and few-step sampling
Off-mode share 8.7% after 4 steps. 2-RF: velocity regressed (kernel, width 0.2) from 200 straight lines joining noise to its 1-RF endpoint; nearly straight, so even one step works, but its error does not vanish with more steps.
Why engineers care

InstaFlow and the SD3-Turbo family use rectified flow and reflow or distillation to generate images in one to four steps, fast enough for interactive and on-board use.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Straight paths allow…
  2. 2. Reflow trains on pairs of…
  3. 3. Each reflow round makes paths…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • 1-rectified flow: flow matching with straight-line interpolation x_t = t x1 + (1 − t) x0 between independent noise x0 and data x1; v(x, t) = E[x1 − x0 | x_t = x].
  • Non-crossing: the ODE dx/dt = v(x, t) has unique solutions, so its trajectories never cross, although the training lines do. Where lines cross, the field averages their directions and the paths bend.
  • Rectification: the new coupling (x0, Z1), with Z1 the ODE endpoint from x0, has the same marginals. For every convex cost c, E c(Z1 − x0) ≤ E c(x1 − x0) (Liu et al., 2023).
  • Reflow: train a 2-rectified flow on straight lines between (x0, Z1); repeat for k-rectified flows. Straightness S = ∫ E|(Z1 − Z0) − v(Z_t, t)|² dt shrinks; S = 0 means one Euler step is exact.
  • Distillation after reflow: InstaFlow (2024) distils the 2-rectified flow of Stable Diffusion into a one-step generator; reflow makes the teacher’s map easy to fit.
  • At scale: Stable Diffusion 3 (2024) trains 1-rectified flows with logit-normal timesteps and resolution shift; FLUX, Wan and HunyuanVideo follow. Reflow itself is used less often than distillation because each round needs a large set of generated pairs and adds error.
📝 Quick check (Level 1)
0/3 answered
  1. 1. The trajectories of the learned ODE…
  2. 2. Rectification never increases…
  3. 3. Straightness S = 0 means…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Running reflow

Exercise 1.

  • Integrate a flow and keep its path.
  • Straightness of a set of paths.
  • Transport cost of a coupling.

Practice.

  • Train the 1-rectified flow well first; reflow inherits all of its errors.
  • Generate pairs with an accurate solver (many steps or an adaptive solver), with the same guidance used at inference.
  • Train the 2-rectified flow initialised from the 1-rectified weights; tens of millions of pairs were used for InstaFlow.
  • Evaluate at 1, 2 and 4 steps; follow with one-step distillation if needed.
  • Watch for drift: the k-rectified flow matches the previous flow’s samples, not the data.
import torch
@torch.no_grad()
def make_pairs(flow, n, d, steps=64):
    z = torch.randn(n, d); x = z.clone()
    for k in range(steps): x = x + flow(x, torch.full((n,), k / steps)) / steps
    return z, x                                   # (noise, endpoint): the rectified coupling
def reflow_step(model, z, x, opt):
    t = torch.rand(z.shape[0]); xt = (1 - t[:, None]) * z + t[:, None] * x
    loss = ((model(xt, t) - (x - z)) ** 2).mean()
    opt.zero_grad(); loss.backward(); opt.step(); return loss.item()
🐍 Exercise 1: paths, straightness and transport cost
Integrate a flow, measure how straight its paths are and compute the transport cost of a coupling.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Reflow pairs should be generated with…
  2. 2. The 2-rectified flow learns to match…
  3. 3. After reflow, one-step generation is often reached by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why the paths bend. With an independent coupling, lines from noise to data cross everywhere. At a crossing point the regression target is the average of the crossing directions, so v points between them and the trajectory turns. At t = 0 the field is E[x1] − x0, pointing at the data mean.

Why rectification helps. The rectified coupling (Z0, Z1) is deterministic: Z1 is a function of Z0. Straight lines between such pairs rarely cross, so the next flow fitted to them is nearly straight. Liu et al. show by Jensen’s inequality that E c(Z1 − Z0) ≤ E c(x1 − x0) for convex c, and that straightness decreases at rate O(1/k) in the number of rounds.

Measuring straightness. For a discretised path with N steps, S ≈ (1/N) Σ_k |(x_N − x_0) − N (x_(k+1) − x_k)|². A quarter turn of radius 1 at constant speed gives S = 2 + π²/4 − 4 ≈ 0.47.

The catch. Each round fits a network to the previous flow’s coupling, so errors accumulate: the k-rectified flow targets the (k − 1)-th flow’s distribution, not the data. With many sampling steps a reflowed model can be worse than the original.

📝 Quick check (Level 3)
0/3 answered
  1. 1. At a crossing, the fitted velocity is…
  2. 2. The rectified coupling is…
  3. 3. Reflow errors…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much does one reflow round straighten the flow, and what does it cost?

History.

  • X. Liu, C. Gong and Q. Liu, “Flow straight and fast: learning to generate and transfer data with rectified flow” (2023).
  • X. Liu et al., “InstaFlow: one step is enough for high-quality diffusion-based text-to-image generation” (2024).
  • P. Esser et al., “Scaling rectified flow transformers for high-resolution image synthesis” (Stable Diffusion 3, 2024).
  • S. Lee, Z. Lin and G. Fanti, “Improving the training of rectified flows” (2024).

Exercise 2. 2-D data: 8 Gaussians (std 0.15) on a circle of radius 2.

  • 1-RF exact: the exact 1-rectified-flow velocity of the mixture, integrated with 100 Euler steps from 2000 noise points; its endpoints form the reflow pairs.
  • 1-RF learned: an MLP (two tanh layers of 32, Adam, 800 steps of batch 256) fitted to straight lines between independent noise and data.
  • 2-RF learned: the same MLP and budget fitted to straight lines between the reflow pairs.
  • Measures: straightness (50 steps); transport cost E|x1 − x0|²; off-mode share (farther than 4 std from every mode) of 1000 samples after N Euler steps.
straightness off-mode, N = 1 N = 2 N = 4 N = 16
1-RF exact 1.463 1.0 0.623 0.075 0.001
1-RF learned 1.392 0.979 0.712 0.512 0.369
2-RF learned 0.0137 0.136 0.084 0.069 0.052
coupling transport cost
independent 6.311
rectified (reflow pairs) 0.868
  • Straighter by 100×: one round cut straightness from 1.46 to 0.014 and transport cost by 7×.
  • One step works: the 1-RF sends every sample to the data mean in one step; the 2-RF puts 86% on a mode.
  • Easier to learn: with the same small network and budget, the 2-RF beat the learned 1-RF at every step count (5.2% vs 36.9% off-mode at 16 steps).
  • Negative result: with 16 steps the exact 1-RF (0.1%) is far better than the 2-RF (5.2%); reflow trades accuracy for speed, and in practice the 1-RF would itself be a learned, imperfect teacher.
  • Seeds 1 and 2: 2-RF straightness 0.0141 and 0.014; one-step off-mode 0.142 and 0.143; 16 steps 0.054 and 0.049; learned 1-RF at 16 steps 0.257 and 0.225; reflow transport cost 0.892 and 0.873.
  • Caveat: the reflow pairs came from the exact 1-RF, which flatters the 2-RF; networks are tiny to fit the browser.
🐍 Exercise 2 (research): how much does one reflow round straighten the flow, and what does it cost?
Run one reflow round on a ring of Gaussians and compare straightness, transport cost and few-step sample quality.

Rectified flow in AI, robotics and aerospace

  • Fast image generation: InstaFlow, SD3 and FLUX derivatives reach one to four steps after rectification and distillation.
  • Robot control: flow-matching action heads (π0) use few integration steps; straighter flows allow higher control rates on embedded GPUs.
  • Data transfer between domains: rectified flow can couple two data distributions directly (for example simulated and real sensor images), not only noise and data.

References

  1. X. Liu, C. Gong and Q. Liu (2023). “Flow straight and fast: learning to generate and transfer data with rectified flow.” ICLR.
  2. X. Liu et al. (2024). “InstaFlow: one step is enough for high-quality diffusion-based text-to-image generation.” ICLR.
  3. P. Esser et al. (2024). “Scaling rectified flow transformers for high-resolution image synthesis.” ICML.
  4. S. Lee, Z. Lin and G. Fanti (2024). “Improving the training of rectified flows.” NeurIPS.