TL;DR
Sharpness-Aware Minimization (SAM) significantly improves model generalization by finding flat loss minima, but it doubles computational costs by requiring two forward/backward passes per iteration. This paper introduces Sparse-Layer SAM (SL-SAM), which frames layer selection as a multi-armed bandit problem to dynamically activate and update only a fraction of the model's layers. SL-SAM reduces active parameters in backpropagation to as low as 21%, cutting training time by up to 25.8% while maintaining or even exceeding vanilla SAM's performance.
What Problem Does This Paper Address?
In deep learning, models trained with standard optimizers often land in "sharp" local minima, making them prone to overfitting and poor generalization under distribution shifts. Sharpness-Aware Minimization (SAM) solves this by seeking out "flat" minima. It does this via a two-step dance: first, it applies an adversarial perturbation to the parameters (gradient ascent), and then it calculates the gradient at this perturbed point to update the model (gradient descent).
The catch? This two-step process requires two full forward and backward passes, effectively doubling the training time. While previous works have tried to make SAM more efficient by reducing the frequency of the perturbation step or randomly dropping parameters, they still typically compute full-dimensional gradients or introduce extra overhead. The challenge addressed here is clear: Can we achieve the generalization benefits of SAM without the prohibitive 2x computational bottleneck?
Methods
The authors propose Sparse-Layer SAM (SL-SAM), which introduces layer-wise sparsity to both the perturbation and update steps of SAM.
Instead of calculating gradients for every layer in the network, SL-SAM freezes a large portion of the layers during each iteration, skipping their gradient computations entirely. The core innovation lies in how these active layers are selected:
- Gradient Norm as a Proxy: The authors observe that layers with larger gradient norms reside in sharper loss regions (making them critical for SAM's perturbation) and are the most influential in driving optimization (making them critical for the update step).
- Multi-Armed Bandit Framework: A purely greedy strategy that only selects the top-$k$ layers with the largest gradient norms fails because it gets trapped in a subset of layers and ignores temporarily dormant ones. To balance exploration and exploitation, SL-SAM treats layer selection as a multi-armed bandit problem using an EXP3-based adaptive sampling algorithm.
- Two-Sided Sparsity: Unlike prior methods that only sparsify the perturbation step, SL-SAM maintains layer sparsity across both the gradient ascent and descent steps.
The workflow is beautifully adaptive: at each step, layers are sampled based on a probability distribution, gradients are computed only for those active layers, and the sampling probabilities are updated using the resulting gradient norms as a reward signal.
The authors also demonstrate that this strategy can be coupled with single-step SAM variants, resulting in an even faster algorithm called SL-$S^2$-SAM.
Datasets
The authors evaluated SL-SAM across three distinct scales of models and tasks:
- Vision: Fine-tuning a DeiT-Small model on CIFAR-10 and CIFAR-100.
- Moderate Language Modeling: Fine-tuning a RoBERTa model on the GLUE benchmark (including CoLA, STS-B, MRPC, RTE, SST2, MNLI, QNLI, and QQP).
- Large Language Modeling (LLM): Fine-tuning a Llama-3.2-3B-Instruct model on the Open-Platypus reasoning dataset, evaluated across downstream benchmarks including MMLU, RTE, Hellaswag, BoolQ, OpenBookQA, and ARC-Challenge.
Key Insights and Ideas
- The Greedy Trap: A naive greedy approach ("Top-SL-SAM") completely fails to converge. In an ablation study on DeiT-Small, the authors found that 137 out of 200 layers were never selected during an entire epoch because of mini-batch stochasticity. This highlights why the multi-armed bandit's exploration mechanism is mathematically essential for convergence.
- Unified Importance Metric: It is highly convenient that the layer-wise gradient norm serves as an excellent proxy for both finding where the loss landscape is sharp (perturbation) and knowing where the model needs to learn the most (updating). This allows a single bandit framework to optimize both steps simultaneously.
- Layer-wise vs. Parameter-wise Sparsity: Instead of choosing random individual weights to drop (which doesn't inherently speed up hardware matrix multiplications), dropping entire layers allows the framework to completely bypass backward passes for those blocks, translating directly into hardware-level wall-clock time and memory savings.
Key Results
SL-SAM delivers an exceptional trade-off between accuracy and computational efficiency across all benchmarks:
- Parameter Reduction: SL-SAM only activates 47% of parameters in the vision task, 22% in the moderate language task, and 21% in the LLM task per gradient pass, compared to 100% for vanilla SAM.
- Wall-Clock Time & Memory Savings: On the RoBERTa MNLI task, SL-SAM reduced peak GPU memory usage by 19.99% and epoch time by 25.85% compared to AdaSAM (vanilla SAM with AdamW). For LLM fine-tuning (Llama-3B), it cut training time by 20.53% and memory by 7.61%.
- Downstream Performance: Despite the massive reduction in computation, SL-SAM achieved performance comparable to vanilla SAM and outperformed other efficient SAM variants (like ESAM and RST). Notably, it secured the #1 average score rank across downstream tasks in the LLM fine-tuning experiments.
Limitations and Future Work
When extending the technique to single-step SAM (SL-$S^2$-SAM), the authors noticed a slight overall performance disadvantage. They attribute this to gradient latency: because layers are sampled sparsely, the historical gradients used to estimate the perturbation direction can become stale for seldom-sampled layers. This introduces a directional bias compared to standard SAM.
The authors note that future work will focus on correcting this perturbation direction to close the performance gap in single-step sparse training.
Summary updated