Abstract
Sharpness-aware Minimization (SAM) has emerged as a powerful technique for improving the generalization of deep neural networks by targeting flat minima in the loss landscape. However, its requirement for two forward and backward passes per iteration doubles the training cost compared to standard Stochastic Gradient Descent (SGD). This paper introduces vSAM (Variation-based SAM), an adaptive sampling strategy designed to mitigate this computational overhead. By decomposing the SAM gradient and identifying a second-order term called the Projection of the Second-order gradient matrix onto the First-order gradient (PSF), we propose a dynamic sampling mechanism that reuses gradient information based on landscape stability. vSAM achieves approximately a 40% reduction in training time with virtually no loss in accuracy, outperforming existing efficient SAM variants on standard benchmarks.
Introduction
Generalization in deep learning is closely linked to the geometry of the loss landscape, specifically the "flatness" of the minima reached during training. SAM explicitly optimizes for flatness by minimizing the maximum loss within a neighborhood of the current weights. While effective, the 2x computational cost is a significant barrier to large-scale adoption. Previous attempts to accelerate SAM, such as LookSAM or ESAM, often involve fixed sampling intervals or heuristics that can lead to accuracy degradation. We address this by proposing an adaptive approach that "pays attention" to second-order information only when it is most critical.
Methodology: Variation-based SAM
The core innovation of vSAM is the decomposition of the SAM gradient into two distinct components: the standard SGD gradient and the PSF (Projection of the Second-order gradient matrix onto the First-order gradient). The PSF captures the essential "sharpness" information that SAM utilizes.
Adaptive Gradient Sampling
Rather than calculating the PSF at every iteration, vSAM employs a dynamic sampling strategy based on two criteria:
- Variance-based Sampling: The frequency of change in the PSF's L2-norm is monitored. When the variance is low, indicating a stable loss landscape, the sampling rate is reduced.
- Norm-based Sampling: The ratio between the PSF norm and the SGD gradient norm is evaluated. If the SGD gradient dominates, the PSF's contribution is less critical, allowing for sparser sampling.
Gradient Reuse and Scaling
In iterations where the PSF is not explicitly calculated, vSAM reuses the PSF from the most recent sampled iteration. To account for the diminishing relevance of stale gradient information, the reused PSF is scaled by a decay factor ($\gamma$). This ensures that the optimization trajectory remains accurate even with reduced sampling.
Experimental Results
We evaluated vSAM on CIFAR-10 and CIFAR-100 datasets using ResNet-18, WideResNet-28-10, and PyramidNet-110 architectures.
Accuracy and Throughput
vSAM consistently demonstrates a superior trade-off between model performance and training speed. On CIFAR-100 with WideResNet-28-10, vSAM achieved 84.64% accuracy, slightly exceeding vanilla SAM (84.45%) while increasing throughput from 343 to 470 images per second.
Comparison with Efficient Variants
Compared to other efficient SAM methods like LookSAM and ESAM, vSAM maintains a higher accuracy profile while offering comparable or better acceleration. The dynamic nature of vSAM's sampling allows it to adapt to different phases of training, unlike the uniform sampling used in LookSAM.
Conclusion
vSAM provides a robust and efficient alternative to vanilla SAM by leveraging the observation that second-order sharpness information does not need to be updated at every step. By using adaptive sampling based on gradient variation and norm ratios, vSAM achieves a ~40% speedup with no sacrifice in generalization. Future work will focus on scaling this approach to larger datasets like ImageNet and exploring its theoretical convergence properties in more detail.
Summary updated