TL;DR
Sharpness-Aware Minimization (SAM) is a powerful technique for improving neural network generalization by seeking "flat" minima, but it effectively doubles training time. This paper introduces Efficient SAM (ESAM), which reduces this computational overhead from 100% to roughly 40% while maintaining or even exceeding the accuracy of the original SAM algorithm.
The "Efficiency Tax" of Flat Minima
In deep learning, models with millions of parameters often achieve zero training error but can fail to generalize to new, unseen data. Recent research suggests that the "geometry" of the loss landscape is a critical factor: models that settle into flat minima (where the loss doesn't change much if you perturb the weights) generalize better than those trapped in sharp minima.
SAM (Sharpness-Aware Minimization) was proposed to actively find these flat regions by solving a minimax problem. It looks for a nearby weight perturbation that maximizes loss (measuring the "sharpness") and then updates the weights to minimize this worst-case loss. However, this process requires two forward and two backward passes per training step—effectively doubling the computational cost compared to standard Stochastic Gradient Descent (SGD). This "efficiency tax" makes SAM difficult to scale to massive datasets or production environments.
Introducing ESAM: Two Strategies for Efficiency
To slash the cost of SAM without losing its generalization benefits, the authors propose two novel strategies that form the core of ESAM:
1. Stochastic Weight Perturbation (SWP)
Instead of calculating the gradient for every single weight to determine the worst-case perturbation, SWP randomly selects a subset of weights (with probability $\beta$) to perturb. By appropriately scaling the resulting perturbation, the authors prove that the expected perturbation remains identical to the original SAM. This significantly reduces the workload of the first backward pass.
Interestingly, the authors found a "linearity bonus" with SWP: it actually improves the linearity of the loss landscape. Because SAM relies on a first-order Taylor expansion to approximate sharpness, a more linear landscape makes this approximation more accurate, which helps explain why ESAM can sometimes outperform standard SAM.
2. Sharpness-Sensitive Data Selection (SDS)
Not all data points contribute equally to the "sharpness" of a minimum. SDS identifies a subset of the training batch (defined by a ratio $\gamma$) where the loss increases the most after the initial perturbation. The final weight update is then calculated using only this sharpness-sensitive subset. This drastically reduces the computation required for the second forward and backward passes. The authors theoretically justify this by showing that the loss calculated on this selected subset serves as an upper bound for the loss of the entire batch.
Key Results and Performance
The authors evaluated ESAM across several standard and large-scale computer vision benchmarks, including CIFAR-10, CIFAR-100, and ImageNet (using architectures like ResNet, WideResNet, PyramidNet, and Vision Transformers).
- Significant Speedups: ESAM reduces the extra computational overhead of SAM from 100% down to approximately 40% relative to base optimizers like SGD. For example, on ImageNet with ResNet-50, ESAM processed 846 images/sec compared to SAM's 654 images/sec.
- Accuracy Gains: Despite being faster, ESAM frequently achieved higher test accuracy than both SGD and SAM. On CIFAR-100 (PyramidNet), ESAM reached 85.56% accuracy, surpassing SAM (84.46%) and SGD (81.89%). On ImageNet (ResNet-50), ESAM achieved 77.05%, beating SAM's 76.70%.
The ablation studies (shown above) demonstrate that you do not need to use all weights or all data points in every step of the sharpness-aware optimization to reap the generalization rewards. The individual components (ESAM-SWP and ESAM-SDS) both push the Pareto front outward, and their combination (ESAM) offers the best balance of high accuracy and lower elapsed time per epoch.
Limitations and Future Directions
While a 40% overhead is a major improvement over 100%, ESAM is still slower than standard SGD or Adam. Additionally, ESAM introduces two new hyperparameters ($\beta$ for weight selection and $\gamma$ for data selection). While the authors found $\beta \in \{0.5, 0.6\}$ and $\gamma=0.5$ to be generally robust across their tests, some tuning may be required when adapting the optimizer to entirely new architectures.
Future work may explore ways to combine the two steps of SAM into a single step by utilizing gradient information from previous iterations, potentially reducing the overhead to near zero.
Summary updated