Abstract
Sharpness-Aware Minimization (SAM) and adaptive sharpness-aware minimization (ASAM) aim to improve the model generalization. And in this project, we proposed three experiments to valid their generalization from the sharpness aware perspective. And our experiments show that sharpness aware-based optimization techniques could help to provide models with strong generalization ability. Our experiments also show that ASAM could improve the generalization performance on un-normalized data, but further research is needed to confirm this.
Introduction
In deep learning, a model can achieve near-zero error on training data but fail to perform on a test set, a phenomenon known as the generalization problem. Research has long observed a correlation between the geometry of the "loss landscape" and generalization: models that settle into "flat" minima tend to generalize better than those in "sharp" minima. While standard Stochastic Gradient Descent (SGD) naturally leans toward flatter regions, it often gets trapped in sharp valleys, particularly when using large batch sizes. This paper investigates whether explicitly optimizing for flatness via Sharpness-Aware Minimization (SAM) and its adaptive variant (ASAM) delivers superior generalization.
Methodology
The study evaluates three optimization strategies using a ResNet-18 architecture on the CIFAR-10 dataset:
- Vanilla SGD: The standard baseline.
- SAM: Instead of just following the gradient, SAM performs a "look-ahead" step to find the worst-case weight perturbation within a small neighborhood ($ε$-ball) and updates weights to minimize loss at that point, forcing the optimizer toward flat regions.
- ASAM: Improves on SAM by rescaling the neighborhood search area based on the magnitude of the parameters, making the optimization scale-invariant.
Results and Discussion
Overcoming the Large Batch Curse
A known challenge in deep learning is that large batch sizes often lead to poorer generalization because they tend to converge to sharper minima. Our results show that SAM effectively mitigates this issue. As seen in Figure 1, SAM maintains significantly higher test accuracy than SGD across various batch sizes. For instance, at a batch size of 128, SAM achieves approximately 71% accuracy, while SGD trails at roughly 64-65%.
The Generalization Gap: Flatness vs. Absolute Loss
One of the most significant findings is that lower training loss does not guarantee better performance. In our experiments, SAM and ASAM often exhibited higher training losses than vanilla SGD but achieved significantly higher test accuracy.
Comparing Figure 1 and Figure 2, the "bz_128 SGD" variant (brown line) reaches the lowest training loss but results in the poorest test performance. Conversely, SAM variants maintain higher training loss but superior generalization, confirming that the flatness of the minimum is a more reliable predictor of performance than the absolute value of the training loss.
Scale Invariance and ASAM
By removing Batch Normalization layers, we observed that parameters can vary wildly in scale. In these un-normalized environments, ASAM’s adaptive rescaling allowed it to find more stable solutions than standard SAM, achieving approximately 66.2% accuracy compared to SAM's 65.5%.
Conclusion and Future Work
Sharpness-aware optimization techniques like SAM and ASAM provide a robust path toward better model generalization. By prioritizing flat regions of the loss landscape, these methods overcome traditional optimization pitfalls like the large batch curse and scale sensitivity. However, SAM requires two gradient computations per step, making it roughly twice as slow as vanilla SGD. Future research should focus on reducing this computational overhead and testing these methods on more diverse architectures like Transformers and larger datasets like ImageNet.
Summary updated