SAM as an Optimal Relaxation of Bayes

Thomas Möllenhoff, Mohammad Emtiyaz Khan

Sharpness-Aware Minimization (SAM) has emerged as a powerful technique for improving neural network generalization by favoring flat minima. While effective, its theoretical connection to Bayesian methods—which handle uncertainty through weight distributions—has remained unclear. This paper establishes a formal bridge by proving that SAM's "max-loss" objective is the optimal convex relaxation of the Bayesian "expected-loss" objective. This discovery leads to Bayesian-SAM (bSAM), an algorithm that combines the performance of SAM with the principled uncertainty quantification of Bayesian inference.

Introduction

Deep learning models often overfit to noise in training data, leading to poor generalization. SAM addresses this by minimizing the maximum loss within a neighborhood of the weights, effectively smoothing the loss landscape. Conversely, Bayesian Deep Learning (BDL) averages loss over a distribution, providing uncertainty estimates but often lagging in raw performance. This work explores whether these two distinct approaches—adversarial worst-case and probabilistic average-case—share a common mathematical foundation.

The Theoretical Bridge

The core contribution of this work is the application of the Fenchel biconjugate from convex analysis to bridge SAM and Bayes. The authors demonstrate that the Bayesian objective (expected negative loss) can be relaxed into its tightest convex lower bound. When this relaxation is applied, the "max-loss" term characteristic of SAM naturally emerges.

Figure 6: (a) Conceptual relationship between SAM and Bayes via the Fenchel biconjugate. (b) Visualization of how increasing variance in the Bayesian objective smooths the loss landscape, aligning with the SAM minimizer.

This equivalence suggests that optimizing for the mean of a Gaussian distribution in a relaxed Bayesian framework is mathematically identical to the SAM optimization process. Essentially, the radius $\rho$ in SAM and the standard deviation $\sigma$ in Bayes are two sides of the same coin, both serving to penalize sharp minima.

Bayesian-SAM (bSAM)

Building on this theoretical link, the authors introduce Bayesian-SAM (bSAM). Unlike standard SAM, which typically uses a fixed scalar hyperparameter for the neighborhood size, bSAM treats this as a learnable variance parameter per dimension. By utilizing the Bayesian Learning Rule (BLR), bSAM updates weights and uncertainty simultaneously. The resulting algorithm behaves similarly to Adam but incorporates SAM-style perturbations, allowing it to "learn" the optimal neighborhood size for each parameter and reducing the need for extensive hyperparameter tuning.

Key Results and Insights

The efficacy of bSAM was validated across benchmarks including CIFAR-10/100 and TinyImageNet using ResNet architectures.

  • Improved Accuracy: bSAM consistently outperformed standard SGD, Adam, and their SAM counterparts. On CIFAR-100, bSAM achieved 62.64% accuracy, significantly higher than SAM-SGD's 58.58%.
  • Calibration and Uncertainty: Unlike standard SAM, which can be overconfident, bSAM provides high-quality uncertainty estimates. It significantly reduced Expected Calibration Error (ECE), matching exact Bayesian solutions on toy problems.
  • Robustness: The Bayesian formulation makes bSAM less sensitive to initial hyperparameter choices compared to standard SAM variants.

Conclusion and Future Work

By framing SAM as a "convex shortcut" to Bayesian inference, this research provides a rigorous foundation for adversarial learning. While bSAM currently uses a diagonal covariance matrix for efficiency, future work may explore full-covariance versions to capture complex weight correlations. Additionally, the empirical success of "m-sharpness" (splitting minibatches) remains a theoretical mystery that warrants further investigation.

Summary updated

BibTeX
@inproceedings{mollenhoff2023sam,
  author = {Thomas Möllenhoff and Mohammad Emtiyaz Khan},
  title = {{SAM as an Optimal Relaxation of Bayes}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=k4fevFqSQcX},
}
Figure