JA EN
LearnGenerative Models
·★ MEMBER·PAPER·10 min read

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.

ModalitytextTaskgeneration

Flow Matching for Generative Modeling


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 xx at time tt, 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).

dxtdt=vθ(xt,t),x0N(0,I)\frac{d x_t}{dt} = v_\theta(x_t, t), \qquad x_0 \sim \mathcal{N}(0, I)
(1)

Here xtx_t is where you are at time tt, the left-hand side is your current heading and speed, vθv_\theta is the network being trained, and N(0,I)\mathcal{N}(0,I) 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 t=0t=0 is noise and t=1t=1 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 ut(x)u_t(x).

LFM(θ)=Et,xptvθ(x,t)ut(x)2\mathcal{L}_{\mathrm{FM}}(\theta) = \mathbb{E}_{t,\, x \sim p_t} \left\| v_\theta(x, t) - u_t(x) \right\|^2
(2)

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.

FIG 1The predicted velocity vector and the true one. Rotate them and watch the dot product and cosine change — since ‖a-b‖² = ‖a‖²+‖b‖²-2a·b, the loss bottoms out exactly when the dot product is largest, i.e. when the arrows coincide

The problem is that ut(x)u_t(x) 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.

The key move in Lipman et al.'s flow matching paper (arXiv:2210.02747) is to condition the target on a single point. You cannot measure the average commute of an entire company, but you can measure one employee's. Likewise, if you pin the destination down, then "how do we carry to " is a route you designed yourself, so

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

References

  1. Flow Matching for Generative Modeling. arXiv:2210.02747Paper page·PDF
  2. Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow. arXiv:2209.03003Paper page·PDF
  3. Scaling Rectified Flow Transformers for High-Resolution Image Synthesis. arXiv:2403.03206Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Comments

Sign in to comment