Foundations to Frontier
Tests
H. Generative Models › H5 Normalizing Flows

Glow: ActNorm and invertible 1×1 convolutions

Glow (Kingma and Dhariwal, 2018) simplified and scaled up RealNVP. Each flow step is ActNorm (a per-channel affine layer initialised from data so activations start with zero mean and unit variance), an invertible 1×1 convolution (a learned c×c channel-mixing matrix replacing RealNVP's fixed permutations) and an affine coupling layer. LU-parameterising the 1×1 convolution makes its log-determinant a cheap sum of log-diagonal entries. Glow reached 3.35 bits per dimension on CIFAR-10, generated sharp 256×256 faces, and showed meaningful latent-space interpolation and attribute manipulation. This page covers the three layers, the LU trick, multi-scale design, reduced-temperature sampling and Glow's known weaknesses (huge depth, out-of-distribution likelihoods). In the exercises you implement ActNorm initialisation and the LU-parameterised weight, then compare three channel mixers in a 2-D Glow on rotated moons. ActNorm standardised the first batch exactly. The learned 1×1 convolution beat a fixed swap on two of three seeds (by 0.11 and 0.09 nats) but lost on the third: in 2-D, the choice of mixer moved the test NLL by about 0.1 nats, no more than the seed-to-seed spread.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Mix the channels, then couple

A coupling layer only lets one group of variables talk to another. RealNVP fixed the groups by hand and swapped them between layers. Glow instead learns how to mix all channels before each coupling, with a tiny invertible matrix, like rotating a set of colour dials before each step. It also adds a normalisation step that starts every layer with well-scaled numbers. The result trains stably at great depth and makes sharp images. In the demo, change the mixer angle and watch the coupling act along a different direction.

Flow lab
The grid is first rotated by 45° (log-det 0), then second coordinate is scaled by exp(s·sin 2u) and shifted by t·u², where u is the first coordinate after mixing. Log-det per point ranges from -0.60 to 0.60.
Why engineers care

Glow-style flows are used for invertible image models, for flow-based priors in super-resolution (SRFlow) and for exact-likelihood anomaly scores on imagery, with the caveats on out-of-distribution data covered below.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Glow's flow step is…
  2. 2. The 1×1 convolution replaces…
  3. 3. ActNorm is initialised…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Glow’s three layers

  • ActNorm: y = (x + b) ⊙ exp(log s) per channel; b and log s initialised so the first minibatch has zero mean and unit variance, then trained freely. Log-det = H·W·Σ log s. Works with batch size 1, unlike batch norm.
  • Invertible 1×1 convolution: y_ij = W x_ij at every pixel with a c×c matrix W. Log-det = H·W·log |det W|, costing O(c³) if computed directly.
  • LU trick: W = P L (U + diag(sign ⊙ exp(log s))) with P a fixed permutation, L unit lower-triangular, U strictly upper-triangular. Then log |det W| = Σ log s, O(c). Initialise W as a random rotation.
  • Affine coupling: as in RealNVP, with the last conditioner layer zero-initialised so each step starts as the identity; Glow used channel-wise splits and a sigmoid-based scale.
  • Architecture: L levels of K steps with squeeze and split (CIFAR-10: L = 3, K = 32; 256×256 faces: L = 6, K = 32).
  • Sampling temperature: draw z ~ N(0, T² I) with T ≈ 0.7 for cleaner, less diverse samples.
  • Results: 3.35 bits/dim on CIFAR-10 (RealNVP 3.49), sharp CelebA-HQ samples, smooth interpolation and attribute vectors.
  • Weaknesses: hundreds of layers and large memory; flows (Glow included) can assign higher likelihood to out-of-distribution images (SVHN under a CIFAR-trained model; Nalisnick et al., 2019).
📝 Quick check (Level 1)
0/3 answered
  1. 1. ActNorm, unlike batch norm, works with…
  2. 2. LU parameterisation makes log |det W| cost…
  3. 3. Glow's CIFAR-10 result was…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Implementing a Glow step

Exercise 1.

  • ActNorm’s data-dependent initialisation and forward pass.
  • The LU-parameterised weight and its log-det.

Practice.

  • Initialise ActNorm on the first real batch, not on noise; do it once.
  • Initialise the 1×1 convolution as a random orthogonal matrix and store it in LU form.
  • Zero-initialise the coupling’s last layer; use a bounded scale.
  • Track bits/dim on a held-out set; expect slow convergence (Glow trained for days on 8 GPUs).
  • Sample at T between 0.6 and 0.8 for presentation, and report T.
  • Do not use raw likelihood for out-of-distribution detection without checks such as likelihood ratios or typicality tests.
import torch, normflows as nf
# one Glow block for C channels: ActNorm -> invertible 1x1 conv (LU) -> affine coupling
C, hidden = 12, 256
block = nf.flows.GlowBlock(channels=C, hidden_channels=hidden, split_mode="channel", scale=True)
x = torch.randn(4, C, 16, 16)
z, log_det = block(x)          # data -> latent with per-example log-det
x_rec, _ = block.inverse(z)    # exact inverse
🐍 Exercise 1: ActNorm and the LU weight
Write ActNorm's data-dependent initialisation and forward pass, and build the LU-parameterised 1×1 convolution weight with its log-det.
📝 Quick check (Level 2)
0/3 answered
  1. 1. ActNorm is initialised on…
  2. 2. A typical sampling temperature is…
  3. 3. For OOD detection, raw flow likelihoods are…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

1×1 convolution as a generalised permutation. A permutation matrix has |det| = 1 and exactly reorders channels; any invertible W includes permutations, rotations and scalings, so learning W can only enlarge the model class. In practice it lets every coupling see a learned mix of all channels.

LU log-det. det(P L U’) = det P · det L · det U’ = ±1 · 1 · Π diag(U’), so log |det W| = Σ log |diag(U’)| = Σ log s. Gradients flow into L, U and log s directly; P stays fixed.

Data-dependent initialisation. Deep flows with hundreds of layers can start with exploding or vanishing activations. ActNorm’s init makes each layer’s output standardised at step 0, analogous to LSUV or weight-norm init; afterwards its parameters are ordinary weights.

OOD likelihoods. Likelihood is dominated by low-level statistics (local smoothness, number of distinct intensities); simpler images can get higher density even if never seen. Glow trained on CIFAR-10 gives SVHN higher likelihood. Typicality tests or likelihood ratios against a background model reduce this.

Exercise check (2-D). The ‘channels’ are the two coordinates, so the 1×1 convolution is a 2×2 matrix. After ActNorm init the first batch had mean 0.0 and std 1.0; the untrained flow (a per-axis standardisation) had test NLL 2.747. Mean final NLL over seeds 0–2 was 2.132 (fixed swap), 2.153 (fixed random rotation) and 2.081 (learned), a difference smaller than the seed-to-seed spread of each.

📝 Quick check (Level 3)
0/3 answered
  1. 1. log |det W| for W = P L (U + diag(s)) is…
  2. 2. A learned 1×1 conv includes permutations because…
  3. 3. Flows can score OOD images higher because likelihood is dominated by…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does a learned channel mixer help a small 2-D Glow?

History.

  • D. P. Kingma and P. Dhariwal, “Glow: generative flow with invertible 1×1 convolutions” (NeurIPS 2018).
  • E. Nalisnick et al., “Do deep generative models know what they don’t know?” (ICLR 2019).
  • A. Lugmayr et al., “SRFlow: learning the super-resolution space with normalizing flow” (ECCV 2020).

Exercise 2. Two moons rotated by 45°, 2000 training and 2000 test points.

  • Model: 4 Glow steps, each ActNorm (data-initialised on the first batch of 256) → 2×2 mixer → affine coupling (second coordinate given the first; conditioner 1 → 16 tanh → 2).
  • Mixers: fixed swap (RealNVP-style ‘reverse’), fixed random rotation, learned LU-parameterised 2×2 matrix initialised at a random rotation.
  • Training: Adam, learning rate 0.01, batch 256, 350 steps; hand-written gradients (checked against finite differences).
seed 0 seed 1 seed 2
after ActNorm init 2.747 2.732 2.722
fixed swap 2.214 2.120 2.061
fixed rotation 2.215 2.177 2.066
learned 1×1 conv 2.101 2.029 2.112
true density 1.605 1.608 1.621
  • ActNorm init worked as designed: zero mean and unit variance on the first batch; the untrained flow is a per-axis standardisation (test NLL about 2.73).
  • Mixer choice (a null result): the learned mixer won on seeds 0 and 1 by about 0.1 nats and lost on seed 2 by 0.05; averaged over seeds it was 0.05 nats better than a fixed swap, which is within run-to-run noise.
  • Why so little: with two channels, alternating swaps already let every coupling see both coordinates; Glow’s gains came from mixing many channels in images.
  • All variants were still about 0.4–0.6 nats above the true density at this budget.
🐍 Exercise 2 (research): does a learned channel mixer help a small 2-D Glow?
Compare a fixed swap, a fixed rotation and a learned LU 1×1 convolution in a 4-step 2-D Glow on rotated moons.

Glow in AI, robotics and aerospace

  • Image restoration: SRFlow and related flows model the full distribution of high-resolution images given a low-resolution one, useful for satellite super-resolution where several plausible outputs exist.
  • Exact-likelihood scoring: flows score imagery or telemetry for anomalies, combined with likelihood ratios to avoid OOD failures.
  • Invertible backbones: Glow-style blocks appear in invertible neural networks for inverse problems (e.g. medical and geophysical imaging) and as decoders in audio models such as WaveGlow.

References

  1. D. P. Kingma and P. Dhariwal (2018). “Glow: generative flow with invertible 1×1 convolutions.” NeurIPS.
  2. E. Nalisnick, A. Matsukawa, Y. W. Teh, D. Gorur and B. Lakshminarayanan (2019). “Do deep generative models know what they don’t know?” ICLR.
  3. R. Prenger, R. Valle and B. Catanzaro (2019). “WaveGlow: a flow-based generative network for speech synthesis.” ICASSP.
  4. A. Lugmayr, M. Danelljan, L. Van Gool and R. Timofte (2020). “SRFlow: learning the super-resolution space with normalizing flow.” ECCV.