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.
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.
- 1. Straight paths allow…
- 2. Reflow trains on pairs of…
- 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.
- 1. The trajectories of the learned ODE…
- 2. Rectification never increases…
- 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()- 1. Reflow pairs should be generated with…
- 2. The 2-rectified flow learns to match…
- 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.
- 1. At a crossing, the fitted velocity is…
- 2. The rectified coupling is…
- 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.
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
- X. Liu, C. Gong and Q. Liu (2023). “Flow straight and fast: learning to generate and transfer data with rectified flow.” ICLR.
- X. Liu et al. (2024). “InstaFlow: one step is enough for high-quality diffusion-based text-to-image generation.” ICLR.
- P. Esser et al. (2024). “Scaling rectified flow transformers for high-resolution image synthesis.” ICML.
- S. Lee, Z. Lin and G. Fanti (2024). “Improving the training of rectified flows.” NeurIPS.