Flow Matching from Scratch — What Came After Diffusion, and Why It Goes Straight
Flow matching — the formulation underneath Stable Diffusion 3 and FLUX — explained with no prerequisites. Velocity fields, ODEs, and rectified flow, told through analogy and interactive figures, all the way to the scheduler settings you actually touch in production.
Flow Matching for Generative Modeling
Primary source — what this article is built on
undefined2026-08-22
Flow Matching for Generative ModelingarXiv:2210.02747Paper page·PDFFlow Straight and Fast: Learning to Generate and Transfer Data with Rectified FlowarXiv:2209.03003Paper page·PDF
Scaling Rectified Flow Transformers for High-Resolution Image SynthesisarXiv:2403.03206Paper page·PDF
From static to a picture: which route do you take?
Boiled down, an image generator turns random numbers into a picture. At the entrance there is meaningless static (Gaussian noise); at the exit there is a photo of a cat. The whole question is how to build the map between them.
Diffusion models answered it with "break it, then play the tape backwards." You define a route that adds noise to an image until it becomes static, then teach a network to walk that route in reverse. Because you chose the corruption procedure yourself, you can manufacture unlimited training data. It is a clever trick, but the shape of the route is locked to "keep adding noise."
Flow matching is more direct: you decide the route from start to finish up front, and the network only has to memorize "from here, which way and how fast do I move?" If diffusion is filming yourself scattering your belongings and rewinding the tape, flow matching is drawing a route from the old apartment to the new one and memorizing only the heading at each point along it. And if you get to draw the route, why not draw the shortest one — a straight line? That is where rectified flow comes from.
The intuition: learn the velocity, not the destination
Picture a river. At every point on the surface there is an arrow saying which way the water there is moving. That map of arrows is a velocity field. No single arrow tells you the destination, yet drop a leaf on the surface and it drifts, arrow by arrow, until it reaches the sea.
The arrow map is the only thing the network learns. Unlike a real river, the arrows may change over time, so we fit one function that answers "if you are at point at time , which way should you move?" Generating a sample is exactly the leaf: draw noise, read the arrow, take a small step, read the arrow again. The model never sees the picture it is heading toward — it only knows the correct next step from wherever it happens to be.
The mechanism: transport by ODE
"Follow the arrows" written as an equation is an ordinary differential equation (ODE).
Here is where you are at time , the left-hand side is your current heading and speed, is the network being trained, and means "draw Gaussian noise." Read plainly, it is a line which says nothing more than "start from noise, then keep moving in whatever direction the network points." By convention is noise and is data.
One piece of theory is worth stating. Fixing a velocity field also fixes how a cloud of particles spreads out — that is, the probability distribution at each time (the fluid-dynamics continuity equation is the formal statement). Turned around: "move the noise distribution onto the data distribution" becomes "find one velocity field that does it." That substitution is the starting point of the whole method.
This is not alien to diffusion, either. Diffusion sampling is usually a stochastic differential equation, but there always exists an ODE that reproduces the same distribution at every time step — the probability flow ODE. Diffusion is also a transport-by-arrows machine; flow matching just learns the arrows directly from the start.
The true arrow cannot be written down
So what is the loss? The obvious choice is squared error against the true velocity field .
Put in words: "make the network's arrow lie on top of the correct arrow." Squared error between vectors decomposes into a difference in length plus a misalignment in direction (the dot product), so training is literally the act of stacking two arrows on top of each other.
The problem is that cannot be written down. The correct arrow at a given point is the average of the directions toward every data point that could pass through it, which requires an integral over the whole data distribution. This is the sticking point of the method — and the reason for its name.
Comments
Sign in to comment