Why Big Networks Generalize
Random labels, sharpness and measures that predict generalization.
Train a standard image classifier on CIFAR-10 with every label replaced by a random one, and it still reaches zero training error. The same network on the real labels generalizes well. Whatever explains generalization, then, cannot be a property of the architecture alone. This lesson proves how cheaply networks memorize, then tests the candidate explanations (flatness, norms and PAC-Bayes, sharpness-aware training, the simplicity bias of random networks) against the evidence, including large studies that tried to rank them.
What you’ll learn
- Prove that a two-layer ReLU network with weights can fit any labels on distinct points in , and state what the randomization experiments rule out.
- Show that expected sharpness under Gaussian noise is a Hessian trace, and explain through PAC-Bayes why sharpness means something only relative to the scale of the weights.
- Describe how generalization measures have been tested at scale, and what the tests found.
- Derive the sharpness-aware minimization update and the realizable PAC-Bayes bound behind the simplicity-bias account, and state what remains unexplained.
Memorization is cheap
Zhang, Bengio, Hardt, Recht & Vinyals (2017) ran randomization tests on standard convolutional networks for CIFAR-10 and ImageNet. On CIFAR-10, with every label replaced by a random one, the networks fit the training set perfectly, and training took only a small constant factor longer than on the true labels; on ImageNet, without retuning any hyperparameter, Inception reached 95% top-1 training accuracy on a million random labels. Replacing the images themselves with random noise did not stop the fit either. As the fraction of corrupted labels grew, test error rose steadily: the networks extracted the remaining signal and fitted the noise by brute force. Weight decay, dropout and data augmentation did not prevent the fit to random labels, and turning them all off did not ruin generalization on the real labels; in their words, explicit regularization "is neither necessary nor by itself sufficient for controlling generalization error."
The consequence for theory is sharp. A guarantee computed from the hypothesis class and the inputs alone, such as one built on the VC dimension or on Rademacher complexity, comes out identical for the random-label run, whose test error is at chance; since it must hold there, it can promise nothing better on the real labels. Stability arguments that ignore the labels fail the same way (Generalization in Modern ML and Rademacher Complexity develop this). And memorization needs surprisingly little machinery:
Pick so that the projections are distinct; every outside finitely many hyperplanes works. Relabel the points so the projections increase, and choose biases that interleave with them:
Hidden unit is active at point only if . For we have , so the matrix of hidden activations is lower triangular, with positive diagonal :
A triangular matrix with nonzero diagonal is invertible, and , so the output weights solve a linear system:
How many weights does this construction need to fit arbitrary labels on the 50,000 CIFAR-10 training images, each a vector of pixel values?
Show the answer
103072
and , so weights in a single hidden layer of width 50,000. Zhang et al. also showed how to trade width for depth: depth with width . Exact fitting of the training set is therefore a weak property, available to almost any large network; it says nothing about which interpolating function training finds.
Real and random labels are not learned the same way, though. Arpit et al. (2017) found that networks fit simple patterns shared across examples first and memorize noise later, and that tuned explicit regularization such as dropout can slow memorization of noise without hurting generalization on real data. Their conclusion: notions of effective capacity that ignore the data are unlikely to explain generalization, because the training data determine how much is memorized.
Flat minima, PAC-Bayes and scale
Hochreiter & Schmidhuber (1997) argued that a minimum surrounded by a large flat region tolerates imprecise weights, so it can be described with few bits, and by a minimum-description-length argument it should generalize better than a sharp one. Keskar, Mudigere, Nocedal, Smelyanskiy & Tang (2017) revived the idea with experiments in which large-batch training converged to sharper minima and generalized worse than small-batch training. PAC-Bayes bounds make the intuition precise: put a Gaussian posterior around the trained weights and pay for the training loss averaged over plus the KL divergence from a prior (the bound itself is proved in Stability, Compression & PAC-Bayes). Both terms depend on the noise level .
Expand the training loss to second order around , with Hessian :
For the linear term has mean zero and ; the cubic term vanishes by symmetry, leaving an error of order . The expected increase of the loss is half the noise variance times the trace of the Hessian:
With the prior on parameters, the complexity term shrinks as grows, while the loss term grows. A good bound needs a minimum that tolerates noise comparable to the size of the weights themselves:
So flatness enters the bound only together with a scale. That is just as well, because sharpness alone carries no meaning. Multiplying one layer of a ReLU network by and the next by leaves the function unchanged but rescales the Hessian blocks by , so a minimum can be made as sharp as you like without changing a single prediction (Dinh, Pascanu, Bengio & Bengio, 2017; derived in Batch Size, Learning Rate & Noise). Neyshabur, Bhojanapalli, McAllester & Srebro (2017) drew the conclusion: a sharpness measure must be normalized by the scale of the weights, and PAC-Bayes provides a principled way to combine the two. "Adaptive" sharpness, with perturbations proportional to each weight's magnitude, is invariant to such rescalings (Kwon, Kim, Park & Choi, 2021).
In a two-layer ReLU network, you multiply the first layer's weights and biases by 10 and divide the second layer's weights by 10. What changes?
- Nothing at all
- The outputs are multiplied by 10
- The function is identical, but the Hessian's eigenvalues and the weight norms change, so sharpness- and norm-based measures change
- The training loss changes, but the test loss does not
Show the answer
C. The function is identical, but the Hessian's eigenvalues and the weight norms change, so sharpness- and norm-based measures change
ReLU is positively homogeneous, , so the factors cancel and every prediction, training or test, is unchanged. The parameters are different, though, so any measure computed from them (Hessian eigenvalues, norms, isotropic PAC-Bayes terms) can change: such measures must be invariant to these symmetries before they can explain generalization.
Which measures predict generalization?
Jiang, Neyshabur, Mobahi, Krishnan & Bengio (2020) ran the first large-scale test. They trained more than 10,000 convolutional networks on CIFAR-10 and SVHN, systematically varying hyperparameters such as depth, width, batch size, learning rate, dropout, weight decay and the optimizer, and scored 40 complexity measures. The methodology is the instructive part. Correlating a measure with the generalization gap across all networks invites spurious results, because a hyperparameter like depth can move both. So they used Kendall's rank correlation granulated by hyperparameter (averaged over changes of one hyperparameter at a time, the others held fixed), and a conditional-independence test based on conditional mutual information.
Their main findings: many norm-based measures correlated poorly with the gap or even in the wrong direction, and the bound built on the product of the layers' spectral norms (like Bartlett, Foster & Telgarsky's) correlated strongly negatively with it: networks with larger spectral complexity generalized better. Sharpness-based measures, both PAC-Bayes flatness and Keskar et al.'s sharpness, performed best overall, with a magnitude-aware perturbation measure especially predictive. Measures of the optimization itself, such as how fast training converges and the gradient noise at the end of training, were also predictive.
| Family | Example | Jiang et al. (2020) | Later evidence |
|---|---|---|---|
| Counting | number of parameters | negatively correlated with the gap: bigger networks generalized better | vacuous in principle once random labels can be fitted |
| Norms and margins | product of spectral norms; distance from initialization | poor, often in the wrong direction | best at predicting the effect of learning-rate changes (Dziugaite et al., 2020) |
| Sharpness and PAC-Bayes | magnitude-aware flatness | among the best | in transformers and fine-tuning, adaptive sharpness correlates weakly with generalization and mostly follows training settings like the learning rate (Andriushchenko et al., 2023) |
| Optimization | steps to reach a training loss; final gradient noise | surprisingly predictive | little theory behind it |
Dziugaite et al. (2020) argued that averages hide failures and evaluated 24 measures by their worst case over families of controlled interventions, on over 1.6 million pairs of experiments. For every one of the measures there was some environment in which it always predicted the wrong direction of change in generalization. Most measures predicted the effect of the training-set size well; the effects of width and depth were hard for all of them, although some PAC-Bayes-based measures were robust over a large fraction of environments. Andriushchenko, Croce, Müller, Hein & Flammarion (2023) found, in modern settings, cases where sharper minima generalized better out of distribution.
Why did Jiang et al. average rank correlations over changes in one hyperparameter at a time, rather than correlating each measure with the generalization gap across all trained networks?
- To reduce the computational cost of the study
- Because a hyperparameter such as depth can change both a measure and the gap, creating correlation without the measure capturing why the networks generalize
- Because Kendall's correlation is undefined for more than two hyperparameters
- To make every measure's correlation positive
Show the answer
B. Because a hyperparameter such as depth can change both a measure and the gap, creating correlation without the measure capturing why the networks generalize
A pooled correlation can be driven entirely by a confounding hyperparameter. Holding all but one hyperparameter fixed, and testing conditional independence given the hyperparameters, targets the question that matters: does the measure track generalization for the right reason?
Sharpness-aware training and simplicity bias
Motivated by a PAC-Bayes-type bound in which the worst training loss in a -ball, plus a term increasing in , bounds the population loss (under the assumption that Gaussian perturbations do not lower the test loss), SAM minimizes the worst-case neighborhood loss:
Linearize the inner problem, with . By Cauchy–Schwarz the maximum over the ball is attained along the gradient:
Differentiate and drop the term that involves the derivative of , which would need Hessian–vector products. The update evaluates the gradient at the perturbed point, at the cost of a second forward–backward pass:
In practice is computed per mini-batch, or per shard of examples. Foret et al. found that smaller generalized better, and that this -sharpness predicted the generalization gap better than the full-training-set sharpness that their bound suggests.
SAM improved test accuracy across many benchmarks and was robust to label noise. But Andriushchenko & Flammarion (2022) argued that neither the PAC-Bayes bound nor convergence to flat minima fully explains it, least of all the role of -sharpness. For diagonal linear networks they proved that SAM's implicit bias selects solutions that generalize better than gradient descent's for a class of problems, an effect amplified by small .
A different account looks at the prior rather than the optimizer. Valle-Pérez, Camargo & Louis (2019) sampled random parameters for a network with 7 Boolean inputs and two hidden layers of 40 ReLU units, and counted how often each of the Boolean functions appeared. The probabilities spread over many orders of magnitude (about 39, if the Zipf law fitted to the rank plot is extended to all functions), and every high-probability function had low Lempel–Ziv complexity: the map from parameters to functions is exponentially biased toward simple functions. Their bound turns this prior into a guarantee.
Start from the kl form of the PAC-Bayes theorem (Langford & Seeger) in the version Valle-Pérez et al. use: for a prior over functions and i.i.d. examples (not the shard size of SAM), with probability at least , simultaneously for all posteriors ,
Let be the set of functions with zero training error and take , the Bayesian posterior with a 0–1 likelihood. Its KL is the log of one over the marginal likelihood , the probability that a random draw from the prior fits the training labels:
Since and :
With training examples, , and a marginal likelihood of , what error rate (in %) does the bound guarantee for ?
Show the answer
5 %
, so . Even a prior that gives the training labels a probability of yields a useful bound, because only the logarithm enters. Valle-Pérez et al. estimated with the network's infinite-width Gaussian-process limit and obtained bounds that tracked the true error across datasets and architectures.
The bound applies to , a random draw from the zero-error region weighted by the prior. Connecting it to SGD requires the authors' informal assumption that SGD samples that region close to uniformly, which is a hypothesis about the optimizer, not a theorem.
Key takeaways
- Networks fit random labels and even random inputs, and a two-layer ReLU network with weights can fit any labels on points. Class-only capacity bounds are therefore vacuous; explanations must involve the data and the training algorithm.
- Expected sharpness under noise is ; PAC-Bayes trades it against , and sharpness is meaningful only relative to the weights' scale.
- In large studies, sharpness- and optimization-based measures predicted generalization best on average and the spectral-norm bound worst, but every measure fails under some intervention.
- SAM steps with the gradient at ; the simplicity-bias account bounds the error by . Neither is a complete explanation.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In the memorization construction, why is the matrix of hidden activations invertible?
- Because ReLU matrices are always invertible
- Because is chosen at random, which makes a random Gaussian matrix
- Because there are more weights than data points
- Because the biases interleave with the sorted projections, so is lower triangular with a positive diagonal
Show the answer
D. Because the biases interleave with the sorted projections, so is lower triangular with a positive diagonal
With , unit is inactive at every point , so is lower triangular, and . The random only serves to make the projections distinct.
An architecture trained by SGD interpolates its training set whether the labels are real or shuffled at random. What can a uniform-convergence bound built only from this architecture's hypothesis class say about its test error on the real labels?
- That the test error on the real labels must be high
- Nothing useful: the same bound has to hold for the shuffled-label run, where test error is at chance
- That the test error is small, since the class is rich enough to fit anything
- The same as for any other model, since shuffled labels never occur in practice
Show the answer
B. Nothing useful: the same bound has to hold for the shuffled-label run, where test error is at chance
Such a bound depends on the class and the sample size, not on which labels were drawn, so its guarantee for the real labels can be no better than for the shuffled ones, where the network performs at chance. An explanation has to use the data and the training procedure.
Which update does sharpness-aware minimization (with the usual first-order approximation) apply?
- with drawn from
- with
- followed by projection onto a ball of radius
Show the answer
C. with
The inner maximization over the -ball is solved to first order by moving along the normalized gradient; the outer step then uses the gradient at that adversarially perturbed point, dropping second-order terms.
In Jiang et al.'s (2020) study of more than 10,000 networks, how did the generalization bound based on the product of the layers' spectral norms fare?
- It was the best predictor of the generalization gap
- It was essentially uncorrelated with the generalization gap
- It correlated strongly negatively with the generalization gap
- It could not be computed for convolutional networks
Show the answer
C. It correlated strongly negatively with the generalization gap
Networks with smaller generalization gaps tended to have larger values of the spectral-norm complexity, the opposite of what a bound should do. Sharpness-based and optimization-based measures did best; many norm-based measures failed, especially when training injected stochasticity.
Further reading
- C. Zhang, S. Bengio, M. Hardt, B. Recht & O. Vinyals, "Understanding deep learning requires rethinking generalization," ICLR (2017).
- S. Hochreiter & J. Schmidhuber, "Flat minima," Neural Computation 9(1), 1–42 (1997).
- Y. Jiang, B. Neyshabur, H. Mobahi, D. Krishnan & S. Bengio, "Fantastic generalization measures and where to find them," ICLR (2020).
- P. Foret, A. Kleiner, H. Mobahi & B. Neyshabur, "Sharpness-aware minimization for efficiently improving generalization," ICLR (2021).
- G. Valle-Pérez, C. Q. Camargo & A. A. Louis, "Deep learning generalizes because the parameter-function map is biased towards simple functions," ICLR (2019).