SAMPa: Sharpness-aware Minimization Parallelized

Wanyun Xie, Thomas Pethick, Volkan Cevher

Abstract

Sharpness-Aware Minimization (SAM) has emerged as a state-of-the-art technique for improving neural network generalization by steering optimization toward "flat minima." However, SAM’s requirement for two sequential gradient computations per update effectively doubles training time. We introduce SAMPa (SAM Parallelized), a novel formulation that breaks this sequential dependency. By maintaining an auxiliary weight sequence, SAMPa allows both gradient steps to be computed simultaneously across parallel devices. Our results demonstrate that SAMPa achieves a near 2x speedup while consistently outperforming vanilla SAM in accuracy across diverse vision and language tasks.

Introduction

A central goal in deep learning is achieving high generalization—ensuring models perform well on unseen data. Recent research highlights the importance of the loss landscape, suggesting that "flat minima" (regions where the loss is stable under small weight perturbations) generalize significantly better than "sharp minima."

Sharpness-Aware Minimization (SAM) is the leading method for finding these regions. It works by first calculating a gradient to find a "worst-case" perturbation and then calculating a second gradient at that perturbed location for the actual update. This sequential dependency is a major bottleneck, making SAM twice as slow as standard SGD.

SAMPa: Parallelizing Sharpness-Awareness

SAMPa overcomes the sequential bottleneck by decoupling the perturbation step from the current weight update.

The Auxiliary Sequence and Parallelization

The core innovation of SAMPa is the introduction of an auxiliary sequence ($y_t$). Instead of computing a perturbation based on the gradient at the current weights ($x_t$), SAMPa uses the gradient from the auxiliary point. This allows the model to compute the gradient for the current weight update and the gradient for the next auxiliary step simultaneously on separate GPUs.

Convergence of the gradient norm for SAMPa variants compared to SAM and RandSAM, demonstrating theoretical stability.

SAMPa-$\lambda$ and Stability

To further enhance performance, the authors integrate SAMPa with Optimistic Gradient Descent (OptGD). The resulting algorithm, SAMPa-$\lambda$, uses a hyperparameter $\lambda$ to interpolate between the parallelized SAM update and an optimistic look-ahead update. This integration provides better stability and helps the model navigate complex loss landscapes more effectively. Unlike many heuristics-based variants, SAMPa is backed by a convergence guarantee using a novel Lyapunov function.

Experimental Results

The researchers evaluated SAMPa on standard benchmarks including CIFAR-10/100, ImageNet-1K, and the GLUE benchmark for NLP.

Efficiency and Speedup

In practical tests on NVIDIA A100 GPUs, SAMPa reduced the per-epoch training time for a ResNet-56 from 18.8 seconds to 10.9 seconds. This near 2x speedup is achieved without sacrificing the theoretical convergence properties of the optimizer.

Comparison of validation accuracy against sequential gradients and wall-clock time, highlighting SAMPa's efficiency and performance gains.

Accuracy and Robustness

Unlike many efficient SAM variants that trade accuracy for speed, SAMPa provides a "win-win" scenario. On CIFAR-10, SAMPa-0.2 improved accuracy to 95.99% (vs. 95.81% for SAM). In NLP tasks using BERT-base on GLUE, SAMPa-0.1 achieved a score of 78.0, significantly higher than the AdamW baseline (74.6). Furthermore, SAMPa demonstrated superior robustness to label noise, outperforming SAM by nearly 2% in high-noise (80%) scenarios.

Conclusion

SAMPa effectively removes the primary barrier to the widespread adoption of sharpness-aware training: its computational cost. By parallelizing the gradient computations through an auxiliary sequence and integrating optimistic updates, SAMPa offers a faster and more accurate alternative to vanilla SAM. Future work includes extending convergence proofs to the $\lambda > 0$ case and further optimizing communication overhead in multi-GPU environments.

Summary updated

BibTeX
@inproceedings{xie2024sampa,
  author = {Wanyun Xie and Thomas Pethick and Volkan Cevher},
  title = {{SAMPa: Sharpness-aware Minimization Parallelized}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=IGn0ktYDwV},
}
Figure