Abstract
Sharpness-Aware Minimization (SAM) has become a standard technique for improving generalization in computer vision, particularly for Vision Transformers (ViTs). However, its application to Large Language Models (LLMs) has historically been unsuccessful, often performing worse than standard AdamW. This research identifies "spurious sharpness minimization" as the primary cause of this failure. By decomposing the SAM gradient, the authors demonstrate that in NLP, the optimizer frequently takes a "shortcut" to reduce sharpness by manipulating logit statistics (the Logit Path) rather than smoothing the model's underlying function (the Functional Path). To address this, the paper introduces FUNCTIONAL-SAM and PRECONDITIONED SAM, which isolate meaningful curvature regularization and align perturbations with the geometry of adaptive optimizers. These methods enable SAM to achieve consistent generalization gains in LLMs across scales up to 1.2 billion parameters.
Introduction
In deep learning optimization, the geometry of the loss landscape is a critical predictor of generalization. "Flat" minima, where the loss changes slowly in response to parameter perturbations, are generally preferred over "sharp" minima. SAM was designed to explicitly seek these flat regions by minimizing the maximum loss within a local neighborhood of the current weights. While SAM is considered a "must-have" for state-of-the-art vision models, it has remained notoriously difficult to apply to the Transformer architectures used in Natural Language Processing (NLP).
This paper, a collaboration between Google DeepMind and ETH Zürich, investigates this discrepancy. The authors ask whether the loss landscape of an LLM is fundamentally different from that of a vision model, or if standard SAM is simply focusing on the wrong metrics of sharpness.
The Phenomenon of Spurious Sharpness
The researchers developed a diagnostic framework to decompose the SAM gradient into two distinct components:
- The Logit Path: Sharpness reduction achieved by altering the statistics of the model's outputs (logits).
- The Functional Path: Sharpness reduction achieved by smoothing the geometry of the neural network function itself (the Jacobian).
Their analysis reveals that in NLP, SAM is "distracted" by the logit path. The optimizer reduces sharpness by making the model's predictions more "one-hot" or overconfident. While this technically lowers the gradient norm and satisfies the SAM objective, it constitutes a form of "spurious" minimization that does not improve the model's actual reasoning capabilities or its ability to generalize to unseen data. In fact, the authors found that the logit and functional paths are often anti-aligned in LLMs; optimizing for one can actively degrade the other.
Proposed Methodology
To overcome the pitfalls of spurious sharpness, the authors propose two algorithmic refinements:
1. FUNCTIONAL-SAM
This variant explicitly discards the logit-perturbation term from the SAM objective. By isolating the functional geometry, the optimizer is forced to focus on smoothing the actual mapping from inputs to representations, preventing the model from taking the overconfidence shortcut.
2. PRECONDITIONED SAM
Standard SAM applies perturbations in a spherical neighborhood. However, LLMs are almost exclusively trained using adaptive optimizers like AdamW, which operate in a non-Euclidean geometry. The authors argue that SAM's perturbations should be "preconditioned" using the same second-moment statistics ($M^{-1}$) used by AdamW. This ensures that the perturbation is scaled appropriately for each parameter, aligning the sharpness search with the actual geometry the optimizer perceives.
Experimental Evaluation
The methods were evaluated using the C4 (Colossal Clean Crawled Corpus) dataset to pre-train decoder-only Transformers (Nanodo) ranging from 2 million to 1.2 billion parameters. For comparison, Vision Transformers were trained on ImageNet-1K, ImageNet-21K, and JFT.
Key Findings
- Performance Gains: PRECONDITIONED FUNCTIONAL-SAM consistently achieved the lowest evaluation loss across all model sizes. For a 1.2B parameter model, it reached an evaluation loss of 2.61, significantly outperforming the 2.63 achieved by AdamW.
- Efficiency and Scaling: The performance boost provided by these methods is roughly equivalent to increasing the model's parameter count by 25% or training for a significantly longer duration.
- Numerical Stability: Unlike standard SAM, which often suffers from numerical instabilities (NaNs) at the billion-parameter scale, the proposed preconditioned version is highly robust, allowing for stable training without the need for complex warm-up schedules for the perturbation radius ($\rho$).
- Model Robustness: Models trained with functional sharpness minimization showed improved resilience to weight pruning, confirming that the resulting minima are indeed fundamentally flatter and more robust than those found by AdamW.
Conclusion and Future Work
By identifying and avoiding spurious sharpness minimization, this work broadens the applicability of SAM to the domain of large-scale language modeling. The results suggest that curvature regularization is a universal benefit, provided the optimizer targets the functional geometry of the model rather than superficial logit statistics.
Despite these gains, the primary limitation remains computational overhead: these methods require two forward/backward passes per step, doubling the compute cost. Future research may focus on developing "one-pass" approximations of Functional-SAM or exploring whether applying perturbations to specific sub-layers (e.g., only attention blocks) can maintain these benefits at a lower cost.
Summary updated