Sam Babichenko

Reading notes / Generalization bounds

Nonvacuous PAC-Bayes bounds

Dziugaite and Roy, 2017; Lotfi et al., 2022

Context. A uniform convergence bound is no smaller than what the class can fit, and Zhang et al. showed that networks which generalize on real labels also fit random ones. PAC-Bayes avoids this by depending on the solution found: it certifies a distribution QQ over weights, and the bound depends on QQ only through its KL divergence from a prior PP fixed before the data. Dziugaite and Roy (2017) made this nonvacuous by optimizing a Gaussian distribution of weights around the SGD solution to minimize the bound itself; Lotfi et al. (2022) put a point mass on a compressed model under a prior that weights each model by its code length. The generalization gap is controlled by how many nats the trained model takes to describe, per training example. A flat minimum near initialization is a short Gaussian description (about one bit per seven examples), a network trained in a random low-dimensional subspace and quantized is a code of a few thousand bits, and what helps in practice (convolutions, pretraining) shows up as shorter codes.

Setting and the bound. Classification with 0-1 loss and mm examples. A randomized classifier QQ has empirical error e^(Q,S)=Ew∼Q e^(hw,S)\hat e(Q,S)=\mathbb E_{w\sim Q}\,\hat e(h_w,S) and true error e(Q)=Ew∼Q e(hw)e(Q)=\mathbb E_{w\sim Q}\,e(h_w). With kl\mathrm{kl} the Bernoulli KL and kl−1(q∣c)=sup⁡{p:kl(q∥p)≤c}\mathrm{kl}^{-1}(q|c)=\sup\{p:\mathrm{kl}(q\|p)\le c\}, Langford and Seeger's form of McAllester's bound says that for every prior PP chosen without the sample, with probability at least 1−δ1-\delta, simultaneously for all QQ, e(Q)≤kl−1(e^(Q,S) ∣ KL(Q∥P)+log⁡mδm−1).e(Q)\le\mathrm{kl}^{-1}\Big(\hat e(Q,S)\,\Big|\,\frac{\mathrm{KL}(Q\|P)+\log\frac m\delta}{m-1}\Big). Because the event does not depend on QQ, the posterior may be chosen after seeing the data, which licenses optimizing it; only PP must be fixed in advance. The exact inverse matters near zero error: kl−1(0∣c)=1−e−c≈c\mathrm{kl}^{-1}(0|c)=1-e^{-c}\approx c, whereas Pinsker's relaxation e^+c/2\hat e+\sqrt{c/2} adds a term of order c\sqrt c. Lotfi et al. plug their KL into Catoni's bound for the risk R(h)R(h) and empirical risk R^(h)\hat R(h) of one model hh: for fixed α>1\alpha>1, with probability at least 1−δ1-\delta, R(h)≤inf⁡λ>1Φλ/m−1(R^(h)+αλ[KL+log⁡1δ+2log⁡log⁡(α2λ)log⁡α]),Φγ−1(x)=1−e−γx1−e−γ,R(h)\le\inf_{\lambda>1}\Phi^{-1}_{\lambda/m}\Big(\hat R(h)+\frac\alpha\lambda\Big[\mathrm{KL}+\log\frac1\delta+2\log\frac{\log(\alpha^2\lambda)}{\log\alpha}\Big]\Big),\qquad\Phi^{-1}_\gamma(x)=\frac{1-e^{-\gamma x}}{1-e^{-\gamma}}, where α\alpha and the last logarithm account for a union bound over a grid of λ\lambda; like the kl form it is of order KL/m\mathrm{KL}/m at small training error. My check (zero training error, KL 2,000 nats, m=60,000m=60{,}000, α=1.1\alpha=1.1 since the paper does not state its α\alpha) gives 3.6% against 3.3% for the kl form.

Main results. Dziugaite and Roy train fully connected networks (0.33M to 2.4M parameters) on MNIST with digits 0-4 against 5-9, m=55,000m=55{,}000. With Q=N(w,diag(s))Q=\mathcal N(w,\mathrm{diag}(s)) optimized from the SGD solution, the bound on the stochastic network's error, valid with probability 0.965, is 16.1% for one hidden layer of 600 units (471k parameters, KL 5,144 nats) and at most 22.3% across six architectures. The stochastic networks have test error 3.2% to 3.5% (the SGD networks 1.3% to 1.8%), so the bound is about five times the truth but far from vacuous. On random labels the optimized posterior gives up training accuracy (11.2% error) and still needs about 40 times the KL, so the bound is vacuous, as it should be. Lotfi et al., at δ=0.05\delta=0.05 with priors fixed before the sample, get 11.6% on MNIST (LeNet-5 compressed to 0.38 KB), 32.8% on FashionMNIST, 58.2% on CIFAR-10 (1.2 KB), 94.6% on CIFAR-100 and 93.5% on ImageNet.

Step 1

A Gaussian prior centered at the random initialization turns the KL into a penalty on precision and on distance traveled. Take Q=N(w,diag(s))Q=\mathcal N(w,\mathrm{diag}(s)) and P=N(w0,λI)P=\mathcal N(w_0,\lambda I), where the initialization w0w_0 is drawn before the data and so is a legal prior mean. The Gaussian KL KL(Q∥P)=12(∥s∥1λ−d+∥w−w0∥22λ+dlog⁡λ−∑ilog⁡si)\mathrm{KL}(Q\|P)=\frac12\Big(\frac{\|s\|_1}{\lambda}-d+\frac{\|w-w_0\|_2^2}{\lambda}+d\log\lambda-\sum_i\log s_i\Big) penalizes every weight that must be stated precisely (−∑ilog⁡si-\sum_i\log s_i), for spread wider than the prior and for how far training moved. Centering at w0w_0 matters: initialization breaks the permutation symmetry of hidden units, the authors expect SGD not to undo it, and the bounds are much better than with a zero mean. No single λ\lambda suits every architecture and PP may not depend on SS, so the prior variance is picked from a grid λ=c e−j/b\lambda=c\,e^{-j/b} by a union bound: the jj-th prior gets confidence 6δ/(π2j2)6\delta/(\pi^2j^2), these sum to δ\delta, and the cost, about 2log⁡j≈122\log j\approx12 nats added to the KL, is negligible next to 5,000.

Step 2

Minimizing the bound maps out a large axis-aligned ellipsoid of low loss around the SGD solution. The objective, a logistic surrogate plus Pinsker's square root of the complexity term, has the flat-minimum trade-off built in: raising sis_i lowers the KL through the −12log⁡si-\tfrac12\log s_i term until the injected noise starts to raise the training loss, so the optimizer learns, weight by weight, how imprecisely each can be stated. The mean is free to move, but the SGD solution stays deep inside the posterior: in the diag(s)−1\mathrm{diag}(s)^{-1} norm it is closer to the posterior mean than every one of 10,000 draws from QQ. The reported number chains a Monte Carlo bound into the exact inverse: e^(Q,S)\hat e(Q,S) cannot be computed, so the mean training error e^n\hat e_n of n=150,000n=150{,}000 draws from QQ is turned into an upper bound by a kl-form Chernoff bound, and since kl−1\mathrm{kl}^{-1} is increasing it can be fed in, e(Q)≤kl−1(kl−1(e^n ∣ 1nlog⁡2δ′) ∣ B),e(Q)\le\mathrm{kl}^{-1}\Big(\mathrm{kl}^{-1}\big(\hat e_n\,\big|\,\tfrac1n\log\tfrac2{\delta'}\big)\,\Big|\,B\Big), with BB the complexity term including the cost of the prior grid, valid with probability 1−δ−δ′=0.9651-\delta-\delta'=0.965. My recomputation from the table (whose training error is already the Monte Carlo upper bound, so only the outer inverse is applied) matches all six bounds within 0.005, and Pinsker's form would have given 0.245 for the 600-unit network, so the exact inversion is worth about eight percentage points.

Step 3

With a point mass and a universal prior, the KL is the code length of the model. Lotfi et al. put a point mass on one compressed model hh and use the prior P(h)=2−K(h)/ZP(h)=2^{-K(h)}/Z, with KK the prefix Kolmogorov complexity given the architecture and the random seed and Z≤1Z\le1 by Kraft's inequality. Then KL(δh∥P)=log⁡1P(h)≤K(h)log⁡2≤l(h)log⁡2+2log⁡l(h),\mathrm{KL}(\delta_h\|P)=\log\frac1{P(h)}\le K(h)\log2\le l(h)\log2+2\log l(h), where l(h)l(h) is the length in bits of any program that reproduces hh. Against a continuous prior a point mass has infinite KL, which is why Dziugaite and Roy needed a Gaussian; against this discrete prior PAC-Bayes is the Occam bound, a union bound over codes at confidence δ 2−l\delta\,2^{-l} each.

Step 4

Training in a random subspace and quantizing makes the code scale with the task instead of the network. Write θ=θ0+Pw\theta=\theta_0+Pw with a fixed random P∈RD×dP\in\mathbb R^{D\times d} and train only w∈Rdw\in\mathbb R^d; given the seed, θ0\theta_0 and PP cost nothing, so the code carries only ww: the selected dd is 1,000 for MNIST, 3,500 for CIFAR-10 and 10,000 for CIFAR-100, and it grows with the difficulty of the task, which lets the bound adapt. Each wiw_i is rounded to one of LL learned levels, trained jointly with straight-through gradients so the network adapts to its own rounding, and arithmetic coding with the empirical level frequencies pp gives l(w)≤⌈d H(p)⌉+L (16+⌈log⁡2d⌉)+2 bitsl(w)\le\lceil d\,H(p)\rceil+L\,(16+\lceil\log_2d\rceil)+2\ \text{bits} for the symbols, a half-precision codebook and the frequencies. For MNIST with d=1000d=1000 and L=7L=7 this is at most 2,992 bits (about 0.37 KB at the paper's 8,192 bits per KB), about 0.04 nats per training example. Standard pruning with the same quantization and coding gives 47.9% on MNIST at 6.5 KB. Every choice made after seeing the data adds to the code length, log⁡2H\log_2H bits for a grid of HH values fixed in advance, so the whole hyperparameter search costs under 10 bits.

Step 5

A prior trained on part of the sample turns the bound into a validation estimate, while a prior pretrained on independent data keeps it explanatory. If the prior is a checkpoint trained on part of the sample and the bound is evaluated on the rest, the optimal subspace dimension is 0 in every dataset: the posterior is the checkpoint itself, and the bound is a validation estimate. All the learning sits in the prior, which the bound does not constrain, so only data-independent bounds speak to why a network generalized. A checkpoint pretrained on an independent dataset avoids the objection: the bound constrains everything learned downstream and nothing learned upstream. CIFAR-10 goes from 58.2% to 35.1% even though the fine-tuned EfficientNet-B0 is much larger than the from-scratch ConvNet, since its difference from the checkpoint compresses to about 1 KB.

Step 6

Breaking structure in the data or the model lengthens the code. At matched size a CNN gets lower bounds than an MLP on CIFAR-10 and loses that advantage when the pixels are shuffled. With shuffled labels every bound is 100%, and this is forced: at most a 2−c+12^{-c+1} fraction of random label strings compress by cc bits, and a fitted model is itself a compressor of the labels, so with probability 1−δ1-\delta K(h∣P)≥∣D∣−NLL(D∣h)−log⁡21δ−2:K(h\mid P)\ge|D|-\mathrm{NLL}(D\mid h)-\log_2\tfrac1\delta-2: a model that fits random labels well must be about as long as the labels. Full-batch training gives about the same bounds as SGD, so SGD's implicit bias is not needed for the certificate.

What the certified numbers mean. Neither certificate is for the network one would deploy. Dziugaite and Roy's is for the stochastic network QQ, about twice as bad as the SGD network it came from, and Nagarajan and Kolter argue that the standard ways of derandomizing it reduce to two-sided uniform convergence. Lotfi et al.'s is for the compressed, quantized subspace model: by my kl-form back-of-envelope (an estimate, not a number the paper reports), a 58.2% bound at about 1.2 KB on 50,000 examples requires that model's training error to be near 32%, or somewhat less under Catoni's form (31% at α=1.1\alpha=1.1, 22% at α=2\alpha=2), much worse than the full network, and relating the two is open. Dziugaite and Roy show that SGD's solutions have this structure but not why SGD finds them, and the compression bounds do not explain why bigger networks generalize better, since the compressed size still increases with width. Compressibility implies generalization here, with no claim of the converse, and ImageNet stays essentially vacuous.

Terms

kl(e^(Q,S)∥e(Q))≤KL(Q∥P)+log⁡(m/δ)m−1\mathrm{kl}(\hat e(Q,S)\|e(Q))\le\frac{\mathrm{KL}(Q\|P)+\log(m/\delta)}{m-1}
the PAC-Bayes-kl bound; holds for all QQ at once, PP fixed before the data
kl−1(q∣c)\mathrm{kl}^{-1}(q|c)
largest pp with kl(q∥p)≤c\mathrm{kl}(q\|p)\le c; about cc when q=0q=0, computed by Newton steps
Stochastic neural network
weights redrawn from QQ at each prediction; the object the bound certifies
P=N(w0,λI)P=\mathcal N(w_0,\lambda I)
prior centered at the random initialization, which breaks hidden-unit symmetries
λ=c e−j/b\lambda=c\,e^{-j/b}
prior-variance grid; confidence 6δ/(π2j2)6\delta/(\pi^2j^2) each, costing about 2log⁡j2\log j nats
KL(δh∥P)≤l(h)log⁡2+2log⁡l(h)\mathrm{KL}(\delta_h\|P)\le l(h)\log2+2\log l(h)
point-mass KL is the code length of the model, plus a delimiter cost
Occam bound
PAC-Bayes with a point mass: a union bound over codes at confidence δ 2−l\delta\,2^{-l}
θ=θ0+Pw\theta=\theta_0+Pw
training in a random dd-dimensional subspace; seed makes θ0,P\theta_0,P free to describe
Hyperparameter bits
a grid of HH values fixed in advance costs log⁡2H\log_2H bits; the whole search under 10
Data-dependent prior
optimal d=0d=0: the bound becomes a held-out estimate for the prior's checkpoint

Quiz

  1. The posterior QQ is optimized on the same training set that the bound is evaluated on. Why does the guarantee survive?
  2. At evaluation Dziugaite and Roy invert the kl bound exactly instead of using Pinsker's e^+c/2\hat e+\sqrt{c/2}. Why does this matter so much when the training error is small?
  3. Which statement about the 16.1% certificate for the 600-unit network is correct?
  4. What does the 58.2% CIFAR-10 bound certify?

Sources