Skip to content
mlmentorship

Normalizing flows

Transport a base density through invertible maps and track local volume. Likelihood and sampling costs depend on the architecture.

Published · 7 min read ·Role-specific ·Intermediate
Reading depth

Summary

A normalizing flow transports a base density through invertible transformations, accounting for their local volume changes. For the differentiable bijections here, density evaluation uses the inverse coordinate and the inverse Jacobian’s absolute determinant:

An invertible coordinate is not a nontrivial VAE-style posterior distribution. Tractable discrete-layer likelihood and fast sampling depend on the selected architecture; neither property uniquely belongs to flows.

The change-of-variables formula

Require a differentiable inverse and nonzero Jacobian determinant on the relevant support. For :

For a composition of flows, the log-determinant decomposes additively:

Evaluate each layer’s determinant at its actual intermediate state. Evaluate standard Gaussian density at . Set and . The states are , with determinant factors two and . The local area triples while probability mass is conserved, so . Gaussian log density gives:

Change of variables

Expanding volume lowers density while preserving probability mass

Expanding volume dilutes density, not probability massThe same four dots carry mass 1 before and after expansion. Doubling the drawn area changes density from 1 to 0.5, not the total probability mass.Stretch the space, not theprobability massMass 1; area 1; density 1Mass 1; area 2; density 0.5Four marks still carry four quartersof the mass.
Derivation
Local volume and density through two invertible flow layers A small patch around z zero has relative area A, probability mass m, and density p zero. The first invertible layer stretches the patch horizontally by two, so its Jacobian determinant is two, its area is 2A, and its density is p zero divided by two. The second layer stretches vertically by three halves, so the total area is 3A and the final density is p zero divided by three. Solid downward arrows mark forward sampling. Dashed upward arrows mark inverse density evaluation. The log-density ledger subtracts log two and log three halves, which equals subtracting log three. 1 · BASE SPACE z₀ area A · mass m · density p₀ = m/A sample forward f₁ · |det J₁| = 2 evaluate density with f₁⁻¹ 2 · AFTER HORIZONTAL STRETCH z₁ area 2A · same mass m · density p₀/2 sample forward f₂ · |det J₂| = 3/2 evaluate density with f₂⁻¹ 3 · DATA SPACE x area 3A · same mass m · density pₓ = p₀/3 LOG-DENSITY LEDGER log pₓ = log p₀ − log 2 − log(3/2) = log p₀ − log 3
Read it this way: forward transforms stretch a local patch without changing its probability mass. Inverse density evaluation divides by the total volume multiplier. Here area multiplies by three and log density loses log three. Dots illustrate mass; they are not point-probability density values. Original construction follows Real NVP and the flows review.
Check: Why does tripling occupied volume divide density by three while leaving total probability mass unchanged?
Read it this way: The same four dots carry mass 1 before and after expansion. Doubling the drawn area changes density from 1 to 0.5, not the total probability mass.
What happens to density if the same mass occupies twice the area?

Inverting returns ; multiplying its transformed density by tripled local area recovers the same mass.

RealNVP / coupling layers (the workhorse)

Split . Then:

The Jacobian is block triangular, with log absolute determinant . Inverse reconstruction uses and . The internal s/t networks need not themselves be invertible.

Stack many coupling layers, alternating which half passes through, with shuffles or 1×1 convs between them.

Change a Scale into Coupling

New task: Use , through constant , .

Picture and change: Apply the triangular coupling and evaluate its explicit inverse.

Check: maps to , determinant two; inverse second coordinate is .

Use when: A structured invertible layer needs a tractable determinant without inverting its internal neural networks.

Change the Required Fast Direction

New task: Prioritize density scoring in three coordinates over generation latency.

Picture and change: In MAF, known x prefixes support masked parallel inverse-coordinate evaluation. Sampling must resolve the x prefixes sequentially; IAF reverses this directional convenience.

Check: Generating x1, x2, x3 takes three dependent coordinate stages in this ordering.

Use when: Density queries and sample generation have different serving priorities.

The map is not a bijection on the real line: positive and negative z collide. Using only one inverse branch in the stated formula loses probability mass.

Common flow families

FamilyStructureImportant limit
CouplingTriangular Jacobian; NICE is an additive special caseExpressiveness needs suitable compositions
MAF/IAFAutoregressive coordinate dependenceFast direction differs
Continuous timeODE and divergence integrationSolver/trace estimation introduces numerical or Monte Carlo error
Invertible channel mixingLearned nonsingular linear transformRetain determinant and conditioning checks

When to use flows in 2026

Compare density estimation, simulation-based conditional inference, forecasting, and generative tasks under their actual accuracy and compute criteria. A high likelihood does not automatically identify in-distribution semantics or provide a reliable anomaly/OOD score. Do not infer a universal image-quality or training-speed ranking from model-family names.

Common pitfalls

  • Wrong determinant direction: density evaluation adds inverse log determinant, equivalently subtracting forward log determinant.
  • Discrete observations: dequantization models a continuous auxiliary distribution; relate its density objective to discrete likelihood explicitly.
  • Numerics: finite precision, nearly singular transforms, and ODE tolerances can invalidate an unqualified “exact” claim.