Flow Matching Posterior Sampling

Steer a frozen flow-matching model toward any condition with no retraining: find the diffusion score hidden inside its velocity, then borrow posterior sampling.

Press FMPS-gradient and watch 150 samples turn toward the purple target. Then drag the strength past 1.5 and watch them leave the data. After that we build, piece by piece, every step the paper takes.

You need a feel for vectors (an arrow with a direction and a length) and the idea of a probability. We build the rest from zero, including what a flow, a score and a posterior are.

A reading for lecture 10, Modern Generative AI, of MIT MMAI: Multimodal AI (Spring 2026). Paper: Kaiyu Song and Hanjiang Lai, “Unraveling the Connections between Flow Matching and Diffusion Probabilistic Models in Training-free Conditional Generation” (arXiv 2411.07625, Sun Yat-Sen University). Later versions rename the method Flow Matching Posterior Sampling.

Steer a frozen flow

0.7

Illustrative toy, not the paper’s images. The “model” is the exact flow for three small Gaussian clusters of equal weight, so every number comes from real maths, not a trained network. The same 150 starting noises are used every run. Strength r is on this toy’s own scale. The method follows Eqs. 11 to 26 of the paper.

Chapter 0

Why Steer a Model You Cannot Retrain

See why a frozen image generator needs a way to follow new conditions, and why one family of generators had no such way

Picture a model that draws faces. Someone hands you a blurry photo of a face and asks for the sharp one. Someone else hands you a quick pencil sketch and asks for a face that matches it. A third person wants a face that a recognition system would match to a given person.

These are three different conditions. A condition is anything you want the picture to obey: a blurry photo, a sketch, a sentence. You could train a new model for each one. That costs weeks of compute and a new dataset every time.

The paper asks for something cheaper. Keep the model frozen. Change only the way you run it. This is called training-free conditional generation: the weights never change, yet the pictures obey a new condition.

Two families of generators

First, how does a model draw anything? A generative model here starts from noise, a picture of random static, and cleans it up in many small steps until a real-looking picture remains. The two families differ in how they take each step.

A diffusion probabilistic model (DPM) learns a score. Think of the score as a compass at every point: it points toward where pictures like your data are more likely. Each step walks a little way along the compass, plus a little fresh randomness.

A flow-matching model (FM) learns a velocity. Think of a river current: at every point and every moment, an arrow says which way and how fast to move. Each step simply follows the arrow. Stable Diffusion 3 is built this way.

Both families go from noise to a picture. Yet they were described in different languages, and tools built for one did not obviously work on the other.

The tool that one family had

DPMs had a clean steering tool called posterior sampling. In plain words: at each step, nudge the picture so that it looks more like something that satisfies your condition. Methods named DPS, FreeDom and MPGD all work this way. They need the score, because the nudge is added to the score.

FMs have no score. They have a velocity. So the nudge had nowhere to attach. The few earlier FM methods paid for it. π-Flow only handles linear inverse problems, where the condition is a known linear damage such as blurring or masking. D-Flow instead retunes the starting noise by differentiating through the whole flow.

The paper’s bet

Song and Lai make two claims. First, the velocity of an FM and the score of a DPM are two views of one object, because both describe the same probabilistic path from noise to data. Second, so you can write the FM’s equation using a score, and then reuse posterior sampling.

They call the result FMPS, flow matching based posterior sampling. It has two versions. FMPS-gradient differentiates through the model. FMPS-free skips that gradient and runs about twice as fast in the paper’s test (15 s against 7 s in Table 4).

Here is the idea in one device. The toy below has three clusters of data, which stand for three kinds of picture. The model is the same frozen flow every time. You pick which cluster the condition points at. Compare the bars with and without FMPS.

One frozen model, three conditions

Each bar shows what share of 150 samples ends in a cluster. Pick the cluster the condition points at, then compare the plain flow with FMPS-gradient.

Illustrative toy. The condition is a point 0.55 from the chosen cluster’s centre, toward the middle of the map, so it is off the data on purpose. FMPS-gradient runs at strength r = 0.7 with the paper’s gradient normalisation. The same 150 starting noises are used in every bar.

The weights did not change between the two bars. Only the sampling loop did. That is the whole promise of the paper. The rest of this lesson earns it, one mechanism at a time.

The road

  1. Paths from noise to data: what DPMs and FMs each define, and why the two paths match.
  2. Score, condition and Bayes: how DPMs steer, and why the nudge needs the score.
  3. The score hidden in the velocity: Proposition 1, derived and checked.
  4. The conditional flow: Lemma 1, and how to guess the clean picture.
  5. Gradient or gradient-free: the two ways to build that guess, and what each costs.
  6. Normalising the push: Algorithm 1 and 2, and why a fixed strength needs it.
  7. What the tables show: Tables 1 to 5, ablations and the figures.
  8. Where it fails: bad seeds, colour drift, and what the paper leaves open.
  9. The paper on one page: numbers, checklist, code and credit.
Why could posterior sampling not be used directly on a flow-matching model before this paper?

Chapter 1

Two Generators, One Path From Noise to Data

Mix a clean sample with noise using a dial, and see that diffusion models and flow-matching models both walk along such a mix

Take one clean picture and call it x0. Take one sheet of random static and call it ε. Now mix them with a dial. At one end of the dial you see only the picture. At the other end you see only static. Every setting in between is a blurry, noisy blend.

The dial is the time t. In this paper, t = 1 is pure noise and t = 0 is the clean sample. Generating a picture means turning the dial from 1 down to 0, one small step at a time.

The mix, written once

Each blend is a weighted sum of the two ends. Two numbers set the weights: how much picture to keep, and how much noise to add.

xt
The blend at time t. This is the noisy picture the model sees at step t. It has the same shape as the picture, for example 3 × 256 × 256 numbers.
at
How much clean picture is kept. It is 1 at t = 0 and 0 at t = 1.
x0
A clean sample drawn from the data. The model never sees it at sampling time; it has to guess it.
bt
How much noise is added. It is 0 at t = 0 and 1 at t = 1.
ε
One draw of standard Gaussian noise: every number is an independent bell-curve random value.

The pair (at, bt) is the schedule. It is the paper’s Eq. 7 for flow matching and, in a slightly different dress, its Eq. 1 for diffusion. A diffusion model uses at = √α̂t and bt = √(1 − α̂t), where α̂t is the noise-schedule number from the DDPM family. A flow-matching model often uses the straight choice at = 1 − t and bt = t, called rectified flow.

Try both schedules in the device. The straight schedule moves the blend along a line. The cosine schedule, a stand-in for the diffusion style, bends the path. Both start at the same noise and end at the same clean sample.

Turn the dial from noise to data

The left plot shows the two weights a and b. The right plot shows where the blend sits. Drag the time slider and switch the schedule.

0.50

Illustrative. One fixed clean point (the centre of cluster B) and one fixed noise draw in two dimensions. Real diffusion schedules use α̂t from a noise schedule; the cosine pair a = cos(πt/2), b = sin(πt/2) only shows the bent shape.

Two ways to walk back

A network has to learn how to undo the mix. The two families train it to output different things.

A DPM network outputs the noise it thinks was added, written εθ(xt, t). That is tied to the score. The reverse walk is a stochastic differential equation. That is a rule for motion that includes random kicks. It reads dxt = [f(t) xt − ½ g(t)2 ∇ log p(xt)] dt, the paper’s Eq. 2.

An FM network outputs a velocity vθ(xt, t), the arrow that says how the blend moves as t changes. The walk is an ordinary differential equation (ODE), a rule for motion with no randomness: dxt = vθ(xt, t) dt, the paper’s Eq. 8.

Walking an ODE with Euler steps

How do you follow an arrow field on a computer? The simplest way is the Euler step. Look at the arrow where you stand. Move a small distance along it. Look again.

Work one by hand with the straight schedule. Let the clean point be x0 = (1.2, 0.9) and the noise be ε = (−1.0, −0.8). At t = 0.5 the blend is 0.5 · x0 + 0.5 · ε = (0.10, 0.05). The straight schedule has velocity v = ε − x0 = (−2.2, −1.7).

x0.4 = x0.5 − h · v = (0.10, 0.05) − 0.1 · (−2.2, −1.7) = (0.32, 0.22)

Check it against the mix directly: 0.6 · (1.2, 0.9) + 0.4 · (−1.0, −0.8) = (0.32, 0.22). They agree, because a straight path is followed exactly by Euler steps. The paper prints this step as xt−1 = xt + h vθ (Eq. 9). Because time runs down, we write the step as x − h v with h > 0, the time gap.

One more fact connects the two families. If you pick the schedule at = √α̂t and bt = √(1 − α̂t), the FM path and the DPM path are the same family of blends. That is the paper’s motivation in Section 3.2: the two models describe the same road, with a different instruction at each step.

In the mix xt = at x0 + bt ε, what are the values of a and b at the start of generation, t = 1?

Chapter 2

The Score, the Condition and Bayes

Learn how a diffusion model adds a condition by adding two arrows, and see why that trick needs a score

You stand on a foggy hillside. You cannot see the peaks, but you carry a compass that always points uphill. The hills are the places where realistic pictures live. The higher you stand, the more likely your blend looks like real data.

That compass is the score. Formally, at time t the blends xt follow some probability density p(xt) (a function that says how likely each blend is). The score is the gradient of its logarithm, written ∇xt log p(xt). A gradient is the arrow of steepest climb. It has the same shape as xt: one number per pixel.

The logarithm is there for a practical reason. It turns a ratio of probabilities into a difference, which makes the next step clean.

Adding a condition with Bayes

Now add a condition c. You want blends that are likely and also fit c. The density you want is p(xt | c), read “the chance of xt given c”. Bayes’ rule splits it into pieces you can handle:

p(xt | c)
What we want: how likely this blend is, if we know the final picture must satisfy c.
p(c | xt)
The condition term: if the picture is on its way to looking like xt, how well does it fit c? A sharp face fits a sharp-face sketch better than a landscape does.
p(xt)
What the frozen model already knows: how likely the blend is with no condition.
p(c)
How common the condition is. It is a single number that does not depend on xt.

Take the logarithm and then the gradient with respect to xt. Products become sums. The last term, log p(c), does not contain xt, so its gradient is zero. What is left is the paper’s Eq. 4:

∇ log p(xt | c) = ∇ log p(xt) + ∇ log p(c | xt)

Read it as two compasses added together. The first is the frozen model’s score. The second points toward blends that fit the condition. You walk along the sum. The frozen model is untouched; you only add an arrow.

Add the two compasses

Each arrow points where a blend at that spot would be pushed. Switch between the model’s own score, the pull toward the purple target, and their sum. Tap the map to move the probe.

0.40
1.0

Illustrative toy with exact maths: three Gaussian clusters, the straight schedule, and a condition term built from the squared distance of the clean-picture guess to the target. Arrow length shows relative size inside each view; the read-out gives true lengths.

At a small t the data compass is strong and points at the nearest cluster. Around t = 0.5, between the clusters, it is weak, because the model has not yet decided which cluster the blend will join. Move the probe to the middle of the map at t = 0.5: the condition pull is now as large as it gets in this toy. The pull matters most while the model is undecided.

How to compute the condition term

The term p(c | xt) is hard. A noisy blend is a poor thing to compare with a sketch. So the posterior-sampling methods (DPS, FreeDom, MPGD) use a trick. They first guess the clean picture x̂0|t that xt would become. Then they measure a distance D between that guess and the condition. D is any differentiable measure of mismatch: how far a blurred copy of the guess is from the blurry photo, or how far the guess’s edges are from the sketch.

The condition term becomes minus the gradient of that distance, scaled by a strength:

∇ log p(c | xt) ≈ − r ∇xt D(x̂0|t, c)

Here r is the guidance strength, a knob that sets how hard the condition pulls. The paper writes the term with a plus sign and lets r carry the sign. We keep the minus, so the walk always goes downhill on D.

A tiny worked case. Let the guess be (0.90, 0.50) and the target (1.15, 0.35), with D equal to the squared distance. The gradient of D with respect to the guess is 2 · (guess − target) = (−0.50, 0.30). The pull is minus r times that, which for r = 0.7 is (0.35, −0.21): right and slightly down, toward the target. (The full gradient also multiplies by how the guess changes with xt. Chapter 5 shows two ways to get it.)

The DPM gets its guess for free. Eq. 6 reads x̂0|t = (xt − √(1 − α̂t) εθ) / √α̂t: remove the predicted noise from the blend. It also gets the first compass for free, since the predicted noise is a rescaled score. A flow-matching model gives neither. The next chapter fixes that.

When Bayes’ rule is differentiated with respect to xt, why does the p(c) term disappear?

Chapter 3

The Score Hidden Inside the Velocity

Derive Proposition 1 in four lines, then check numerically that a velocity and a score carry the same information

Back to the river. A velocity arrow tells a leaf where the current carries it. A compass tells it which way is uphill. The paper claims the two are not independent. The current at any spot is a fixed mix of two things: “where you stand” and “what the compass says”. If that is true, a network that outputs velocity also holds the score, and we only need to read it out.

Two facts

Fact 1: the network learns an average. Many different pairs (x0, ε) can produce the same blend xt. The velocity of one pair is ȧ x0 + ḃ ε, where the dots mean the rate of change of the weights with time. The network cannot know which pair it is looking at, so the best it can do is the average over all pairs that fit. That average is the velocity v(xt, t) it learns.

Fact 2: the noise average is the score. The blend is Gaussian around atx0 with width bt. The gradient of a Gaussian’s log density is minus the offset divided by the variance. Averaged over the clean samples that could have led to xt, this gives

E[ε | xt]
The best guess of the noise that was mixed in, given only the blend. The DPM network outputs this.
bt
The noise weight from Chapter 1. It scales the score up to a noise guess.
∇ log p(xt)
The score from Chapter 2.

This is why DPM papers can say the network output “is” the score. Now combine the two facts. From xt = a x0 + b ε we can solve for the clean sample: x0 = (xt − b ε) / a. Average both sides and use Fact 2:

E[x0 | xt] = (xt + bt2 ∇ log p(xt)) / at

Put the two averages into Fact 1:

v(xt, t)
The velocity the flow-matching network outputs. It has the same shape as xt.
λt
A plain number at each t. It says how strongly the current drags along with the blend itself.
βt
A plain number at each t. It says how much the compass adds to the current.
∇ log p(xt)
The score again. This is the hidden part.

This is the paper’s Proposition 1, which it takes from the stochastic-interpolant work of Albergo and Vanden-Eijnden. Because λ and β depend only on the schedule, you can turn it around and read the score out of any velocity: score = (λt xt − v) / βt.

A worked check: one clean point

Use the straight schedule: a = 1 − t, b = t, so ȧ = −1 and ḃ = 1. Then λ = −1/(1 − t) and β = t(1 + t/(1 − t)) = t/(1 − t). Let the data be a single point at zero, so xt = tε. The blend is Gaussian with variance t2, and the score is −xt/t2.

v = −x/(1 − t) + [t/(1 − t)] · x/t2 = x/(1 − t) · (−1 + 1/t) = x/t

The true velocity is ε − x0 = ε = x/t. They match. The device repeats this check on the three-cluster toy, where the score comes from a numerical gradient of the true density and the velocity comes from the average of Fact 1.

Rebuild the velocity from the score

Tap the map to place the probe. The solid arrow is the velocity from the average of Fact 1. The dashed arrow is lambda times x minus beta times the score.

0.50

Exact maths on a toy: three equal Gaussian clusters. The score is a central finite difference of the exact log density, with step 0.0001. The two arrows are computed by different routes, so their agreement is a real test of the identity.

Move the probe and the schedule. The gap stays near the size of the rounding error, about 10−7 or smaller. The two views are one object.

You have a trained flow-matching network that outputs v(xt, t). How do you get the unconditional score at that point?

Chapter 4

The Conditional Flow and the Clean-Picture Guess

Add the condition to the velocity with Lemma 1, then learn how to guess the finished picture from a half-finished blend

You now hold the key. The frozen network gives a velocity v. Chapter 3 showed that v is already “the score, wrapped in the schedule”. Chapter 2 showed that a condition adds a second compass to the score. So the conditional velocity should be the old velocity plus a wrapped copy of the second compass. Lemma 1 makes that precise.

Lemma 1, line by line

Start from the unconditional ODE written with a score (Eq. 13). Replace the marginal density p(xt) by the conditional density p(xt | c), as posterior sampling does (Eq. 14). Split the conditional score with Bayes (Chapter 2). The result is Eq. 11:

dxt
The tiny change of the blend over a tiny change of time. Sampling follows it from t = 1 to t = 0.
λt xt
The part of the current that comes from where you stand (Chapter 3).
βt
The schedule number that turns a score into a velocity change (Chapter 3).
∇ log p(xt)
The frozen model’s own score. We never compute it alone.
∇ log p(c | xt)
The condition compass from Chapter 2.

Now the useful step, the paper’s Eqs. 18 and 19. Regroup the terms: (λx − β ∇ log p(x)) is exactly the network’s own velocity v. So the conditional flow is

dxt = [ vθ(xt, t) − βt ∇ log p(c | xt) ] dt

That is the whole trick. You never separate the score from the velocity in code. You run the network as usual, then add one correction. Insert the Chapter 2 estimate ∇ log p(c | xt) ≈ − r ∇ D and the corrected velocity is

vc = vθ(xt, t) + r βt ∇xt D(x̂0|t, c)

Time runs down, so the Euler step is xt−h = xt − h vc. The sign works out: a positive push along the gradient of D in vc becomes a step against it, so D falls. The paper writes the same update as Eq. 26 and lets r absorb the sign.

Guessing the clean picture

One piece is still missing: x̂0|t, the guess of the finished picture. The DPM got it by removing predicted noise. The FM has a neater route. If you stand at xt with velocity v, and you take one Euler step all the way to t = 0, you land at

x̂0|t
The guess of the clean picture, made at time t. The hat means “an estimate”.
xt
The current blend.
t
The step size: the whole remaining time from t down to 0.
vθ
The network’s velocity at this blend and time.

This is Eq. 21. Check it with Chapter 1’s numbers: x0.5 = (0.10, 0.05) and v = (−2.2, −1.7) give (0.10, 0.05) − 0.5 · (−2.2, −1.7) = (1.20, 0.90), the clean point. That case had a straight path, so the one big step was exact. In a real flow the velocity changes along the way, so the guess is only a smoothed average of the possible endings. It is blurry early and sharp late.

Guess the ending from the middle

Each warm dot is a half-finished sample of the plain flow. The blue diamond at the end of its line is the one-step guess. The faint ring is where the sample really ends. Slide the time.

0.60

Illustrative toy. The plain flow uses 60 Euler steps with the exact velocity of three Gaussian clusters. The error is the average distance from each guess to the point where that same sample ends.

This matters for the condition. Comparing the guess to a sketch or a blurry photo only makes sense when the guess already looks like a picture. Late in the walk it does. Early on, the guess is a smear of everything, which is why the correction needs care in Chapter 6.

One step of FMPS, with shapes

  1. Take xt, shape [3, H, W] for an RGB picture (the paper’s sizes follow its checkpoints).
  2. Run the frozen network: vθ(xt, t), shape [3, H, W].
  3. Guess the picture: x̂0|t = xt − t v, shape [3, H, W].
  4. Score the guess against the condition: D(x̂0|t, c), one number. For inpainting this can be the squared difference on the known pixels; for super-resolution, the difference after down-sampling.
  5. Back-propagate to xt: ∇D, shape [3, H, W].
  6. Combine and step: xt−h = xt − h ( v + r βt ∇D ).
In Lemma 1, why does the code never need to compute the model’s score on its own?

Chapter 5

Gradient or Gradient-Free: Two Ways to Guess

Compare the two clean-picture estimates the paper offers, and count what each one costs in model calls and seconds

Suppose a student must hand in a picture that matches a sketch. At every step the student asks two questions. “Where am I heading?” and “if I nudge here, how does my final picture change?” The second question is the expensive one. It needs the gradient of the distance D with respect to the current blend xt.

That gradient passes through the guess x̂0|t. In Chapter 4 the guess was xt − t vθ(xt, t). It contains the network. So the gradient must go through the network, by back-propagation: run the chain rule backwards over every layer. For a big model this is slow and uses a lot of memory.

FMPS-gradient: ask the model

The first version keeps Eq. 21 and pays the price. The chain rule gives

∇xt D = ( I − t ∂vθ/∂xt )T ∇x̂0 D

Here I is the identity (the xt term of the guess) and ∂v/∂xt is how the network’s output changes when its input changes. The second term is the model’s own opinion about the ending. The paper argues this gradient information helps conditional tasks, and its tables agree (Chapter 7). The price is extra compute and memory at every step.

FMPS-free: remember the start

The second version asks a different question. At the start of sampling you drew one noise sample, call it x1. It never changes. In the straight schedule, every blend is a point on the line between the clean picture and that noise. So if you know xt and x1, you can solve the mix of Chapter 1 for the clean end, with no network involved:

x̂0|t
The guess of the clean picture, as before.
xt
The current blend.
bt
The noise weight at time t.
x1
The starting noise, stored once and never changed.
at
The picture weight at time t. It is zero at t = 1.

This is Eqs. 22 and 23. Check with Chapter 1’s numbers: x0.5 = (0.10, 0.05), x1 = (−1.0, −0.8), a = b = 0.5. Then (0.10 + 0.50, 0.05 + 0.40) / 0.5 = (1.20, 0.90). Right again.

Now the gradient is cheap. With the straight schedule, ∇xt D is just ∇x̂0 D divided by at. No back-propagation through the network. The paper says this “decouples” the guess from the network. There is one catch: a1 = 0, so the very first step cannot use this estimate. Algorithm 2 takes a plain, unguided step first and starts guiding on the second step.

Why can FMPS-free be off? It assumes the road back to the clean picture is the straight line to x1. Guidance pushes xt off that line, and a real flow curves toward the data. So the estimate drifts. FMPS-gradient asks the model every time and does not drift in the same way.

Count the work in one step. Both versions run the network forward once to get v. FMPS-gradient then sends the gradient back through that same call. A common rule of thumb says a backward pass costs about as much as the forward pass, so the step costs roughly twice as much (our estimate, not the paper’s). It must also keep every layer’s activations in memory until the backward pass ends. FMPS-free sends the gradient only through D. For inpainting, D is a masked squared difference, so that part is almost free. Over T = 100 steps, the network runs 100 times in both versions, but only the gradient version back-propagates through all 100 of those calls.

The two bills also differ in what can go wrong. The gradient version can run out of memory on a large model, which is the reason the authors skip it for Stable Diffusion 3. The free version never runs out of memory this way, but its guess can drift off the real ending. Memory decides which version you can run. Accuracy decides which one you would prefer.

Two guesses, two bills

The toy view plots how far each guess is from where the sample really ends, from noise (left) to data (right). The paper view shows Table 4 for super-resolution on AFHQ.

Toy view: plain unguided flow, 60 steps, 150 samples. The error is the mean distance from the guess to the sample’s final point. It stops at t = 0.95 because the free guess divides by at. Paper view: Table 4, AFHQ 4× super-resolution, one RTX 4090 GPU, T = 100.

Look at the bills in the paper view. FMPS-gradient gets SSIM 0.74, LPIPS 0.12 and FID 7.68 in 15 s. FMPS-free gets SSIM 0.69, LPIPS 0.13 and FID 7.82 in 7 s. The paper calls this a 2× speed-up at a small loss. For Stable Diffusion 3 the gradient version was out of reach: the authors write that its GPU cost was unaffordable, so the text-style experiment uses FMPS-free only.

Why does Algorithm 2 (FMPS-free) take its first step without guidance?

Chapter 6

Normalising the Push and Running the Algorithm

Fix the length of the condition gradient with the paper’s normalisation trick, so one strength r means the same thing everywhere

Picture a tug of war with two ropes on one sample. The first rope is the model’s velocity v. It pulls toward real data. The second rope is the condition gradient. It pulls toward the target. If the second rope is much weaker, the condition is ignored. If it is much stronger, the sample is dragged to the target even when that means leaving the data. The result obeys the condition and looks like garbage.

The trouble is that the gradient’s length is arbitrary. It depends on the units of D (pixels, classifier scores, edge maps), on the estimator (the free version divides by at, the gradient version multiplies by a Jacobian) and on the time t. A value of r that works for one task is wrong for the next. The paper (following earlier DPM work) calls this the unstable phenomenon: the gradient “will be over powerful or too weaken”.

The trick: keep the direction, fix the length

The direction of ∇D says where the target is. Its length says nothing useful. So the paper throws the length away and replaces it with the length of the velocity, which is the natural scale of one step:

g
The rescaled condition gradient. It points the same way as ∇D and always has the length of v. Same shape as xt.
∥v∥
The length (2-norm) of the model’s velocity: the square root of the sum of squares of all its numbers.
∥∇D∥
The length of the raw condition gradient.
∇D
The raw gradient of the distance with respect to xt.

That is Eq. 24. The corrected velocity is vc = v + r βt g (the paper’s Eq. 25 with its sign convention), and one Euler step is xt−h = xt − h vc.

Work it with the numbers from Chapter 1. Let v = (−2.2, −1.7), so ∥v∥ = 2.78. Suppose the raw gradient is ∇D = (0.002, −0.001), tiny, with length 0.00224. The ratio is 2.78 / 0.00224 = 1,243, so g = (2.49, −1.24). Now suppose the gradient is huge: (40, −20), length 44.7. The ratio is 0.0622 and g = (2.49, −1.24). The same g, whatever the scale.

Take r = 0.7 and the straight-schedule value β = t/(1 − t) = 1 at t = 0.5. The push is 0.7 · g = (1.74, −0.87). The corrected velocity is (−2.2 + 1.74, −1.7 − 0.87) = (−0.46, −2.57). With h = 0.01 the new blend is x0.49 = x0.5 − 0.01 · vc. Now r reads in plain words: it is how many “velocity lengths” of push you add, scaled by β.

The loop, as the paper writes it

  1. Draw x1 from a standard Gaussian, set xt = x1, and choose T steps (the paper uses T = 100), so h = 1/T.
  2. For each step from t = 1 toward 0: compute at, bt and their time derivatives, then λt and βt.
  3. Run the network once to get vθ(xt, t).
  4. Get x̂0|t: Eq. 21 for FMPS-gradient, Eq. 23 for FMPS-free (skipping the first step).
  5. Compute ∇D, normalise it to g, and take the Euler step.

Put the trick to the test. The device sweeps r over 12 values for both estimators, with and without the normalisation. It measures two things on 100 samples: how many reach the target cluster (potency), and how many still land on some real cluster (safety).

Find the safe range of r

Top plot: share of samples that reach the target. Bottom plot: share that still land on a real cluster. The bold line is your choice; the faint line is the other one. Drag the strength marker.

1.0

Illustrative toy, not the paper’s images: 100 samples, 50 steps, straight schedule, β capped at 3 for the toy. A sample counts as on the data if it ends within 0.36 of a cluster centre (three standard deviations). The scale of r belongs to this toy.

Read the two plots together. With the normalisation, both estimators rise smoothly and stay on the data up to about r = 1, then fall off together. Without it, the gradient version stays safe to r = 4. The free version swings from one r to the next, as you can see when you flip the switch. Its raw gradient has no steady scale. So a normalised r transfers between estimators.

The toy also shows a cost. Where the raw gradient version is safe it reaches more of the target than the normalised one. The trick buys calm and comparability, not extra power. The paper tests only the normalised form, so we cannot say how the raw form fares on images.

The raw gradient of D is multiplied by 1,000 because D is measured in different units. What happens to the normalised push g?

Chapter 7

What the Tables and Figures Show

Read all five tables and four figures, learn what each metric rewards, and spot where FMPS wins, ties or loses

A result table can mislead if you do not know what its columns reward. So first the setup, then the numbers, then the places where the story is less tidy than the abstract.

The setup

The paper tests three families of conditions. The inverse-problem runs use T = 100 steps; the paper does not state T for the text-style task. Every experiment runs on a single RTX 4090 GPU. The inverse-problem tasks use the official rectified-flow checkpoint trained on CelebA-HQ faces. The text-style task uses Stable Diffusion 3.

TaskWhat the condition isMetrics
Inpainting, super-resolution 4×, Gaussian deblurA damaged photo: a box is missing, or the photo is small or blurred (linear inverse problems)SSIM ↑, LPIPS ↓, FID ↓
Segmentation, sketch, face IDA segmentation map, a sketch, or a face identity read by a classifier (non-linear inverse problems)Distance ↓, FID ↓, KID ↓
Text-styleA text prompt plus a style image; 1,000 prompt and image pairs, nine stylesStyle distance ↓, CLIP score ↑

The metrics, in plain words. SSIM compares local structure between two images; higher is closer. LPIPS compares them through the features of a neural network, which tracks human judgment better than pixel error; lower is closer. FID and KID compare the whole set of outputs with a set of real faces; lower means more realistic. CLIP score measures how well the picture matches the prompt; higher is better. The style distance compares texture statistics (a Gram matrix) of the output and the style image.

The numbers, task by task

Use the explorer to read every table. Pick a task and a metric. The bars show every method that reports it. Warm bars are the paper’s two methods; grey bars are baselines. Missing bars mean the original table has a dash.

Read Tables 1, 2 and 5

Choose a task, then a metric. The green outline marks the best score. Arrows tell you which direction is better.

Numbers are copied from the paper: Table 1 (CelebA-HQ linear problems), Table 2 (CelebA-HQ non-linear problems) and Table 5 (text-style with Stable Diffusion 3). Each is one reported value; the paper gives no error bars or seeds.

Reading the tables honestly

Linear problems (Table 1). FMPS-gradient has the lowest LPIPS and FID on all three tasks. In inpainting it reaches FID 3.29 against 11.83 for the best baseline that reports it, MPGD. In super-resolution FMPS-gradient gets FID 17.83 against 30.30 for DPS+DSG. SSIM tells a quieter story: MPGD keeps 0.79 in super-resolution against 0.78 for FMPS-gradient. The authors note a slight colour deviation and say SSIM is “not well reported” in this task.

Non-linear problems (Table 2). FMPS-gradient is best on segmentation (distance 1213.3, FID 34.10) and face ID (distance 0.39, KID 0.0287). On sketches both FMPS versions cut the distance from FreeDom’s 34.12 to about 19.3, a 43% drop. But FMPS-free pays in realism: its sketch FID is 60.61 against 52.18, and its segmentation FID 40.36 against 38.65. The paper reads this as proof that gradient information is useful.

Text-style (Table 5). FMPS-free has the best CLIP score, 32.65. LGD-MC has a lower style distance, 404.0 against 435.2, but a CLIP score of only 21.16, so it follows the style and loses the prompt. Figure 2 shows long prompts such as a cat holding a sign that says “hello world”.

Why the columns can disagree

A distance column and a FID column ask different questions. Distance asks: does the output match the condition? FID asks: does the set of outputs look like real faces? A method can score well on one and badly on the other. FMPS-free on sketches is the example: distance 19.25, the lowest in the table (FMPS-gradient has 19.31), yet FID 60.61, the worst in that table. It follows the sketch closely and drifts a little from real faces. So read both columns before you call a method better.

Also read the dashes. In Table 1, ILVR reports only super-resolution, and LGD-MC and DPS+DSG report no SSIM. A dash means no number, not a bad number. The text we have does not say whether the authors reran each baseline or copied its published numbers, so treat small gaps with care. Large gaps, such as inpainting FID 3.29 against 11.83, are harder to explain away.

The ablations

Against π-Flow (Table 3, Fig. 3). On AFHQ, the authors rerun π-Flow on the same checkpoint. FMPS then lowers the super-resolution FID from 21.22 to 7.82, and the deblur FID from 22.02 to 7.83. π-Flow’s SSIM is 0.02 in both, against 0.69 and 0.72. Treat this with care: the paper says it kept π-Flow’s published settings, and an SSIM of 0.02 suggests the transfer to this checkpoint may not be tuned.

Gradient against free (Table 4). 15 s against 7 s for a small loss in quality, as in Chapter 5. Strength r (Fig. 4). From r = 0.3 to r = 2 the cat-sign prompt still works, but the middle range 0.5 to 1.5 obeys prompt and style best.

On sketch guidance, FMPS-free has a much lower distance than FreeDom but a worse FID. What does the paper take from the comparison with FMPS-gradient?

Chapter 8

Where It Fails and What Stays Open

See why a bad starting seed can doom a guided run, and separate what the authors state from what we derived or tested ourselves

A method is only as useful as your knowledge of where it breaks. The paper gives a short “Limitation” paragraph with two points. We will take them one at a time, then add what the maths in Chapters 3 to 6 implies.

What the authors say

The seed is the key. In the authors’ words, if the seed is bad, the process fails. The seed is the starting noise x1. A flow is deterministic: the same noise always gives the same ending. Guidance can bend the road, but it can only bend it so far, and some starting points lie in a basin the guide cannot escape.

A colour shift. The colours of the outputs deviate a little from DPM-based methods. The authors find this interesting, since SSIM is not well reported on the linear tasks, and guess that it may come from the gap between stochastic and arbitrary paths. They leave it for future work. Their guess is a guess, not a result.

Which seeds can be saved

Each square is one starting noise on a grid. Its colour is where that sample ends. Switch on guidance, change the strength, and tap a square to draw its path.

0.7

Illustrative toy: 825 starting noises on a 33 by 25 grid over the plane, 40 steps each, normalised gradient. Green means the sample ends within 0.36 of the target cluster centre. Real image seeds live in millions of dimensions, so this only shows the idea.

Look at the plain map first. Each cluster owns a region of starting noise. Now turn guidance on. A band of seeds near the border flips to the target. Seeds deep inside another cluster’s region stay where they were. Raise r far enough and the failure changes kind: the seeds that did flip are joined by red squares that never reach any cluster.

Why a large r leaves the data

Chapter 6 gave the push its length: r times βt times the length of v. Work it with the numbers from there. The velocity has length 2.78. At t = 0.5 the straight schedule has β = 1. With r = 0.7 the push is 0.7 × 2.78 = 1.95, a bit under the velocity. With r = 2.5 it is 6.95, about 2.5 times the model’s own arrow. Now the condition outvotes the data, and the sample can leave it.

Time makes it worse. Near the start, β = t/(1 − t) grows. At t = 0.9 it is 9, so even r = 0.7 gives a push of 6.3 velocity lengths. That is the blow-up the list below mentions. The paper does not say how it handles these early steps. A reproduction must choose: cap β, skip the first few steps, or start the guidance later.

What the maths adds

These points are ours, derived from the chapters above. They are not in the paper’s limitation section.

Later versions

The arXiv listing shows that version 3 (August 2025) carries a new title, Flow Matching Posterior Sampling: A Training-free Conditional Generation for Flow Matching, and more authors. Its abstract describes the same idea as a correction term that steers the velocity field and can be reformulated with a surrogate score function, and names the same two variants. This lesson follows version 1, the one with the assigned title.

You raise the strength r very high. What does the seed map show happening to the samples that did not reach the target?

Chapter 9

The Paper on One Page: A Field Guide

Keep the numbers, the terms, a reproduction checklist and the core code, and see where the paper sits in the field

In one paragraph. A flow-matching model walks from noise to data by following a velocity. That velocity equals a schedule-dependent mix of the current blend and the diffusion score (Proposition 1). So you can add a condition exactly as diffusion posterior sampling does, by adding a correction to the velocity (Lemma 1). The correction is the gradient of a distance between a guess of the clean picture and the condition, rescaled to the length of the velocity. The guess can be made in two ways, which gives two versions: FMPS-gradient (more accurate, 15 s) and FMPS-free (about twice as fast, 7 s, slightly lower quality).

The numbers to remember

NumberWhat it isWhere
T = 100Euler steps used in all inverse-problem runsSection 5.1
15 s and 7 sTime for FMPS-gradient and FMPS-free, 4× super-resolution on AFHQTable 4
FID 3.29FMPS-gradient on inpainting, against 11.83 for the best baseline that reports it (MPGD)Table 1
FID 17.83 and 18.49FMPS-gradient on super-resolution and Gaussian deblurTable 1
Distance 19.31 against 34.12Sketch guidance, FMPS-gradient against FreeDom, a drop of about 43%Table 2
1213.3 and 0.39FMPS-gradient segmentation distance and face ID distance, both the best reportedTable 2
CLIP 32.65FMPS-free on text-style, the best CLIP score of four methodsTable 5
FID 21.22 to 7.82π-Flow against FMPS on AFHQ super-resolutionTable 3
r from 0.5 to 1.5The strength range that obeyed prompt and style bestFig. 4

The terms

TermPlain meaningShape
xtThe blend of clean picture and noise at time t[3, H, W]
vθThe velocity the frozen network outputs[3, H, W]
scoreThe gradient of the log density: the uphill compass[3, H, W]
λt, βtSchedule numbers linking velocity and score (Chapter 3)one number each
x̂0|tThe guess of the clean picture at time t[3, H, W]
DA differentiable distance between the guess and the conditionone number
gThe gradient of D rescaled to the length of v[3, H, W]
rThe guidance strengthone number

A reproduction checklist

The core as code

pythonimport torch

def fmps_sample(v_net, dist, c, shape, T=100, r=0.7, mode="grad", beta_cap=3.0):
    x1 = torch.randn(shape)                         # starting noise, kept for FMPS-free  [B,3,H,W]
    x, h = x1.clone(), 1.0 / T
    for k in range(T):
        t = 1.0 - k * h                              # time runs from 1 (noise) down to 0 (data)
        xt = x.detach().requires_grad_(True)
        if mode == "grad" and k > 0:
            v = v_net(xt, t)                         # graph kept: gradient flows through the network
            x0 = xt - t * v                         # Eq. 21, one Euler step to t = 0
        else:
            with torch.no_grad(): v = v_net(xt, t)
            x0 = (xt - t * x1) / (1.0 - t) if k > 0 else None   # Eq. 23, a_t = 1 - t, b_t = t
        if k > 0 and r > 0:
            D = dist(x0, c)                         # one number: how far the guess is from the condition
            (gD,) = torch.autograd.grad(D, xt)
            g = gD * v.norm() / (gD.norm() + 1e-12)   # Eq. 24: keep direction, length of v
            beta = min(t / (1.0 - t), beta_cap)      # straight schedule; the cap is our choice
            v = v.detach() + r * beta * g           # Lemma 1 with the Eq. 5 estimate
        x = (xt - h * v).detach()                    # Euler step downward in t
    return x

# inpainting condition: only the known pixels count
def dist(x0, y, mask=None): return ((mask * (x0 - y)) ** 2).sum()

Our sketch of Algorithms 1 and 2 for the straight schedule, written from the equations in the paper. The cap on β and the use of the first step are our choices; the authors’ code may differ.

Where it sits in the field

Training-based control (ControlNet, LoRA) retrains for each task. Training-free control for diffusion uses posterior sampling (DPS, FreeDom, MPGD, DSG, LGD-MC). For flow models there were π-Flow (linear problems only) and D-Flow (optimise the start). FMPS carries the DPM recipe over to flows, which matters because newer large generators, such as Stable Diffusion 3, are flow models.

Keep going

Credit. This lesson teaches “Unraveling the Connections between Flow Matching and Diffusion Probabilistic Models in Training-free Conditional Generation” by Kaiyu Song and Hanjiang Lai, Sun Yat-Sen University, arXiv 2411.07625. Proposition 1 comes from Albergo and Vanden-Eijnden’s work on stochastic interpolants. Rectified flow is from Liu, Gong and Liu; flow matching from Lipman and colleagues; posterior sampling from DPS (Chung and colleagues) and FreeDom (Yu and colleagues). The toy in the devices is ours, built for teaching, and is not the authors’ code.

The takeaway. A flow-matching velocity is a score in disguise. Once you see the disguise, every steering trick built for diffusion models can be added as one correction to the velocity, with the gradient scaled to the velocity’s own length, and the weights never change.
Put FMPS-gradient, FMPS-free and a plain flow in order of how much they cost per step, cheapest first.

Now press Present or Teach and explain, from memory, why a velocity contains a score, how the correction enters, and why the gradient is rescaled. Then go back to the steering device at the top, switch to FMPS-gradient, and move the strength from 0 to 2.5: you can now say what every part of that curve means.

Flow Matching Posterior Sampling
Read the paper (arXiv 2411.07625) · MIT MMAI schedule · Lecture 10: Modern Generative AI · Back to Gleams