Simple Algorithm
Deep Learning · Representation · 24 min

Flows, Autoregressive & Energy-Based Models

Exact likelihoods from invertible maps and the chain rule, and unnormalized energies.

A VAE can only bound its likelihood and a GAN has none. Two other families compute it exactly: normalizing flows push noise through an invertible network and pay for every layer with a log-determinant, and autoregressive models multiply one-step predictions. A third, the energy-based model, writes down any density it likes, up to a normalizing constant it cannot compute. This lesson derives all three and the bargain each one strikes.

What you’ll learn

  • Derive the change-of-variables formula in one dimension, state it in dd dimensions, and write a flow's exact log-likelihood as a base log-density plus a sum of log-determinants.
  • Build affine coupling layers with triangular Jacobians, implement one with its inverse, and explain Glow's actnorm and invertible 1×11\times1 convolutions.
  • Show that an autoregressive model with Gaussian conditionals is a flow, and compare the network passes that flows and autoregressive models need to train and to sample.
  • Define an energy-based model, explain why its partition function blocks maximum likelihood while its score does not, and describe continuous-time flows trained by flow matching.

Densities through invertible maps

A normalizing flow models data x∈Rd\mathbf x\in\R^d with a simple base density pZ=N(0,I)p_Z=\mathcal N(\mathbf 0,I) and an invertible, differentiable network fθ:Rd→Rdf_{\boldsymbol\theta}:\R^d\to\R^d that maps data to noise, z=fθ(x)\mathbf z=f_{\boldsymbol\theta}(\mathbf x). (In this lesson z\mathbf z is that noise vector, a latent variable, never a pre-activation.) Its inverse g=fθ−1g=f_{\boldsymbol\theta}^{-1} is the generator: draw z∼pZ\mathbf z\sim p_Z and output x=g(z)\mathbf x=g(\mathbf z). The name comes from the data-to-noise direction, which "normalizes" data into a Gaussian. What density does such a model put on x\mathbf x?

DerivationThe change of variables, in one dimension and in d
  1. FX(x)=P(X≤x)=P(Z≤f(x))=FZ(f(x))F_X(x)=P(X\le x)=P\big(Z\le f(x)\big)=F_Z\big(f(x)\big)

    Start in one dimension with an increasing ff. The event X≤xX\le x is the event f(X)≤f(x)f(X)\le f(x), that is Z≤f(x)Z\le f(x), so the two cumulative distribution functions agree:

  2. pX(x)=pZ(f(x)) ∣f′(x)∣p_X(x)=p_Z\big(f(x)\big)\,\abs{f'(x)}

    Differentiate with the chain rule. A decreasing ff flips the inequality and the sign, and the absolute value absorbs both cases:

  3. log⁡pX(x)=log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣,Jf=∂f∂x∈Rd×d\log p_X(\mathbf x)=\log p_Z\big(f(\mathbf x)\big)+\log\abs{\det J_f(\mathbf x)},\qquad J_f=\frac{\partial f}{\partial\mathbf x}\in\R^{d\times d}

    In dd dimensions the same bookkeeping holds box by box: a small box around x\mathbf x carries the same probability as its image, and ff scales the box's volume by ∣det⁡Jf(x)∣\abs{\det J_f(\mathbf x)}, the Jacobian determinant. That gives the change-of-variables formula:

  4. log⁡pX(x)=log⁡pZ(z)−log⁡∣det⁡Jg(z)∣\log p_X(\mathbf x)=\log p_Z(\mathbf z)-\log\abs{\det J_g(\mathbf z)}

    Where ff stretches the neighborhood of x\mathbf x, ∣det⁡Jf∣>1\abs{\det J_f}>1, the box's probability equals that of a larger region of noise, so the data density at x\mathbf x exceeds the noise density at f(x)f(\mathbf x) by that factor. In the generator's direction, with x=g(z)\mathbf x=g(\mathbf z), the sign of the correction flips:

log⁡pX(x)=log⁡pZ(hK)+∑k=1Klog⁡∣det⁡Jfk(hk−1)∣,h0=x,hk=fk(hk−1)\log p_X(\mathbf x)=\log p_Z(\mathbf h_K)+\sum_{k=1}^{K}\log\abs{\det J_{f_k}(\mathbf h_{k-1})},\qquad\mathbf h_0=\mathbf x,\quad\mathbf h_k=f_k(\mathbf h_{k-1})
A flow is a stack f=fK∘⋯∘f1f=f_K\circ\dots\circ f_1. The chain rule multiplies the layers' Jacobians and determinants multiply, so log-determinants add. Training maximizes this exact likelihood over the data, with no bound and no sampling: plain maximum likelihood, which is the same as minimizing DKL(pdata ∥ pθ)\KL(p_{\text{data}}\,\|\,p_{\boldsymbol\theta}).
Predict before you look

One layer of a flow doubles every coordinate of a 28×28=78428\times28=784-dimensional image, fk(h)=2hf_k(\mathbf h)=2\mathbf h. How many nats does its log-determinant add to log⁡pX(x)\log p_X(\mathbf x)?

Show the answer

543 nats

Jfk=2IJ_{f_k}=2I, so log⁡∣det⁡Jfk∣=784ln⁡2≈543.4\log\abs{\det J_{f_k}}=784\ln2\approx543.4 nats: exactly one bit per dimension. Scaling alone buys likelihood. On 8-bit pixels this has no limit: a continuous density that squeezes its mass ever closer to the 256 integer values makes the likelihood arbitrarily large. That is why pixel values are dequantized with uniform noise before a flow's likelihood means anything (Evaluating Generative Models).

Coupling layers: cheap determinants by design

For a generic network the log-determinant costs O(d3)\order{d^3}, and inverting it means solving an equation iteratively. Flows are built instead from layers with triangular Jacobians, whose determinants are products of their diagonals. The simplest is the additive coupling layer of NICE (Dinh, Krueger & Bengio, 2015): split x\mathbf x into halves (xa,xb)(\mathbf x_a,\mathbf x_b), keep xa\mathbf x_a, and shift the rest by any network of it, yb=xb+m(xa)\mathbf y_b=\mathbf x_b+\mathbf m(\mathbf x_a). Its Jacobian has ones on the diagonal, so it preserves volume, and NICE ended with a diagonal scaling layer to let volume change. RealNVP (Dinh, Sohl-Dickstein & Bengio, 2017) made the coupling affine:

DerivationAffine coupling: log-determinant and inverse
  1. ya=xa,yb=xb⊙exp⁡(s(xa))+t(xa)\mathbf y_a=\mathbf x_a,\qquad\mathbf y_b=\mathbf x_b\odot\exp\big(\mathbf s(\mathbf x_a)\big)+\mathbf t(\mathbf x_a)

    Keep the first kk coordinates; scale and shift the others by functions of them, where s,t:Rk→Rd−k\mathbf s,\mathbf t:\R^k\to\R^{d-k} are arbitrary networks:

  2. J=(Ik0∂yb/∂xadiag⁡(exp⁡s(xa)))⟹log⁡∣det⁡J∣=∑jsj(xa)J=\begin{pmatrix}I_k&0\\ \partial\mathbf y_b/\partial\mathbf x_a&\diag\big(\exp\mathbf s(\mathbf x_a)\big)\end{pmatrix}\quad\Longrightarrow\quad\log\abs{\det J}=\sum_{j}s_j(\mathbf x_a)

    The Jacobian is block lower-triangular. The derivatives of s\mathbf s and t\mathbf t fill the off-diagonal block, which never enters the determinant:

  3. xa=ya,xb=(yb−t(ya))⊙exp⁡(−s(ya))\mathbf x_a=\mathbf y_a,\qquad\mathbf x_b=\big(\mathbf y_b-\mathbf t(\mathbf y_a)\big)\odot\exp\big(-\mathbf s(\mathbf y_a)\big)

    The inverse costs one more pass, because ya=xa\mathbf y_a=\mathbf x_a is available on both sides. Neither s\mathbf s nor t\mathbf t is ever inverted, so they can be any networks at all:

Check your understanding

At some input, an affine coupling layer on R6\R^6 computes the log-scales s(xa)=(0.3, −0.5, 0.1)\mathbf s(\mathbf x_a)=(0.3,\,-0.5,\,0.1). What is the layer's log⁡∣det⁡J∣\log\abs{\det J} there?

  1. −0.1-0.1
  2. e0.3e−0.5e0.1≈0.905e^{0.3}e^{-0.5}e^{0.1}\approx0.905
  3. 00, since coupling layers preserve volume
  4. It needs the full 6×66\times6 determinant, including the derivatives of s\mathbf s and t\mathbf t
Show the answer

A. −0.1-0.1

The log-determinant is the sum of the log-scales, 0.3−0.5+0.1=−0.10.3-0.5+0.1=-0.1: on net the layer shrinks volume slightly, by the factor e−0.1≈0.905e^{-0.1}\approx0.905.

python
import math
import torch
import torch.nn as nn

class AffineCoupling(nn.Module):
    def __init__(self, d, hidden=256):
        super().__init__()
        self.k = d // 2
        self.net = nn.Sequential(nn.Linear(self.k, hidden), nn.ReLU(),
                                 nn.Linear(hidden, 2 * (d - self.k)))

    def forward(self, x):                        # data -> noise, plus log|det J|
        xa, xb = x[:, :self.k], x[:, self.k:]
        s, t = self.net(xa).chunk(2, dim=-1)
        s = torch.tanh(s)                        # keeps each scale in (1/e, e)
        return torch.cat([xa, xb * torch.exp(s) + t], dim=-1), s.sum(dim=-1)

    def inverse(self, z):                        # noise -> data; s, t never inverted
        za, zb = z[:, :self.k], z[:, self.k:]
        s, t = self.net(za).chunk(2, dim=-1)
        return torch.cat([za, (zb - t) * torch.exp(-torch.tanh(s))], dim=-1)

def log_prob(layers, x):                         # exact log-likelihood of each row
    logdet = torch.zeros(x.shape[0])
    for layer in layers:
        x, ld = layer(x)
        logdet = logdet + ld
        x = x.flip(dims=[1])                     # reverse the order: |det| = 1
    base = -0.5 * (x ** 2).sum(dim=1) - 0.5 * x.shape[1] * math.log(2 * math.pi)
    return base + logdet

A coupling layer and the exact log-likelihood of a stack. Reversing the coordinates between layers, a permutation, lets every coordinate be transformed by some layer. Train by minimizing -log_prob(layers, x).mean(); to sample, push Gaussian noise through the layers in reverse order, undoing each flip and calling inverse. The tanh bounds the log-scales, a common guard against exploding scales early in training.

Images. RealNVP splits pixels by a checkerboard pattern and channels into halves, and uses a squeeze that turns an s×s×cs\times s\times c tensor into s2×s2×4c\tfrac s2\times\tfrac s2\times4c, trading resolution for channels. Its multi-scale architecture factors out half of the dimensions after each scale, so later layers work on fewer of them. Glow (Kingma & Dhariwal, 2018) made each step of the flow three layers:

  • actnorm, a per-channel scale and bias initialized from a first minibatch so that each channel starts with zero mean and unit variance, then trained freely; for an h×wh\times w feature map its log-determinant is h⋅w⋅∑clog⁡∣sc∣h\cdot w\cdot\sum_c\log\abs{s_c};
  • an invertible 1×11\times1 convolution, a learned c×cc\times c matrix WW that mixes the channels at every pixel and generalizes the fixed permutations of RealNVP; its log-determinant is h⋅w⋅log⁡∣det⁡W∣h\cdot w\cdot\log\abs{\det W}, an O(c3)\order{c^3} computation that drops to O(c)\order{c} when WW is stored in LU form, W=PL(U+diag⁡s)W=PL(U+\diag\mathbf s);
  • an affine coupling layer.

On CIFAR-10 this improved the likelihood from RealNVP's 3.49 bits per dimension to 3.35, while the autoregressive PixelCNN++ had already reached 2.92. Glow's samples were shown at reduced temperature, with the noise scaled by 0.7 before decoding, trading diversity for cleaner images.

Autoregressive models are flows too

The overview lesson wrote every distribution as a product of one-step predictions, p(x)=∏ip(xi∣x<i)p(\mathbf x)=\prod_ip(x_i\mid\mathbf x_{<i}). Give each conditional a Gaussian whose mean and standard deviation are networks of the earlier coordinates, and sampling becomes a map from noise to data:

xi=μi(x<i)+σi(x<i) zi,zi=xi−μi(x<i)σi(x<i),log⁡p(x)=∑i=1d[log⁡N(zi;0,1)−log⁡σi(x<i)]x_i=\mu_i(\mathbf x_{<i})+\sigma_i(\mathbf x_{<i})\,z_i,\qquad z_i=\frac{x_i-\mu_i(\mathbf x_{<i})}{\sigma_i(\mathbf x_{<i})},\qquad\log p(\mathbf x)=\sum_{i=1}^{d}\Big[\log\mathcal N(z_i;0,1)-\log\sigma_i(\mathbf x_{<i})\Big]
The map x↦z\mathbf x\mapsto\mathbf z has a lower-triangular Jacobian with diagonal entries 1/σi1/\sigma_i, so the change-of-variables formula reproduces the chain rule term by term. This is an autoregressive flow (Kingma et al., 2016; Papamakarios, Pavlakou & Murray, 2017). A coupling layer is the special case in which the first half of the coordinates conditions on nothing and the second half only on the first.

For discrete data no flow is needed. PixelCNN predicts each pixel value, WaveNet each audio sample and a GPT each token with a softmax over the possible values, and the exact log-likelihood is the sum of the log-probabilities given to the true values. What the autoregressive family shares is its cost structure:

  • Training and density evaluation take one pass. All of x\mathbf x is known, so one network computes every conditional at once, provided its connections respect the ordering: masked weights (MADE), masked or causal convolutions (PixelCNN, WaveNet), or a causal attention mask.
  • Sampling takes dd sequential passes, since xix_i must exist before xi+1x_{i+1} can be predicted: 3,072 for a 32×3232\times32 color image generated one channel value at a time, 16,000 for one second of 16 kHz audio.
Modellog⁡p(x)\log p(\mathbf x) of a given x\mathbf xOne sample
Coupling flow (RealNVP, Glow)one passone pass
Autoregressive model (PixelCNN, WaveNet, GPT, masked autoregressive flow)one passdd sequential passes
Inverse autoregressive flow (IAF)dd sequential passesone pass
An autoregressive flow is fast in exactly one direction, set by whether its μi,σi\mu_i,\sigma_i are computed from the data or from the noise. The Emergence lesson Autoregressive Density Models derives both and shows how Parallel WaveNet trained a fast-sampling inverse autoregressive flow to imitate a WaveNet.
Think first Why can a coupling layer be inverted in one pass, while an autoregressive layer of the same Gaussian form is fast in only one direction?

A coupling layer's scales and shifts depend only on the half it leaves unchanged, which is available in both directions. An autoregressive layer's μi,σi\mu_i,\sigma_i depend on x<i\mathbf x_{<i}: given data they are all available at once, but when sampling, xix_i exists only after xi−1x_{i-1} has been computed. The coupling layer pays for its speed in flexibility. Half of its outputs condition on nothing, so it takes many layers, with permutations between them, to capture dependencies that one autoregressive layer models directly.

Energy-based models: any network, no normalizer

An energy-based model (EBM) drops invertibility and every other architectural constraint. Any network Eθ:Rd→RE_{\boldsymbol\theta}:\R^d\to\R defines a density that is high where the energy is low:

pθ(x)=exp⁡(−Eθ(x))Zθ,Zθ=∫Rdexp⁡(−Eθ(x)) dxp_{\boldsymbol\theta}(\mathbf x)=\frac{\exp\big(-E_{\boldsymbol\theta}(\mathbf x)\big)}{Z_{\boldsymbol\theta}},\qquad Z_{\boldsymbol\theta}=\int_{\R^d}\exp\big(-E_{\boldsymbol\theta}(\mathbf x)\big)\,d\mathbf x
The partition function ZθZ_{\boldsymbol\theta} must be finite, so the energy has to grow fast enough far from the data. In high dimensions the integral has no closed form, and naive Monte Carlo estimates of it fail because almost all of the volume carries negligible weight.

Without ZθZ_{\boldsymbol\theta} the model cannot report log⁡pθ(x)\log p_{\boldsymbol\theta}(\mathbf x), only the energy, which is −log⁡pθ-\log p_{\boldsymbol\theta} up to an unknown constant: enough to rank two inputs, not to compare two models. Maximum likelihood still works in principle. The gradient of the log-likelihood splits into a term at the data point and an expectation under the model itself:

∇θlog⁡pθ(x)=−∇θEθ(x)+Ex′∼pθ[∇θEθ(x′)].\nabla_{\boldsymbol\theta}\log p_{\boldsymbol\theta}(\mathbf x)=-\nabla_{\boldsymbol\theta}E_{\boldsymbol\theta}(\mathbf x)+\E_{\mathbf x'\sim p_{\boldsymbol\theta}}\big[\nabla_{\boldsymbol\theta}E_{\boldsymbol\theta}(\mathbf x')\big].

Lower the energy of the data, raise it on the model's own samples; at the optimum the two averages balance. The catch is the second term, which needs samples from pθp_{\boldsymbol\theta}, a distribution known only up to ZθZ_{\boldsymbol\theta}. Restricted Boltzmann machines were trained by approximating it with a few steps of Markov chain Monte Carlo started at the data, the contrastive divergence of Hinton (2002).

One quantity escapes ZθZ_{\boldsymbol\theta} entirely: the score, the gradient of the log-density with respect to the input,

∇xlog⁡pθ(x)=−∇xEθ(x)−∇xlog⁡Zθ⏟= 0.\nabla_{\mathbf x}\log p_{\boldsymbol\theta}(\mathbf x)=-\nabla_{\mathbf x}E_{\boldsymbol\theta}(\mathbf x)-\underbrace{\nabla_{\mathbf x}\log Z_{\boldsymbol\theta}}_{=\,0}.

That opens two doors. Langevin dynamics samples from pθp_{\boldsymbol\theta} by following −∇xEθ-\nabla_{\mathbf x}E_{\boldsymbol\theta} plus noise, and score matching (Hyvärinen, 2005) fits a model's score to data without ever touching ZθZ_{\boldsymbol\theta}. Learning the scores of noise-blurred data at many noise levels is exactly what diffusion models do (Diffusion Models).

Check your understanding

A colleague proposes to train an EBM by minimizing the average energy 1n∑iEθ(xi)\frac1n\sum_iE_{\boldsymbol\theta}(\mathbf x_i) of the training data, "since log⁡Zθ\log Z_{\boldsymbol\theta} is just a constant". What goes wrong?

  1. Nothing: a constant does not change the gradient
  2. The energy network would have to be invertible
  3. The gradient of the energy cannot be computed by backpropagation
  4. ZθZ_{\boldsymbol\theta} depends on θ\boldsymbol\theta; without it the network can lower the energy everywhere, so the loss falls without bound while the density learns nothing
Show the answer

D. ZθZ_{\boldsymbol\theta} depends on θ\boldsymbol\theta; without it the network can lower the energy everywhere, so the loss falls without bound while the density learns nothing

−log⁡pθ(x)=Eθ(x)+log⁡Zθ-\log p_{\boldsymbol\theta}(\mathbf x)=E_{\boldsymbol\theta}(\mathbf x)+\log Z_{\boldsymbol\theta}, and log⁡Zθ\log Z_{\boldsymbol\theta} moves with every weight. Its gradient, −Epθ[∇θEθ]-\E_{p_{\boldsymbol\theta}}[\nabla_{\boldsymbol\theta}E_{\boldsymbol\theta}], is what pushes the energy up away from the data. Drop it and nothing stops the network from subtracting an ever larger constant everywhere.

Flows in continuous time

Shrink the steps of a residual flow, hk+1=hk+Δt vθ(hk,tk)\mathbf h_{k+1}=\mathbf h_k+\Delta t\,\mathbf v_{\boldsymbol\theta}(\mathbf h_k,t_k), toward zero and the stack becomes an ordinary differential equation, a neural ODE (Chen, Rubanova, Bettencourt & Duvenaud, 2018). Time runs from noise at t=0t=0 to data at t=1t=1, the convention of flow matching:

dxtdt=vθ(xt,t),x0∼N(0,I).\frac{d\mathbf x_t}{dt}=\mathbf v_{\boldsymbol\theta}(\mathbf x_t,t),\qquad\mathbf x_0\sim\mathcal N(\mathbf 0,I).

If the velocity field is Lipschitz in x\mathbf x (uniformly in tt) and continuous in tt, solutions exist, are unique and can be run backward, so the map from x0\mathbf x_0 to x1\mathbf x_1 is invertible whatever the network looks like. The sum of log-determinants becomes an integral of a trace, ddtlog⁡pt(xt)=−tr⁡∂vθ∂x(xt,t)\frac{d}{dt}\log p_t(\mathbf x_t)=-\operatorname{tr}\frac{\partial\mathbf v_{\boldsymbol\theta}}{\partial\mathbf x}(\mathbf x_t,t). Such a continuous normalizing flow has an exact likelihood, up to the accuracy of the ODE solver, but training it by maximum likelihood means solving the ODE, and estimating traces, at every step.

Flow matching (Lipman et al., 2023) and rectified flow (Liu, Gong & Liu, 2023) skip the simulation. Draw noise x0\mathbf x_0, a data point x1\mathbf x_1 and a time tt, form xt=(1−t)x0+tx1\mathbf x_t=(1-t)\mathbf x_0+t\mathbf x_1, and regress vθ(xt,t)\mathbf v_{\boldsymbol\theta}(\mathbf x_t,t) on x1−x0\mathbf x_1-\mathbf x_0 with a squared error. The Emergence lesson Continuous Flows & Flow Matching proves that this simple regression learns a field whose flow carries the noise to the data.

Think first In the two-cluster target, which noise points end up in the left cluster?

Those that start left of the vertical axis. The noise and the target are mirror-symmetric, so on that axis the field has no horizontal component, and since solutions of an ODE with a Lipschitz field are unique, no exact trajectory crosses it. Half of the noise lies on each side, matching the clusters' equal weights. No learned notion of the "nearest" cluster is involved: the noise is carried by a map that must be continuous and invertible.

Familylog⁡p(x)\log p(\mathbf x)SamplingArchitectureMain cost
Coupling flows (RealNVP, Glow)exact, one passone passinvertible layers with triangular Jacobians; latent as large as the datamany layers needed; likelihoods behind autoregressive models
Autoregressive (PixelCNN, WaveNet, GPT)exact, one passdd sequential passesany network that respects an orderingslow sampling
Continuous flows (CNFs, flow matching)exact via an ODE and a traceone ODE solve: tens of stepsany velocity networkmany network calls per sample
Energy-based modelsonly up to log⁡Zθ\log Z_{\boldsymbol\theta}MCMC: many gradient stepsany scalar networktraining needs model samples or a score-based objective
Exact likelihood is bought with architectural constraints (coupling flows), with sequential sampling (autoregressive models) or with ODE solves (continuous flows). Energy-based models buy complete freedom by giving it up.

Key takeaways

  • Change of variables: log⁡pX(x)=log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣\log p_X(\mathbf x)=\log p_Z(f(\mathbf x))+\log\abs{\det J_f(\mathbf x)} for an invertible ff from data to noise. Stacked layers add their log-determinants, so a flow is trained by exact maximum likelihood.
  • Coupling layers keep half the coordinates and scale and shift the rest by networks of the first half: a triangular Jacobian with log⁡∣det⁡J∣=∑jsj(xa)\log\abs{\det J}=\sum_js_j(\mathbf x_a) and a one-pass inverse. Glow adds actnorm and invertible 1×11\times1 convolutions.
  • An autoregressive model with Gaussian conditionals is a flow with a triangular Jacobian; on discrete data the chain rule gives exact likelihoods directly. Training takes one parallel pass, sampling dd sequential passes.
  • An energy-based model pθ∝e−Eθp_{\boldsymbol\theta}\propto e^{-E_{\boldsymbol\theta}} accepts any network but hides ZθZ_{\boldsymbol\theta}: its likelihood gradient needs samples from the model, while its score −∇xEθ-\nabla_{\mathbf x}E_{\boldsymbol\theta} does not involve ZθZ_{\boldsymbol\theta} at all.
  • Continuous flows integrate a learned velocity field from noise to data; flow matching trains them by regression on straight noise-to-data paths, without solving the ODE during training.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A flow maps data to noise by z=f(x)\mathbf z=f(\mathbf x). Near a data point x\mathbf x, ff doubles volumes: ∣det⁡Jf(x)∣=2\abs{\det J_f(\mathbf x)}=2. How does the model's density at x\mathbf x compare with the base density at f(x)f(\mathbf x)?

  1. It is half as large
  2. It is the same, since invertible maps preserve density
  3. It is twice as large
  4. It cannot be determined without the inverse map
Show the answer

C. It is twice as large

pX(x)=pZ(f(x)) ∣det⁡Jf(x)∣p_X(\mathbf x)=p_Z(f(\mathbf x))\,\abs{\det J_f(\mathbf x)}. A small box around x\mathbf x carries the same probability as its image, which is twice as large in noise space, so the probability per unit volume at x\mathbf x is twice the base density at f(x)f(\mathbf x).

Question 2

A Glow step applies an invertible 1×11\times1 convolution with a c×cc\times c weight matrix WW to an h×w×ch\times w\times c tensor. What is its log-determinant?

  1. log⁡∣det⁡W∣\log\abs{\det W}
  2. h⋅w⋅log⁡∣det⁡W∣h\cdot w\cdot\log\abs{\det W}
  3. c⋅log⁡∣det⁡W∣c\cdot\log\abs{\det W}
  4. 00, since a 1×11\times1 convolution only permutes channels
Show the answer

B. h⋅w⋅log⁡∣det⁡W∣h\cdot w\cdot\log\abs{\det W}

The same WW acts on the cc channels at each of the h⋅wh\cdot w pixels, so the full Jacobian is block-diagonal with h⋅wh\cdot w copies of WW, and the blocks' log-determinants add.

Question 3

You need to draw 10,000 samples quickly from a model of 32×3232\times32 color images, and you also want exact test log-likelihoods. Which model fits both needs best?

  1. A PixelCNN
  2. An energy-based model
  3. A coupling flow such as Glow
  4. A GAN
Show the answer

C. A coupling flow such as Glow

A coupling flow evaluates log⁡p(x)\log p(\mathbf x) exactly in one pass and samples in one pass. A PixelCNN gives exact likelihoods but needs 3,072 sequential passes per sample, an energy-based model gives its likelihood only up to a constant and samples by MCMC, and a GAN has no likelihood at all.

Question 4

Which quantity of an energy-based model can be computed exactly at any x\mathbf x without knowing its partition function ZθZ_{\boldsymbol\theta}?

  1. The score ∇xlog⁡pθ(x)\nabla_{\mathbf x}\log p_{\boldsymbol\theta}(\mathbf x)
  2. The density pθ(x)p_{\boldsymbol\theta}(\mathbf x)
  3. The parameter gradient ∇θlog⁡pθ(x)\nabla_{\boldsymbol\theta}\log p_{\boldsymbol\theta}(\mathbf x)
  4. The log-likelihood ratio log⁡pθ(x)−log⁡pθ′(x)\log p_{\boldsymbol\theta}(\mathbf x)-\log p_{\boldsymbol\theta'}(\mathbf x) between two parameter settings
Show the answer

A. The score ∇xlog⁡pθ(x)\nabla_{\mathbf x}\log p_{\boldsymbol\theta}(\mathbf x)

The score is −∇xEθ(x)-\nabla_{\mathbf x}E_{\boldsymbol\theta}(\mathbf x): log⁡Zθ\log Z_{\boldsymbol\theta} does not depend on x\mathbf x, so its gradient vanishes. Langevin sampling and score matching rely on exactly this.

Go deeper

Further reading

  • L. Dinh, J. Sohl-Dickstein & S. Bengio, "Density estimation using Real NVP," ICLR (2017).
  • D. P. Kingma & P. Dhariwal, "Glow: Generative flow with invertible 1×1 convolutions," NeurIPS (2018).
  • G. Papamakarios, E. Nalisnick, D. J. Rezende, S. Mohamed & B. Lakshminarayanan, "Normalizing flows for probabilistic modeling and inference," Journal of Machine Learning Research 22(57), 1–64 (2021).
  • S. J. D. Prince, Understanding Deep Learning, ch. 16 "Normalizing flows" (MIT Press, 2023), free at udlbook.github.io.