Residual Flows & iResNet

Free-form flows via Lipschitz-constrained residual connections: invertible ResNets, spectral normalization for invertibility, unbiased log-likelihood estimation, and Russian roulette estimators.

Advanced

Prerequisites

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. Invertible Residual Networks
  5. Lipschitz Constraint for Invertibility
  6. Log-Determinant via Power Series
  7. Unbiased Estimation: Russian Roulette
  8. Spectral Normalization
  9. Comparison with Coupling Flows
  10. Common Pitfalls
  11. Summary
  12. Exercises

Learning Objectives

  1. State the sufficient condition for a residual network to be invertible.
  2. Derive the power series expansion for the log-determinant of I+Jg\mathbf{I} + \mathbf{J}_g.
  3. Explain the Russian roulette estimator for unbiased truncation.
  4. Apply spectral normalization to enforce the Lipschitz constraint.
  5. Compare free-form (residual) vs structured (coupling/autoregressive) flows.

Notation

  • Lip(g)\text{Lip}(g) — Lipschitz constant of gg
  • σ1(W)\sigma_1(\mathbf{W}) — spectral norm (largest singular value) of W\mathbf{W}
  • NGeometric(p)N \sim \text{Geometric}(p) — random truncation point

Core Intuition

Coupling and autoregressive flows constrain architecture severely (splits, masking, triangular structure). Residual flows take a different approach: use a standard ResNet f(x)=x+g(x)f(\mathbf{x}) = \mathbf{x} + g(\mathbf{x}) and constrain gg to have Lipschitz constant less than 1. This guarantees invertibility via the Banach fixed-point theorem, while allowing ALL dimensions to interact simultaneously.

Residual Flow (f = I + g)

f(x) = x + g(x), inverse via fixed-point: x ← y − g(x)iter 0iter 1iter 2iter 3iter 4iter 5iter 6iter 7iter 8Contractive ✓Lip(g) < 1
Lipschitz
0.50
Start yConverged x
Explore: Residual flows f = I + g are invertible when g is contractive (Lipschitz < 1). The inverse is computed by fixed-point iteration x ← y − g(x).

Invertible Residual Networks

i-ResNet (Behrmann et al., 2019): The residual mapping

f(x)=x+gθ(x)(1)f(\mathbf{x}) = \mathbf{x} + g_\theta(\mathbf{x}) \tag{1}

is invertible if Lip(g)<1\text{Lip}(g) < 1.

Proof: ff is a contraction mapping perturbation of identity. By Banach fixed-point theorem, f1f^{-1} exists and can be found iteratively:

x(0)=y,x(t+1)=yg(x(t)).(2)\mathbf{x}^{(0)} = \mathbf{y}, \quad \mathbf{x}^{(t+1)} = \mathbf{y} - g(\mathbf{x}^{(t)}). \tag{2}

Converges geometrically: x(t)xLip(g)tx(0)x\|\mathbf{x}^{(t)} - \mathbf{x}^*\| \leq \text{Lip}(g)^t \cdot \|\mathbf{x}^{(0)} - \mathbf{x}^*\|.


Lipschitz Constraint for Invertibility

Sufficient condition: Lip(g)<1\text{Lip}(g) < 1, i.e., g(x)g(y)cxy\|g(\mathbf{x}) - g(\mathbf{y})\| \leq c\|\mathbf{x} - \mathbf{y}\| for all x,y\mathbf{x}, \mathbf{y} with c<1c < 1.

For a neural network gg with layers g=gLg1g = g_L \circ \cdots \circ g_1:

Lip(g)lLip(gl)=lσ1(Wl)Lip(ϕl),(3)\text{Lip}(g) \leq \prod_l \text{Lip}(g_l) = \prod_l \sigma_1(\mathbf{W}_l) \cdot \text{Lip}(\phi_l), \tag{3}

where ϕl\phi_l is the activation function (Lip(ReLU)=1\text{Lip}(\text{ReLU}) = 1, Lip(ELU)1\text{Lip}(\text{ELU}) \leq 1).

Enforcement: Normalize each weight matrix so σ1(Wl)c1/L\sigma_1(\mathbf{W}_l) \leq c^{1/L} where c<1c < 1.


Log-Determinant via Power Series

The Jacobian is Jf=I+Jg\mathbf{J}_f = \mathbf{I} + \mathbf{J}_g. Log-determinant:

logdet(I+Jg)=tr(log(I+Jg))=k=1(1)k+1ktr(Jgk).(4)\log\det(\mathbf{I} + \mathbf{J}_g) = \text{tr}\left(\log(\mathbf{I} + \mathbf{J}_g)\right) = \sum_{k=1}^\infty \frac{(-1)^{k+1}}{k}\text{tr}(\mathbf{J}_g^k). \tag{4}

Convergence: Guaranteed when Lip(g)<1\text{Lip}(g) < 1 (spectral radius of Jg\mathbf{J}_g is less than 1).

Stochastic estimation using Hutchinson:

tr(Jgk)=Ev[vTJgkv].(5)\text{tr}(\mathbf{J}_g^k) = \mathbb{E}_{\mathbf{v}}[\mathbf{v}^T\mathbf{J}_g^k\mathbf{v}]. \tag{5}

Each Jgkv\mathbf{J}_g^k\mathbf{v} computed by kk JVPs (Jacobian-vector products via autodiff). Total cost: O(Kd)O(K \cdot d) for KK-term truncation.


Unbiased Estimation: Russian Roulette

Problem: Truncating the series at KK terms gives a BIASED estimate.

Solution: Russian roulette estimator. Draw Np(n)N \sim p(n) (e.g., geometric distribution), then:

logdet^=k=1N(1)k+1kP(Nk)tr(JgkvvT).(6)\widehat{\log\det} = \sum_{k=1}^N \frac{(-1)^{k+1}}{k \cdot P(N \geq k)} \text{tr}(\mathbf{J}_g^k\mathbf{v}\mathbf{v}^T). \tag{6}

Property: E[logdet^]=logdet(I+Jg)\mathbb{E}[\widehat{\log\det}] = \log\det(\mathbf{I} + \mathbf{J}_g) (unbiased).

Variance: Depends on distribution p(n)p(n). Geometric with p=0.5p=0.5 gives reasonable variance with average 2\sim 2 terms evaluated.


Spectral Normalization

Method to enforce σ1(W)c\sigma_1(\mathbf{W}) \leq c:

W^=cWσ1(W).(7)\hat{\mathbf{W}} = c \cdot \frac{\mathbf{W}}{\sigma_1(\mathbf{W})}. \tag{7}

Power iteration to estimate σ1\sigma_1:

vWTuWTu,uWvWv,σ1uTWv.(8)\mathbf{v} \leftarrow \frac{\mathbf{W}^T\mathbf{u}}{\|\mathbf{W}^T\mathbf{u}\|}, \quad \mathbf{u} \leftarrow \frac{\mathbf{W}\mathbf{v}}{\|\mathbf{W}\mathbf{v}\|}, \quad \sigma_1 \approx \mathbf{u}^T\mathbf{W}\mathbf{v}. \tag{8}

One iteration per training step (amortized). Cost: two matrix-vector products.

Practical target: Set c=0.97c = 0.97 per layer; with L=10L=10 layers: Lip(g)0.97100.74<1\text{Lip}(g) \leq 0.97^{10} \approx 0.74 < 1.


Comparison with Coupling Flows

AspectCoupling (RealNVP)Residual (i-ResNet)
Expressiveness/layerLow (half dims frozen)High (all dims interact)
Jacobian costExact, O(d)O(d)Approximate, O(Kd)O(Kd)
InversionExact, analyticIterative (fixed-point)
Architecture freedomConstrained splitsNearly unconstrained
LikelihoodExactUnbiased estimate

When to use residual flows: When modeling complex high-dimensional densities where coupling flows would need impractically many layers.


Common Pitfalls

Pitfall 1. Setting Lipschitz constant too close to 1 (e.g., 0.99). Inversion converges slowly and the power series needs many terms. Use Lip(g)0.7\text{Lip}(g) \leq 0.70.90.9.

Pitfall 2. Using only 1 Hutchinson vector for trace estimation. The variance is high; use 5-10 vectors for stable training.

Pitfall 3. Forgetting that inversion is iterative. If you need fast exact inversion (e.g., for real-time generation), coupling flows are better despite lower expressiveness.


Summary

  • Residual flows: f(x)=x+g(x)f(\mathbf{x}) = \mathbf{x} + g(\mathbf{x}) with Lip(g)<1\text{Lip}(g) < 1.
  • Invertibility via Banach fixed-point theorem; iterative inversion.
  • Log-det via power series + Hutchinson's trace estimator.
  • Russian roulette gives unbiased estimates without infinite series.
  • Spectral normalization enforces Lipschitz constraint efficiently.
  • More expressive per layer than coupling flows; less exact.

Exercises

Exercise 1. For g(x)=0.5Axg(\mathbf{x}) = 0.5\mathbf{Ax} with A=0.9\|\mathbf{A}\| = 0.9: compute Lip(g)\text{Lip}(g) and verify invertibility.

Exercise 2. Compute the first 3 terms of the power series for logdet(I+0.5A)\log\det(\mathbf{I} + 0.5\mathbf{A}) where A=[[0.2,0.1],[0.3,0.4]]\mathbf{A} = [[0.2, 0.1], [0.3, 0.4]].

Exercise 3. How many fixed-point iterations are needed to invert f(x)=x+0.8g(x)f(\mathbf{x}) = \mathbf{x} + 0.8g(\mathbf{x}) to accuracy 10610^{-6}?

Exercise 4. Design a Russian roulette estimator with geometric(p=0.3p=0.3) distribution. Compute expected number of terms and prove unbiasedness.

Exercise 5. Compare the wall-clock time for training a 10-layer residual flow vs 30-layer Glow on CIFAR-10 (estimate FLOPs per training step).