Autoregressive Models & Normalizing Flows
Two families that provide exact likelihoods, each at a cost. Autoregressive models factor the joint by the probability chain rule and learn each conditional with a masked network: exact , but sampling proceeds one coordinate at a time.
╌╌╌╌
The variational autoencoder optimizes a bound on ; the GAN never writes a density at all. This lesson covers the two families that compute exactly (no bound, no adversary) by constraining the architecture so the likelihood stays tractable. Autoregressive models accept slow sampling; normalizing flows accept a restricted class of invertible maps. Both are trained by plain maximum likelihood.1
Autoregressive models: the chain rule as architecture
Any joint distribution over an ordered vector factors exactly, with no assumptions, by the probability chain rule:
Taking logs turns the product into a sum, and the training objective is the negative log-likelihood averaged over the data, one term per coordinate:
Generation walks the same factorization left to right: sample , feed it back to get , sample , and so on. Each draw conditions on every coordinate already produced.2
The defining tension is built into this picture. The likelihood is a single forward pass (every conditional evaluated in parallel because the true are known at training time), but sampling is inherently sequential: cannot be drawn until exists.
| Operation | Cost | Why |
|---|---|---|
| Likelihood | one parallel forward pass | all are observed, so every conditional evaluates at once |
| Sampling | sequential passes | depends on the freshly sampled |
| Training | parallel (teacher forcing) | condition on ground-truth , not model samples |
Enforcing the ordering with masks
The architectural problem is leakage: a naive network mixing all inputs would let the prediction of peek at itself or at future coordinates, making the conditional ill-defined. The fix across the whole family is the same: zero out the forbidden connections so output is a function of inputs only.
MADE (Masked Autoencoder for Distribution Estimation) realizes this in a plain autoencoder. Assign each hidden unit a number in ; keep a weight from input to a unit only if , and from a unit to output only if . Element-wise multiplying each weight matrix by a binary mask enforces the constraint with no change to the forward cost:3
and the masks are chosen so that whenever — exactly the autoregressive property.
PixelRNN and PixelCNN apply the same idea to images, generating pixels in raster order. PixelRNN threads an LSTM along rows; PixelCNN is faster, replacing the recurrence with a stack of masked convolutions. The convolution kernel is masked so the receptive field covers only pixels above the current one, and to its left within the current row; the future half of the kernel is zeroed.
WaveNet carries the construction to raw audio, where is tens of thousands of samples. It stacks dilated causal convolutions: causal so output depends only on samples , dilated so the receptive field grows exponentially with depth: a stack of layers with dilations reaches back samples while keeping the parameter count linear in .
| Model | Conditional network | Domain | Mask mechanism |
|---|---|---|---|
| MADE | masked MLP / autoencoder | vectors | masked weight matrices |
| PixelRNN | row LSTM | images | recurrence is causal by construction |
| PixelCNN | masked CNN | images | future half of the kernel zeroed |
| WaveNet | dilated causal CNN | audio | causal conv, exponential dilation |
Normalizing flows: change of variables
Flows take a different route to an exact likelihood. Start from a simple base density (a standard Gaussian) and push a sample through an invertible, differentiable map :
The density of follows from conservation of probability mass. A region of -space of volume carries probability ; the map stretches it to a region of volume in -space, where is the Jacobian. Mass is preserved, so the density must scale inversely with the volume.4
Writing and substituting gives the change-of-variables formula, on which the whole family rests:
In log space, products become sums and the inverse becomes a sign flip:
The objective is now plain maximum likelihood, computed exactly:
The Jacobian-determinant bottleneck
The formula is exact but useless unless three operations are cheap. Computing for a general dense costs , fatal for image-sized . Every flow architecture is therefore engineered around making the Jacobian structured so its determinant is trivial.
| Requirement | Why | Constraint on |
|---|---|---|
| exists | evaluate for the likelihood | bijective |
| cheap | likelihood at scale | invert in , not by solving a system |
| cheap | the log-likelihood term | triangular / diagonal Jacobian → |
The recurring trick: if is triangular, its determinant is just the product of its diagonal entries, — an computation. The question becomes how to build an expressive bijection whose Jacobian is triangular.
Coupling layers: NICE and RealNVP
The answer is the coupling layer. Partition the coordinates into two blocks, . Copy the first block unchanged; transform the second block with a function whose parameters are produced by a network reading only the first block:
where and (scale and translation) are arbitrary neural networks; they need not be invertible themselves. This is the affine coupling of RealNVP; dropping the scale () recovers the additive coupling of NICE.
Two properties make the coupling layer the standard building block of flows. First, it is trivially invertible without inverting or — given , recover , recompute , and solve:
Second, the Jacobian is triangular. Since and depends on only through the diagonal scaling :
The block-triangular structure means the determinant ignores the messy off-diagonal block entirely:
The expensive determinant has collapsed to a sum of the scale outputs, an operation, independent of and 's complexity.5
A worked Jacobian and likelihood
Trace a single point through one affine coupling layer with real numbers. Work in , split as and , and suppose the scale and shift networks happen to output and . Take the input , so gives and . The forward map is
The Jacobian of this map is lower-triangular,
and its log-determinant ignores the off-diagonal entirely: . Confirm the lemma numerically — the determinant is , whose log is , exactly the sum of the scale outputs, no matter what equals.
Now read off the likelihood. Under a standard Gaussian base, the point maps back to during evaluation; for a single-layer flow the base point is the pre-image, but to make the change-of-variables arithmetic concrete, suppose an input whose inverse is with accumulated log-determinant . The base log-density of a 2-D unit Gaussian is . The change-of-variables formula then gives
The stretch cost is subtracted directly: because this layer expanded volume (positive log-scale ), it spread the base mass thinner, so the data density is lower than the base density at the corresponding point. A contracting layer () would add to the log-likelihood. Stacking layers just accumulates , and every term is an sum of scale outputs.
Composing flows
A single coupling layer leaves half its coordinates untouched, so flows alternate which block is transformed and stack many layers. Because the composition of diffeomorphisms is a diffeomorphism, the whole stack is one valid flow, and its log-determinant is just the sum of the per-layer terms, the chain rule applied to the determinant:
with and . Each term is the coupling determinant above, so the total cost stays linear.
- 1
- 2accumulated log-determinant
- 3for down to do
- 4invert one coupling layer
- 5sum of scale outputs,
- 6
- 7return
The exact-likelihood families, side by side
Autoregressive models and flows are duals: an autoregressive model is itself a flow whose Jacobian is triangular by ordering rather than by partition, which is why inverse autoregressive flows and masked autoregressive flows unify the two.6 Each family makes a different trade among the three things a generative model is asked to do — score a sample, draw a sample, and draw a good sample.
| Family | Exact likelihood | Sampling speed | Sample quality | Mechanism |
|---|---|---|---|---|
| Autoregressive | yes (chain rule) | slow ( sequential steps) | high | masked conditionals |
| Normalizing flow | yes (change of variables) | fast (one parallel pass) | medium | invertible map, triangular Jacobian |
| VAE | lower bound (ELBO) | fast | medium (blurry) | amortized variational inference |
| GAN | none | fast | high (sharp) | adversarial min–max |
Each family trades one axis for the other two. Autoregressive models get exactness and quality at the cost of slow sampling; flows get exactness and fast sampling at the cost of a constrained, less expressive map; the VAE gets fast sampling and a flexible decoder at the cost of exactness (a bound); the GAN gets sharp samples at the cost of the likelihood entirely. No single family wins on all three axes, which is why the field keeps all four, and why hybrids (flow-decoded VAEs, autoregressive flows) combine one family's strength with another's. The next lesson turns to a fifth route, the energy-based and Boltzmann machines that model an unnormalized density, with the difficulty moved to the partition function.
Flows and autoregressive models today
Both families kept advancing after Goodfellow's text, and their two headline weaknesses — slow autoregressive sampling, weak flow expressiveness — were the targets.
Autoregressive models became the backbone of modern generation. WaveNet's dilated-causal design set the template, and the Transformer is now the dominant autoregressive architecture: a masked (causal) self-attention layer applies the leakage-prevention mask of this lesson to a sequence, and every large language model generates by the same left-to-right chain rule.7 The slow-sampling problem drove parallel WaveNet, which distilled a trained autoregressive teacher into an inverse-autoregressive-flow student that samples in one pass — a direct use of the AR/flow duality noted above.8
Flows gained expressiveness and exact-inverse attention. Kingma and Dhariwal's Glow added invertible convolutions (a learned channel permutation with a cheap determinant) and actnorm, producing the first flow with GAN-competitive high-resolution samples.9 Continuous normalizing flows then replaced the discrete stack with an ordinary differential equation, computing the log-determinant as an integral of a trace via the Hutchinson estimator — the FFJORD model — which removed the architectural constraints on the Jacobian entirely.10
The families converged with diffusion. A diffusion model can be read as a deep, fixed flow whose per-step Jacobian is trivial, and score-based models share the continuous-flow ODE formulation; the next lesson's energy-based models and the diffusion models after them inherit the exact-likelihood ambitions of this lesson while relaxing the invertibility that made flows rigid.
Takeaways
- Autoregressive models factor the joint exactly by the chain rule and learn each conditional with a network; likelihood is one parallel pass, but sampling is sequential steps.
- Masked connectivity (MADE's , PixelCNN's zeroed kernel half, WaveNet's dilated causal convolutions) enforces the ordering so output cannot see input .
- Normalizing flows push a Gaussian base through an invertible map and read off : exact likelihood, contingent on a cheap Jacobian determinant.
- Coupling layers (NICE/RealNVP) split coordinates and transform one half conditioned on the other, yielding a triangular Jacobian whose log-determinant is just ; composing many such layers keeps the cost .
- The four families trade among exact likelihood, sampling speed, and sample quality; no family dominates, which is the reason all of them persist.
Footnotes
- Goodfellow, Deep Learning, §20.10.7–20.10.10 — autoregressive networks and flow-based generation as the exact-likelihood alternatives to the VAE's bound and the GAN's implicit objective. ↩
- Goodfellow, Deep Learning, §20.10.7 — fully visible belief networks and autoregressive factorization , with parallel training and sequential sampling. ↩
- Goodfellow, Deep Learning, §20.10.8–20.10.10 — masked autoregressive networks (NADE/MADE) and masked/dilated convolutional variants (PixelCNN, WaveNet) that enforce the conditioning order through connectivity. ↩
- Goodfellow, Deep Learning, §3.9.2 — the change-of-variables formula that converts a base density through an invertible map. ↩
- Goodfellow, Deep Learning, §20.10.10 — normalizing flows and coupling layers (NICE/RealNVP) whose triangular Jacobian makes the log-determinant a cheap sum of scale outputs. ↩
- Goodfellow, Deep Learning, §20.10.10 — the duality between autoregressive models and flows, and the inverse/masked autoregressive flows that interpolate between fast sampling and fast density evaluation. ↩
- Vaswani et al.,
Attention Is All You Need,
NeurIPS 2017 — masked (causal) self-attention as the autoregressive architecture behind modern language models. ↩ - van den Oord et al.,
Parallel WaveNet: Fast High-Fidelity Speech Synthesis,
ICML 2018 — probability-density distillation of an autoregressive teacher into an inverse-autoregressive-flow student for single-pass sampling. ↩ - Kingma & Dhariwal,
Glow: Generative Flow with Invertible 1×1 Convolutions,
NeurIPS 2018 — invertible 1×1 convolutions and actnorm for high-resolution flow synthesis. ↩ - Grathwohl et al.,
FFJORD: Free-Form Continuous Dynamics for Scalable Reversible Generative Models,
ICLR 2019, building on Chen et al.,Neural Ordinary Differential Equations,
NeurIPS 2018 — continuous normalizing flows with an ODE-integrated log-determinant. ↩
╌╌ END ╌╌