Flow-Based Generative Models · UFRJ · 2026.2
Since U1.T2, one question has stood on the left board:
What does \(\log\lvert\det J\rvert\) become in continuous time?
Today:
| Family | Density | Sampling | Trick, and its price |
|---|---|---|---|
| NICE / RealNVP | exact, triangular | direct | coupling; depth |
| Glow | exact | direct | mixing, multi-scale |
| MAF | parallel | sequential | AR, data side |
| IAF | sequential | parallel | AR, source side |
| Residual flow | direct; series log-det | iterative | contraction, traces |
| Neural ODE | inverse: ODE solve / NFE; \(\log\lvert\det J\rvert\) ??? | ODE solve / NFE | no inverse layer; Lipschitz field |
One cell is marked. It is today’s question.
When a field pushes densities around, we call it \(u\) — remember the symbol table.
Today’s statements are pointwise equations for \(p_t\). They need \(p_t\) differentiable in \(x\), which asks for one more derivative of the flow than Tier 2. Here \(\partial_x u\) is the Jacobian of \(u\) in \(x\).
\(u\) is continuous on \([0,1] \times \mathbb{R}^{d}\), \(C^{2}\) in \(x\) with \(\partial_x u\), \(\partial_x^2 u\) continuous on \([0,1] \times \mathbb{R}^{d}\), and \(\partial_x u\) bounded. The initial density is \(p_0 = \mathcal{N}(0, I_d)\).
Then \(\psi_t\) is a \(C^{2}\) diffeomorphism, and the density \(p_t\) of \(\psi_t(X_0)\) is positive and \(C^{1}\) in \((t, x)\).
Every box that uses (H) says so. The weak form needs only Tier 1; the integrated identity needs only Tier 2.
Under (H), let \(X_0 \sim p_0\) and \(X_t = \psi_t(X_0)\). The density \(p_t\) of \(X_t\) satisfies, for every bounded measurable \(\varphi\), \[ \mathbb{E}_{x \sim p_t}\big[\varphi(x)\big] = \mathbb{E}_{x_0 \sim p_0}\big[\varphi\big(\psi_t(x_0)\big)\big] . \]
Since \(\psi_t\) is a diffeomorphism, U1.T1’s change-of-variables theorem gives \(p_t(x) = p_0(\psi_t^{-1}(x))\,\lvert\det J_{\psi_t^{-1}}(x)\rvert\).
That formula needs the flow map, which is the solution of an ODE. Does \(p_t\) satisfy an equation written with \(u\) alone?
\(d = 1\), \(u_t(x) = a(t)\,x\) with \(a(t) = 1.2 - 2t\), and \(p_0 = \mathcal{N}(0,1)\). Then \[ \psi_t(x_0) = x_0\,e^{A(t)}, \qquad A(t) = 1.2\,t - t^{2}, \] so \(p_t = \mathcal{N}\big(0, e^{2A(t)}\big)\).
The field expands the line until \(t = 0.6\), then contracts it: the scale \(e^{A(t)}\) peaks at \(1.4333\) and ends at \(1.2214\).
\[ \frac{\mathrm{d}}{\mathrm{d}t} \int_V p_t\,\mathrm{d}x \;=\; -\oint_{\partial V} p_t\, u_t \cdot n\;\mathrm{d}S \]
This is the picture. It is not yet a proof: “flux” is a modelling statement.
For a smooth, compactly supported test function \(\varphi\):
\[ \begin{aligned} \frac{\mathrm{d}}{\mathrm{d}t}\,\mathbb{E}_{x \sim p_t}[\varphi(x)] &= \mathbb{E}_{x_0 \sim p_0}\big[\nabla\varphi(\psi_t(x_0)) \cdot u_t(\psi_t(x_0))\big] \\ &= \mathbb{E}_{x \sim p_t}\big[\nabla\varphi(x) \cdot u_t(x)\big] \end{aligned} \]
It uses nothing but the trajectory definition: Tier 1 is enough.
Write the right side as an integral and move the derivative onto \(p_t u_t\):
Both gaps are filled, in full, in the recorded clinic. It is required viewing before U3.T1.
\[ \partial_t p_t + \nabla\cdot\big(p_t\, u_t\big) = 0 \] \(p_t\) is positive and \(C^{1}\). The weak form needs only Tier 1.
This exact equation is the foundation of everything after the break. U3 begins by reading it in the other direction.
\[ \begin{aligned} \partial_t p_t &= a(t)\Big(x^{2} e^{-2A(t)} - 1\Big)\,p_t, \\ \nabla\cdot(p_t u_t) &= a(t)\Big(1 - x^{2} e^{-2A(t)}\Big)\,p_t . \end{aligned} \] The two terms cancel at every \((t, x)\).
Along a trajectory \(x_t = \psi_t(x_0)\), with \(\log p_t\) of class \(C^{1}\):
\[ \frac{\mathrm{d}}{\mathrm{d}t}\log p_t(x_t) = (\partial_t \log p_t)(x_t) + \nabla \log p_t(x_t) \cdot u_t(x_t) \]
Expand the continuity equation and divide by \(p_t > 0\):
\[ \partial_t \log p_t = -\nabla\cdot u_t - u_t \cdot \nabla \log p_t \]
\[ \begin{aligned} \frac{\mathrm{d}}{\mathrm{d}t}\log p_t(x_t) &= \bigl(-\nabla\cdot u_t - u_t\cdot\nabla\log p_t\bigr) \\ &\quad {}+ \nabla\log p_t\cdot u_t \\ &= -(\nabla\cdot u_t)(x_t) \end{aligned} \]
Every term on the right is evaluated at \(x_t\). The first bracket is the continuity equation; the last term is the observer riding with the sample. What is left is compression and expansion.
Under (H), along every trajectory \(x_t = \psi_t(x_0)\): \[ \frac{\mathrm{d}}{\mathrm{d}t}\log p_t(x_t) = -(\nabla\cdot u_t)(x_t) \] and, integrating over \([0, 1]\) with \(x_1 = \psi_1(x_0)\): \[ \log p_1(x_1) = \log p_0(x_0) - \int_0^{1} (\nabla\cdot u_t)(x_t)\,\mathrm{d}t \] Equivalently, \(\log\lvert\det J_{\psi_1}(x_0)\rvert = \int_0^{1} (\nabla\cdot u_t)(x_t)\,\mathrm{d}t\).
Cited as (Chen et al. 2018, sec. 4, Thm. 1).
What does \(\log\lvert\det J\rvert\) become in continuous time?
U1.T2 wrote it. U2.T1 circled the cell. Today it is answered.
\[ \log\lvert\det J_{\psi_1}(x_0)\rvert = \int_0^{1} (\nabla\cdot u_t)(x_t)\,\mathrm{d}t \]
A determinant became a trace, accumulated in time. In the density it enters with a minus sign, as in U1. Checked off the board.
| U1: a stack of \(K\) blocks | U2: a flow | |
|---|---|---|
| log-determinant | \(\sum_k \log\lvert\det J_{\psi_k}(z_{k-1})\rvert\) | \(\int_0^1 (\nabla\cdot u_t)(x_t)\,\mathrm{d}t\) |
| why tractable | the architecture | nothing is designed: a trace |
| ancestor | change of variables (U1.T1) | same theorem, differential form |
Same object, discrete against continuous. U1 as in U1.T1: block \(k\) maps \(z_{k-1}\) to \(z_k = \psi_k(z_{k-1})\).
To evaluate a density, \(x_1\) is given at \(t = 1\) and a backward solve finds \(x_0\).
Along the trajectory through the data point \(x_1\): \[ \Delta(t) := \log p_t(x_t) - \log p_1(x_1) \]
Then \(\Delta(1) = 0\), \(\dot\Delta = -(\nabla\cdot u_t)(x_t)\), and \(\Delta(0) = \log p_0(x_0) - \log p_1(x_1)\):
\[ \log p_1(x_1) = \log p_0(x_0) - \Delta(0) \]
The trap: do not start a variable at \(0\) and call its terminal value “the log-likelihood”. \(\Delta(0)\) is a difference of log-densities.
\(\nabla\cdot u_t = a(t)\) at every \(x\), so \(\Delta(0) = A(1) = 0.2\) for every data point. For \(x_1 = 1.0\):
\(x_0 = 0.8187\), \(\;\log p_0(x_0) = -1.2541\), so \[ \log p_1(x_1) = -1.2541 - 0.2000 = -1.4541 , \] the log-density of \(\mathcal{N}(0, e^{2A(1)})\) at \(x_1\).
The continuity route is run under (H), and gives more: the pointwise equation, and uniqueness.
Setting: \(u\) satisfies (H); \(p_0 = \mathcal{N}(0, I_d)\), smooth and positive; \(p_t\) is the density of \(\psi_t(X_0)\) and satisfies the continuity equation pointwise.
In (d), \(J\) is the field’s Jacobian at the Euler point, \(\partial_x u(t_k, x_k)\).
Replace the field \(u_t\) by a network \(u_t^{\theta}\), and solve from \([x; \Delta](1) = [x_1; 0]\) down to \(t = 0\):
\[ \frac{\mathrm{d}}{\mathrm{d}t}\begin{pmatrix} x \\ \Delta \end{pmatrix} = \begin{pmatrix} u_t^{\theta}(x) \\ -\nabla\cdot u_t^{\theta}(x) \end{pmatrix} \]
\[ \mathcal{L}_{\mathrm{NLL}}(\theta) = \mathbb{E}_{x_1 \sim q}\Bigl[-\log p_0\bigl(x_0^{\theta}(x_1)\bigr) + \Delta^{\theta}_{x_1}(0)\Bigr] \]
This is a continuous normalizing flow (CNF), trained by maximum likelihood.
A vector–Jacobian product (VJP) \(w^{\top}\partial_x u\) is one reverse-mode pass through \(u\), at about the cost of one evaluation of \(u\).
| Divergence per RHS call | calls of \(u\) | extra passes | returns |
|---|---|---|---|
| exact trace | 1 | \(d\) VJPs | \(\nabla\cdot u\) exactly |
| Hutchinson | 1 | 1 VJP | unbiased, with variance |
NFE counts calls of \(u\). The VJPs are extra work, visible in wall-clock time, and are not extra NFE.
\(A \in \mathbb{R}^{d \times d}\), \(\mathbb{E}_v[v v^{\top}] = I_d\) (Rademacher or Gaussian), \(S = \tfrac12(A + A^{\top})\).
(i) Unbiased: \(\mathbb{E}_v[v^{\top} A\, v] = \operatorname{tr}(A)\).
(ii) Symmetric part only: \(v^{\top} A\, v = v^{\top} S\, v\).
(iii) Variance. Gaussian: \(2\lVert S\rVert_F^{2}\). Rademacher: \(2\big(\lVert S\rVert_F^{2} - \sum_i A_{ii}^{2}\big)\).
The Rademacher variance is below the Gaussian one by exactly \(2\sum_i A_{ii}^{2}\), so it is never above it. Version 1 is U1.T2’s box, “Hutchinson’s trace estimator”; its proof was deferred to today.
Let \(x_t\) not depend on \(v\), and \(A_t = (\partial_x u)(t, x_t)\). With one probe fixed on \([0,1]\): \[ \hat I(v) = \int_0^{1} v^{\top} A_t\, v\,\mathrm{d}t = v^{\top}\bar A\,v, \qquad \bar A = \int_0^{1} A_t\,\mathrm{d}t . \] \(\mathbb{E}_v[\hat I(v)] = \int_0^{1}(\nabla\cdot u_t)(x_t)\,\mathrm{d}t\), and (iii) holds with \(\bar A\).
Fubini: \(\mathbb{E}_v\lVert v\rVert^{2} = d < \infty\) and \(\sup_t\lVert A_t\rVert < \infty\). Here \(A_t\) is the Jacobian along the trajectory (Box U2.T1-3 writes it \(A(t)\)); on this page \(A(t)\) is the antiderivative of the linear example, and for that field \(A_t = a(t)\).
The proof of (i) needs no zero mean: only \(\mathbb{E}_v[v v^{\top}] = I_d\).
Contract. One probe per example, for one likelihood solve, held fixed across every RHS call of the adaptive solver (Grathwohl et al. 2019, sec. 3.1, eq. 8). The course adds: and across every recomputation of the adjoint.
Limits. The statement is about the exact integral: a solver’s steps depend on \(v\). No blanket claim that every training gradient is unbiased. The estimate is unbiased for \(\log p_1\), not for \(p_1\).
The design tension of U1 is dissolved. Each likelihood and each training step still performs a numerical integration.
U2.L1, TODO 2.3 and its reference run: the forward NFE of a small Neural ODE classifier, at every training step (seed 0, dopri5 at its defaults).
| first steps | at step 4 | peak | at step 300 |
|---|---|---|---|
| 44 | 20 | 134 (step 48) | 122 |
A solver’s cost depends on the field, and the field can change at every optimizer step. The count can change during training. No direction is claimed.
(Finlay et al. 2020): charge the trajectory \(x_t\) through \(x_1\), for the speed and the variation of the field, with weights \(\lambda_K, \lambda_J \ge 0\).
\[ \begin{aligned} \mathcal{L}_{\mathrm{reg}}(\theta) &= \mathcal{L}_{\mathrm{NLL}}(\theta) + \lambda_K\,\mathbb{E}_{x_1 \sim q}\Big[\int_0^{1} \lVert u_t^{\theta}(x_t)\rVert^{2}\,\mathrm{d}t\Big] \\ &\quad {}+ \lambda_J\,\mathbb{E}_{x_1 \sim q}\Big[\int_0^{1} \lVert (\partial_x u_t^{\theta})(x_t)\rVert_F^{2}\,\mathrm{d}t\Big] \end{aligned} \]
For \(J = (\partial_x u_t^{\theta})(x_t)\): \(\lVert J\rVert_F^{2} = \mathbb{E}_v\lVert v^{\top}J\rVert^{2}\), and \(v^{\top}J\) is the VJP the divergence estimate already computes: no extra VJP call (Finlay et al. 2020, secs. 4–5).
Nothing new is derived: the machinery planted in U2.T1 certifies the training of the regularized model.
| Family | Density | Sampling | Trick, and its price |
|---|---|---|---|
| NICE / RealNVP | exact, triangular | direct | coupling; depth |
| Glow | exact | direct | mixing, multi-scale |
| MAF | parallel | sequential | AR, data side |
| IAF | sequential | parallel | AR, source side |
| Residual flow | direct; series log-det | iterative | contraction, traces |
| CNF (FFJORD) | ODE solve + divergence per call | ODE solve | free-form field; the price is the solve |
| Task | integrates | per RHS call | headline |
|---|---|---|---|
| sampling | \(x\), \(0 \to 1\) | \(u_t^{\theta}\) | NFE |
| density, exact | \([x; \Delta]\), \(1 \to 0\) | \(u_t^{\theta}\) and \(d\) VJPs | NFE; VJPs extra |
| density, Hutchinson | \([x; \Delta]\), \(1 \to 0\) | \(u_t^{\theta}\) and 1 VJP | NFE; VJP extra |
| training step | solve; backprop or adjoint | as density, then differentiated | NFE, all solves |
NFE is the headline count; wall-clock is the honest total.
MLE training of a CNF places an adaptive numerical solve inside each optimization step. Density-mode RHS calls include both \(u_t^{\theta}\) and a divergence calculation; differentiation adds either stored-solver backpropagation or a second adjoint solve. NFE is data-, parameter-, tolerance-, and solver-dependent and may drift substantially during training. The cost of learning sits inside the innermost loop.
Can we obtain \(u_t^{\theta}\) by regression —
without ever simulating during training?
When we meet in U3.T1, you will have felt what this question is worth.