Improved Deep Neural Network Generalization Using m-Sharpness-Aware Minimization

Kayhan Behdin, Qingquan Song, Aman Gupta, David Durfee, Ayan Acharya, Sathiya Keerthi, Rahul Mazumder

TL;DR

Sharpness-Aware Minimization (SAM) enhances deep network generalization by seeking out flatter minima in the loss landscape, but standard SAM computes only a single adversarial weight perturbation per mini-batch. This paper systematically evaluates mSAM, a variant that partitions batches into $m$ disjoint micro-batches to average perturbations along multiple directions. By treating $m$ as a tunable hyperparameter decoupled from hardware constraints, mSAM consistently converges to flatter solutions and improves test accuracy across vision and NLP benchmarks with modest computational overhead.

What Problem Does This Paper Address?

Deep neural networks have non-convex loss surfaces filled with numerous local minima that yield very different generalization performance on unseen test data. Optimization methods that find "flatter" regions typically generalize better.

SAM encourages flatness by optimizing the worst-case loss within an $\ell_2$-ball around the current weights. However, SAM evaluates sharpness using a single adversarial direction computed across the entire mini-batch. While an empirical variant—mSAM—was previously used as a distributed training trick to avoid multi-GPU synchronization, $m$ was tied strictly to the number of accelerators rather than treated as an algorithmic hyperparameter. A comprehensive empirical evaluation of mSAM across modern architectures, datasets, and loss-landscape metrics has been missing.

Methods

The paper develops a flexible implementation of mSAM that runs seamlessly on both single- and multi-accelerator setups without coupling $m$ to the hardware count:

  • mSAM Formulation: A mini-batch $S$ is split into $m$ disjoint shards (micro-batches) $S_1, \dots, S_m$. Instead of calculating a single global perturbation $\hat{\epsilon}$, mSAM calculates a localized adversarial perturbation $\hat{\epsilon}^{(i)} \propto \rho \nabla L_{S_i}(w) / \|\nabla L_{S_i}(w)\|_2$ for each micro-batch $i \in [m]$.
  • Gradient Update: The parameter gradient is calculated by averaging the gradients across micro-batches evaluated at their respective perturbed weights: $$\nabla L_S^{\text{mSAM}}(w) = \frac{1}{m} \sum_{i=1}^m \nabla L_{S_i}\left(w + \rho \frac{\nabla L_{S_i}(w)}{\|\nabla L_{S_i}(w)\|_2}\right)$$
  • Hybrid Training: The authors also explore efficiency improvements by switching dynamically between mSAM and vanilla optimization (e.g., running mSAM for the first 20% of training epochs and vanilla SGD/AdamW for the rest).

Datasets

The authors evaluate performance on standard computer vision and natural language processing benchmarks:

  • Vision: CIFAR-10 and CIFAR-100 (trained from scratch on ResNet-50 and WideResNet-28-10, and fine-tuned on pre-trained ViT-B/16).
  • NLP: Four tasks from the GLUE benchmark fine-tuned with RoBERTa-base: CoLA and MRPC (smaller datasets), as well as SST-2 and QQP (larger datasets).
  • No new datasets or benchmarks were introduced.

Key Insights and Ideas

  • Multiple Perturbation Directions Capture Flatness Better: Probing $m$ separate adversarial vectors across micro-batches provides a richer representation of local curvature than a single batch-averaged perturbation vector.
  • Measurably Flatter Solutions: Using power iteration to compute $\lambda_{\max}$ (the largest eigenvalue of the Hessian matrix at convergence), the authors confirm that mSAM finds significantly flatter minima than SAM.
  • There is a Sweet Spot for $m$: Increasing $m$ steadily improves accuracy up to $m \approx 32$ on CIFAR-100. Beyond this threshold, micro-batches become too small, leading to noisy gradient estimates that degrade perturbation quality.
  • Debunking the Runtime Misconception: Prior literature suggested mSAM is $m$ times slower due to multiple forward-backward passes. In reality, because each pass processes a micro-batch that is $m$ times smaller, the work is amortized. On ViT-B/16, mSAM takes 8,163 seconds compared to SAM's 7,007 seconds (only ~1.16× slower).

Key Results

  • CIFAR-100 Classification:
  • ResNet-50: mSAM reaches 83.37% test accuracy, outperforming SAM (81.49%) and Vanilla (80.68%).
  • WideResNet-28-10: mSAM reaches 84.07%, beating SAM (82.93%) and Vanilla (81.01%).
  • ViT-B/16: mSAM attains 89.00%, vs. 88.75% (SAM) and 88.02% (Vanilla).
  • Hessian Sharpness ($\lambda_{\max}$ on CIFAR-100):
  • WideResNet-28-10: drops from 92 ± 4 (Vanilla) to 30 ± 2 (SAM), and down to 17 ± 1 (mSAM).
  • ResNet-50: drops from 26 ± 2 (Vanilla) to 21 ± 3 (SAM), and down to 18 ± 1 (mSAM).
  • GLUE Benchmark (RoBERTa-base): mSAM achieves consistent improvements across tasks (e.g., CoLA MCC improves to 64.57 vs. 64.30 for SAM; MRPC accuracy reaches 90.92% vs. 90.37% for SAM).
  • Hybrid Training: On WideResNet-28-10, using mSAM for only the first 20% of training matches the accuracy of training with mSAM for 100% of the epochs.

Limitations and Future Work

  • Lack of Formal Theory: The paper provides empirical evidence of flatter minima, but leaves formal theoretical proofs justifying mSAM's implicit regularization and generalization bounds to future work.
  • Hyperparameter Interactions: How optimal $m$ interacts with overall mini-batch size, learning rate schedules, and dataset scale remains an open question.
  • Uniform Perturbation Radius: The perturbation radius $\rho$ was kept identical across all micro-batches to avoid exhaustive tuning; per-shard adaptive radii were not explored.

Summary updated

BibTeX
@inproceedings{behdin2022improved,
  author = {Kayhan Behdin and Qingquan Song and Aman Gupta and David Durfee and Ayan Acharya and Sathiya Keerthi and Rahul Mazumder},
  title = {{Improved Deep Neural Network Generalization Using m-Sharpness-Aware Minimization}},
  booktitle = {OPT @ NeurIPS},
  year = {2022},
  url = {https://openreview.net/forum?id=cbUI6a9Sw4X},
}
Figure