Flow matching and straight paths
The Diffusion Policy from lesson 1.5 builds an action chunk from noise in 10–16 denoising steps, and every step is a network pass. While the chunk is being computed, the robot stands still or follows the old plan. ACT from lesson 1.7 outputs a chunk in one pass, but it can't choose between manners the way diffusion does. Flow matching keeps that choice for the policy and cuts the number of steps.
The network is trained on straight paths between random noise and a random chunk from the demonstrations. At any point of the segment, the network must predict the velocity: where and how fast the point moves from the noise to the chunk. During generation, every flow step takes one network pass: the network outputs the velocity at the current point, and the point moves along it. That's how π0 from lesson 1.6, GR00T N1 (NVIDIA, 2025; lesson 3.7) and SmolVLA (Hugging Face, 2025; lesson 3.5) build a chunk in 4–10 flow steps.
Straight training paths do not yet mean straight generation paths. First we'll check why one step isn't enough: segments to different chunks pass through the same point, the network learns their average direction, and the path from noise comes out curved. Then we'll fine-tune the network on pairs of “noise — the chunk the model itself led it to”. This is called reflow: the paths straighten, and one step becomes almost enough. Finally, we'll find how many flow steps Ada's chunk needs.
Velocity along the line from noise to data
A diffusion model needs many denoising steps to turn noise into data. In lesson 1.5 every such step became a network pass over the whole action chunk: Diffusion Policy makes 10–16 passes per chunk, and all that time the robot stands still or follows the old plan. ACT from lesson 1.7 gets by with one pass, but it can't choose between manners: on the robot it uses , and in the same situation the chunk is always the same. We need a policy that, like diffusion, picks one manner out of several, but gets by with a few steps.
Why does diffusion need many steps? The path from noise to data is curved. In lesson 1.4 the denoiser pointed toward the mean of the data under heavy noise and toward the nearest spiral under light noise, so a point first heads to the center and only then turns. The network knows the direction only at the current point, and a big step along it cuts the corner. The scheme shows this on simple data — two blobs, that is, two dense clusters of points on a plane. That's what two ways of doing the same thing look like, for example going around a kettle on the left or on the right.
In lesson 1.4 the steps were cut down with the DDIM sampler: the same network steps without fresh noise and keeps the shape where DDPM is already pulling points to the center. But at a really small number of steps DDIM loses the shape too: in the lab of lesson 1.4 it held the shape from 6–8 steps.
We can start with a simpler training task: define a straight path for each “noise — data” pair and teach the network to predict the velocity along it. This is the approach used by flow matching (Lipman et al., 2022) and the closely related rectified flow (Liu et al., 2022). A single given straight line can indeed be covered in one step: the direction at the start points right at the end. But the network learns from many pairs at once, so the path it builds during generation need not be straight. Let's see where this distinction comes from.
Take a random noise point and a random data point and connect them with a straight line. For a robot, is an action chunk from a demonstration, and is a random chunk of the same shape. At time the point on the line is : at it's noise, at it's data. The velocity along the line is constant and equals . The network learns to predict that velocity from and . It's ordinary regression: nothing has to be modeled step by step.
The network's predictions at all points and all moments form a velocity field. Picture it this way: at every point and at every moment there is an arrow — where and how fast a point that happens to be here at this moment should move. The network outputs such an arrow for any point in one pass. Where the arrows come from: at time , lines of different pairs, going to different data points, pass through the same point. From the point alone the network can't tell which pair it belongs to, so regression learns the average velocity of these lines. That's how the field is put together from straight lines.
Generation works like this: take noise and follow this field from to in a few Euler steps. An Euler step moves the point by the velocity at that point times the step length : . Such a step is called a flow step: one network pass and one move. On a straight path the velocity doesn't change, and a step of any length stays on the line. On a curved path the velocity changes along the way, but an Euler step knows it only at the starting point, so it cuts the corner.
Diffusion Policy also spends one network pass per denoising step, but its network predicts noise. To move the chunk, the schedule formula turns the predicted noise into an estimate of the clean chunk and mixes it with the same noise in the proportion of the next step. A flow network outputs the velocity directly, and a flow step is simply a move along it. The scheme below shows the whole method: training, generation and, for comparison, the steps of Diffusion Policy.
At every point the field is the average of the lines that pass through it toward different data points. Will the generation paths themselves be straight then, and will one step be enough? Let's check on two blobs, as in the first scheme of this section. The velocity field here is computed by an exact formula, without a network, so everything we see follows from the method itself.
Under the hood: paths, the training objective and the exact field
Lipman et al. define the path conditionally: for each data point they take a Gaussian that coincides with the noise at and shrinks around by . In the variant the authors call the optimal transport path, the center and the width change linearly:
As this is exactly the straight line from the text and the target ; Liu et al. use the same training target. The paper's main theorem: the gradients of this “conditional” objective coincide with the gradients of the objective where the true generation field stands in place of . So it's enough to train the network on random pairs rather than know the field in advance.
What field an ideal network learns: the average of all velocities passing through a point, . At the point is the noise itself, and it says nothing about where to go. So : the arrow points at the mean of the data.
In the lab the data is a mixture of two Gaussians, and the average is computed exactly. For a component with center and spread :
The component weights are their likelihoods at the point . The blobs are centered at (±1.2; 1.0) with spread . The probe path is computed in 200 Euler steps.
The generation paths are curved, even though every training pair is a straight line. Through the points in the middle run lines to both blobs, and the field equals their average. So the point, just as in diffusion, first heads to the mean of the data and only then turns, and one step brings all the noise to the mean — into the void between the blobs. That's how regression in lesson 1.3 drove Ada into the kettle between the left and right detours. Here the field is computed by formula. What will a real network learn when it sees only random pairs?
Ada is the home humanoid robot the course's labs are built around. More about her in lesson 0.1.
Training the velocity field
What will a network learn when it sees only random pairs? For real data there's no formula for the field, and at every point the network runs into lines to different data points, that is, different right answers.
Let's train a small network right on the page and check two things: how low the loss drops, and where the field's arrows point at different moments t.
The data is harder than in lab 1: eight blobs on a ring, 4000 points. The network takes a point and a time and outputs a velocity. At every training step the network sees 128 random “noise — data” pairs and random moments t. The arrows on the scene show what the network thinks the velocity is at each point at the selected moment.
The training loss is the mean squared difference between the velocity the network predicted and the target . The square of the target itself averages about 3 here: the noise contributes 2, one for each of the two coordinates, and the ring's points lie at distance 1 from the center and contribute another 1. That's what a network that always answers zero would get. The dashed line on the plot shows the loss of the ideal field, computed by an exact formula, as in lab 1.
Horizontal axis: training steps; vertical: mean squared velocity error.
Under the hood: the training loop and why the loss doesn't drop to zero
- Network. It takes the point , 32 Fourier features of the point (cosines and sines of projections onto 16 random directions) and 5 time features: . Then come two hidden layers of 48 neurons with SiLU, and the output is the velocity . It is trained by Adam with a learning rate of 0.005, which decays toward the end of training. Without Fourier features such a small network draws a blurry ring instead of eight blobs.
- Why the loss doesn't go to zero. Through one point run lines to different blobs, and the target is random for it. The best the network can do is predict the mean, and the spread around the mean remains as loss. For this data the field can be computed exactly, as in lab 1: even with it the mean loss is 1.87. The dashed line on the plot shows that bound.
- What the scene shows. The arrows show the network's field on a 15 × 15 grid. Gray ones pull toward the center, orange ones push away from it. The cloud consists of 300 noise points the network carried along its field up to time , 100 Euler steps for the full path.
The network learned a field close to the ideal one: at every point it equals the average velocity of all the lines through it. The loss stopped just above the bound below which no network can go. Where the bound comes from: lines to different blobs and from different noise points pass through one point . At the start of the path the point doesn't tell which blob it's heading to; at the end, which noise point it came from. No network can guess that part of the target, and almost all of the loss comes from this irreducible spread. So the training curve is a poor guide to how well the model draws. Until about halfway along the path the field pulls the noise toward the center of the ring and only then flips it toward the blobs, so the point's path is curved again. How many Euler steps does it take to follow such a path, and is it fewer than diffusion needs?
Diffusion and flow on the same data
How many steps does a flow model need, and is it fewer than diffusion? Its paths are curved, so the win isn't obvious.
Let's put the diffusion from lesson 1.4 alongside and compare on equal terms. For each model we'll find the smallest number of steps at which it holds the shape of the ring.
Same data, same network, same training budget — 1500 steps. The difference is in two things. The diffusion model works as in lesson 1.4: the network predicts the added noise, and generation proceeds in DDIM steps, without fresh noise. The flow network predicts velocity, and each of its steps moves the point along that velocity. Both start from the same 600 noise points.
Horizontal axis: number of generation steps (log scale); vertical: share of points in blobs. A dot appears for every number of steps you try. The green dashed line marks the threshold: the shape holds if at least 72% of the points are in blobs and all eight blobs are present; for the real data about 96% of the points are in blobs.
Under the hood: a DDIM step is an Euler step too
A DDIM step () first estimates the clean point from the predicted noise, then mixes it with the same noise in the proportion of the next moment:
An Euler step along the straight path works the same way. From the velocity come a data estimate and a noise estimate , and
So DDIM and Euler are the same sampler if the schedule is the same. Gao et al. in the survey “Diffusion Meets Flow Matching” put it this way: with Gaussian noise, flow matching and diffusion are equivalent, and the DDIM sampler coincides with the Euler sampler.
Where the difference in the lab comes from, then. First, the schedule: in DDPM almost the whole first half of the path is heavy noise, and a uniform grid wastes steps there. Second, the training target: at the first step DDIM gets its data estimate by dividing by , and the network's error in the predicted noise grows about 160-fold. That's why at one step the diffusion points scatter. A network that predicts velocity has no such division.
Lipman et al. compared optimal transport paths with diffusion paths in one setting: the former give faster training and generation, and on ImageNet 32 × 32 they need about 60% of the field evaluations to reach the same error. That doesn't mean flow is always better: Gao et al. show that for wide distributions a different schedule can give straighter paths. The result depends on the schedule, the target and the sampler, not on the name of the method.
How quality is measured. A point is “in a blob” if it's within 0.2 of the center of one of the eight blobs (2.5 spreads). A blob is “present” if at least a quarter of its share of points landed in it. Both networks have 48 × 48 neurons and train for 1500 steps of 128 examples with the same seed. For the real data about 96% of the points are in blobs.
Flow holds the shape from 8 steps, diffusion from 16. And yet flow and diffusion belong to one family: a DDIM step is the same as an Euler step. The difference in the number of steps comes from two things.
The first is the noise schedule. On the straight flow path the data gains amplitude evenly: halfway along, it has half. Under the DDPM schedule the data has less than a third of its amplitude halfway along, and for most of the first half the point is almost pure noise. A uniform grid spends many steps there.
The second is what the network predicts. The diffusion network predicts noise, and a DDIM step gets a data estimate from it: it subtracts the predicted noise from the point and divides the remainder by the signal share — the formula from lesson 1.4. At the start of the path the signal share is about 0.006, and dividing by it multiplies the network's error in the predicted noise about 160-fold. A small DDIM step multiplies this estimate by the signal share of the next moment, which is almost as small, and the error barely reaches the new point. A big step multiplies it by the signal share far ahead, close to one, and the error passes into the point almost entirely: with one step the diffusion points scatter across the whole scene. The flow network predicts velocity, and a step is the move : the velocity error passes into the point multiplied by the step length , so it doesn't grow.
One step still doesn't work: the flow model gathers all the noise into one blob at the center of the ring, because the first step leads to the mean of the data. Can the generation paths themselves be straightened so that one step is enough?
Straightening: reflow
Can the generation paths be straightened so that one step is enough? Right now one step gathers all the noise at the center of the ring.
The paths are curved because the training lines cross: through one point run lines to different blobs, and the network learns their average.
So far the turn was taken in small steps: the flow model in lab 3 needed 8, and each one took a network pass.
So the network has to be trained on pairs whose lines don't cross. Liu et al. suggested where to get them.
Plain flow matching makes pairs at random: a random noise point and a random data point, not connected in any way. Reflow makes them with the help of an already trained model. Take a noise point and run generation from it in small steps to the end of the path. Call the point where the path ends . The pair is the noise and the place the model itself led it to. Collect 2000 such pairs and fine-tune the same network, now on these pairs instead of random ones. That is reflow.
The lines of such pairs barely cross, because the model's paths don't cross. At every point at every moment the field gives one direction, so two paths can't meet at one point at one moment: after that they would go the same way. Since the paths don't cross, the segments between their start and end rarely cross either.
Let's check how many crossings remain, whether one step is enough after that, and what it costs.
Under the hood: reflow, distillation and one-step models
- What the authors proved. The output distribution of reflow is the same as the original model's, and the transport cost doesn't grow. The more repetitions, the straighter the paths can get, but the authors advise against many repetitions: error accumulates. They fine-tune the new model from the previous one's weights, as we do.
- The cost. The pairs have to be generated by model 1 over many steps, and the network trained once more. Model 1's errors pass into the pairs, so at a large number of steps the straightened model draws worse than the original. On CIFAR-10, for Liu et al., one Euler step gave FID 378 for the original model and 12.21 after reflow, while an exact solver gave 2.58 and 3.36.
- In the lab. For reflow we generate 2000 pairs from a separate noise sample. Model 2 is a copy of model 1, fine-tuned for 1000 steps of 128 pairs at learning rate 0.002. Crossings are counted for 100 pairs, that is, among 4950 pairs of segments.
- Other routes to one step. Distillation trains the network to output the end of the path directly: that's how InstaFlow got a one-step Stable Diffusion, at a cost of 199 A100 GPU-days. Consistency models map any point of the path to its end and give FID 3.55 in one step on CIFAR-10. MeanFlow (NeurIPS 2025) learns the average velocity over an interval and gives FID 3.43 in one step on ImageNet 256 × 256.
Reflow pairs barely cross, and the straightened model in one step puts about two thirds of the points into blobs and finds all eight. The price is one more training run, pairs that the original model builds over many steps, and quality at a large number of steps: the original model's errors pass into the pairs. All of this we checked on points. How many flow steps does a robot's action chunk need, and how many milliseconds do they cost?
How π0 builds an action chunk
How many flow steps does an action chunk need, and what do they cost? The robot has two requirements at once: the chunk must go around the obstacle and be computed quickly, because while it's being computed the robot stands still or follows the old plan.
Let's look at how it's done in π0 — the large policy from lesson 1.6, which we'll take apart fully in lesson 3.6. Next to a 3B-parameter VLM (a model that reads images and text) runs a separate action expert with 300M. It generates a chunk of 50 actions: it starts from noise of shape 50 × action dimension and in 10 Euler steps turns it into motion. At every flow step the expert makes one pass over the 50 action tokens. The VLM processes the images and text once per chunk and caches the keys and values, and the expert reads them at every step — that's the block mask of π0 from lesson 1.6.
On an RTX 4090 with three cameras, inference takes 73 ms: 14 ms for the image encoders, 32 ms for the pass over the observation and 27 ms for all 10 flow steps. If the model runs off the robot, 13 ms of network time is added. In GR00T N1 the action head is a DiT transformer, and 4 flow steps are enough for it: it builds a chunk of 16 actions in 63.9 ms on an L40. π0.7 (a late version of π0, 2026; lesson 3.8) generates a chunk of 50 actions in 5 flow steps.
Let's check on Ada how many flow steps the chunk needs to clear the kettle, and how many of them fit into the time budget.
Top view of the table: Ada's gripper (the dot on the left) moves left to right, 60 cm in 1 s, and a chunk of 50 actions ends at the “in 1 s” label. In the middle stands the kettle, and the dashed circle shows a 2 cm clearance around it. Gray lines are 40 demonstrations: half go around the kettle above, half below. Orange lines are 20 chunks from different noise, and the small dots show the 50 actions of one chunk, one per 20 ms tick.
The bar shows what the inference time of one chunk is made of, in ms. Ada executes 25 actions (0.5 s) and stands still while the next chunk is computed; that's where the share of time the robot is idle comes from.
Time convention in this course: is noise, is data, velocity = data − noise. That's how Lipman and Liu write it, and that's how the time is introduced in the π0 and GR00T N1 papers. In openpi, the open-source code of π0, it's the other way round: , the target is noise − actions, and generation runs from to 0 with step . The authors say outright in a comment that this is the opposite of the paper. The π0 and SmolVLA implementations in Hugging Face's LeRobot library work the same way. When reading code, check where the noise is.
Under the hood: the π0 formulas and what's behind the 73 ms
- A sign error. In the 2024 versions of the paper the target is written as . With this path and a step of that would lead from data to noise. In the January 2026 version the sign is corrected to . In the code the sign is right in its own convention.
- Choosing τ. The Beta distribution gives more training examples with heavy noise, that is, small . Moments aren't needed as long as the integration step is larger than 0.001.
- Why 10 flow steps are cheaper than the images. The expert is 10 times smaller than the VLM and works only with the 50 action tokens, while the observation is computed once and sits in the cache. That's why 10 steps cost 27 ms, and one pass over the cameras and text costs 46 ms.
- In the lab. The chunk consists of 50 lateral offsets of the gripper across the table, one per 20 ms tick; the gripper moves left to right, 60 cm in 1 s. Instead of a trained head, here we use the exact field for 40 demonstrations: 20 go around the kettle above, 20 below. That shows what the Euler steps themselves do, without training errors; a trained network would add its own errors on top. The calculator computes the latency from the π0 breakdown: 14 + 32 + 2.7 ms per flow step (27 ms / 10) + 13 ms for the network. We simplify and assume that every step costs the same. Idle time is the share of time the robot stands still: it has executed 25 actions (0.5 s) and waits for inference.
- One-step heads. FlowPolicy and MP1 generate actions in one step: 19.9 and 6.8 ms. In a single-author tech report (2026), a one-step head for GR00T sped up inference from 45 to 5 ms, but success dropped noticeably: on the long tasks of the LIBERO benchmark, from 74.5 to 26%.
In one flow step every chunk drives into the kettle: the first step from noise leads to the mean of the demonstrations. On the exact field Ada needs 4 flow steps, and on a server both the detour and the budget hold from 4 to 10 steps. The steps themselves are cheap: most of the latency comes from the pass over the observation. So how do the ways of building a chunk we have covered differ?
Four ways to build a chunk
We have covered four ways to build an action chunk: diffusion from lessons 1.4 and 1.5, ACT from lesson 1.7, flow matching, and flow matching with reflow. Sort the properties by method; each method has two. Everything you need is in this lesson and the previous ones. Drag a card, or click it and then a bin.
Eight common misconceptions
Lesson takeaways
- Diffusion Policy spends 10–16 denoising steps per chunk, and the robot waits for every network pass. ACT gets by with one pass but doesn't choose between manners. Flow matching keeps the choice, as in diffusion: it learns a velocity field by regression on straight lines between random noise and a random data point, and generation takes a few flow steps, one network pass per step.
- The training lines cross, the network learns their average, so the generation paths are curved. One step from noise lands at the mean of the data.
- With Gaussian noise, flow matching and diffusion belong to one family: DDIM is an Euler step with a different schedule. The difference in the number of steps comes from the schedule and what the network predicts: a data estimate from predicted noise amplifies the network's error under heavy noise, while a move along the velocity doesn't.
- Reflow trains the model on its own “noise → where the model led it” pairs. Such pairs barely cross, the paths straighten, and one or two steps are almost enough. You pay for this with one more training run and a little quality.
- Robot heads on flow matching take 4–10 flow steps: π0 takes 10, GR00T N1 takes 4, and π0.7 takes 5. The expert's steps are cheap; most of the latency comes from the pass over the observation.
- Time conventions differ: in this course is noise; in the openpi code it's the other way round.
Open questions
Why doesn't π0 generate a chunk in one step, if reflow and distillation allow it?
One step gives the mean if the paths are curved, and straightening or distillation costs extra training and usually a little quality. Meanwhile the expert's 10 steps cost 27 ms out of 73: the main part of the latency comes from the pass over the cameras and text, and one step instead of ten would save about a third of the time. For dexterous tasks the loss of precision costs more than those milliseconds. One-step heads are being tested, but in the GR00T tech report such a head lost noticeably in success.
The demonstrations go around the kettle sometimes left, sometimes right. What does each Euler step do to the chunk, and why is the first step the most dangerous?
At the start the noise says nothing yet about the detour side, and the field pulls the chunk toward the mean of the demonstrations — straight into the kettle. If there's one step, the chunk stays there. If there are several, after the first the chunk is still noisy, and the next steps already “see” which side it's closer to and carry it there. That's why quality rises fast from one step to three or four, and then barely changes.
Paper guide
- Read closelySections 3–4: conditional paths, the training objective and the theorem on matching gradients. The example with optimal transport paths and the figure where they are straight.
- Safe to skipThe proofs in the appendices and the likelihood experiments.
- Question to keep in mindWhy is the conditional path straight, but the field the network learns is not? Where in the paper is this stated?
X. Liu, C. Gong, Q. Liu, “Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow”, ICLR 2023 — reflow, the theorems on non-crossing paths and one-step generation.
Resources
- MIT 6.S184: Introduction to Flow Matching and Diffusion ModelsP. Holderrieth, E. Erives — lectures, videos and exercises; lecture notes at arXiv 2506.02070
- Diffusion Meets Flow Matching: Two Sides of the Same CoinGao et al., Google DeepMind, 2024 — why DDIM and Euler coincide and what is actually straight
- Flow Matching Guide and CodeLipman et al., 2024 — a detailed guide and the flow_matching library
- An introduction to Flow MatchingCambridge MLG blog, 2024 — the derivation with formulas and figures
- Let us Flow TogetherQ. Liu's series of posts on rectified flow and reflow
- How I Understand Flow MatchingVideo by Jia-Bin Huang
- openpiπ0 and π0.5 code: the flow matching head is in src/openpi/models/pi0.py
Check yourself on all of Part 1. The check has 15 questions from lessons 1.1–1.8, shuffled, plus an exercise on a live scene: that shows what has stuck. At the end you will see a score per lesson and the sections worth revisiting.
Part 1 policies build a chunk fast and choose a manner, but each needs dozens of demonstrations per skill, and most of them can't follow a command in words: you can't ask one to “put the red cube in the bowl”.