Generalization Bounds for Deep Networks
Norm-based, PAC-Bayes and compression bounds, and when they stop being vacuous.
A bound that counts parameters is vacuous for every network worth training, and so is any bound blind to the labels, since the same network fits random ones. The bounds that say something about deep networks measure other things: how much the layers can stretch their inputs relative to the margin, how far the weights can move without changing the predictions, how few bits describe the trained network. This lesson proves a spectrally normalized margin bound, computes compression bounds that are non-vacuous for ImageNet classifiers and language models, and dissects a construction in which no uniform-convergence bound can succeed.
What you’ll learn
- Explain why parameter-counting bounds are vacuous for deep networks, and what any valid bound must output for a network trained on random labels.
- Prove the perturbation lemma for ReLU networks and derive from it, through a PAC-Bayes margin argument, a bound governed by (Neyshabur, Bhojanapalli & Srebro, 2018).
- Compute an Occam bound for a network described in bits, and prove that a network fitting random labels cannot be compressed.
- Compare the non-vacuous bounds from MNIST to ImageNet and language models by what each one actually certifies.
- Reconstruct the Nagarajan–Kolter construction, in which every two-sided uniform-convergence bound is nearly vacuous although the test error is small.
What a bound must beat
A generalization bound says that with probability at least over the training examples, the test error is at most the training error plus a complexity term. The Machine Learning course proves the classical routes: uniform convergence over a class through the VC dimension or Rademacher complexity, and PAC-Bayes bounds, which charge the KL divergence of a learned distribution over weights from a prior fixed in advance (VC Dimension & the Fundamental Theorem, Rademacher Complexity, Stability, Compression & PAC-Bayes). This lesson is about what changes when the class is a deep network.
Two hurdles come first. Counting fails. For piecewise-linear networks with weights and layers the VC dimension is at most of order , and this is nearly tight (Bartlett, Harvey, Liaw & Mehrabian, 2019). For a 50-layer network with weights and training images, ; even without constants or the , the square root is about 400, four hundred times the largest possible error.
Blindness fails. A network trained on random labels has training error 0 and test error 0.9 (10 classes). A valid bound must say at least 0.9 for that network, and if it depends only on what the two runs share (the architecture, the training inputs, ), it says at least 0.9 for the true-label run too. A useful bound must depend on something that differs between the runs: the trained weights, through their norms, margins or compressibility, or the behavior of the algorithm.
Norms instead of counts. Bartlett (1998) found the way out: for sigmoid networks whose units each have weights of small total absolute value, the error of classifying with a margin is controlled by the size of the weights rather than their number. For deep networks, norm bounds take a product form, because a change in layer is stretched by every later layer. Neyshabur, Tomioka and Srebro (2015) proved such bounds for several norms, some with a factor exponential in depth; the Machine Learning course's Rademacher Complexity tabulates the main ones.
Any norm bound for ReLU networks must respect two symmetries. Since for , multiplying layer by and layer by leaves the function unchanged, so a sensible capacity is invariant to such rebalancing: products of layer norms are, sums of squared norms are not. And multiplying every layer by multiplies every output, and every margin, by , so margins must be measured relative to the network's scale.
A network trained on uniformly random CIFAR-10 labels has zero training error. A proposed bound, computed from the trained weights, certifies a test error of at most 0.15 for it. What follows?
- The network has learned something about the images after all
- The bound cannot be valid as stated: the true test error is about 0.9, so some assumption or step of the bound must fail
- Nothing: bounds hold only with probability , and this is the unlucky case
- The bound is fine, because random labels are not drawn i.i.d.
Show the answer
B. The bound cannot be valid as stated: the true test error is about 0.9, so some assumption or step of the bound must fail
With labels independent of the images, no classifier beats chance: the expected test error is 0.9. A bound of 0.15 would fail for almost every random-label training set, far more often than the allowed probability . Random labels are a cheap sanity test that every valid bound passes, which is why useful bounds must depend on the trained weights or on the algorithm.
Spectral margin bounds, by perturbation
Take a bias-free ReLU network , writing for the weight matrix , with width at most , outputs and inputs . Its margin on is ; is the fraction of training points with margin at most , and is the test error. The route of Neyshabur, Bhojanapalli and Srebro (2018) has two steps: a PAC-Bayes lemma that turns robustness to weight noise into a bound for the unperturbed network, and a lemma that measures that robustness with spectral norms.
Claim. If every perturbation satisfies , then for every input with
Let be the pre-activations, with , tildes mark the perturbed network, and with . Add and subtract . The ReLU is 1-Lipschitz with , so and :
Unperturbed activations grow by at most each layer's spectral norm, , and the assumption gives . Induction on then gives
At , , which proves the claim. The product of spectral norms bounds how much the network can stretch anything, and each layer's relative perturbation enters once.
From lemma to bound. By ReLU homogeneity, rebalance the layers so that all have the same spectral norm ; nothing in the bound changes. Take the prior and perturbations . A matrix concentration inequality and a union bound over layers show that with probability at least every , so choosing of order keeps the lemma's bound below . The KL term is , and because depends on , a union bound over a grid of values of completes the proof.
What the bound gets right. It is invariant to rebalancing the layers; it measures the margin relative to , an upper bound on the network's Lipschitz constant; and the ratio (the stable rank) is at most the rank, so the bound rewards weight matrices dominated by a few directions. Bartlett et al. found the normalized margins of networks trained on random labels much smaller than with true labels, as a valid bound requires.
What it gets wrong. The numbers are astronomical. Arora, Ge, Neyshabur and Zhang (2018) evaluated such quantities for a VGG-19 trained on CIFAR-10: the smallest, of the Bartlett–Foster–Telgarsky type, was about (with constants and logarithms dropped), to be compared with training examples, and far above the parameter count. Products of norms assume that every layer stretches the worst-case direction, which trained networks rarely do. The spectral product also correlates poorly, even negatively, with generalization across hyperparameters (Jiang et al., 2020), and Nagarajan and Kolter (2019) found such bounds growing with the training-set size.
In the perturbation lemma, why does the product of all the layers' spectral norms multiply each layer's relative perturbation?
- Because spectral norms of random matrices multiply
- Because the lemma assumes all layers have the same spectral norm
- Because the KL divergence of Gaussians multiplies across layers
- Because a change in one layer acts on an input already stretched by the earlier layers, and is then stretched by every later one
Show the answer
D. Because a change in one layer acts on an input already stretched by the earlier layers, and is then stretched by every later one
An error introduced at layer has size at most , and each later layer multiplies it by at most . Together that is the full product times .
Compress, then count
Arora, Ge, Neyshabur and Zhang (2018) turned the perturbation idea around. A network that tolerates noise in its weights can be compressed, for instance by replacing each layer with a low-rank or randomly projected version, and a compressed network is a small, countable object. The argument never needs the capacity of the original network's class.
For a VGG-19 trained on CIFAR-10, noise stability let the later layers be compressed to around 1% of their parameters, though some earlier layers not at all. The bound beat naive parameter counting and the earlier norm-based bounds, the latter by orders of magnitude. It was still far from non-vacuous: even with constants and logarithms dropped, the effective parameter count ran into the millions, against 50,000 training examples. The simplest form of the idea counts bits directly.
A trained network can be described in 10,000 bits and has 2% training error on examples. With , what test error does the Occam bound certify?
Show the answer
0.283
The KL term is nats and , so the complexity term is and the bound is . The tighter kl form of the PAC-Bayes bound gives 0.187 for the same numbers. Describing one million 32-bit weights instead, bits, makes the complexity term about 14.9: vacuous.
Fix the inputs and draw labels uniformly from classes: equally likely labelings, with . Fewer than binary strings have at most bits, and each describes at most one labeling, so
A network that outputs class probabilities, followed by the labels arithmetic-coded with those probabilities, is a description of the labels. With , the negative log-likelihood in bits,
Taking in the first step: with probability at least no description is shorter than bits. Combining the two,
A network that fits random labels confidently has a small , so it needs nearly bits, about 166,000 for 50,000 labels from 10 classes, and its Occam bound is vacuous, as it must be. Real labels escape the argument only because they are predictable from the images, so a short network can describe them: compressibility is a property of the data as much as of the network.
| Work | Setting | Bound | What is certified |
|---|---|---|---|
| Dziugaite & Roy (2017) | Fully connected networks on MNIST relabeled into two classes | Error 0.16 to 0.22 (measured: about 0.03); 1.35 with random labels | A Gaussian-perturbed network around the SGD solution, with the PAC-Bayes bound optimized directly |
| Zhou et al. (2019) | LeNet-5 on MNIST; a pruned, quantized MobileNet on ImageNet | MNIST: error 46%. ImageNet: top-1 error 96.5%, top-5 error 89% (chance: 99.9% and 99.5%) | The compressed network with Gaussian noise on its weights |
| Lotfi et al. (2022) | Training in a random low-dimensional subspace, then quantization and arithmetic coding | MNIST 11.6%; CIFAR-10 58.2%, or 35.1% when starting from an ImageNet-trained network | The compressed network, with a prior fixed before seeing the data |
| Lotfi et al. (2024) | GPT-2-architecture language models on OpenWebText, compressed with SubLoRA | 12.12 bits per token (uniform guessing: 15.62); top-1 next-token error 96.41% (chance: 99.99%) | The compressed model with predictions smoothed toward uniform, and documents as the i.i.d. samples |
Two caveats run through the table. Each certificate is for a modified network, compressed or randomized, not the one SGD returned. And the bounds explain generalization by compressibility, which itself needs explaining: Lotfi et al. (2022) found that shuffling the pixels of CIFAR-10 made convolutional networks much less compressible (fully connected networks, which never used the image structure, were unaffected), and that models fitting shuffled labels were not compressible at all, as the counting argument predicts. The compression view says that trained networks on real data are simple to describe; why gradient descent finds such networks is the open part (Pruning, Sparsity & Lottery Tickets, Training in a Tiny Subspace).
When uniform convergence fails
Every bound so far, whether from VC dimension, Rademacher complexity, covering numbers or the usual PAC-Bayes argument, controls the gap between test and training error two-sidedly and uniformly over some set of networks. Nagarajan and Kolter (2019) asked whether any bound of this kind can work even when the set is cut down to the bare minimum: the networks the algorithm actually outputs on typical training sets.
Data. Inputs , labels with equal probability, a fixed with , signal and independent noise , with . Algorithm. One gradient step of size 1 from zero that increases :
Training points are fitted. Since and , the margin of a training point is
Test points are classified correctly. On a fresh point the noise term has mean zero and standard deviation about , so for large enough the margin is about and the test error is below any chosen :
The mirrored training set is misclassified. Negate the noise, . The noise is symmetric, so has exactly the distribution of a training set, yet
No uniform bound survives. Any of probability at least contains, with positive probability, a training set such that too, has test error at most , and misclassifies all of . Then , so .
The result does not make generalization inexplicable: here provably generalizes, and the classifier with set to zero even has a non-vacuous bound, since it has very few parameters, though that bound says nothing about the classifier actually returned. What fails is a proof technique, bounding the gap uniformly over a set of networks: collectively, the algorithm's outputs fit typical-looking data adversarially, even though each one generalizes. Responses work around it. Negrea, Dziugaite and Roy (2020) bound the learned predictor through a surrogate, a partly derandomized or denoised version of it, that does enjoy uniform convergence. And uniform convergence restricted to interpolators of small norm can be tight for linear regression (Koehler, Zhou, Sutherland & Srebro, 2021; the Machine Learning course's Benign Overfitting).
Key takeaways
- A useful bound must depend on the trained weights or the algorithm: one computed only from the architecture, the inputs and must exceed 0.9 for random labels, so it is vacuous for real labels too.
- For ReLU networks a perturbation moves the output by at most ; with a PAC-Bayes margin lemma this gives a bound governed by , invariant to rebalancing but numerically enormous.
- A network described in bits has a gap of at most about . Networks fitting random labels need about bits, so their bounds are vacuous, while compressed real-label models give non-vacuous bounds on ImageNet and for language models, for the compressed model.
- Nagarajan and Kolter built settings where the algorithm generalizes but every two-sided uniform-convergence bound, even over its own outputs, is at least ; explanations must use the algorithm or surrogate predictors more directly.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Multiplying every layer of a bias-free ReLU network by 2 multiplies all its outputs by . Why must a margin bound divide the margin by something like ?
- Otherwise the bound could be made as small as you like by scaling up the weights, which changes no prediction
- Spectral norms are cheaper to compute than Frobenius norms
- Larger weights always mean worse generalization
- The margin is undefined for large weights
Show the answer
A. Otherwise the bound could be made as small as you like by scaling up the weights, which changes no prediction
Scaling all layers by scales every margin by and changes no prediction, so a bound in terms of the raw margin could be driven to zero for free. Dividing by , which scales the same way, makes the ratio scale-free.
A network fits 50,000 uniformly random labels from 10 classes. With high probability, about how many bits must any description of it take (given the inputs), and what does a compression bound then give?
- About 10 bits per parameter, so the bound is small if the network is small
- About 50,000 bits, so the bound is about 0.5
- About 166,000 bits, the information in the labels, so the bound exceeds 1
- No bound applies, because random labels violate its assumptions
Show the answer
C. About 166,000 bits, the information in the labels, so the bound exceeds 1
The labels carry bits of entropy, and a network that predicts them all is a description of them, so with high probability it needs nearly that many bits. McAllester's complexity term is then about : vacuous, as it must be when the test error is 90%.
In the Nagarajan–Kolter construction, what does the noise-negated training set achieve?
- It is an adversarial example found by gradient ascent on the classifier
- It shows that the learned classifier has a large test error
- It has the same distribution as a real training set, yet the classifier learned from misclassifies all of it, so every likely collection of training sets contains a pair that defeats two-sided uniform convergence
- It is used to train a second classifier that generalizes worse
Show the answer
C. It has the same distribution as a real training set, yet the classifier learned from misclassifies all of it, so every likely collection of training sets contains a pair that defeats two-sided uniform convergence
Because the noise is symmetric, is distributed exactly like , so any collection of training sets of probability contains some together with its . The classifier has test error at most but error 1 on , so the uniform-convergence gap over the algorithm's own outputs is at least .
Lotfi et al. (2024) reported non-vacuous generalization bounds for models with the GPT-2 architecture. Which statement is accurate?
- They bound the next-token error of the original, uncompressed checkpoints
- Their bounds show that language models do not memorize training text
- They bound heavily compressed models trained in a low-dimensional parameterization (SubLoRA), with predictions smoothed toward uniform and whole documents as the i.i.d. samples; the uncompressed model's bound is vacuous
- Their bounds hold for any text, not only text from the training distribution
Show the answer
C. They bound heavily compressed models trained in a low-dimensional parameterization (SubLoRA), with predictions smoothed toward uniform and whole documents as the i.i.d. samples; the uncompressed model's bound is vacuous
A compression bound needs a short description, so the models are trained in a compressed parameterization; prediction smoothing keeps the log loss bounded, and documents rather than tokens are the independent samples. The bound, 12.12 bits per token against 15.62 for uniform guessing, is non-vacuous; for the original model it is vacuous.
Further reading
- B. Neyshabur, S. Bhojanapalli & N. Srebro, "A PAC-Bayesian approach to spectrally-normalized margin bounds for neural networks," ICLR (2018).
- P. L. Bartlett, D. J. Foster & M. Telgarsky, "Spectrally-normalized margin bounds for neural networks," NeurIPS (2017).
- S. Arora, R. Ge, B. Neyshabur & Y. Zhang, "Stronger generalization bounds for deep nets via a compression approach," ICML (2018).
- W. Zhou, V. Veitch, M. Austern, R. P. Adams & P. Orbanz, "Non-vacuous generalization bounds at the ImageNet scale: a PAC-Bayesian compression approach," ICLR (2019).
- S. Lotfi, M. Finzi, Y. Kuang, T. G. J. Rudner, M. Goldblum & A. G. Wilson, "Non-vacuous generalization bounds for large language models," ICML (2024).
- V. Nagarajan & J. Z. Kolter, "Uniform convergence may be unable to explain generalization in deep learning," NeurIPS (2019).