Flat Seeking Bayesian Neural Networks

Van-Anh Nguyen, Long Tung Vuong, Hoang Phan, Thanh-Toan Do, Dinh Phung, Trung Le

In the world of deep learning, we often talk about "landscapes." We imagine the loss function as a rugged mountain range where our goal is to find the lowest valley. But not all valleys are created equal. Some are narrow, steep "canyons" (sharp minima), while others are broad, gentle "basins" (flat minima). It is a well-established piece of deep learning folk wisdom—backed by significant theory—that flat minima generalize better to new data.

While point-estimation techniques like Sharpness-Aware Minimization (SAM) have successfully exploited this for standard training, Bayesian Neural Networks (BNNs) have largely been left in the canyons. A new paper from researchers at Monash University, VinAI, and NYU changes that by introducing Flat-Seeking Bayesian Neural Networks.

TL;DR

The authors develop a theoretical framework to bake "sharpness-awareness" directly into the Bayesian posterior. By forcing BNNs to sample models from flatter regions of the loss landscape, they achieve superior generalization, better uncertainty calibration, and increased robustness across standard benchmarks.

What Problem Does This Paper Address?

Bayesian Neural Networks are the "gold standard" for uncertainty quantification. Instead of finding one set of weights, they infer a distribution (the posterior) over all possible weights. However, standard BNNs have a blind spot: their mathematical formulation only cares about how well the models fit the training data and how close they stay to the prior. They don't explicitly care if a model sits on a precarious, sharp peak or in a stable, flat valley.

If a BNN samples a model from a sharp peak, that model might perform perfectly on the training set but fail miserably if the test data is even slightly shifted. This paper addresses this gap by redefining the Bayesian posterior to inherently prefer "flat" regions, ensuring that the entire ensemble of models sampled from the BNN is more robust.

Methods

The authors bridge the gap between Bayesian inference and sharpness-aware optimization through several key steps:

  1. The Optimization View of Posteriors: They first prove that the standard Bayesian posterior is actually the optimal solution to a specific optimization problem that balances training loss and "simplicity" (KL divergence).
  2. The Sharpness-Aware Posterior: Inspired by SAM, they replace the standard empirical loss with a "sharpness-aware" loss. This loss doesn't just look at the error at point $\theta$, but the maximum error within a small neighborhood around $\theta$.
  3. Variational Inference (VI) for Flatness: Since the true sharpness-aware posterior is mathematically intractable, they derive a new Variational Inference objective. This allows them to approximate the "flat" posterior using a simpler distribution (like a Gaussian).
  4. Geometry-Awareness: They introduce a "Geometry SA BNN" that scales the neighborhood search based on the importance of different weights, preventing the search from being dominated by less significant parameters.

Crucially, this isn't a standalone algorithm but a framework. The authors show how to "flat-ify" existing popular BNN methods, creating "F-versions" of MC-Dropout, SGLD, SWAG, and Deep Ensembles.

Datasets

The researchers evaluated their approach on several standard computer vision benchmarks:

  • CIFAR-10 & CIFAR-100: Standard image classification tasks.
  • ImageNet (ILSVRC-2012): Large-scale classification to test scalability.
  • CIFAR-10-C: A corrupted version of CIFAR-10 (adding noise, blur, etc.) used to test how well the models handle out-of-distribution data.

Key Insights and Ideas

  • Flatness is a Distributional Property: Most previous work treated sharpness as a property of a single model. This paper is among the first to develop a rigorous theory for the sharpness of a distribution of models.
  • The "F-Counterpart" Advantage: The most striking insight is that adding flatness-seeking behavior improved every baseline method. Whether it was a simple MC-Dropout or a sophisticated SWAG ensemble, the "Flat" version (e.g., F-SWAG) consistently performed better.
  • Visualizing the Basin: The authors provide loss landscape visualizations that clearly show the F-SWAG models residing in much broader, smoother basins compared to standard SWAG models.
Loss landscape comparison between F-SWAG and SWAG
  • Calibration Matters: Beyond just accuracy, the flat-seeking BNNs showed much lower Expected Calibration Error (ECE). This means when the model says it is 90% sure, it is actually right about 90% of the time—a critical trait for safety-conscious AI.

Key Results

The quantitative improvements were consistent across the board:

Performance comparison of Bayesian methods and their flat-seeking counterparts
  • Accuracy Boost: On CIFAR-100 using a WideResNet28x10, F-MC-Dropout reached 83.24% accuracy compared to the baseline 82.30%.
  • Uncertainty & Calibration: On the same setup, the Negative Log-Likelihood (NLL) dropped from 0.6500 to 0.6144, and the ECE was more than halved (from 0.0574 to 0.0250).
  • Robustness: On the corrupted CIFAR-10-C dataset, flat-seeking models significantly outperformed baselines. For instance, the average ECE across all corruptions for F-SWAG was 0.0200, compared to 0.0454 for standard SWAG.
  • Scalability: The method held up on ImageNet, with F-SGLD and F-SWAG outperforming their standard counterparts on ResNet-152 and DenseNet-161 architectures.

Limitations and Future Work

  • Computational Cost: Like the original SAM algorithm, finding the "worst-case" neighbor requires an additional gradient calculation per step. This makes training roughly twice as expensive as standard BNNs.
  • Hyperparameter Tuning: The "neighborhood size" ($\rho$) is a new hyperparameter that needs to be tuned. If $\rho$ is too large, the model might become too conservative; if it's too small, the benefits of flatness disappear.
  • Theoretical Constraints: The proofs assume a compact parameter space and certain "mild conditions" on the loss function, which may not perfectly describe every exotic neural network architecture.

The authors suggest that future work could explore more efficient ways to estimate the sharpness-aware gradient or apply these principles to other domains like Natural Language Processing.

Summary updated

BibTeX
@inproceedings{nguyen2023flat,
  author = {Van-Anh Nguyen and Long Tung Vuong and Hoang Phan and Thanh-Toan Do and Dinh Phung and Trung Le},
  title = {{Flat Seeking Bayesian Neural Networks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=eX6xDto3Ed},
}
Figure