Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Conditioner architectures

The network that reads the passive half: what it holds, how its size changes the fit, and what bounding its log-scales does to training

02 · Conditioner architectures

Open In Colab

A coupling layer has two parts: the transformer TθT_\theta (notebook 01) and the conditioner cϕc_\phi, which reads the passive half and returns the transformer’s parameters, θ=cϕ(xA)\theta = c_\phi(\vect{x}_A) (1). The transformer is what makes the log-determinant a cheap sum; the conditioner decides how each coordinate’s map changes with the others, which is where a coupling flow’s modelling power comes from Papamakarios et al., 2021. In gauss_flows the conditioner is an equinox.nn.MLP sized by nn_width and nn_depth, and it returns the parameters of the whole active half at once. This notebook fixes the transformer, a mixture CDF with M=8M = 8 components, and studies the conditioner.

Python implementation: CPython
Python version       : 3.13.12
IPython version      : 9.12.0

jax             : 0.12.1
numpy           : 2.4.3
optax           : 0.2.8
flowjax         : 19.1.0
pipekit_train   : 0.3.4
gauss_flows_maps: 0.3.1

Compiler    : Clang 21.1.4 
OS          : Linux
Release     : 6.8.0-1044-azure
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit

1. Inside one coupling layer

We build one MixtureGaussianCDFCoupling on Dx=2D_x = 2, with the default conditioner of notebook 01 (width 32, depth 2), and list its weight arrays.

weight array of shape (32, 1)
weight array of shape (32,)
weight array of shape (32, 32)
weight array of shape (32,)
weight array of shape (24, 32)
weight array of shape (24,)
1912 weights in all

The six arrays are the weights and biases of a three-layer MLP, 1→32→32→241 \to 32 \to 32 \to 24, and they are all the weights the layer has: the transformer holds none of its own. The MLP reads the one passive coordinate and returns 24 numbers, the 3M3M weights, means and log-scales of the mixture that maps the one active coordinate. The form of the map is fixed; how it reacts to the passive coordinate is whatever this network can represent, so the fit should follow the network’s size.

2. The size of the conditioner

We fit flows that differ only in the conditioner’s width, on the two-arm spiral of notebook 01: Nt=3000N_t = 3000 training rows and Nv=1000N_v = 1000 held-out rows.

The flows have three blocks of a rotation and two mixture-CDF couplings with a flip between them, as in notebook 01; only the conditioner’s width and the log-scale bound change. The rotation is a HouseholderRotation with random vectors, since its default vectors are all equal (gauss_flows#239), and the base is a fixed standard normal. A fresh mixture-CDF coupling has all eight components equal, and because its conditioner’s last layer starts at zero they stay equal through training, so the layer trains as an affine coupling (gauss_flows#265); until that is fixed, make_coupling moves every weight of each fresh layer by 0.1 times a standard-normal draw with perturb_weights.

A flow stacks three blocks of them.

Training is that of notebook 01 with 1,200 steps: pipekit-train on the mean negative log-likelihood (1), Adam on a one-cycle cosine rate peaking at 3×10−33 \times 10^{-3}, and the gradient clipped to a global norm of 1. We also keep the training loss of every step.

One function trains a flow and returns it with its training losses.

For each width we count the flow’s weights and give the mean negative log-likelihood on the training rows and, on the held-out rows, the median, the mean and the worst row.

width  4:    900 weights, NLL 2.435 on training rows; held out: median 2.436, mean 2.505, worst 24.8
width  8:   1836 weights, NLL 2.185 on training rows; held out: median 2.383, mean 2.261, worst 11.8
width 16:   4284 weights, NLL 1.599 on training rows; held out: median 1.474, mean 1.648, worst 9.5
width 32:  11484 weights, NLL 1.519 on training rows; held out: median 1.429, mean 1.579, worst 9.2
width 64:  35100 weights, NLL 1.376 on training rows; held out: median 1.362, mean 1.443, worst 7.9
<Figure size 1200x500 with 1 Axes>

Figure 1:The negative log-likelihood of flows that differ only in the width of their conditioners, against their number of weights: the mean over the training rows and the median over the held-out rows.

The fit improves with the conditioner’s width, while the transformer and the depth stay the same: from 2.44 to 1.38 nats on the training rows, and from 2.44 to 1.36 nats for the median held-out row. Most of the gain comes between width 8 and width 16, where the held-out median drops from 2.38 to 1.47; after that it keeps falling, more slowly, to 1.43 at width 32 and 1.36 at width 64 (35,100 weights), with 1,200 steps. The worst held-out row costs between 7.9 and 24.8 nats, so no single row moves the held-out mean far: it stays within 0.18 nats of the median at every width.

3. Bounding the log-scales

Among the conditioner’s outputs are the log-scales of the mixture components. MixtureGaussianCDFCoupling passes each raw output uu through btanh⁡(u)b \tanh(u), so every component’s scale stays in [e−b,eb][e^{-b}, e^{b}], with bb = log_scale_bound (5 by default). A tight bound keeps a bad batch from pushing a scale to an extreme; a loose one lets components become very narrow. We train the width-32 flow with b=3b = 3 and b=50b = 50 and compare with the default.

b =    3: peak training loss 3.4, final NLL 1.525 on training rows, held-out median 1.461
b =    5: peak training loss 3.8, final NLL 1.519 on training rows, held-out median 1.429
b =   50: peak training loss 17.8, final NLL 1.860 on training rows, held-out median 1.825
<Figure size 1200x500 with 1 Axes>

Figure 2:The training loss of every step for the width-32 flow with the log-scales bounded at b = 3, 5 and 50.

With b=3b = 3 and b=5b = 5 the runs train alike: each has its highest loss at the start (3.4 and 3.8 nats) and ends at 1.53 and 1.52 nats on the training rows, with held-out medians 1.46 and 1.43. With b=50b = 50 the run also has its highest loss at the start, 17.8 nats, then spikes now and then until about step 800, and ends behind, at 1.86 nats on the training rows and 1.83 for the held-out median. Part of that is the start: each log-scale is btanh⁡(u)b \tanh(u), and the three flows share their keys, so the same perturbation of the conditioner’s weights gives log-scales ten times larger with b=50b = 50 than with b=5b = 5. With one run per setting we cannot separate the start from the bound, only say that the loose bound cost fit here and the two tighter ones did not differ.

4. The conditioner is the part that changes with the data

Everything above used an MLP because the data are unstructured vectors. The coupling contract does not care what cϕc_\phi is, so the conditioner is the place to put the structure of the data, and the later parts of this curriculum do so:

DataConditionerWhere
vectorsan MLPhere
a context, such as a class or an observationthe context joined to the passive halfPart 7
sequencesa network that reads only past valuesPart 11
images and spatial fieldsa convolutional network, which keeps the spatial layoutPart 12
space-time fieldsa network over frames, or over space and time separatelyPart 13

The triangular Jacobian and the cheap inverse stay the same; only the network that reads xA\vect{x}_A changes.

Recap

KnobEffect here
the conditioner holds every weightits size is the coupling’s size
conditioner widthwider fitted better, on the training rows and on the median held-out row, up to width 64, most between widths 8 and 16
log_scale_boundb=3b = 3 and b=5b = 5 trained alike; b=50b = 50 started far higher and fitted worst
the conditioner’s architecturewhere later parts put the structure of the data

The transformer sets what shape a coordinate’s map can take; the conditioner sets how that shape follows the rest of the data.

Next. A coupling layer transforms only its active half, so which coordinates are active, and how that changes from layer to layer, matters. Notebook 03 looks at masks.

References
  1. Papamakarios, G., Nalisnick, E., Rezende, D. J., Mohamed, S., & Lakshminarayanan, B. (2021). Normalizing Flows for Probabilistic Modeling and Inference. Journal of Machine Learning Research, 22(57), 1–64.