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.

RBIG as a warm start

What a greedy RBIG fit hands to a trainable flow, and what it is worth once both starts get the same budget and a fair learning rate

01 · RBIG as a warm start

Open In Colab

Notebook 00 found that a greedy RBIG fit is quick and that a trained flow generalises better. The obvious combination is to start training from the greedy fit. fit_rbig returns a FlowJax Transformed distribution whose blocks are all trainable except its rotations, so it can go straight into the training loop of notebook 00. This notebook asks what that start hands over and what it is worth. The warm-start example shows the start itself (its likelihood before training, its pushforward and its samples) and trains both starts at one learning rate; here we compare them on held-out data, with a learning rate chosen for each.

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_models: 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

As in notebook 00 the notebook runs in float32, because fit_rbig cannot run with float64 turned on today, a bug in gauss_flows (gauss_flows#247). The data are the same: N=4000N = 4000 points of two moons with noise of standard deviation 0.08, standardised per coordinate and split into Nt=3000N_t = 3000 training rows and Nv=1000N_v = 1000 held-out rows.

1. What the warm start hands over

We build both starts with K=8K = 8 layers of 8-component mixture marginals. The cold start is gaussianization_flow with a fixed standard-normal base, as notebook 00 recommends. The warm start is fit_rbig on the training rows. fit_rbig also builds a trainable base, the defect notebook 00 found (gauss_flows#256), and unlike the factory it has no base_dist argument, so we swap the base for a fixed one with eqx.tree_at. Its base starts at N(0,I)\mathcal{N}(\vect{0}, \mat{I}), so the swap changes no density, only what training may move.

A small function counts the numbers each flow holds and how many of them the optimiser may move. Rotations wrapped in paramax.NonTrainable stay out of the optimiser, as in Part 2.

cold: Invert(Scan(...)), one layer ['MixtureGaussianCDF', 'HouseholderRotation'] run 8 times
warm: Invert(Chain(...)), first blocks ['FixedRotation', 'MixtureGaussianCDF'] of 16
cold: 416 numbers, 416 trainable, 0 frozen
warm: 416 numbers, 384 trainable, 32 frozen

The two starts are not the same flow. The cold flow runs each layer as a marginal map gkg_k followed by a trainable Householder rotation Qk\mat{Q}_k (2), stored once and run by Scan. The warm flow is a Chain of 16 blocks that runs the PCA frame Qk\mat{Q}_k (3) of the current state first and the marginal map after it, which is how fit_rbig fits them, so the two compositions are

fcold=(QK∘gK)∘…∘(Q1∘g1),fwarm=(gK∘QK)∘…∘(g1∘Q1)\begin{aligned} f_{\mathrm{cold}} &= (\mat{Q}_K \circ g_K) \circ \ldots \circ (\mat{Q}_1 \circ g_1), \\ f_{\mathrm{warm}} &= (g_K \circ \mat{Q}_K) \circ \ldots \circ (g_1 \circ \mat{Q}_1) \end{aligned}

with the same number of numbers in each, 416. In the warm flow the 32 numbers of the eight 2×22 \times 2 frames are frozen: training moves only the mixture marginals. The warm start therefore hands over two things, the EM fit of every marginal and a set of rotations that training will never change. The source of this tutorial checks that the two starts share a structure by comparing the name of the outer bijection, which is Invert for both; the layers inside differ.

How far apart the starts are shows in their negative log-likelihood before training.

greedy: NLL  1.926 on training rows,  2.430 held out
warm  : NLL  1.926 on training rows,  2.430 held out
cold  : NLL 16.254 on training rows, 16.276 held out

The warm start begins at the greedy fit’s likelihood, about 14 nats per point better than the cold start, which the swap of base left unchanged. It also begins with the greedy fit’s overfitting: half a nat between its training and held-out rows, the gap notebook 00 found.

2. The comparison as the source ran it

The training loop is notebook 00’s: pipekit-train on (1), Adam with gradients clipped to a global norm of 1 on a one-cycle cosine learning rate, 3,000 steps of 512 rows in 30 epochs, with the held-out loss after each epoch. Only the peak learning rate changes from run to run, so the optimiser is built from it.

The source trains the cold start at a peak learning rate of 3×10−33 \times 10^{-3} and the warm start at 10-3, a smaller rate so that training does not throw away the greedy fit.

cold, peak 3e-3: NLL after epoch 1 15.462 held out; after epoch 30 1.886 on training rows, 1.901 held out
warm, peak 1e-3: NLL after epoch 1 2.406 held out; after epoch 30 1.599 on training rows, 1.852 held out
<Figure size 750x440 with 1 Axes>

Figure 1:The comparison as the source ran it: the training (solid) and held-out (dashed) negative log-likelihood per epoch of the cold start at a peak learning rate of 3 × 10⁻³ (blue) and the warm start at 10⁻³ (orange). The grey line is the greedy fit on the held-out rows.

At these settings the warm start wins, as the source reports: after 3,000 steps it is at 1.852 nats held out against the cold start’s 1.901, and at 1.599 against 1.886 on the training rows. The source reports log-likelihoods on its training data (in float64, with all of its 3,000 points used for training) of -1.66 for the warm start, -1.98 for the cold one and -1.96 for the greedy fit; ours on the training rows are -1.599, -1.886 and -1.926, the same order. What the training rows alone hide is the warm start’s gap between training and held-out loss, a quarter of a nat (1.599 against 1.852), where the cold start’s is 0.015. The two starts also had different learning rates, so this comparison cannot say how much of the difference is the start.

3. The same budget and a fair learning rate

A learning rate chosen for one start is not a fair setting for the other, so we train each start at the same four peak rates, from 10-3 to 10-1, for the same 3,000 steps, and keep each start’s best held-out result.

A third start separates the two things the warm start hands over. It keeps the warm flow’s frozen PCA frames and replaces its EM marginals with the cold flow’s random initial ones, so it has the frames without the marginal fit. The cold flow stores its layers stacked along a leading axis inside Scan; indexing that axis gives the layers one at a time, a trick the next notebook uses to look inside a trained flow.

Each of these goes in place of a warm marginal.

frames-only start: NLL 15.984 on training rows, 15.968 held out

The frames alone are worth almost nothing before training: the frames-only start begins close to the cold one. We now train the three starts at the four peak rates; the warm run at 10-3 is the one from section 2. The twelve runs take several minutes.

held-out NLL after 3,000 steps (training NLL in brackets)
peak                  cold              warm       frames only
1e-03       2.076 (2.055)    1.852 (1.599)    2.118 (2.095)
1e-02       1.716 (1.712)    1.763 (1.561)    1.783 (1.761)
3e-02       1.659 (1.628)    1.694 (1.559)    1.675 (1.619)
1e-01       1.673 (1.603)    1.680 (1.574)    1.639 (1.590)
best peak per start: {'cold': 0.03, 'warm': 0.1, 'frames only': 0.1}
<Figure size 1300x440 with 2 Axes>

Figure 2:Left: the held-out negative log-likelihood after 3,000 steps against the peak learning rate, for the cold start (blue), the warm start (orange) and the frames-only start (green); the grey line is the greedy fit. Right: the held-out loss per epoch of each start at its best peak rate.

Every start does best at a higher peak rate than the source used: the cold start at 3×10−23 \times 10^{-2} (1.659), the warm and frames-only starts at 10-1 (1.680 and 1.639). The warm start is far ahead at 10-3, where the others are still far from their best after 3,000 steps, but its lead is gone by 10-2, and at each start’s best rate the three end within 0.04 nats of each other. What the warm start keeps is its early lead, seen on the right: it is below the greedy fit from the first epoch, while the cold start needs four epochs to get there. It also keeps the largest gap between its training and held-out loss at every peak rate, from 0.25 nats at 10-3 to 0.11 at 10-1; the cold start’s is between 0.004 and 0.07, and the frames-only start’s between 0.02 and 0.06.

How much of the difference between the best runs is noise? We train the cold and warm starts at their best peak rates twice more, with other batch orders.

cold, peak 3e-02: held-out NLL [1.659 1.67  1.661], mean 1.663
warm, peak 1e-01: held-out NLL [1.68  1.685 1.665], mean 1.676

Changing only the batch order moves the cold start’s result by up to 0.011 nats and the warm start’s by up to 0.020. Every cold run ends below the warm runs’ mean, and the means differ by 0.013 nats. With a fair learning rate and the same budget, the warm start does not end better than the cold start on held-out data; here it ends a little worse. The frames-only start’s 1.639 is a single run, 0.02 nats below the best cold run, so we read it as showing that the frozen frames do no harm, not that they help. What the warm start buys is time: a good model after one epoch, and the right answer at a learning rate too small for a cold start.

4. What training leaves of the greedy fit

The greedy fit overfits because EM gives its mixtures narrow components, fitted to the training rows of each layer. We compare the component scales σm\sigma_m of (2) in the greedy fit with those after training, for the warm and cold starts at their best peak rates.

greedy        : 128 scales, median 0.215, 10% quantile 0.159
warm, trained : 128 scales, median 0.488, 10% quantile 0.218
cold, initial : 128 scales, median 0.698, 10% quantile 0.698
cold, trained : 128 scales, median 0.640, 10% quantile 0.255

EM leaves the greedy fit’s components narrow, with a median scale of 0.215 against 0.698 for every component of the cold start before training. Training widens them, but the warm start’s stay narrower than the cold start’s: a median of 0.488 against 0.640, and a 10% quantile of 0.218 against 0.255. That is consistent with the larger gap between the warm start’s training and held-out loss: the warm start keeps part of the greedy fit’s adaptation to the training rows.

grid points where log p_x is minus infinity: greedy 156, cold, trained 0, warm, trained 0

The greedy fit’s log-density is −∞-\infty at 156 of the 14,400 grid points, the NaN that MixtureGaussianCDF returns far in a mixture’s tail (gauss_flows#248), as in notebook 00. Neither trained flow has any. The figure clips the log-density at -6.

<Figure size 1500x480 with 3 Axes>

Figure 3:The log-density of the greedy fit (left), the cold start trained at its best peak rate (centre) and the warm start trained at its best peak rate (right), on one colour scale clipped at −6.

Both trained flows follow the two moons, which the greedy fit does not. The cold start’s density is smooth and leaves some mass in the gap at the right-hand end of the moons. The warm start’s bands are narrower, with a few small islands of mass off the moons and sharp seams across the bands near (−0.6,1.5)(-0.6, 1.5) and (0.5,−1.6)(0.5, -1.6).

Recap

PieceEquationIn code
the two starts, block by block(1)gaussianization_flow against fit_rbig
the warm start’s frozen frames(3)FixedRotation, paramax.NonTrainable
a fixed base for the warm start(3)eqx.tree_at on base_dist (gauss_flows#256)
training each start(1)train_flow, one_cycle_adam
a layer taken out of a Scaneqx.partition, index the leading axis, eqx.combine
the components EM leaves narrow(2)component_scales

Next. Every comparison so far read one number, the likelihood of the whole flow. The next notebook opens the flows up and follows the data through them one block at a time.