NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

GA-SAM: Gradient-Strength based Adaptive Sharpness-Aware Minimization for Improved Generalization

Zhiyuan Zhang, Ruixuan Luo, Qi Su, Xu Sun

Abstract

Sharpness-Aware Minimization (SAM) has emerged as a powerful technique for improving model generalization by seeking "flat" regions in the loss landscape. However, its application to Natural Language Processing (NLP) has been limited by the volatile gradient dynamics inherent in language tasks. We present GA-SAM (Gradient-Strength based Adaptive SAM), an optimization algorithm that adaptively scales perturbations based on gradient intensity. By proving that distribution shifts can be modeled as virtual parameter corruptions, we justify an inverse relationship between gradient strength and perturbation scale. Empirical results across text classification, language modeling, and machine translation demonstrate that GA-SAM consistently outperforms standard SAM and its variants, particularly in stabilizing training for recurrent and transformer-based architectures.

Introduction

A central goal in deep learning is achieving robust generalization to unseen data. Empirical evidence suggests that "flat minima"—regions where the loss function is relatively insensitive to small parameter perturbations—generalize better than "sharp minima." Sharpness-Aware Minimization (SAM) explicitly targets these regions by minimizing the maximum loss within a neighborhood of the current parameters. While highly effective in computer vision, SAM often falters in NLP. Language models frequently exhibit significant gradient heterogeneity across different layers and training phases. Standard SAM's fixed perturbation radius is often too rigid, potentially destabilizing training in high-gradient layers or failing to find flat regions in low-gradient ones.

Methodology: GA-SAM

GA-SAM introduces a principled approach to adaptive perturbation scaling through three key contributions:

1. Theoretical Foundation: Distribution Shift as Parameter Corruption

The authors provide a theoretical framework showing that the distribution shift between training and test data can be mathematically treated as a virtual parameter corruption. This connection reinforces the intuition that seeking robustness to parameter noise (flatness) directly improves generalization to shifted data distributions.

2. Gradient-Strength Adaptation

A core insight of GA-SAM is the inverse relationship between ideal perturbation strength and gradient intensity. In regions with large gradients, the loss landscape is naturally more sensitive; here, even a small perturbation is sufficient to probe local sharpness. Conversely, in low-gradient regions, larger perturbations are needed. GA-SAM adaptively adjusts the perturbation scale for different parameter groups (e.g., layers) based on their current gradient norms.

3. Multi-step Exploration

To more accurately navigate the local loss geometry, GA-SAM employs a multi-step perturbation approach. This iterative process, inspired by adversarial training techniques, allows for a more precise identification of the "sharpest" direction within the adaptive neighborhood.

Experimental Results

The efficacy of GA-SAM was evaluated across several NLP tasks, including text classification (IMDb), language modeling (PTB), and neural machine translation (IWSLT 15/14).

Performance Gains

GA-SAM consistently outperformed the baseline and standard SAM. On the IMDb dataset, it achieved an accuracy of 86.11%, a +1.69% improvement over the baseline. Most notably, on the PTB language modeling task, standard SAM actually degraded performance (increasing perplexity by +2.96), whereas GA-SAM successfully reduced perplexity by -2.18.

Table 1: Performance comparison of GA-SAM against baselines and other SAM variants on IMDB and PTB-LM datasets.

Verification of Flatness

To confirm that GA-SAM achieves its goal of finding flatter minima, the researchers performed a Hessian analysis. The eigenvalue spectrum of the Hessian matrix at the converged minima shows that GA-SAM leads to significantly lower top eigenvalues compared to standard training.

Figure 1: Eigenvalue spectrum of the Hessian at the final model parameters. GA-SAM finds minima with lower eigenvalues, indicating a flatter loss landscape.

Discussion and Key Insights

  • Layer-wise Heterogeneity: In Transformer models, higher layers often exhibit much larger gradients than lower layers. GA-SAM's adaptive mechanism naturally handles this imbalance, which is a primary reason for its success in translation tasks where standard SAM often struggles.
  • Stabilizing LSTMs: Recurrent architectures are notoriously sensitive to training dynamics. GA-SAM is one of the first sharpness-aware methods to provide consistent gains for LSTMs by preventing the destabilizing effects of over-perturbation in high-gradient regimes.

Conclusion and Future Work

GA-SAM addresses a critical gap in sharpness-aware optimization for NLP by introducing gradient-based adaptation. While the method significantly improves generalization and stability, it still relies on a global hyperparameter $\epsilon$ to control the overall perturbation scale. Future research will focus on automating the scheduling of this parameter to further reduce the computational overhead of hyperparameter tuning.

Summary updated

BibTeX
@inproceedings{zhang2022ga,
  author = {Zhiyuan Zhang and Ruixuan Luo and Qi Su and Xu Sun},
  title = {{GA-SAM: Gradient-Strength based Adaptive Sharpness-Aware Minimization for Improved Generalization}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=iuFrLqZD6Q},
}
Figure