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 and the data sample is .
- Draw a noise sample. Take from a standard Gaussian. Here . Check: the noise is just a number near zero, so is a plausible draw.
- Draw a data sample. Take from the training set. Here . Check: is a point the model should learn to produce.
- Pick a random time. Choose between 0 and 1. Say . Check: is the noise end and is the data end.
- Place the point on the straight line. The point at time is the weighted average . With the numbers: . Check: is halfway between and , which is .
- Compute the target velocity. Along a straight line the speed never changes, so the velocity is the difference . It is the same at every time . Check: moving from to is a distance of , and the line takes one unit of time, so the speed is .
- Ask the network for a velocity and compare. The network reads and and outputs a number . Training pushes toward the target . If the network outputs , the squared error is , and gradient descent moves the weights to reduce that error. Check: a perfect network outputs at this point, so the error is .
- Sample. Start from fresh noise at , for example . 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 gives . Check: one step lands on the data, because the path has no bend.
- Reflow. Run the trained sampler from many noise samples to get pairs , where is the model's output for . 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]
- straight path
- curved path
The math
Given a noise distribution (usually , the standard Gaussian, where is the identity matrix, so each coordinate has mean and variance ) and a data distribution , rectified flow is the Flow Matching model whose conditional paths are straight lines. A pair is drawn with and , and the path is for .
Step 4 in symbols: the straight path
For fixed endpoints, the path is
At this is , and at it is . 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 . Each term is linear in , so
The derivative does not contain , so the velocity is the same at every point of the path. The worked example used at every time, and this is why.
Step 6 in symbols: the loss
The network is trained to match the velocity along the path:
Here is the Expected Value over random noise, data and time, is the uniform distribution on the interval from to (a random time chosen with equal chance anywhere on it), and 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 steps, where is the number of steps and is the time covered by each step, start from and update
This is the Euler Method applied to the ODE . In the one-dimensional example, , and give .
Step 8 in symbols: reflow
Let be the map from noise to output given by the sampler above. Build new pairs with , then train with the same loss as step 6, but with and . 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
Start with and . Find the point at and the velocity.
- The path is .
- Substitute : .
- Evaluate: .
- The velocity is .
- Interpretation: at a quarter of the way through the time, the point sits at , and it moves right at speed . Since , the point reaches the data after the remaining three quarters of the time.
Start with and . Check that a perfect model is recovered by two Euler steps.
- The velocity is .
- The midpoint at is .
- Take the first Euler step with : .
- This is the midpoint from step 2, as it should be.
- Take the second step: .
- Interpretation: . A perfect constant field makes any number of Euler steps exact, and a field that bends would make the two-step result miss .
A training pair has noise and data . The sampled time is . The network predicts . Find the loss for this sample.
- Compute the point on the path: .
- First component: .
- Second component: . So .
- The target velocity is .
- The error is .
- The squared length is .
- Interpretation: this sample contributes to the loss. A training batch averages this quantity over many samples, and gradient descent lowers the average.
Try it: keep and , but take . Find and the target velocity, and say why the target does not change.
Answer: . The target is still , 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 .
- 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 and data under rectified flow?Show answer
The target is . The straight path has derivative with respect to , and this does not depend on , so the same target is used at every time.
QuestionComputation: and . Find the point on the path at , and the target velocity.Show answer
The point is . The target velocity is .
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 . A single step of size 1 with the correct constant velocity therefore reaches 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
- Liu, Gong, Liu (2022), Flow Straight and Fast: arXiv:2209.03003
- Lipman, Chen, Ben-Hamu, Nickel, Le (2022), Flow Matching for Generative Modeling: arXiv:2210.02747
- Optimal transport: Wikipedia