Abstract: Recently, Sharpness-Aware Minimization (SAM), which connects the geometry of the loss landscape and generalization, has demonstrated a significant performance boost on training large-scale models such as vision transformers. However, the update rule of SAM requires two sequential (non-parallelizable) gradient computations at each step, which can double the computational overhead. In this paper, we propose a novel algorithm—LookSAM—that only periodically calculates the inner gradient ascent to significantly reduce the additional training cost of SAM. The empirical results illustrate that LookSAM achieves similar accuracy gains to SAM while being tremendously faster—it enjoys comparable computational complexity with first-order optimizers such as SGD or Adam. To further evaluate the performance and scalability of LookSAM, we incorporate a layer-wise modification and perform experiments in the large-batch training scenario, which is more prone to converge to sharp local minima. Equipped with the proposed algorithms, we are the first to successfully scale up the batch size when training Vision Transformers (ViTs). With a 64k batch size, we are able to train ViTs from scratch in minutes while maintaining competitive performance.
Introduction
In deep learning, the geometry of the loss landscape is a critical factor in model generalization. Models that settle into "sharp" local minima—where small weight perturbations lead to significant error spikes—often generalize poorly. Conversely, "flat" minima are more robust and typically yield better performance on unseen data. Sharpness-Aware Minimization (SAM) was developed to explicitly seek these flat regions by performing a "look-ahead" step to find a nearby point with higher loss and updating weights based on the gradient at that perturbed location. While effective, SAM's requirement for two sequential gradient computations per update makes it twice as slow as standard optimizers like SGD or Adam, limiting its scalability for large-batch training.
Methods
The authors introduce LookSAM, an algorithm designed to provide the benefits of SAM without the 100% computational overhead. The core of the approach lies in Gradient Decomposition. The SAM update direction can be split into two distinct components: $g_h$, which is parallel to the standard SGD gradient, and $g_v$, an orthogonal component that specifically biases the model toward flat regions.
Through empirical analysis, the researchers discovered that while the standard gradient fluctuates, the flatness-seeking direction ($g_v$) changes very slowly across iterations. LookSAM leverages this Directional Reuse by only calculating the full SAM update every $k$ steps (e.g., $k=5$ or $10$). In intermediate steps, it uses the current SGD gradient but adds the previously calculated $g_v$, scaled appropriately. This reduces the per-step cost to nearly that of standard SGD. To handle the instabilities of massive batch sizes (up to 64k), the authors also incorporated Look-LayerSAM, a layer-wise scaling rule that ensures weight perturbations are proportional to the weights in each specific layer.
Key Insights
- The Stability of Flatness: The most surprising finding is that the direction required to find a "flat" region is remarkably stable compared to the standard gradient. Reusing this direction allows for significant speedups without losing the generalization benefits of SAM.
- The Necessity of Carry-Over: Naive periodicity—simply running SAM every $k$ steps and standard SGD in between—fails to maintain accuracy. The flatness-seeking component must be "carried over" into every step to be effective.
- Scaling Vision Transformers: Large-batch training for ViTs is notoriously difficult due to convergence to sharp minima. By combining LookSAM with layer-wise scaling, the authors successfully scaled batch sizes to 64,000, breaking previous performance barriers.
Key Results
LookSAM demonstrates that it is possible to achieve SAM-level accuracy with the speed of standard first-order optimizers. On ImageNet-1k, LookSAM-5 achieved a top-1 accuracy of 79.8% for ViT-B/16—matching vanilla SAM—while significantly increasing throughput.
Using a 64k batch size, the authors trained a ViT-B/16 from scratch in just 42 minutes (0.7 hours), representing an 8x speedup over standard training settings. The method proved generalizable across architectures (ResNets and ViTs) and base optimizers (SGD, AdamW, and LAMB).
Conclusion
LookSAM addresses the primary bottleneck of Sharpness-Aware Minimization by reusing the stable flatness-seeking gradient component. This approach enables the training of high-performance models like Vision Transformers at unprecedented scales and speeds. Future work may explore applying LookSAM to other domains, such as Large Language Models (LLMs), where training efficiency is paramount.
Summary updated