Diffusion and flow matching look like two recipes. Under Generator Matching they are one family, and one dial mixes them. Run the sampler below and turn the dial.
Pick a sampler, press Run, then drag the network error and run again. Watch 4,000 dots travel from noise to two clusters of data, and watch the bars follow the exact curve at every moment. Then we build, piece by piece, the idea that lets one picture hold both methods.
You need a feel for what a probability distribution is (a rule that says how likely each value is) and a little calculus (what a derivative is). We build the rest from zero.
Based on “Exploring Diffusion and Flow Matching Under Generator Matching” by Zeeshan Patel, James DeLoye and Lance Mathias (UC Berkeley, December 2024), arXiv:2412.11024. It is a reading of the framework of Holderrieth et al., and it is the assigned reading for MMAI Lecture 10, Modern Generative AI, in MIT’s Multimodal AI course (Spring 2026, Paul Liang). Every idea is re-taught here in our own words and devices.
Toy, not the paper’s experiment (the paper has none). The data are two clusters at −2 and +2 holding 35% and 65% of the mass, each 0.25 wide. The velocity and the score come from exact formulas, not a trained network. “Network error” adds a constant push to the drift. Noise strength g is 0, 1 or 2. Each run uses 4,000 dots and 60 Euler steps with a fixed seed, so the same settings give the same picture.
Chapter 0
See why diffusion and flow matching, two methods that look unrelated, can share a single mathematical home
Picture a heap of sand and a sandcastle. You want a machine that turns the heap into a castle. Nobody hands you instructions. You only have thousands of photos of real castles, and you must learn the rule from those.
That is the job of a generative model: a model that learns what real data looks like, then makes new examples that look the same. The sand is noise, random numbers that carry no information. The castle is a sample from the data distribution, the rule that says how likely each possible picture, sound or sentence is.
The usual trick is to build the castle in many small steps. Start with noise. Nudge it a little toward something real. Repeat. After enough nudges the heap has become a castle. Two families of models work this way, and the paper compares them.
Diffusion models tell a story about destruction. Take a real photo and add a little noise, then a little more, until only static is left. A neural network (a function with millions of adjustable numbers) learns to undo one small step of that damage. To make a new image, you start from static and undo the damage step by step.
Flow matching models tell a story about travel. Every grain of sand has a destination, and a network learns an arrow for each place and time that says which way to move. This arrow field is the velocity field (it says how fast, and in which direction). To make a new image, you start from static and follow the arrows.
The two stories sound different. One is about repair, one is about travel. Diffusion samplers also add fresh random kicks along the way, while a flow sampler follows its arrows with no randomness at all. So are these really two different ideas?
The paper is a short theory note, seven pages long, by Zeeshan Patel, James DeLoye and Lance Mathias of UC Berkeley. It has no experiments, no tables and no figures. Everything in it is an argument, and we will treat it as one. It makes three claims.
The paper opens by saying these methods improve on earlier approaches that relied on direct maximum likelihood or adversarial training (GANs). It does not test that. We take it as the authors’ background claim and move on to what they prove.
Here is the idea that makes the claim believable. Follow one dot, and a flow sampler and a noisy sampler take different paths. The noisy one wiggles, and the flow one glides. But look at the whole crowd of 4,000 dots at one moment, and both crowds have the same shape. That shape is the marginal probability path: the distribution of the crowd at each time, from pure noise at the start to the data at the end.
In the device below, both samplers use exact formulas for their arrows, so the only thing that can differ is the style of travel. Drag the time and compare each crowd with the exact curve.
The blue shape is the exact distribution at time t. The pink outline is 4,000 dots from the flow sampler. The purple outline is 4,000 dots from the noisy sampler. Drag t from 0 (noise) to 1 (data).
Toy, same world as the sampler at the top: two data clusters at −2 and +2 holding 35% and 65%, exact velocity and score, 60 Euler steps, 4,000 dots each, fixed seed. About 0.02 to 0.04 is the floor from counting 4,000 dots in 36 bins. Dot 1 is the first dot of each run.
The outlines wobble a little around the blue shape. That is only counting noise, from using 4,000 dots. The two crowds agree with the exact curve, yet dot 1 sits in a different place in each. The paper’s whole story rests on this: many different processes can produce the same path of distributions. The framework lets us describe all of them with one kind of object.
We follow the paper in order. First the two methods on their own, then the proof that they match. Then the framework: paths, generators, the equation that links them, the loss that trains them, and the sum that mixes them.
Chapter 1
Follow one number as noise buries it, then run the sampler that digs it back out
Take a photo and look at it through frosted glass. Now thicken the glass, a little at a time. First you lose the fine detail. Then the shapes. At the end you see only grey fuzz. Nothing mysterious happened: each step mixed in a bit more noise and let a bit less of the photo through.
A diffusion model learns to run that film backward. If it can look at a slightly fuzzier picture and guess the slightly clearer one, then it can start from pure fuzz and walk all the way to a photo. This chapter writes the film as one equation, and the walk back as three lines.
The paper writes a corrupted sample as a weighted mix. Here x is a clean data point (one pixel, or a whole image) and ε is a fresh draw of Gaussian noise (random numbers shaped like a bell curve, with average 0 and spread 1). The time t runs from 0 to 1. In this chapter and the next two, we use the paper’s clock: t = 0 is clean data and t = 1 is pure noise.
The pair (αt, σt) is the noise schedule. A popular choice is αt = cos(πt/2) and σt = sin(πt/2). Work one number. Let x = 2 and ε = 0.8. At t = 0.5, both weights equal 0.7071, so z = 0.7071 × 2 + 0.7071 × 0.8 = 1.414 + 0.566 = 1.980. At t = 1 the weights are 0 and 1, so z = 0.8, which is just the noise.
The learned part is a network fθ. You give it the corrupted sample zt and the time t, and it estimates the clean data x. In an image model, the input and the output are both arrays of shape (B, C, H, W), for a batch of B images (the shapes here are illustrative; the paper names none). The training pair is easy to make: take real data x, pick a t, draw ε, build zt with the equation above, and ask the network to give back x. The paper does not fix the loss in this section. Section 4.3 later says that a standard denoising diffusion model is a flow model trained with a squared-error loss, which is the usual choice.
Sampling starts from z1, a draw of pure noise. At each step the sampler does three things. It asks the network for its best guess of the clean data, x̂. It works out which noise draw would explain the current sample, ε̂. Then it re-runs the forward film, but at a lower noise level r < t, using those two guesses.
This is the DDIM sampler (denoising diffusion implicit models, Song, Meng and Ermon). The paper stresses one fact about it. All the randomness is in z1. After that first draw, every step is a fixed calculation. You can also skip time points and use far fewer steps than the full schedule. The paper names this as the reason DDIM samples efficiently.
In code, the whole sampler is a short loop. Each pass costs one network call, so ten steps cost ten calls.
pythonz = torch.randn(B, C, H, W) # z_1: pure noise, the only randomness
for t, r in zip(ts[:-1], ts[1:]): # ts runs from 1.0 down to 0.0
x_hat = net(z, t) # (B, C, H, W) estimate of the clean data
eps_hat = (z - alpha(t) * x_hat) / sigma(t)
z = alpha(r) * x_hat + sigma(r) * eps_hat
# z is now a sample (at r = 0, alpha = 1 and sigma = 0, so z = x_hat)
To see the loop with no trained-network error in the way, the device below gives it a perfect network for a tiny world: the data are the two numbers −2 (35% of the time) and +2 (65%). A perfect network returns the exact average of all clean values that could have produced z. Try one step first.
Each line is one of 50 dots walking from noise (left, t = 1) to data (right, t = 0). Each corner is one network call. Drag the number of steps. The blue rings are the true data.
Toy: the “perfect network” is the exact average of the two possible clean values (weights 35% and 65%) given z, so no training is involved. 2,000 dots, fixed seed, steps evenly spaced in t. “On a data point” means within 0.3 of −2 or +2.
With one step, every dot lands on the same spot, 0.60. That is the average of the data (−2 × 0.35 + 2 × 0.65), and it is a place where no data ever lives. This is the failure to remember. The symptom is a blurry average. The measurement is 0% of dots within 0.3 of a data point. The fix is more steps: with 3 steps, 94% of dots land on a data point, and with 8, essentially all of them.
Why does one step blur? At t = 1 the sample is pure noise and carries no hint about which cluster to pick. The best single guess is the average of all of them. Later steps carry a hint, because the sample has already drifted a little toward one cluster.
The paper also writes the film as a stochastic differential equation (SDE): a rule for how a quantity changes in a tiny time step dt, plus a random kick. The forward film is dzt = ft zt dt + gt dW. Here ft pulls the sample toward zero, dW is a tiny Gaussian kick of size about √dt (Brownian motion), and gt sets how big the kicks are. The pair (ft, gt) is the other way to write the schedule; Chapter 3 links the two.
To sample, run the SDE backward in time. The backward rule needs the score, written ∇ log pt(z). The score is an arrow that points toward where samples are more likely at time t. It is the missing piece that tells the backward walk which way is “back toward data”. The paper’s backward rule has one extra dial.
The dial ηt sets how random the sampling is. At η = 0 the kick vanishes and the walk is deterministic, as in DDIM. At η = 1 it is the standard backward SDE. The paper also links η to churn, from Karras and coauthors: the fraction of a backward step that you undo by adding noise again.
Chapter 2
Draw a straight line from a data point to a noise draw, and see that a DDIM step is already a step along it
Imagine a train that must go from a station named Data to a station named Noise. The simplest timetable is a straight track at constant speed. At time 0 the train is at Data. At time 1 it is at Noise. At any time in between, it is a fixed fraction of the way along.
That is flow matching. Chapter 1 mixed data and noise with two weights that came from a schedule. Flow matching picks the plainest schedule there is, and the rest follows from it.
Pick a data point x and a noise draw ε. The sample at time t is the point a fraction t of the way from x to ε. We keep the paper’s clock: t = 0 is data and t = 1 is noise.
Compare this with Chapter 1. If we set αt = 1 − t and σt = t, the diffusion film zt = αt x + σt ε becomes exactly this straight line. So Gaussian flow matching is a diffusion with one particular noise schedule. Work one number: x = 2, ε = 0.5, t = 0.8 gives z = 0.8 × 0.5 + 0.2 × 2 = 0.4 + 0.4 = 0.8.
Take two times r < t. The train covered the distance from zr to zt in a time t − r, at a constant speed. We call the speed the velocity, v. Subtract the two positions and the data cancels in a useful way.
zt − zr = (t − r) ε − (t − r) x = (t − r)(ε − x), so v = ε − x
The velocity is the noise minus the data. It never changes along the trip. The network fθ now has a new job: given zt and t, estimate that velocity, v̂ = fθ(zt; t) = ε̂ − x̂. The input and output shapes are the same as in Chapter 1, (B, C, H, W) (illustrative). Only the target changes: ε − x in place of x.
To sample, ride the train backward. Start at noise (t = 1) and step toward data. Each step moves against the velocity: zr = zt + (r − t) v̂. Because r < t, the factor (r − t) is negative. This is the Euler method, the simplest way to follow an arrow field: move a short step along the arrow, then read the arrow again.
Here is the first real result for this paper’s argument. Put the linear schedule into the DDIM step from Chapter 1. The step was zr = αr x̂ + σr ε̂, which now reads zr = (1 − r) x̂ + r ε̂. Now start from the Euler step and expand it, using zt = (1 − t) x̂ + t ε̂ (the definition of ε̂).
zt + (r − t)(ε̂ − x̂) = (1 − t) x̂ + t ε̂ + (r − t) ε̂ − (r − t) x̂ = (1 − r) x̂ + r ε̂
The two right-hand sides match. A DDIM step with the linear schedule and an Euler step along the learned velocity are the same calculation. Check it with numbers. Let x̂ = 2 and ε̂ = 0.5 at t = 0.8, so zt = 0.8. Then v̂ = 0.5 − 2 = −1.5. Go to r = 0.5. Euler gives 0.8 + (−0.3)(−1.5) = 0.8 + 0.45 = 1.25. DDIM gives 0.5 × 2 + 0.5 × 0.5 = 1.0 + 0.25 = 1.25. Same.
The device below runs both on any estimates you like. The identity does not depend on the network being any good.
The grey line runs from the clean estimate x̂ to the noise estimate ε̂. The sample zt sits a fraction t of the way along. Both rules slide it to a fraction r. Drag any slider.
Exact arithmetic in your browser, no trained model. The “difference” is the computer’s rounding error, which is why it is not always printed as exactly zero.
Whatever you choose, the two answers agree to the last digit the computer keeps. This is the paper’s first equivalence, and it is worth saying what it does not say. It says the sampling steps match when the schedule is linear. It does not say the two training recipes are identical in every detail. Chapter 7 gets to the loss.
Let the steps shrink to zero and the train follows an ordinary differential equation (ODE): dzt = ut dt, where ut = α̇t x + σ̇t ε is the velocity and the dots mean “rate of change in t”. An ODE has no random kick, so its path is fixed once the start is fixed. To generate, you run it backward in time.
The paper then adds a score-correction term, because in practice the network only approximates the velocity. It writes the backward flow as dzt = (ut − ½ εt2 ∇ log pt(zt)) dt, and an SDE version that adds a kick εt dz. Here εt (with a subscript t) is the level of randomness, the knob that plays the role of ηt gt from Chapter 1. It is not the noise draw ε. Tune it up and the sampler becomes more stochastic.
Chapter 3
Turn the drift and the kick of a random equation into the two weights that mix data with noise, and check the result against a simulation
A leaf floats on a pond. A slow current pulls it toward the middle. Ripples kick it left and right at random. After a minute, where is the leaf? Even if you knew where it started, you could say only two things: it is probably a little closer to the middle, and it is somewhere inside a cloud of possible places.
Chapter 1 gave the diffusion film in two forms. One form was a mix, zt = αt x + σt ε. The other was a random equation with a pull and a kick. This chapter shows how to get from the second form to the first. It is the paper’s Section 2.3, and it is the bridge that lets us call the two views one.
The random equation was dzt = ft zt dt + gt dW. Read it as the leaf. The term ft zt is the drift, the current: a push whose size depends on where the leaf is. The term gt dW is the diffusion: ripples of size gt. Start at z0 = x.
First ask what the current alone would do. Switch the ripples off and you have the plain equation żt = ft zt. Its solution is zt = αt x, where the paper defines the scale factor as follows. The symbol ∫ means “add up the tiny pieces”, so ∫0t fr dr is the total pull from time 0 to time t.
Now bring the ripples back. They add random noise on top of the shrinking signal. But a ripple that lands early gets shrunk by the current afterwards, while a ripple that lands late does not. To compare them fairly, measure each ripple in the frame where the shrinking has been divided out. A ripple of size gr at time r then counts as gr / αr, which is gr exp(−∫0r f). Independent ripples add their squares, so the total noise variance in that frame is:
The last link is the paper’s third formula, εt = ηt gt. It says the random-kick level of the sampler (Chapter 2) is the forward ripple strength, scaled by the dial η from Chapter 1. So the three SDE numbers (f, g, η) fix the three mixing numbers (α, σ, ε).
There is one detail to handle with care. The paper’s σt is the noise in the frame where the shrinking has been divided out. The noise inside zt itself is the shrunk version, which is αt σt. So if you want the σ of the mix zt = αt x + σt ε from Chapter 1, multiply the paper’s value by αt. In the special case f = 0, α = 1 and the two coincide. Here is a worked case, with f = −0.5, g = 1 and t = 1.
α = e−0.5 = 0.6065; paper’s σ2 = (1 − e1) / (2 × (−0.5)) = 1.7183, σ = 1.3108; noise inside z = 0.6065 × 1.3108 = 0.7951
As a test of this scale: for these numbers, α2 + 0.79512 = 0.3679 + 0.6321 = 1.0000. The mix keeps a constant total variance, as a variance preserving diffusion should. If we had used the paper’s 1.3108 directly, the total would be 2.09. The device below tests the same claim against a simulation of the forward SDE.
Set the pull f and the ripple size g. The lines are the formulas. The dots are measured from 3,000 simulated paths that all start at x = 0. Do the dots land on the purple line?
Constant f and g for simplicity (the paper’s formulas allow any ft and gt). The closed forms are α = eft and, for the noise inside z, g√((e2ft − 1)/(2f)); the simulation is Euler-Maruyama with 200 steps and a fixed seed. This is our check of the formula, not an experiment from the paper.
Slide f to 0 and the grey and purple curves meet, since α = 1. Slide f below 0 and they split: the grey curve (the paper’s effective noise) rises above the purple one (the noise in z). The dots follow the purple one, so the scale note above is right.
The paper leaves the reverse direction as an exercise. Here is the answer. Suppose someone hands you (αt, σt), meaning zt = αt x + σt ε. The pull must reproduce the shrinking, so ft = α̇t / αt. The noise variance V = σ2 must grow by the pull stretching it (2fV) plus the new ripples (g2), so gt2 = d(σt2)/dt − 2 ft σt2.
Try the flow schedule α = 1 − t, σ = t. Then f = −1/(1 − t) and g2 = 2t + 2t2/(1 − t) = 2t/(1 − t). Both grow without bound as t approaches 1, because the signal weight α reaches 0 there. That is a small reason to prefer writing flow matching as a straight-line film and an ODE: the weights stay finite.
Chapter 4
Describe a generative model by the sequence of crowds it moves through, and see two ways to build that sequence
A flock of starlings leaves a field at dusk. A photographer takes one picture every second. In the first picture the birds are scattered across the field. In the last they form a tight cloud over the trees. You cannot follow any one bird, but the pictures, laid in order, tell the story.
Generator Matching describes a generative model in exactly this way. It does not care how any one bird flies. It cares about the sequence of pictures, and then asks which kinds of motion can produce that sequence. This chapter builds the sequence. The next two chapters build the motion.
From here on we use the clock of the paper’s Section 3, which runs the other way from Chapters 1 to 3. Now t = 0 is noise and t = 1 is data. It is the more natural direction for a generator: it starts at the prior and ends at the answer. (The two clocks are related by tnew = 1 − told.) The sampler at the top of this page, and every device from here on, uses this clock.
A probability path is a list of distributions pt, one for every time t from 0 to 1. At the start, p0 = psimple, an easy distribution we can sample from, usually Gaussian noise. At the end, p1 = pdata, the distribution we want. In between, pt is the crowd at time t. The paper calls it the marginal path because it describes the whole crowd, not any single bird.
We cannot write the middle distributions down directly. So we build them from simple pieces. Pick a single data point z. Decide what the crowd would look like at time t if the data had only that one point. That is the conditional path, written pt(dx | z). (The notation dx means “a tiny region around x”.) Then average over all data points:
This is the only design choice in the whole framework: the prior p0 and the conditional path. The paper names two common choices.
The first is a mixture. At time t, a coin with chance κt decides: with probability κt the dot is exactly at z, otherwise it is still a fresh draw from the noise p0. The number κt rises from 0 to 1.
pt(dx | z) = (1 − κt) · p0(dx) + κt · δz(dx)
The symbol δz is a delta distribution: all its probability sits on the single point z, like a spike. The mixture never moves a dot partway. A dot is either still noise or has already jumped to its answer.
The second is a geometric average, for spaces like Rd where positions can be blended. Draw noise x0, and place the dot at a blend of noise and data:
pt(dx | z) = Ex0 [ δσt x0 + αt z(dx) ]
In words: the dot is at σt x0 + αt z, averaged over the noise draw x0. Here αt rises from 0 to 1 and σt falls from 1 to 0. This is the same film as Chapters 1 and 2, now in the new clock. The dot slides smoothly. Work one example with αt = κ = 0.5 and z = 2. The geometric dot is at 0.5 x0 + 1, a bell curve centred at 1 with spread 0.5. The mixture dot is at 2 with chance 0.5, and otherwise anywhere a noise draw would land.
Why would anyone want the mixture? Think of a word. Between “cat” and “dog” there is no 40% of the way. A dot there would be nonsense. For spaces like this, with a finite list of states, the mixture is the natural path. The paper notes that for such spaces the generator is a rate matrix and the process is a continuous-time Markov chain (CTMC). Chapter 5 returns to that.
8,000 dots, two data values (−2 and +2). Top: the mixture path. Bottom: the geometric path. Drag the progress κ and compare. Bars that hit the top are spikes.
Toy, our own construction in the paper’s notation: the data are exactly −2 (35%) and +2 (65%) and p0 is a standard Gaussian. The geometric path uses α = κ and σ = 1 − κ. “Exactly on” counts dots that equal a data value to the last digit.
At κ = 0 and κ = 1 the two paths agree. In between they differ a lot. The mixture keeps a noise bump that only shrinks, plus two spikes that only grow. The geometric path has a single bump that slides toward the data and narrows. Yet the average position of the crowd is the same in both, up to counting noise, because both blend the same pair (noise, data) with the same weights. Different paths can share some statistics and differ in the rest.
Chapter 5
Ask a moving crowd one question, and read the answer as a rate with a flow part, a diffusion part and a jump part
You play a board game. Your next square depends on the square you stand on and on a roll of dice, and on nothing else. It does not matter how you got to the square. This forgetting is called the Markov property, and a process that has it is a Markov process.
Every sampler in this lesson is a Markov process. The dot at time t+h depends on the dot at time t and on fresh randomness, not on the path before. The paper’s big idea is to describe a Markov process by a single object that tells you how it changes right now. That object is the generator.
Write Xt for the position of one dot at time t. The transition kernel kt+h|t(· | x) is the distribution of Xt+h if Xt = x. It is the full table of odds for the next short hop. If h is zero, nothing has happened yet, so the dot is still at x with certainty: kt|t(· | x) = δx, a spike at x.
For a small h, the kernel changes only a little from that spike. The paper writes this with a first-order Taylor expansion (“a tiny change is a slope times a tiny step”):
A whole distribution is a big object. The paper makes it manageable with test functions. A test function f is a question you ask each dot. “What is your position?” is f(x) = x. “What is the square of your position?” is f(x) = x2. The average answer across the crowd is ⟨pt, f⟩ = Ex~pt[f(x)]. If you know the average answer to every question f in the set, you know the distribution. That is why the paper says the test functions “fully characterize” it.
Now ask the question of a single dot over a hop. Starting from x, the expected answer after time h is E[f(Xt+h) | Xt = x]. The generator is how fast that expected answer moves away from f(x):
A generator is just a derivative: the instant rate of change of an expected answer. The paper adds that, under mild conditions, there is a one-to-one match between Markov processes and generators. Know one and you know the other.
On the real line, every generator the paper writes splits into three pieces. Each has a simple recipe for a short hop, and each gives its part of L f by a quick Taylor expansion.
Work a number. Take the question f(x) = x2 at x = 1. Let the flow velocity be u = −1, the kick size σ = 0.8, and let the dot jump by +1 at rate λ = 1 (so it jumps in a hop of length h with probability about λh). The flow part is f′ u = 2x u = −2. The diffusion part is ½ f″ σ2 = ½ × 2 × 0.64 = 0.64. The jump part is λ [(x+1)2 − x2] = 1 × (4 − 1) = 3. The total is −2 + 0.64 + 3 = 1.64. The device checks this against a simulation of short hops.
Choose a question f and set the dot’s rule at x = 1. The bars add the flow, diffusion and jump parts into the formula total. The teal mark is measured from 200,000 simulated hops.
Our check, not the paper’s. The simulation takes hops of length h = 0.01 from x = 1: X = 1 + uh + σ√h Z, plus a jump of +1 with probability λh, and averages (f(X) − f(1))/h over 200,000 dots (paired ±Z draws and evenly spread jumps keep the noise small).
Switch to f(x) = x and the diffusion part disappears, because a straight-line question has no curvature to feel the kicks. The flow and jump parts remain: u + λ. So different questions reveal different parts of the process. The generator holds all of them at once.
Now let the dot live on a short list, say the 50,000 words of a vocabulary. There is no velocity and no blend. The process can only hop from word to word. Its generator is then a table of hop rates: the rate matrix Qt, where Qt(y | x) is how fast probability flows from word x to word y. The matching process is a continuous-time Markov chain (CTMC). The jump part above is exactly this, with the integral turned into a sum over y. Our CTMC lesson builds it in detail.
Chapter 6
Link a generator to the crowd it creates, then average many simple generators into the one the network must learn
A shopkeeper tracks the average price of the goods on a shelf. Each item changes price at its own rate: some rise, some fall. The shopkeeper does not need to watch every item to know how the shelf average moves. She only needs the average of the individual rates. That plain bookkeeping fact is the Kolmogorov forward equation.
The previous chapter gave us two objects. A path pt says which crowd should exist at time t. A generator Lt says how each dot changes. This chapter connects them, and then uses the link to build the generator that matches a path.
Ask a question f of the whole crowd and take the average answer, ⟨pt, f⟩. Its rate of change is the average of the individual rates. The paper writes this as the Kolmogorov forward equation (KFE):
The proof takes three short steps. Write the average one hop later, E f(Xt+h) = E[ E[ f(Xt+h) | Xt ] ]. Replace the inner average with its definition from Chapter 5, which is f(Xt) + h Lt f(Xt) plus a smaller error. Subtract E f(Xt), divide by h, and let h go to zero. What is left is E[Lt f(Xt)].
The paper says the link runs both ways. If you give a generator, you get the path. If you give a path, you can recover a generator that satisfies the equation. This second direction is the one we use: we choose the path, and we ask for a generator that makes it happen.
Check it with numbers. Take noise N(0,1) and two data points −2 and +2, a flow with the straight-line path xt = (1 − t) ε + t z, and the question f(x) = x2. The average of xt2 is (1 − t)2 + 4t2 (since E[ε2] = 1, E[z2] = 4 and ε and z are independent). Its rate of change is −2(1 − t) + 8t, which is 3 at t = 0.5. The right side needs the average of 2x ut(x). For this path u = z − ε, so it is 2E[((1 − t)ε + tz)(z − ε)] = 2(4t − (1 − t)), also 3 at t = 0.5. The two sides agree.
Now the main step. For one data point z, the conditional path of Chapter 4 has an easy generator Lzt. For the straight-line path to z, the dot’s velocity at x is ut(x | z) = (z − x) / (1 − t): head straight for z, and cover the remaining distance in the remaining time. We want the generator of the marginal path, the one that works when the data have many points.
The dot at x does not know its destination z. Many destinations could have led there. The right move is to weigh each destination by how likely it is, given that the dot is at x at time t. This weight is the posterior p1|t(z | x), found by Bayes’ rule: it is proportional to how common z is in the data, times how likely the conditional path puts a dot at x. The paper’s result is that the marginal generator is the posterior average of the conditional generators:
Because the generator is a sum of a flow part, a diffusion part and a jump part, and each part is linear in its ingredient, the average splits. The marginal velocity is the posterior average of the conditional velocities. The marginal squared kick size is the posterior average of the conditional ones. The marginal jump rate Q is the posterior average of the conditional rates. The paper writes all three on one line.
Take the probe x = 0.5 at t = 0.5, with data +2 (65%) and −2 (35%). The conditional velocities are (2 − 0.5)/0.5 = 3 for the +2 destination and (−2 − 0.5)/0.5 = −5 for the −2 destination. The posterior says the dot is far more likely heading to +2. Weight 0.65 × exp(−0.5) = 0.394 for +2 and 0.35 × exp(−4.5) = 0.0039 for −2 (the exponents are −d2/(2(1−t)2), with d the distance from t z to x). The shares are 99.0% and 1.0%. The marginal velocity is 0.990 × 3 + 0.010 × (−5) = 2.92.
Each thin line is the velocity a dot would have if it knew its destination. The thick curve is the marginal velocity, their posterior average. The shaded shape shows where the crowd is. Drag the time and the probe.
Toy: data exactly at −2 (35%) and +2 (65%), a standard Gaussian prior, the straight-line path. The check at the end averages 2x ut(x) over 20,000 dots drawn from the path. This is our check of the forward equation, not an experiment from the paper.
Look at the thick curve. Far to the left of the crowd it follows the −2 line, and far to the right it follows the +2 line. Near the middle it switches from one to the other, and the switch gets sharper as t grows. The marginal field is not straight even though every conditional field is. This is the earlier warning made visible. The network learns the bent average, and the dots follow bent paths.
The paper then writes the whole marginal generator for Rd in one formula. We have only expressed it in words and in the scalar case above. Its three parts are the posterior averages E[ut(x|z)], E[σt2(x|z)] and E[Qt(dy; x|z)].
Chapter 7
Teach a network to output the marginal generator by showing it only conditional examples, and see why the average comes out right
A teacher wants a student to guess the price of a house from its photo. She cannot show the student the “true” price of a photo, because many houses look alike and sell for different amounts. She can show one sale at a time: this photo, this price. After thousands of sales, the student learns to guess the average price for a look. Nobody ever showed her that average. It emerged from the penalty for being wrong.
Generator Matching trains a network the same way. The thing we want, the marginal generator, is an average over destinations that we cannot see. What we can see is one destination at a time. This chapter shows why that is enough.
The generator is built from simple ingredients: a velocity u, a kick size σ2, a jump rate Q. The paper packs them into one object, Ft(x), and says the generator is linearly parameterized by it. That means Lt is a linear function of Ft, so averaging F averages L, and the averaging rule from Chapter 6 carries over to F. For a pure flow model, F is simply the velocity u. For a model with jumps, it also holds the jump rates.
The network Ftθ(x) takes the position x and the time t and returns an object of the same type as F. Its job is to match the marginal Ft(x). The paper scores a guess with a Bregman divergence D, which we explain next. The first loss is the ideal one.
A Bregman divergence comes from any smooth bowl-shaped function φ (strictly convex, in the paper’s words). It is the gap between φ(a) and the straight-line estimate of φ(a) from the point b: D(a, b) = φ(a) − φ(b) − ⟨∇φ(b), a − b⟩. The paper prints a plus sign in front of the last term. The standard definition has a minus, which makes D non-negative and zero only when a = b, so we use the minus. With φ(a) = a2, D(a, b) = (a − b)2, the plain squared error.
The ideal loss cannot be computed, since we do not know the marginal Ft(x). So the paper swaps in the loss you can compute, using one destination z at a time:
The paper states that the two losses have the same gradients, so minimising one minimises the other. Here is the reason in three lines. Fix x and t, and let Y be the conditional ingredient Fzt(x), which varies with z. For any Bregman divergence, E[D(Y, b)] = D(E[Y], b) + (E[φ(Y)] − φ(E[Y])). The second term does not contain b, so it does not depend on the network at all. The first term is exactly the ideal loss, because E[Y] is the marginal F. Therefore the best output is b = E[Y], the posterior average from Chapter 6.
The device below lets you see it. At t = 0.5 and a position x, a dot may be heading to +2 or to −2, and the two destinations give two conditional velocities. Your guess is one number. Slide it and watch the cost.
The two blue marks are the conditional velocities a dot might have, sized by their posterior weight. The curve is the average cost of a guess. Pick a loss, then drag the guess to the bottom of the curve.
Toy at t = 0.5 with the data at −2 (35%) and +2 (65%); weights come from Bayes’ rule as in Chapter 6. The curve is drawn on a square-root scale so that all three losses fit. The “absolute” loss is our contrast case: it is not a Bregman divergence, and the paper does not use it.
With the squared loss and the quartic Bregman loss, the bottom of the curve sits at the same place: the weighted average of the two velocities. With the absolute loss, it jumps to the heavier target. This is the whole point of requiring a Bregman divergence. It is the family of losses whose best guess is the mean, which is exactly the marginal ingredient. A loss from outside that family would teach the network the wrong thing.
For a pure flow model with the squared loss (the case the paper calls out in Section 4.3), a training step is short. Let B be the batch size and d the size of one data point. The shapes below are illustrative.
z = data_batch() # (B, d) real data, the destinations eps = torch.randn(B, d) # (B, d) noise, the starting points t = torch.rand(B, 1) # (B, 1) one random time per example x_t = (1 - t) * eps + t * z # (B, d) a dot on the conditional path target = z - eps # (B, d) F_t^z(x_t): conditional velocity pred = net(x_t, t) # (B, d) F_t^theta(x_t): the network's guess loss = ((pred - target) ** 2).mean() # Bregman divergence with phi(a) = a^2 loss.backward(); opt.step()
The network never sees which z a dot came from. It sees only xt and t, as at sampling time. Many different z produce the same xt, and the squared loss averages their targets. That is the whole mechanism.
Chapter 8
Add generators to build a dial from flow to diffusion, then weigh the paper’s argument that the flow end of the dial is the sturdier one
Two cooks make the same soup by different methods. One simmers it slowly with no stirring. The other stirs hard while it heats. If both soups end with the same flavour, you may blend the methods: stir a little, simmer a lot. The result is still the same soup. This chapter shows the exact condition under which that is true for generators, and then asks whether one method is safer than the other.
The paper’s Section 3.5 rests on one fact. A generator Lt is a linear operator: L(af + bg) = aLf + bLg. And the forward equation of Chapter 6 is a linear equation in L. Now suppose two generators L and L′ both produce the same path pt. Mix them with weights a, b ≥ 0 that add to 1:
So the mixed generator also satisfies the forward equation: it makes the same path. The paper concludes that diffusion, flow and jump processes can be combined inside one generator. It adds, citing the original Generator Matching paper, that this gives more diverse samples and closer approximations. We did not check that source, and the present paper runs no experiment on it.
Which second generator should we mix with the flow? The paper names a “divergence-free, Langevin-like” one. Here is what that means in the simplest terms. Take a process with a random kick of size g and a drift that pushes dots uphill toward likelier places, with strength ½ g2 times the score. The kick scatters the crowd. The uphill push gathers it. At every moment the two cancel exactly, and the crowd pt does not change. A generator that leaves the crowd unchanged adds zero to the forward equation, so it can be added to the flow for free.
Adding it to the flow gives the sampler:
This matches the paper’s backward-time formula from Chapter 2. There it is written with the opposite sign on the score term, because time runs from 1 to 0 on that clock. At g = 0 you recover the plain flow. Turning g up is the dial. The sampler at the top of the page is exactly this equation, with g set to 0, 1 or 2.
To run it you need the score. For the straight-line path, the score follows from the velocity the network already gives you: ∇ log pt(x) = (t ut(x) − x) / (1 − t). (We derived this from E[ε | x] = x − t u; the paper does not state it.) We checked it on the toy to 14 digits. Near t = 1 the division by 1 − t blows up, so real samplers stop a little short of 1.
pythonx = torch.randn(B, d) # (B, d) start at t = 0
for k in range(K):
t = torch.full((B, 1), k / K)
u = net(x, t) # (B, d) learned velocity
s = (t * u - x) / (1 - t) # (B, d) score from the velocity
x = x + dt * (u + 0.5 * g**2 * s) + g * dt**0.5 * torch.randn(B, d)
# g = 0 is the pure flow ODE; larger g adds the cancelling kick
A last remark on the paper’s proposal in Section 4.3: let the kick size depend on position, g(x). The cancelling push is then ½ g2 ∇ log p + ½ ∇(g2); the extra term is easy to forget. The paper suggests a learned, state-dependent schedule that adds noise where the data are complex and relies on the flow where they are simple. It cites a time-series paper for the idea and runs no experiment. Treat it as a research direction.
The paper’s second claim is that the flow end of the dial is more robust. Its reasoning is about the equations the two methods obey. A diffusion step smooths, like heat spreading through a metal bar. It is a second-order equation (it involves a second derivative, the Laplacian). Smoothing is easy to do and hard to undo. Blur a photo and add one grain of noise: sharpening it back raises that grain into a storm. The paper says this inversion is ill-posed, meaning small errors can become huge and the answer may not be unique. A flow only carries mass along arrows. It is a first-order equation, and a small error in the arrows moves mass a small distance.
The device below makes the mathematical core of that argument concrete. In the heat equation, a wave of frequency k decays by the factor e−k2τ after time τ. To undo it, you must multiply by ek2τ. In a transport equation, a wave of any frequency only slides, so undoing it multiplies by exactly 1.
Each bar group is a wave of frequency k from 1 to 8. Purple: how many powers of ten an error grows when a heat step of length τ is undone. Pink: the same for undoing a slide. Drag τ.
Textbook arithmetic, not the paper’s experiment: the 1D heat equation ∂tu = ∂xxu on a periodic domain, where mode k is scaled by e−k²τ, against pure transport, where mode k only gets a phase shift of size 1. The assumed starting error is 0.001 in every mode. It shows why undoing smoothing is ill-posed; it does not show how a trained diffusion sampler behaves.
At τ = 0.2, the eighth wave is multiplied by e12.8, about 360,000. An error of 0.001 becomes 360. For the slide, it stays at 0.001. This is the sharpest form of the paper’s argument. But a sampler does not invert the heat equation in Fourier space. It runs a learned reverse process that also uses a score, and the score term is a correction. So we ran the other direction ourselves.
On our toy, give the velocity a constant error b (a bias in the network’s output), keep the score exact, and sweep the noise strength g from 0 (pure flow) to 2. Measure how far the final crowd lands from the target. The button runs the 15 simulations.
Each point is one run of 4,000 dots. Lower is better. Press Run the sweep, then compare the three lines.
Our toy, same world and settings as the sampler at the top (60 Euler steps, 4,000 dots, seed 3, total variation over 36 bins; about 0.02 to 0.03 is the counting floor). The error is a constant added to the drift and the score is exact. This is a different setting from the paper’s argument and is not a test of it.
Here is what the toy shows. With no error, every noise level lands near the floor, 0.024 to 0.026, until g = 2, where the 60-step discretisation costs a little (0.055). With a velocity error of 0.6, pure flow ends 0.437 away from the target, and a noise strength of 2 cuts that to 0.086. The extra noise, with its score term, pulls dots back toward the right crowd. In this setting the noisier sampler is the more forgiving one.
Does that contradict the paper? Not directly. The paper argues about the stability of inverting a smoothing operator when the drift or density estimate has small errors. Our toy has a bias in the velocity and a perfect score. The two settings differ, and a short note cannot settle which matters for trained models. The honest summary is this. The paper offers an argument, not a measurement. The argument is clear about the mathematics (Chapter 8’s first device). Whether a trained flow beats a trained diffusion for these reasons is left to experiments the paper does not contain.
Chapter 9
Keep the numbers, the terms, the checklist and the core code, and know what the paper leaves open
Diffusion and Gaussian flow matching are one family. A diffusion corrupts data with zt = αt x + σt ε. Flow matching is the case α = 1 − t, σ = t, and its Euler step equals a DDIM step. The drift f and ripple g of the diffusion SDE fix α and σ. Generator Matching puts both in one frame: a path of crowds pt, a generator Lt for the motion, and the forward equation linking them. A network learns the marginal ingredient Ft by regressing on conditional targets with a Bregman loss. Generators add, so a flow plus a cancelling Langevin-like part gives a dial from deterministic to noisy sampling. The authors argue the first-order flow end is more robust. They run no experiment.
| What | Number | Where it comes from |
|---|---|---|
| The paper | 7 pages, 3 authors, 0 tables, 0 figures, 0 experiments | The paper itself (arXiv:2412.11024) |
| Flow schedule | αt = 1 − t, σt = t, velocity v = ε − x | Paper, Section 2.2 |
| DDIM vs Euler, linear schedule | x̂ = 2, ε̂ = 0.5, t = 0.8 to r = 0.5: both give 1.25 | Chapter 2, our worked check |
| One DDIM step, perfect network | 0% of dots on a data point, all at 0.60; 3 steps: 94% | Chapter 1 toy (cosine schedule) |
| SDE to schedule, f = −0.5, g = 1, t = 1 | α = 0.6065; paper’s σ = 1.3108; noise inside z = 0.7951 | Chapter 3, formula and simulation |
| Generator of f = x² at x = 1 | flow −2 + diffusion 0.64 + jump 3 = 1.64 | Chapter 5, formula and short hops |
| Marginal velocity at x = 0.5, t = 0.5 | 0.990 × 3 + 0.010 × (−5) = 2.92 | Chapter 6 toy |
| Forward equation for f = x² at t = 0.5 | left side 3, right side 3 | Chapter 6, by hand and by simulation |
| Best guess under a Bregman loss | −0.16 (the average); absolute loss: −3.80 | Chapter 7 toy at x = −0.1 |
| Heat step undone, mode 8, τ = 0.2 | error grows by e12.8, about 360,000 | Chapter 8, textbook arithmetic |
| Velocity error 0.6, distance from target | 0.437 at g = 0; 0.086 at g = 2 | Chapter 8 toy, not the paper |
| Term | Plain meaning | Chapter |
|---|---|---|
| Marginal probability path | The crowd at each time, from noise to data | 4 |
| Conditional path | The crowd if the destination were one known data point | 4 |
| Generator Lt | The instant expected rate of change of any question f | 5 |
| Test function | A question you ask every dot, such as its position | 5 |
| CTMC | A process that hops between a finite list of states at set rates | 5 |
| Kolmogorov forward equation | The crowd’s average changes at the average of the dots’ rates | 6 |
| Bregman divergence | A distance whose best single guess is the mean | 7 |
| Markov superposition | Mixing generators with weights that add to 1 | 8 |
pythondef train_step(net, opt, data_batch):
z = data_batch() # (B, d) destinations
eps = torch.randn_like(z) # (B, d) noise
t = torch.rand(z.size(0), 1) # (B, 1) times in [0, 1]
x_t = (1 - t) * eps + t * z # (B, d) dot on the conditional path
loss = ((net(x_t, t) - (z - eps)) ** 2).mean() # Bregman, phi(a) = a^2
opt.zero_grad(); loss.backward(); opt.step()
@torch.no_grad()
def sample(net, B, d, K=60, g=0.0, t_end=0.98):
x, dt = torch.randn(B, d), t_end / K
for k in range(K):
t = torch.full((B, 1), k * dt)
u = net(x, t) # learned velocity
s = (t * u - x) / (1 - t) # score from velocity (straight-line path)
x = x + dt * (u + 0.5 * g**2 * s) + g * dt**0.5 * torch.randn_like(x)
return x # g = 0 is pure flow; g > 0 mixes in diffusion
The paper is a theory note, and its limits are plain. It has no experiments, so the claim that flow is more robust is an argument, not a measurement. The equivalence is shown for the Gaussian case. The state-dependent noise schedule of Section 4.3 is a proposal, with no test. The treatment of regularity (when generators and processes match one to one) is a short remark.
A reader should also know the places where the text is loose. The clock flips between Sections 2 and 3. The symbol ε is used both for the noise draw and for the sampler’s randomness level. The Bregman divergence is printed with a plus sign where the standard definition has a minus. The formula for σt gives the noise before it is scaled by αt (Chapter 3). The ODE line carries a score term that belongs with the SDE (Chapter 2). None of these changes the main ideas, and each is fixed in the chapters above.
This note reads the Generator Matching framework of Holderrieth and coauthors (2024) through two familiar models. The framework is the general machine, and diffusion and flow matching are two of its settings. For the step-by-step view of flow matching itself, see the lecture reading Flow Matching Guide and Code. For this paper as part of MIT’s course, see Lecture 10, Modern Generative AI.
Now press Present or Teach and explain from memory why a DDIM step equals an Euler step, and why a conditional target trains a marginal generator. Then go back to the sampler at the top, set the network error to 0.45, and explain why the noisy sampler ends up closer to the target than the pure flow.
Credit: “Exploring Diffusion and Flow Matching Under Generator Matching” by Zeeshan Patel, James DeLoye and Lance Mathias, UC Berkeley, December 2024. arXiv:2412.11024. All devices, toy numbers and code on this page are ours and are labelled as such.