Flatness After All?

Neta Shoham, Liron Mor-Yosef, Haim AvronarXiv 2025

TL;DR

While deep learning folklore states that "flat minima generalize better," classic metrics like the Hessian trace fail because they can be artificially manipulated via layer rescaling. This paper rescues the flatness narrative by introducing a soft rank measure of the Hessian, proving theoretically and empirically that it accurately tracks the generalization gap while remaining robust to reparameterization.

What Problem Does This Paper Address?

The deep learning community has long debated the link between the geometry of loss minima (flat vs. sharp) and a model's ability to generalize to unseen data. While intuitive, standard metrics of flatness—like the trace or spectral norm of the Hessian matrix—have a glaring flaw: they can be manipulated by simply rescaling a network's weights without changing its predictions. This means a perfectly good, generalizing model can be mathematically transformed to appear arbitrarily "sharp."

The authors address this contradiction, asking: Can we redefine and measure flatness in a way that truly explains and predicts generalization?

Methods

The authors propose measuring flatness using the soft rank of the Hessian matrix $H(\theta^\star)$ at a local minimum, defined as: $$\text{rank}_\lambda(H(\theta^\star)) := \text{Tr}(H(\theta^\star)(H(\theta^\star) + \lambda I)^{-1})$$ where $\lambda$ is the weight decay coefficient.

To make this metric computationally practical for deep networks, they introduce several key innovations:

  • Fisher Information Matrix (FIM) Substitution: They substitute the expensive Hessian with the FIM, proving they coincide under practical calibration and non-correlation assumptions.
  • Structural Approximations: They utilize Kronecker-Factored Approximate Curvature (KFAC) and diagonal approximations to compute the soft rank efficiently without calculating full matrices.
  • Concave Trace Function Theory: They prove mathematically that keeping only diagonal blocks (as in KFAC) provides a safe, non-optimistic upper bound on the true soft rank.

Datasets

The authors evaluated their approach on three standard image classification datasets:

  • MNIST
  • CIFAR-10
  • SVHN

Note on preprocessing: To accommodate the massive computational overhead of calculating exact information matrices across a massive grid of hyperparameter configurations (varying architectures, learning rates, batch sizes, and weight decays), all images were downsampled to $7 \times 7$ pixels.

Key Insights and Ideas

  • Weight Decay Rescues Flatness: The classic argument that good minima can be "arbitrarily sharp" falls apart when weight decay ($L_2$ regularization) is active. Weight decay breaks layer-rescaling invariance, meaning well-regularized, good minima cannot be arbitrarily sharp unless the model is confidently wrong.
  • Parameter Estimation vs. Generalization: The requirements for accurate parameter estimation and good generalization are fundamentally opposed. For parameter estimation, you want sharp minima (minimizing the trace of the inverse Hessian). For generalization (predictive accuracy), you want flat minima.
  • The Overfitting Blindspot: For uncalibrated models, the generalization gap depends on both flatness (soft rank) and an error-to-uncertainty ratio. The authors show that this ratio collapses to zero on training data during overfitting, making it impossible to estimate from training data alone. However, the soft rank factor remains highly robust and measurable.

Key Results

  • Superior Correlation: The proposed soft rank of the FIM achieved a Kendall $\tau$ rank correlation of 0.84 with the true generalization gap, vastly outperforming traditional metrics like the trace ($\tau = 0.28$) and the spectral norm ($\tau = 0.08$).
  • Cheap Yet Effective: The KFAC approximation of the soft rank maintained a remarkably high correlation ($\tau = 0.78$), proving that the metric can be approximated cheaply without losing its predictive power.
  • Calibration Alignment: Moving-window analysis demonstrated that as a model's calibration improves on the test set, the soft rank metric tracks the true generalization gap with increasing precision.

Limitations and Future Work

  • Scale of Evaluation: Due to the extreme computational cost of computing full and structured information matrices, empirical validation was restricted to heavily downsampled ($7 \times 7$) images. Scaling these metrics to full-sized images and modern, massive architectures remains an open engineering challenge.
  • Highly Uncalibrated Regimes: While the soft rank factor avoids the limitations of overfitting data, if a model makes mistakes with extreme confidence at test time, the generalization gap bounds loosen, making it harder to assess generalization solely via the Hessian.

Summary updated

BibTeX
@misc{shoham2025flatness,
  author = {Neta Shoham and Liron Mor-Yosef and Haim Avron},
  title = {{Flatness After All?}},
  year = {2025},
  eprint = {2506.17809},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.17809},
}
Figure