Sharpness-Aware Minimization (SAM) has emerged as a highly effective alternative to standard Stochastic Gradient Descent (SGD) for training deep neural networks. While the traditional consensus suggests that SAM's success stems from its ability to find "flatter" minima that generalize better, recent studies have shown conflicting evidence regarding the relationship between flatness and generalization. This paper offers a fresh perspective, arguing that SAM's true power lies in an orthogonal effect: it acts as a feature-balancing machine that overcomes "simplicity bias" to learn a more diverse, high-quality set of representations.
The Problem: Simplicity Bias and OOD Generalization
Standard deep learning optimizers like SGD suffer from simplicity bias. They tend to latch onto the simplest, most easily accessible features that can minimize the training loss for a given task. For example, when trained to identify a "waterbird," SGD might rely entirely on the blue water background rather than the complex features of the bird itself. Once the training loss is minimized using these easy features, SGD effectively stops learning, leaving more complex or redundant features untapped.
This simplicity bias is a major hurdle for Out-of-Distribution (OOD) generalization. If the "easy" feature is merely a spurious correlation (like the background), the model will fail catastrophically when that correlation breaks in real-world, out-of-distribution data.
How SAM Balances Learning
To understand how SAM circumvents this issue, the authors analyze its gradient update step. Unlike SGD, which calculates a gradient exactly at the current model weights ($w$), SAM calculates its gradient at a "phantom" point ($\tilde{w}$) located a small distance away in the direction of steepest ascent. By calculating gradients at this perturbed point, SAM essentially "looks ahead." At the perturbed point, the easy features provide less useful signal, forcing the gradient to be dominated by the features the model has not yet mastered.
The paper identifies two core mechanisms triggered by this phantom step:
- Importance Weighting Effect: SAM implicitly re-weights training examples. It identifies "hard" examples—those where complex features are necessary because simple ones are insufficient—and grants them more influence in the gradient update.
- Learning Rate Scaling Effect: SAM adaptively scales the learning rates of individual features. It effectively "slows down" the learning of features the model has already mastered, giving the network the "room" and incentive to learn the remaining, harder features.
To isolate and study these effects mathematically and visually, the authors introduce LSAM (Layer-wise SAM), a simplified version where only the last layer is perturbed.
Key Insights: Visualizing Balanced Learning
Remarkably, while SAM was not explicitly designed to fight simplicity bias, it does so more effectively than many algorithms built specifically for that purpose (such as GroupDRO), and it does so implicitly without requiring extra metadata or group labels.
The authors demonstrate this "balanced learning" effect clearly using a toy spiral experiment. When presented with data containing both an easy linear feature and a complex spiral feature, SGD completely ignores the complex spiral once it learns the linear boundary. In contrast, LSAM captures both features perfectly, demonstrating its ability to balance the learning of diverse representations.
Empirical Results on Real Datasets
The authors validated their theory across a variety of datasets known for having redundant or spurious features, including CelebA, Waterbirds, CIFAR-MNIST, and DomainBed.
- Improved Feature Quality: Using "linear probes" to measure how much information is stored in the model's representations, the authors found that SAM consistently reduces the error on "hard" features. For example, on the CelebA dataset (where "hair color" is an easy feature and "gender" is a harder, correlated feature), the probing error for the hard feature dropped significantly from 20.9% (SGD) to 15.1% (SAM).
- OOD Performance: On the DomainBed benchmark, a standard for domain generalization, SAM outperformed SGD across almost every domain transfer task. For instance, on the PACS dataset, SAM improved accuracy from 0.910 to 0.914 on the Art domain and from 0.893 to 0.908 on the Sketch domain.
- Robustness: The authors also demonstrated that SAM’s feature-balancing effect remains robust even when the training data is noisy or when batch sizes vary significantly.
Limitations and Future Directions
While the "Importance Weighting" effect was successfully verified on real data, the "Learning Rate Scaling" effect is more challenging to measure in deep, non-linear networks without a perfectly disentangled architecture. Furthermore, the mathematical analysis relies on a first-order Taylor expansion and the simplified LSAM model; the full dynamics of SAM in very deep networks are likely even more complex.
Ultimately, understanding these two balancing effects opens exciting avenues for future work. It suggests that researchers could design new, more efficient optimizers that target feature diversity directly, potentially achieving SAM's robust OOD generalization without the computational overhead of its double-gradient requirement.
Summary updated