You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 882e741
Browse filesBrowse the repository at this point in the historyBrowse files
or "Generator Matching for Computer Scientists" - Ben Murrell
128
+
or "Generator Matching for Computer Scientists"
129
+
</div>
130
+
<divstyle="text-align: center; color: #666;">
131
+
by Ben Murrell
129
132
</div>
130
133
</header>
131
134
132
135
<divclass="abstract">
133
-
<strong>Abstract.</strong> We give an intuitive description of generator matching in terms of a simple “resample–and–step” construction. Starting from conditional Markov processes indexed by a data variable $Z$, we define a hypothetical marginal process that, at each time $t$ and state $x$, resamples a fresh $Z$ from the posterior $Z \mid (X_t = x)$ and then moves one tiny step according to the corresponding conditional Markov process. We explain why this process preserves the desired marginal distributions, and why in the small–step limit it is equivalent to running a single Markov process with an <em>averaged generator</em>.
136
+
<strong>Motivation.</strong> Generator Matching (GM) is an incredible framework that subsumes nearly all flow matching and diffusion models.
137
+
Understanding it unlocks the ability to easily construct <ahref="https://arxiv.org/pdf/2511.09465">entirely novel methods</a>, and let's you understand existing approaches with greater clarity.
138
+
Depending on your math background, however, it can be somewhat unapproachable, since it uses the formalism of <ahref="https://en.wikipedia.org/wiki/Infinitesimal_generator_(stochastic_processes)">generators</a> to handle the generality needed to cover all kinds of stochastic processes and state spaces.
139
+
Here we use a simple reframing to attempt to explain Generator Matching without Generators, using only concepts from basic probability. Working through this should make it clear why GM works, and give you the ability to construct your own GM methods without learning measure theory and advanced stochastic processes.
140
+
<p>
141
+
Note: If you are in the target audience for this simplified presentation of GM, this will not be easy reading, and will require some work on your side. But it will be worth it. So set aside a few quiet hours, grab some coffee, and get ready to dive in.
142
+
</p>
134
143
</div>
135
144
136
145
<section>
137
-
<h2>1. High–level picture</h2>
138
-
<p>Generator Matching (GM) starts from two ingredients:</p>
146
+
<h2>1. Preliminaries</h2>
147
+
<p>
148
+
In generative modeling, you typically have a training dataset of samples from some "target" distribution, and you wish to train a model that can generate new samples from this distribution. These could be images, sequences of text, songs, proteins, etc, each with their own state space (continuous, discrete, manifold, or mixtures of these).
149
+
<p> This is what Generator Matching (GM) lets you do. Like <ahref="https://mlg.eng.cam.ac.uk/blog/2024/01/20/flow-matching.html">flow matching</a> (which GM generalizes), this is done by starting from an easy-to-sample-from "prior" distribution, and learning how to transform this into the target distribution. It does this through many small steps in what we call "time" (which we denote with $t$), starting at $t=0$ (the simple prior) and ending at $t=1$ (the target distribution).
150
+
</p>
151
+
<p>
152
+
[Insert image and protein examples.]
153
+
</p>
154
+
<p>
155
+
We denote the state of the model at time $t$ as $x_t$. For example, if you are modeling images, then $x_1$ would be an image from the training dataset, and $x_0$ would be an image with random pixel values.
156
+
</p>
157
+
<p>We need to introduce the notion of a "conditional processs". GM requires that you can:</p>
139
158
<ul>
140
-
<li>a simple “prior” distribution $p_{\text{simple}}$ (usually Gaussian);</li>
141
-
<li>a conditional path of distributions $p_t(\cdot \mid z)$,
142
-
interpolating between the prior and a specific data point $z$.</li>
159
+
<li>sample a $z$ from some distribution $p(z)$, which controls where the process ends when $t=1$.</li>
160
+
<li>conditioned on $z$, sample $x_{t+\Delta t}$ from $p(x_{t+\Delta t} \mid x_t, z, t)$ for some small time step $\Delta t$;</li>
143
161
</ul>
144
162
145
-
<p>The marginal generator turns out to be the appropriate <em>average</em> of the generators of the conditional processes. The goal of this note is to give an intuitive route to why this marginal generator is an average.</p>
163
+
<p>What is $z$? Often $z$ is just a single training data sample $x_1$, but $z$ is an extremely flexible "latent variable", and can include other information that controls the path of the process. More about that later.</p>
164
+
165
+
<p>You can think of $p(x_{t+\Delta t} \mid x_t, z, t)$ as a function that takes the current state $x_t$, the latent $z$, and the time $t$, and returns the next state $x_{t+\Delta t}$, which may or may not involve some randomness. The only constraint is that when you repeatedly step through time by calling this function over and over, when $t$ reaches $1$, the state $x_1$ will be the sample from the training distribution that is associated with the latent $z$.</p>
166
+
167
+
<p>With a simple prior distribution $p(x_0)$ that governs where the process starts, $p(x_{t+\Delta t} \mid x_t, z, t)$ specifies the distribution of each subsequent step, and pins down what we call the "conditional path" (because it is conditioned on $z$ to terminate at a given $x_1$).</p>
168
+
146
169
</section>
147
170
148
171
<section>
149
-
<h2>2. The Posterior Calculation</h2>
172
+
<h2>2. The marginals of the process $p(x_t \mid t)$, and the conditional posterior distribution $p(z \mid x_t, t)$.</h2>
173
+
174
+
<p>Importantly, we can sample from $p(x_t \mid z, t)$, the conditional process at any $t$, by first sampling $z$, sampling $x_0$ from the prior, and then stepping through $p(x_{t+\Delta t} \mid x_t, z, t)$ for each step until $t$ is reached. A central distribution of interest is the <strong>marginal distribution</strong> of $x_t$ at each time $t$. If we have $n$ training data samples, and each $z$ has equal probability, then:
<p>Conceptually, you can think about this as the distribution you get when you repeatedly sample $z$ from $p(z)$ and then sample $x_t$ from $p(x_t \mid z, t)$ and accumulate the $x_t$ samples. This is the marginal distribution of $x_t$ at each time $t$. <strong>Note:</strong> by construction, since each $z$ terminates at a sample from the training distribution, this marginal distribution at $t=1$ is the same as the training data distribution $p(z)$.</p>
150
178
151
-
<p>Define a joint model for $(Z, X_t)$: Sample $Z \sim p_{\text{data}}$, then run a conditional process $(X^z_t)$. In simple flow matching, the conditional path is a straight line:
152
-
$$ X_t = (1-t)X_0 + t Z $$
153
-
where $X_0 \sim \mathcal{N}(0, I)$.</p>
179
+
<p>Using Bayes theorem, we can then write the posterior distribution of $z$ given $x_t$ and $t$ as $p(z \mid x_t, t) \propto p(x_t \mid z, t)$ (since $p(z)$ is a constant). In practice we will not need to calculate it, but we do need to understand what it means to explain GM.</p>
180
+
</section>
181
+
182
+
<section>
183
+
<h2>3. A concrete example</h2>
184
+
185
+
<p>As a working concrete example, we'll consider the case of standard <ahref="https://arxiv.org/abs/2210.02747"> flow matching</a>, where the state space is continuous, $p(x_0)$ is a Gaussian distribution, and the conditional path is simply a straight line that points towards $x_1$. In this case, $p(x_{t+\Delta t} \mid x_t, z, t)$ is just a point mass at $x_t + \frac{(x_1 - x_t)\Delta t}{1-t}$.</p>
154
186
155
-
<p>To calculate the posterior $p(z \mid x, t)$, we invert this relationship. If we observe $x$ at time $t$, and we hypothesize it came from $z$, then the starting point must have been:
156
-
$$ x_0 = \frac{x - t z}{1-t} $$
157
-
The likelihood of $z$ is proportional to the density of the prior at this projected $x_0$.
187
+
<p>With this example, $p(z \mid x_t, t)$ is simple to compute. There is no noise in the conditional process, so the only source of uncertainty is in the prior $p(x_0)$. Given $x_t$ and $t$, we can thus compute $p(z \mid x_t, t)$ for each $z$ proportional to the probability of $x_0$ under the Gaussian prior $p(x_0)$, and we can get $x_0$ by extrapolating backwards from $x_1$ through $x_t$:
188
+
$$ x_0 = -t \cdot \frac{x_1 - x_t}{1-t} $$
158
189
</p>
190
+
191
+
<p>The following interactive figure shows an example with a one-dimensional state, where you control $t$ and $x_t$, and $p(z \mid x_t, t)$ is shown as the opacity of the blue lines. Move around a little and understand how the training data points at $t=1$ get reweighted as $t$ and $x_t$ change.</p>
159
192
</section>
160
193
161
194
<!-- Interactive Figure 1: The Posterior -->
162
195
<divclass="interactive-figure">
163
-
<h4style="margin-top:0;">Viz 1: The Time-Dependent Posterior</h4>
<p>If the step size is larger, we "hold" a specific $Z$ for longer, leading to a more "jagged" path, but as $\Delta t \to 0$,
198
-
the random fluctuations cancel out, and the path follows the expected velocity (the smooth average).
199
-
</p>
230
+
231
+
232
+
<!-- Why resampling preserves marginals -->
233
+
<divstyle="margin: 1.2rem 0;">
234
+
<h3>Why this preserves the marginal path \(p_t\)</h3>
235
+
<p>The resample–and–step chain exactly matches the one–time marginals of the original conditional construction. The reason is simple:</p>
236
+
<ul>
237
+
<li><strong>Same joint at time \(t\):</strong> In the original model, sampling \(Z \sim p_{\text{data}}\) and then \(X_t \sim p_t(\cdot \mid Z)\) induces some joint law for \((Z, X_t)\). In the resampling chain, we first have \(X_t \sim p_t\), then draw \(Z \sim p(z \mid X_t, t)\). By Bayes’ rule these two procedures produce the <em>same</em> joint distribution for \((Z, X_t)\) at time \(t\).</li>
238
+
<li><strong>Same tiny step given \(Z\):</strong> From that shared \((Z, X_t)\), both constructions apply the <em>same</em> conditional transition kernel \(K^{(Z)}_{t+\Delta t \mid t}(\cdot \mid X_t)\) to obtain the next state.</li>
239
+
<li><strong>Therefore same next marginal:</strong> Because both start from the same \((Z, X_t)\) law and use the same kernel, the distribution of \(X_{t+\Delta t}\) is identical in both. Hence, if \(X_t \sim p_t\), then \(X_{t+\Delta t} \sim p_{t+\Delta t}\).</li>
240
+
</ul>
241
+
<p>Iterating over steps keeps the whole grid of marginals \(\{p_t\}\) intact, and letting \(\Delta t \to 0\) preserves the continuous path. A short Bayes–rule proof appears in the appendix of the note.</p>
242
+
</div>
243
+
244
+
<p>This interactive figure shows...</p>
200
245
</section>
201
246
202
247
<!-- Interactive Figure 2: Resample vs Average -->
@@ -227,6 +272,14 @@ <h4 style="margin-top:0;">Resampling faster and faster until things are smooth</
227
272
</div>
228
273
</div>
229
274
275
+
<h3>The infinite switching limit</h3>
276
+
277
+
<p>If the step size is larger, we "hold" a specific $Z$ for longer, leading to a more "jagged" path, but as $\Delta t \to 0$,
278
+
the random fluctuations cancel out, and the path follows the expected velocity (the smooth average).
279
+
</p>
280
+
281
+
282
+
230
283
<!-- LOGIC -->
231
284
<script>
232
285
// =========================================
@@ -943,7 +996,7 @@ <h4 style="margin-top:0;">Resampling faster and faster until things are smooth</
943
996
</script>
944
997
945
998
<section>
946
-
<h2>4. Posterior–averaged tiny step (and the red arrow)</h2>
999
+
<h2>5. Posterior–averaged tiny step (and the red arrow)</h2>
947
1000
<p>In the “resample–and–step” view, we repeatedly (i) look at the current $x$, (ii) resample a fresh $Z \sim p(z \mid x,t)$, and (iii) take one tiny step using the conditional rule for that $Z$. As the step size $\Delta t \to 0$, the randomness from resampling washes out and what remains is the <em>average tiny step</em> at $(t,x)$.</p>
948
1001
<p>For simple flow matching, the conditional velocity is $u_t(x\mid z) = \dfrac{z - x}{1-t}$. The <em>posterior–averaged velocity</em> is</p>
0 commit comments