Flow-Based Generative Models · UFRJ · 2026.2
| Left open | By | Paid in |
|---|---|---|
| The depth question — how expressive is a stack of coupling layers? | U1.T1 | the universality block |
| The fine print — a flow is a diffeomorphism; what can one not do? | U1.T1 | the topology block |
| The checkerboard gaps — \(29.8\%\) of the mass where the data density is zero | U1.L1 | the topology block |
Before the debts: the rest of the zoo (the Glow and autoregressive blocks), read through one table.
| Operation | Direction | Needs, per layer | Cost driver |
|---|---|---|---|
| Sampling | forward, \(z \to x\) | evaluate \(\psi_k\) | one pass per layer |
| Density / training | inverse, \(x \to z\) | \(\psi_k^{-1}\) and \(\log\lvert\det J_{\psi_k}\rvert\) | the inverse, and the log-det |
The unit’s thesis: the zoo is a list of tricks to make both rows cheap at once.
Today the table gets one row per family (v2). Convention unchanged: \(\psi \colon z \to x\) generates; a library’s \(f \colon x \to z\) is \(f = \psi^{-1}\). U1.T1 wrote the same two rows as \(x_0 \to x_1\) and \(x_1 \to x_0\); these are U1.L1’s letters.
Affine coupling at \(32 \times 32\) and \(256 \times 256\) (Kingma and Dhariwal 2018, sec. 3), with two extra layer types whose log-determinants are as cheap as coupling’s:
and a multi-scale arrangement of the stack. No new theorem.
On an \(h \times w \times c\) feature map, with \(s, b \in \mathbb{R}^{c}\), at every position \((i, j)\):
\[ \begin{aligned} y_{ij} &= s \odot x_{ij} + b, \qquad x_{ij} = (y_{ij} - b)/s, \\ \log\lvert\det J\rvert &= h\,w \sum_{j=1}^{c} \log\lvert s_j\rvert . \end{aligned} \]
Example, a \(32 \times 32 \times 12\) map: \(24\) parameters; \(\log\lvert\det J\rvert = 1024 \sum_{j=1}^{12} \log\lvert s_j\rvert\) — twelve logarithms, one sum.
Data-dependent initialization chooses the starting point. It is not a normalization layer.
One matrix \(W \in \mathbb{R}^{c \times c}\) at every position; a permutation is the case \(W = P\):
\[ \begin{aligned} y_{ij} &= W x_{ij}, \qquad \log\lvert\det J\rvert = h\,w\,\log\lvert\det W\rvert \\ &= h\,w \sum_{i=1}^{c} \log\lvert s_i\rvert \quad\text{for } W = P L (U + \operatorname{diag} s). \end{aligned} \]
| Density / likelihood | Sampling | |
|---|---|---|
| Glow | exact: coupling sums \(+\) actnorm sums \(+\) PLU sums | direct: every layer has an analytic inverse |
The coupling row, engineered for images. It removes no limitation that the universality and topology blocks will state.
Any density on \(\mathbb{R}^{d}\) factorizes by the chain rule. With coordinates \(x = (\xi_1, \dots, \xi_d)\):
\[ p(x) = \prod_{i=1}^{d} p(\xi_i \mid \xi_{<i}), \qquad \xi_{<i} = (\xi_1, \dots, \xi_{i-1}). \]
A network that produces each factor from earlier coordinates only has an exact likelihood and a fixed ordering. That is the whole autoregressive (AR) family.
Coordinates are \(\xi_i\) (of \(x\)) and \(\zeta_i\) (of \(z\)): in this course \(x_1\) is a data point, never a coordinate.
Parameterize \(f = \psi^{-1} \colon x \to z\) coordinate by coordinate (Papamakarios, Pavlakou, and Murray 2017, sec. 3):
\[ \zeta_i = \frac{\xi_i - \mu_i(\xi_{<i})}{\sigma_i(\xi_{<i})}, \qquad \log\lvert\det J_{\psi}(z)\rvert = \sum_{i=1}^{d} \log\sigma_i(\xi_{<i}) . \]
Parameterize \(\psi \colon z \to x\) instead, with the conditioner reading the source coordinates (Kingma et al. 2016, secs. 3–4):
\[ \xi_i = \mu_i(\zeta_{<i}) + \sigma_i(\zeta_{<i})\,\zeta_i, \qquad \log\lvert\det J_{\psi}(z)\rvert = \sum_{i=1}^{d} \log\sigma_i(\zeta_{<i}) . \]
| Family | Density / likelihood | Sampling |
|---|---|---|
| MAF | parallel, one pass | sequential inverse (event dimension) |
| IAF | sequential inverse (event dimension) | parallel, one pass |
“\(d\) passes” is an intuition for affine scalar autoregression. The implementation-level statement is sequential in the event dimension — along the \(d\) coordinates of one point — not a promise about a count of network calls.
Two blocks in place of \(d\) coordinates: \(z_A = x_A\) copied, \(z_B = (x_B - t_\theta(x_A)) \odot e^{-s_\theta(x_A)}\) conditioned on the first.
Coupling, MAF and IAF: one triangular idea, at different block sizes, in different directions.
NICE’s additive layers, and any stack of them, are volume-preserving: \(\lvert\det J\rvert = 1\).
Flows with constant Jacobian determinant are not universal distribution approximators under KL. A flow of constant-Jacobian diffeomorphisms has the same number of modes as its base distribution.
A constant factor on the density cannot move a maximum. NICE’s final scaling layer does not help: its determinant is a constant, so the theorem applies with the layer as without it — the answer to U1.T1’s Exercise 2. What removes the obstruction is a determinant that varies with the input: RealNVP’s \(e^{s_\theta(x_A)}\) (Draxler et al. 2024, sec. 4).
Constant-Jacobian stacks are capped. Does depth in a richer family do better? Yes, with fine print:
For every continuous density \(p\) on \(\mathbb{R}^{d}\) with finite first and second moments and infinite support, there is a sequence of flows \(f_n\) of \(n\) affine coupling blocks, each \(L\)-bi-Lipschitz (distances stretched or compressed by at most a factor \(L\), in either direction), with \((f_n)_{\#}\,p \to \mathcal{N}(0, I_d)\) as \(n \to \infty\) — in the paper’s convergence measure \(\Delta_{\text{affine}}\) (the KL improvement one more block could buy), which KL-convergence implies.
The classical argument (Papamakarios et al. 2021, sec. 2.2, §3.1.2):
So the classical existence argument says nothing about RealNVP. The theorem on the previous slide is what settles the affine case.
Universality holds, with fine print, for targets of infinite support.
What happens when the target has literal hard-zero gaps — a support in several pieces — that a flow from a Gaussian source cannot reproduce exactly?
That is the checkerboard. The answer is a theorem about supports.
Eight separated squares, exactly zero density between them; \(0\) of \(100{,}000\) generated points outside. The model: \(29.8\%\) of its mass in the gaps, NLL \(0.50\) nats above \(\log 18\).
“Topology obstruction” is a statement about supports and globally invertible maps.
It is not a statement about density level sets. A diffeomorphism can make a bimodal density from a unimodal source — U1.L1’s two-moons model is the proof by example.
Recall: the support of \(P\) is the closed set of points all of whose open neighbourhoods have positive measure. \(\operatorname{supp}\mathcal{N}(0, I_d) = \mathbb{R}^{d}\). The checkerboard’s support is eight closed squares: disconnected.
Let \(P\) have support \(S\) and let \(\psi \colon \mathbb{R}^{d} \to \mathbb{R}^{d}\) be a homeomorphism (onto, continuous, continuous inverse). Then \[ \operatorname{supp}(\psi_{\#}P) = \psi(S). \] If \(S\) is connected, so is the support of the pushforward.
Proof. (\(\supseteq\)) \(V\) open around \(\psi(s)\), \(s \in S\): \(\psi^{-1}(V)\) is open around \(s\), so \(P(\psi^{-1}(V)) > 0\).
(\(\subseteq\)) \(y\) in the support, \(s = \psi^{-1}(y)\), \(U\) open around \(s\): \(\psi(U)\) is open around \(y\), so \(P(U) = \psi_{\#}P(\psi(U)) > 0\), hence \(s \in S\). Connectedness: continuous image of a connected set. \(\blacksquare\)
| Layer | Why it is a bijection of \(\mathbb{R}^{d}\) onto \(\mathbb{R}^{d}\) |
|---|---|
| affine coupling | analytic inverse, defined for every \(x\) |
| actnorm, \(1 \times 1\) conv | affine and linear, \(s_j \neq 0\), \(\det W \neq 0\) |
| MAF, IAF, \(\sigma_i > 0\) | inverse recursion: one affine equation per coordinate |
| permutation, squeeze | reshapes and swaps |
| residual, \(\operatorname{Lip}(g) < 1\) | \(x + g(x) = z\) has one solution (residual-flow block) |
\[ \operatorname{supp} p_\theta = \psi^{\theta}(\mathbb{R}^{d}) = \mathbb{R}^{d} \qquad\text{for every } \theta . \]
A flow of this unit cannot exactly equal:
Not capacity, not depth, not optimization.
Not about level sets. The model’s superlevel sets \(\{p_\theta > c\}\) can be disconnected: \(\lvert\det J\rvert\) varies from point to point. A constant Jacobian guarantees the mode count (the universality block); a variable one guarantees nothing, and two-moons shows the count changing. Do not write “level-set topology is preserved” — it is false.
The proposition rules out equality. What does closeness cost? Define the bi-Lipschitz constant \[ \begin{aligned} \operatorname{BiLip}(f) = \inf\Big\{ M \in [1, \infty] :\ & M^{-1}\lVert z - z'\rVert \le \lVert f(z) - f(z')\rVert \\ & \qquad \le M \lVert z - z'\rVert \ \text{ for all } z, z' \Big\}. \end{aligned} \]
\(\operatorname{BiLip}(f) = \infty\) when no finite \(M\) works. A large constant means that somewhere the map stretches or compresses enormously, and its inverse does the opposite: the constant measures how numerically invertible \(f\) is.
If \(\operatorname{supp} P_Z\) and \(\operatorname{supp} P^{\star}\) are not homeomorphic, then for any measurable \(f_n\): \[ (f_n)_{\#}P_Z \to P^{\star} \ \text{weakly} \quad\Longrightarrow\quad \operatorname{BiLip}(f_n) \to \infty . \]
Weak convergence — expectations of bounded continuous functions converge — is implied by minimizing KL. So: approaching the checkerboard forces the flow to become arbitrarily badly conditioned (Cornish et al. 2020, sec. 2).
Corollary 2.2. For any weak-topology metric \(\rho\) there is \(M(\varepsilon) \to \infty\) as \(\varepsilon \to 0\) such that: target within \(\varepsilon\) of a mismatched \(P^{\star}\), model within \(\varepsilon\) of the target \(\Rightarrow\) \(\operatorname{BiLip}(f) \ge M(\varepsilon)\).
| Observation on a trained flow | Status |
|---|---|
| nonzero model density in hard-zero gaps | structural (full-support source \(+\) diffeomorphism) |
| extreme Jacobian conditioning as the mismatch is pushed | supported by the theorem |
| inverse round-trip degradation, instability | plausible numerical consequence; measure it |
| NLL plateau, poor samples | non-specific: capacity or optimization |
Topology is a hypothesis to test, not a verdict every bridge proves.
Everything so far bought a cheap log-det by forcing a triangular Jacobian. Residual flows give that up.
The literature writes the map the way a residual network computes it — data to source. That is the density transform:
\[ f = \psi^{-1}, \qquad f(x) = x + g(x), \qquad g \colon \mathbb{R}^{d} \to \mathbb{R}^{d} \text{ a network}. \]
The identity plus a perturbation. If the perturbation is small enough, the identity wins. “Small enough” is a Lipschitz condition (Behrmann et al. 2019, sec. 2).
Fix \(z\); \(x + g(x) = z\) is the fixed-point equation \(x = z - g(x)\). Iterate: \[ x^{(m+1)} = z - g\big(x^{(m)}\big), \qquad x^{(0)} = z . \]
If \(\operatorname{Lip}(g) = L < 1\), then \(T_z(x) = z - g(x)\) satisfies \[ \lVert T_z(x) - T_z(x')\rVert = \lVert g(x') - g(x)\rVert \le L\,\lVert x - x'\rVert . \]
Banach on the complete space \(\mathbb{R}^{d}\): a unique fixed point, hence a unique solution of \(f(x) = z\) — \(f\) is a bijection of \(\mathbb{R}^{d}\) onto itself, and the iteration converges to \(f^{-1}(z)\) from anywhere (Behrmann et al. 2019, Thm. 1). On the Measured, on one block slide: \(L = 0.5\) reaches \(10^{-10}\) in \(27\) iterations; \(L = 0.95\) has not after \(60\).
With \(\operatorname{Lip}(g) = L < 1\) and \(f(x) = x + g(x)\):
Enforcing \(L < 1\): spectral normalization — divide each weight matrix by (a bound on) its largest singular value (Behrmann et al. 2019, sec. 2.1). This is the bounded constant of the topology block.
\(J_f = I + J_g\) is dense. Under \(\lVert J_g\rVert_2 \le L < 1\): every eigenvalue of \(J_f\) has positive real part, so \(\det J_f > 0\); and \(\log\det = \operatorname{tr}\log\) has a power series:
\[ \begin{aligned} \log\det\big(I + J_g\big) &= \sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{k}\,\operatorname{tr}\big(J_g^{k}\big), \\ &\qquad \text{valid when } \rho(J_g) < 1 . \end{aligned} \]
The condition is part of the formula — the Maclaurin series of \(\log(1 + a)\) with a matrix for \(a\), convergent for the same reason. Truncation after \(n\) terms: error \(\le d \sum_{k > n} L^{k}/k\), geometric at rate \(L\) (Behrmann et al. 2019, sec. 3, Thm. 3).
Infinitely many traces of matrices that are never formed. The device:
For \(A \in \mathbb{R}^{d \times d}\) and a random \(v\) with \(\mathbb{E}_{v}[v v^{\top}] = I_d\) (Rademacher \(\pm 1\), or Gaussian): \[ \operatorname{tr}(A) = \mathbb{E}_{v}\big[\, v^{\top} A\, v \,\big]. \]
Usage. \(v^{\top} J_g^{k} v\) by \(k\) vector–Jacobian products: \(w^{\top} \leftarrow v^{\top}\), then \(w^{\top} \leftarrow w^{\top} J_g\) \(k\) times, then \(w^{\top} v\). One backward pass of \(g\) per product; \(J_g\) never materialized. One probe serves every term.
Deferred. Proof and variance: U2.T2, where the estimator carries the weight. Named only: the truncated series is biased; the Russian-roulette estimator of (Chen et al. 2019) removes the bias by a random truncation with reweighting.
| Density / likelihood | Sampling | |
|---|---|---|
| Residual flow | \(f(x) = x + g(x)\) direct; \(\log\lvert\det J\rvert\) an infinite series, estimated stochastically | \(\psi = f^{-1}\) by fixed-point iteration, several evaluations of \(g\) per block |
One row stochastic and approximate, the other iterative and exact to any tolerance. Not “both directions are stochastic”.
Put a step \(h = 1/K\) in front of each residual branch and let the branch depend on a time \(t_k = k h\):
\[ x_{k+1} = x_k + h\,f(t_k, x_k), \qquad k = 0, \dots, K-1 . \]
The letter \(f\) is now the right-hand side of a differential equation, time first — the course’s f(t, x); the residual branch of the residual-flow block is \(g_k = h f(t_k, \cdot)\). This is the forward-Euler step, and as \(h \to 0\) the stack’s output converges, for a regular enough \(f\), to the solution of \[
\frac{\mathrm{d}x}{\mathrm{d}t} = f(t, x), \qquad t \in [0, 1] .
\]
What does \(\log\lvert\det J\rvert\) become in continuous time?
Not answered today. U2.T1 sets up the flows of differential equations and the cost of a solver inside every training step; U2.T2 answers this question, with Hutchinson’s estimator on the critical path.
| 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 |
Version 3 in U2.T2, where the cells change. U3.L1 touches neither column.
| On the board | Status |
|---|---|
| The depth question | Answered twice (universality) |
| The fine print | Examined (topology): support, not level sets |
| The checkerboard gaps | Explained and calibrated (topology) |
| \(\log\lvert\det J\rvert\) in continuous time | Open. U2 |
Assigned today: PS1.5. Next session: the lab (U1.L2), multi-scale flows on images. The theory session after it opens U2 on the question above.