Simulation-based generative models are all the rage.
In particular, flow matching now dominates the image and video generation landscape.
Because it tolerates few simulation steps well, it has also been widely adopted
in applications sensitive to inference time (mostly, robotics).
Like we did for denoising diffusion models, this post studies flow matching from first principles.
$\quad$ This post overlaps with another, focused on
ODE solvers.
The latter is a good complementary read.
This section introduces the necessary tools to understand and describe flow matching.
In particular, we will focus on ordinary differential equations (ODEs).
In the next section, we will see that colloquially, flow matching is about learning an ODE’s vector field,
and letting a numerical solver generate samples by simulating some particle’s dynamics.
But first, we will need some foundations.
Cauchy problems
Let $f:\mathbb{R}^d\times[0,1]\mapsto\mathbb{R}^d$
describe a family of vector fields indexed by the time variable $t\in[0,1]$
(these bounds are for convenience; any bounded interval of $\mathbb{R}$ would do).
Let $y:[0,1]\mapsto\mathbb{R}^d$ describe the motion of a ‘particle’ which
follows the instantaneous vector field $f(\cdot, t)$.
This motion is described by a non-autonomous ODE;
when paired with an initial position $y_0$ in $\mathbb{R}^d$, it forms a Cauchy problem:
$$
\tag{1}
\frac{dy}{dt}(t) = f\big(y(t), t\big)\; \text{ for any } t\in[0,1] \text{ and } y(0)=y_0\;.
$$
The existence and uniqueness of a solution $y$ to a given Cauchy problem is not guaranteed, and essentially depends
on the smoothness of the vector fields.
This is captured by the Cauchy-Lipschitz theorem, which states some sufficient conditions for a Cauchy problem
to be well-posed.
We state a (weak) version of said theorem:
$\qquad\qquad\qquad\qquad \text{Let } f \text{ be continuous over } \mathbb{R}^d\times[0,1] \text{ and } f(\cdot, t) \text{ } L\text{-Lipschitz for all } t\in[0,1]. \\ \qquad\qquad\qquad\qquad \text{Then
(1) has a unique solution.}
$
Cauchy-Lipschitz
▶Proof
We have already provided a proof for the autonomous case in our ODE solver post,
based on a fixed-point argument.
This argument extends directly to the non-autonomous case, since all vector fields
$\{f(\cdot, t)\}_t$ share the same Lipschitz constant $L$.
$\blacksquare$
Flow
From now on, the vector fields $f$ respect the conditions of the above theorem.
In such conditions, each Cauchy problem admits a unique solution.
It is quite convenient to have a shorthand for the state of the solution of any given Cauchy problem
at some given time $t$.
That’s the point of the flow $\psi: \mathbb{R}^d \times [0,1]\mapsto\mathbb{R}^d$ where, concretely,
$\psi(y_0, t)=y(t)$ with $y$ the solution of the ODE with initial condition $y(0)=y_0$.
In particular, we have that for any $y_0\in\mathbb{R}^d$ and $t\in[0,1]$:
$$
\frac{\partial \psi}{\partial t}(y_0, t) = f(\psi(y_0, t), t) \quad\text{ and }\quad \psi(y_0, 0) = y_0\;.
$$
A consequence of the Cauchy-Lipschitz theorem is that $\psi(\cdot, t)$ is an invertible map
from $\mathbb{R}^d$ to itself.
In practical terms, this means that trajectories starting from different initial positions do not collide; two
particles that started from different positions cannot sit at the same place at the same time.
When $f$ is continuously differentiable, one can further prove that the flow is a diffeomorphism: a continuously differentiable,
invertible map from $\mathbb{R}^d$ to itself, whose inverse is also continuously differentiable (we will not prove this result here).
▶Proof
The proof studies a Cauchy problem with a different boundary condition. With $\tau\in[0,1]$ and $\bar{y}\in\mathbb{R}^d$:
$$
\tag{$\star$}
\frac{dy}{dt}(t) = f\big(y(t), t\big)\; \text{ for any } t\in[0,\tau] \text{ and } y(\tau)=\bar{y}\;.
$$
Clearly, the Cauchy-Lipschitz theorem holds for (1) iff it holds for ($\star$).
The flow’s injectivity is proven as follows. Fix $\tau$ and assume that there exist $y_0, y_0^\prime$
such that $\psi(y_0, \tau) = \psi(y_0^\prime, \tau)=\bar{y}$. Both $\psi(y_0, \cdot)$ and $\psi(y_0^\prime, \cdot)$ are solutions
of ($\star$); by uniqueness of the solution, they are therefore equal on $[0,\tau]$ and in particular at $t=0$.
This proves that $y_0 = y_0^\prime$, and the injectivity of $\psi$.
Surjectivity follows a similar argument; since a solution for ($\star$) exists for any $\bar{y}$, we can find a predecessor for any point of $\mathbb{R}^d$ under ($\star$).
One can easily check that this provides a starting condition $y_0$ for (1) that will check $\psi(y_0, \tau)=\bar{y}$. This is true
for any $\bar{y}$ and proves that the flow is a surjective map.
$\blacksquare$
t = 0.00
Fig1. The flow of a two-dimensional (autonomous) ODE.
Continuity equation
The flow $\psi$ describes the evolution of each particle under the vector fields $f(\cdot, t)$.
Below, we will be interested in how densities change under said fields.
More precisely, given some probability measure $p$, we will want to know the push-forward
$p_t := [\psi(\cdot, t)]_\sharp p$.
For convenience, we will overload probability measures with their densities
and denote $p(\cdot, t)$ the density of $p_t$.
(Observe that $p_t$ does have a density, since $\psi(\cdot, t)$ is a diffeomorphism.)
It is characterised by a differential equation known as the continuity equation.
$\qquad\qquad\qquad\qquad\quad \; \text{ For any }t\in[0,1] , \, p(\cdot, t) \text{ is the unique solution to the partial differential equation}:$
$$
\tag{2}
\frac{\partial p}{\partial t}(y, t) + \sum_{i=1}^d \frac{\partial (p f_i)}{\partial y_i}(y, t) = 0,\quad \forall y\in\mathbb{R}^d\;.
$$
Continuity equation
The continuity equation is essentially a statement of mass preservation; the variation of mass in an (infinitesimal) volume
is explained by how much density comes in and out of said volume.
▶Proof
There are elegant proofs of this result; this is not one of them—we will rely on brute-force computations.
Fix $t\in[0,1]$.
The density $p(\cdot, t)$ of the push-forward of $p$ under $\psi(\cdot, t)$ is given by the change-of-variable formula;
equivalently $p$ is the push-forward of $p(\cdot, t)$ under $\psi(\cdot, t)^{-1}$. For any $y\in\mathbb{R}^d$ this writes:
$$
p(y) = \vert \det J\psi(y, t)\vert p(\psi(y, t), t) \;,
$$
with $J\psi$ being the flow’s Jacobian matrix.
The left-hand side does not depend on time; differentiating wrt. time therefore yields (with $\det J\psi > 0$, by continuity from $\det J\psi(y, 0) = 1$):
$$
\tag{$\star$}
\frac{\partial \det J\psi}{\partial t}(y, t)\,p(\psi(y, t), t) + \vert \det J\psi(y, t)\vert\left(\frac{\partial \psi}{\partial t}(y, t)^\top\frac{\partial p}{\partial y}(\psi(y, t), t) + \frac{\partial p}{\partial t}(\psi(y, t), t)\right) = 0\;.
$$
Observe that by definition we have $\partial_t \psi(y, t) = f(\psi(y, t), t)$. Dividing by $\vert \det J\psi(y, t)\vert$ (never zero since $\psi(\cdot, t)$ is a diffeomorphism) yields:
$$
\underbrace{\vert \det J\psi(y, t)\vert^{-1} \frac{\partial \det J\psi}{\partial t}(y, t)\,p(\psi(y, t), t)}_{(\text{i})} + f(\psi(y, t), t)^\top\frac{\partial p}{\partial y}(\psi(y, t), t) + \frac{\partial p}{\partial t}(\psi(y, t), t) = 0\;.
$$
Let’s focus on (i) for now. Recall that for any invertible matrix $A(t)$ we have $\partial_t \det(A(t))= \det(A(t))\text{Tr}(A^{-1}(t)\partial_t A(t))$.
Applying it to the first term of the above, we get:
$$
(\text{i}) = \text{Tr}\left(J\psi(y, t)^{-1}\frac{\partial J\psi}{\partial t}(y, t)\right)p(\psi(y, t), t)\;.
$$
We can simplify this one further; indeed, for any $i, j$:
$$
\begin{aligned}
\frac{\partial }{\partial t} \frac{\partial \psi_i}{\partial y_j} &= \frac{\partial}{\partial y_j}\frac{\partial \psi_i}{\partial t}\;, &(\text{smoothness}) \\
&= \frac{\partial}{\partial y_j}f_i(\psi(y, t), t)\;, &(\text{def of flow}) \\
&= \sum_{k=1}^d \frac{\partial f_i}{\partial y_k}(\psi(y, t), t) \frac{\partial \psi_k}{\partial y_j}(y, t)\;.
\end{aligned}
$$
This yields that $\frac{\partial J\psi}{\partial t}(y, t) = Jf(\psi(y, t), t) \cdot J\psi(y, t)$ and therefore that:
$$
\begin{aligned}
(\text{i}) &= \text{Tr}\left(J\psi(y, t)^{-1}Jf(\psi(y, t), t) J\psi(y, t)\right)p(\psi(y, t), t)\;,\\
&= \text{Tr}\left(J\psi(y, t)J\psi(y, t)^{-1}Jf(\psi(y, t), t)\right)p(\psi(y, t), t)\;, &(\text{Tr}(AB)=\text{Tr}(BA))\\
&= \text{Tr}\left(Jf(\psi(y, t), t)\right)p(\psi(y, t), t)\;.
\end{aligned}
$$
Putting everything back together, and denoting $z=\psi(y, t)$ as a shorthand, we get:
$$
\text{Tr}\left(Jf(z, t)\right)p(z, t) + f(z, t)^\top\frac{\partial p}{\partial y}(z, t) + \frac{\partial p}{\partial t}(z, t) = 0\;,
$$
which is exactly the continuity equation at $z$ (expand the divergence of $pf$); since $\psi(\cdot, t)$ is surjective, it holds for all $z\in\mathbb{R}^d$. We proved that $p(\cdot, t)$ is a solution to the continuity equation.
To prove uniqueness, we walk back to ($\star$). Observe that ($\star$) characterises $p(\cdot, t)$;
if it holds, then $\vert \det J\psi(y, t)\vert p(\psi(y, t), t)$
is constant wrt. $t$—in particular, it equals for all $t$ its value at $t=0$:
$$
\begin{aligned}
\vert \det J\psi(y, t)\vert p(\psi(y, t), t) &= \vert \det J\psi(y, 0)\vert p(\psi(y, 0), 0) \;, \\
&= \vert \det I_d\vert p(y, 0) \;, \\
&= p(y)\;,
\end{aligned}
$$
since $\psi(y, 0)=y$ for any $y\in\mathbb{R}^d$.
This is the change-of-variable formula; hence $p(\cdot, t)$ is the push-forward of $p$ by $\psi(\cdot, t)$, which concludes the proof.
$\blacksquare$
Flow matching
Let $p_\star$ some distribution over $\mathbb{R}^d$ that we which to model—at least, create some $\hat{p}$ that
resembles $p_\star$ and that we can freely sample from.
Similarly to denoising diffusion models, flow matching [1,2]
attempts this by “transforming noise to data”.
Given some initial distribution $p_0$, it transforms its samples by simulating their motion under a non-autonomous ordinary differential
equation (ODE). It is the vector fields of said ODE that are learned from data, so that the resulting $\hat{p}$
provides a good approximation of $p_\star$.
t = 0.35
Fig2. Transporting $p_0$ to $p_\star$.
▶Solving the ODE
Like almost always, we will not be able to solve the ODE in closed-form.
Sampling through this generative process will require the use of ODE solvers;
often, the simplest ones (e.g., the explicit Euler method) will be enough
for the applications we pursue here.
From now on, we write the time index after a bar: $p(\cdot\vert t)$ denotes the density at time $t$
(it plays the role of $p(\cdot, t)$ in the previous section) and $f(\cdot\vert t)$ the vector field at time $t$.
This leaves room for extra conditioning variables, as in $p(\cdot\vert z, t)$.
Conditional paths
We first look at the simpler problem
of turning $p_0$ into $\delta_z$, the point mass located at $z\in\mathbb{R}^d$.
How we interpolate between the two distributions is called the conditional probability path $p(\cdot\vert z, t)$;
it is a sequence of distributions that only has to satisfy the boundary conditions that
$p(\cdot\vert z, 0)=p_0(\cdot)$ and $p(\cdot\vert z, 1)=\delta_z(\cdot)$.
The conditional probability path is declarative—in the sense that it is a design choice left
to the experimenter.
▶About point masses
Strictly speaking no flow can reach a point-mass since $\psi(\cdot, 1)$ is a bijection.
A rigorous treatment targets $\mathcal{N}(z, \sigma_{\min}^2\mathbf{I}_d)$ instead, for some small $\sigma_{\min}>0$,
and assumes that $p_\star$ has bounded support.
In practice, though, using $\sigma_{\min}=0$ works fine since neither training nor sampling evaluates the vector fields at $t=1$.
To be relevant, one still needs to find a family of conditional vector fields $\{f(\cdot\vert z, t)\}_t$ that generates it—
meaning that the flow of the related ODE checks
$
[\psi(\cdot, t)]_\sharp p_0 = p(\cdot\vert z, t)\;.
$
Moving forward, we will make the assumption that the conditional vector fields supporting the chosen interpolating path are known.
By the continuity equation, this means that for any $y\in\mathbb{R}^d$:
$$
\tag{3}
\frac{\partial p}{\partial t}(y\vert z, t) + \sum_{i=1}^d \frac{\partial (pf_i)}{\partial y_i}(y\vert z, t) = 0\;.
$$
Marginal paths
Now that we can turn $p_0$ into a point mass, we can go back to transforming it to $p_\star$.
Choosing a conditional interpolating path $p(\cdot\vert z, t)$ is enough, in the sense that the marginal path:
$$
p(\cdot\vert t) := \int_z p_\star(z)p(\cdot\vert z, t)dz
$$
turns $p_0$ into $p_\star$.
Indeed, it checks $p(y\vert 0)=p_0(y)$ and $p(y\vert 1)=p_\star(y)$.
The vector fields that support this transformation, called the marginal vector fields,
can be derived from the conditional ones.
Indeed, we have $[\psi(\cdot, t)]_\sharp p_0 = p(\cdot\vert t)$ for the ODE whose
vector fields write, for any $y\in\mathbb{R}^d$:
$$
\tag{4}
f_\star(y\vert t) = \int_{z} f(y \vert z, t) \frac{p_\star(z)p(y\vert z, t)}{p(y\vert t)}dz \;.
$$
▶Proof
This is a proof by verification; it is enough to check that for the vector fields (4) the continuity
equation for $p(\cdot\vert t)$ is satisfied. (Indeed, the continuity equation characterises the push-forward.)
There is one issue with (4): it requires computing an integral which involves the unknown $p_\star$.
Instead, we will approximate the vector fields $f_\star$ as the solution of a regression problem.
Define, for $t\in[0,1]$:
$$
\tag{5}
\hat{f}(\cdot\vert t) := \argmin_{\tilde f\in\mathcal{F}} \mathbb{E}_{z\sim p_\star}\mathbb{E}_{y\sim p(\cdot\vert z, t)}\Big[ \big\| \tilde f(y\vert t) - f(y\vert z, t)\big\|^2\Big] \;,
$$
where $\mathcal{F}$ is some hypothesis class. Observe that we are regressing directly against the (assumed known) conditional vector fields.
This is not an issue; one can show that if $f_\star\in\mathcal{F}$, then $\hat{f}=f_\star$.
As (5) can easily be approximated by sampling, finding $\hat{f}$ essentially boils down to some form of stochastic gradient descent.
We illustrate this plainly in the following section.
▶Proof
It is enough to prove that:
$$
\argmin_{\tilde f\in\mathcal{F}} \mathbb{E}_{z\sim p_\star}\mathbb{E}_{y\sim p(\cdot\vert z, t)}\Big[ \big\| \tilde f(y\vert t) - f(y\vert z, t)\big\|^2\Big] = \argmin_{\tilde f\in\mathcal{F}}\mathbb{E}_{y\sim p(\cdot\vert t)}\Big[ \big\| \tilde f(y\vert t) - f_\star(y\vert t)\big\|^2\Big]\;.
$$
Let’s expand the left-hand side; the term inside the expectation decomposes as:
$$
\begin{aligned}
\| \tilde f(y\vert t) - f(y\vert z, t)\|^2
&=\| \tilde f(y\vert t) - f_\star(y\vert t)\|^2 + \|f_\star(y\vert t)- f(y\vert z, t)\|^2 + 2(\tilde f(y\vert t) - f_\star(y\vert t))^\top(f_\star(y\vert t)- f(y\vert z, t))\;.\\
\end{aligned}
$$
Since $\tilde f(y\vert t) - f_\star(y\vert t)$ does not depend on $z$, the cross term writes:
$$
\int_y \big(\tilde f(y\vert t) - f_\star(y\vert t)\big)^\top \underbrace{\Big[f_\star(y\vert t)p(y\vert t) - \int_z f(y\vert z, t)p_\star(z)p(y\vert z, t)dz\Big]}_{=0 \text{ by (4)}}dy = 0\;,
$$
where we used $\int_z p_\star(z)p(y\vert z, t)dz = p(y\vert t)$. For the same reason, the first term integrates against $p(y\vert t)$. Hence:
$$
\mathbb{E}_{z\sim p_\star}\mathbb{E}_{y\sim p(\cdot\vert z, t)}\Big[ \big\| \tilde f(y\vert t) - f(y\vert z, t)\big\|^2\Big] = \mathbb{E}_{y\sim p(\cdot\vert t)}\Big[ \big\| \tilde f(y\vert t) - f_\star(y\vert t)\big\|^2\Big] + \blacksquare\;,
$$
where $\blacksquare$ is a constant wrt. $\tilde{f}$—which concludes the proof.
$\blacksquare$
▶About conditional distributions
The methods described here naturally extend to modelling conditional distributions $p_\star(\cdot\vert c)$—typically,
with $c$ some label describing some class to generate a sample from.
The extension works well on paper; in practice, it needs some augmentation like
classifier-free guidance [4]
to produce satisfying results.
Gaussian paths
Let’s take a step back to describe the workflow we have proposed so far to transform $p_0$ to $p_\star$:
$$
\text{choose }p(\cdot\vert z, t) \underset{(3)}{\longrightarrow} \text{ find } f(\cdot \vert z, t)\underset{(4)}{\longrightarrow} \text{ compute }f_\star(\cdot\vert t)
$$
We have so far assumed that the second step was done for us—this is far from trivial as we do not have a constructive tool for it,
only a way to verify a candidate (the continuity equation). In this section, we choose a particular conditional interpolating path which
satisfies this assumption. It also births the algorithm that most actually refer to when talking about flow matching.
Let $p_0 = \mathcal{N}(0,\mathbf{I}_d)$ and $\mu, \sigma$ be two real-valued functions, such that $\mu(0)=\sigma(1)=0$ and $\mu(1)=\sigma(0)=1$. Define:
$$
\tag{6}
p(y\vert z, t) := \mathcal{N}\big(y\vert \mu(t)z, \sigma(t)^2\mathbf{I}_d\big)\;.
$$
▶About denoising diffusion models
The ’typical’ flow-matching schedule writes $\mu(t)=t$ and $\sigma(t)=1-t$; it yields so-called straight interpolating paths.
Also of interest are variance preserving paths, where
$\mu(t) = \sqrt{\alpha(t)}$
and $\sigma(t) = \sqrt{1-\alpha(t)}$ for some well-chosen schedule $\alpha$.
In this case, rewriting (6) accordingly:
$$
p(y\vert z, t) = \mathcal{N}(y\vert \sqrt{\alpha(t)}z, (1-\alpha(t))\mathbf{I}_d)\;,
$$
is reminiscent of denoising diffusion models—see eq. (3) in this post.
The relationship between flow matching and denoising diffusion models goes deeper; see
[1]
[3]
.
The conditional path of (6) is generated by the conditional vector fields:
As we said, this is about verification; let’s show that (6) and (7) check the continuity equation.
Observe that
$$
\begin{aligned}
\frac{\partial p}{\partial t}(y\vert z, t) &= p(y\vert z, t)\frac{\partial\log p}{\partial t}(y\vert z, t) \;, \\
&= p(y\vert z, t)\frac{\partial}{\partial t}\left(-\frac{d}{2}\log(2\pi\sigma(t)^2) - \| y - \mu(t)z\|^2/(2\sigma(t)^2)\right) \;, \\
&= p(y\vert z, t)\left(-d\frac{\dot\sigma(t)}{\sigma(t)}+ \frac{\dot\mu(t)z^\top(y-\mu(t)z)}{\sigma(t)^2}+\frac{\dot\sigma(t)\| y - \mu(t)z\|^2}{\sigma(t)^3}\right)\;.
\end{aligned}
$$
On the other hand:
$$
\begin{aligned}
\frac{\partial (pf_i)}{\partial y_i}(y\vert z, t) &= f_i(y\vert z, t)\frac{\partial p}{\partial y_i}(y\vert z, t) + p(y\vert z, t)\frac{\partial f_i}{\partial y_i}(y\vert z, t)\;,\\
&= f_i(y\vert z, t)p(y\vert z, t)\frac{\partial \log p}{\partial y_i}(y\vert z, t) + p(y\vert z, t)\frac{\dot\sigma(t)}{\sigma(t)}\;, \\
&= -p(y\vert z, t)\big( \dot\mu(t) z_i + \dot\sigma(t)(y_i-\mu(t)z_i)/\sigma(t)\big)(y_i - \mu(t)z_i)/\sigma(t)^2 + p(y\vert z, t)\frac{\dot\sigma(t)}{\sigma(t)}\;, \\
&= p(y\vert z, t)\left(-\frac{\dot\mu(t) z_i(y_i - \mu(t)z_i)}{\sigma(t)^2} - \frac{\dot\sigma(t)(y_i - \mu(t)z_i)^2}{\sigma(t)^3} + \frac{\dot\sigma(t)}{\sigma(t)}\right)\;.
\end{aligned}
$$
Clearly, the continuity equation is verified.
$\blacksquare$
▶About straight paths
With the ‘straight’ schedule $\mu(t)=t$ and $\sigma(t)=1-t$, the vector fields of (7) become
$$f(y\vert z, t) = (z-y)/(1-t)\;.$$
Along the conditional flow started at $y_0$, we have $y(t) = tz + (1-t)y_0$ and $f(y(t)\vert z, t) = z - y_0$:
each conditional trajectory is a straight line, travelled at constant speed.
That is often understood to back the intuition behind ‘flow matching requires fewer integration steps’.
This is however misleading. ‘Straightness’ does not carry over to the marginal trajectories, which will
mechanically bend if $p_\star$ has finite support (which, through the lense of the training process, is true).
To get truly straight marginal trajectories, additional work is needed [2]
.
That is enough to give ’the’ flow matching algorithm.
Below, we provide some pseudocode that illustrates this; the regression searches over a parametric hypothesis class
$\mathcal{F}_\Theta=\{f_\theta : \mathbb{R}^d\times[0,1]\mapsto\mathbb{R}^d, \theta\in\Theta\}$.
Compared to (5), the regression loss also includes sampling over the time interval. Observe that the training algorithm
is simulation-free; we do not have to simulate the ODE.
As described earlier, drawing samples from our learned model $\hat{p}$ boils down to ‘solving’ the ODE
induced by the vector fields $f_{\hat\theta}(\cdot\vert t)$.
We illustrate below how this can be approximated, with a simple Euler scheme.
We finish this post by showing how one can
derive the likelihood of any sample $y_1$ under the flow matching model.
This makes it an ’explicit’ generative model (opposed to implicit, which can only produce samples).
Denote $g(t) = \log p(y(t)\vert t)$ the log-probability density following a particle—that is, with $y(t)$ satisfying (1).
Thanks to the continuity equation, one can show that $g(t)$ also checks a differential equation; for $t\in[0,1]$:
$$
\tag{8}
\frac{dg}{dt}(t) = - \sum_{i=1}^d \frac{\partial f_i}{\partial y_i}(y(t)\vert t)\;.
$$
▶Proof
Observe that:
$$
\begin{aligned}
p(y(t)\vert t)\frac{dg}{dt}(t) &= \frac{d}{dt}p(y(t)\vert t) \;, \\
&= \frac{\partial p}{\partial t} (y(t)\vert t) + \sum_{i=1}^d \frac{\partial p}{\partial y_i}(y(t)\vert t) \frac{d y_i}{dt}(t) \;,\\
&= \frac{\partial p}{\partial t} (y(t)\vert t) + \sum_{i=1}^d \frac{\partial p}{\partial y_i}(y(t)\vert t)f_i(y(t)\vert t) \;.
\end{aligned}
$$
since $y(t)$ solves (1). From there, using the continuity equation at $y(t)$ yields the announced result:
$$
\begin{aligned}
p(y(t)\vert t)\frac{dg}{dt}(t) &= -\sum_{i=1}^d \left(\frac{\partial p}{\partial y_i}(y(t)\vert t)f_i(y(t)\vert t) + p(y(t)\vert t)\frac{\partial f_i}{\partial y_i}(y(t)\vert t)\right) + \sum_{i=1}^d \frac{\partial p}{\partial y_i}(y(t)\vert t)f_i(y(t)\vert t) \;, \\
&= -p(y(t)\vert t)\sum_{i=1}^d \frac{\partial f_i}{\partial y_i}(y(t)\vert t)\;.
\end{aligned}
$$
Dividing both sides by $p(y(t)\vert t)>0$ yields the announced result.
$\blacksquare$
This gives us a direct route to computing $p(y_1\vert 1)$ for any $y_1\in\mathbb{R}^d$.
We start by solving the original ODE from (1) backward in time, starting from $y(1)=y_1$.
This gives us the trajectory $y(\cdot)$ that checks the final condition, and we
denote $y_0 = y(0)$ the associated initial condition.
We can then solve (8) forward, since $g(0)=\log p(y_0\vert 0)$ is known. This yields $g(1)=\log p(y(1)\vert 1)$
and the desired result.
$\quad$ Above is a $\textit{very}$ inefficient (but somewhat intuitive) protocol. See Section C of [1]
for the real deal.
⚠
References
[1] Flow matching for generative modelling. Lipman et al. 2023.[2] Flow straight and fast. Liu et al. ICLR 2023[3] Diffusion meets flow matching: two sides of the same coin. Gao et al. 2024[4] Classifier-free diffusion guidance. Ho & Salimans, 2022.
The structure (and content) for this post was very largely influenced by this course.