Lookbehind-SAM: k steps back, 1 step forward

Goncalo Mordido, Pranshu Malviya, Aristide Baratin, Sarath Chandar

TL;DR

Lookbehind-SAM is a novel optimization algorithm that improves upon Sharpness-Aware Minimization (SAM). By utilizing multiple ascent steps to find more challenging "worst-case" perturbations and maintaining stability through weight interpolation, it achieves a superior trade-off between low loss and low sharpness. This results in better generalization, higher robustness to noisy weights, and reduced catastrophic forgetting in lifelong learning scenarios.

What Problem Does This Paper Address?

Deep learning models often struggle with generalization—performing exceptionally well on training data but failing on unseen data. Research has long linked good generalization to "flat minima," which are regions in the loss landscape where small changes to model weights don't cause the loss to spike.

Sharpness-Aware Minimization (SAM) was designed to find these flat regions by solving a minimax problem: it searches for a nearby "worst-case" perturbation (the maximization step) and then updates the model to minimize the loss at that perturbed point (the minimization step).

However, SAM suffers from a "Goldilocks" problem. If you search too narrowly (a small neighborhood), you fail to find the flattest regions. If you search too broadly or use multiple steps to find a worse perturbation (Multistep-SAM), the gradients become unstable. The model often converges to regions that are flat but have unacceptably high loss.

Training loss vs. sharpness trade-off for different SAM variants.

The authors aim to break this trade-off, allowing for a deeper search for sharpness without sacrificing training stability or accuracy, ultimately pushing the Pareto front of training loss versus sharpness closer to the ideal bottom-left corner.

Methods

The authors introduce Lookbehind-SAM, drawing inspiration from the Lookahead optimizer. The core logic involves two main components:

  1. "Looking Behind" (Multiple Ascent Steps): Instead of taking a single step to find a perturbation, Lookbehind takes $k$ ascent steps. This allows the algorithm to climb higher up the loss landscape to find a more informative "worst-case" scenario.
  2. Linear Interpolation (The Stabilizer): To handle the gradient instability caused by these $k$ steps, the algorithm maintains "slow weights" and "fast weights." After the fast weights undergo $k$ steps of ascent and descent, the slow weights are updated toward the fast weights using linear interpolation (controlled by a step size $\alpha$).
Comparison of Multistep-SAM and the proposed Lookbehind-SAM, highlighting the linear interpolation step.

Key Innovations:

  • Adaptive $\alpha$: To avoid manually tuning the interpolation step size, the authors propose an analytical way to calculate $\alpha$ based on the alignment of gradients during the ascent steps. If gradients are well-aligned, $\alpha$ is higher; if they are chaotic, $\alpha$ is lower to preserve stability.
  • Switching Minibatches: For computationally expensive models like Transformers, they demonstrate that you can sample a new minibatch at each inner step to maintain efficiency without losing the benefits of the "Lookbehind" mechanism.

Datasets

The researchers evaluated Lookbehind-SAM across a wide range of standard benchmarks:

  • Image Classification: CIFAR-10, CIFAR-100, and ImageNet.
  • Architectures: ResNet-18, ResNet-34, ResNet-50, Wide ResNet (WRN-28-2, WRN-28-10), and ViT-Base.
  • Machine Translation: IWSLT’14 (DE-EN) using a 12-layer Transformer.
  • Lifelong Learning: Split-CIFAR100 and Split-TinyImageNet (benchmarks designed to test how well a model learns a sequence of tasks without forgetting).

Key Insights and Ideas

  • Stability is the Bottleneck: The failure of previous multi-step SAM variants wasn't because looking deeper into the neighborhood was inherently bad, but because the resulting updates were too noisy. Interpolation acts as a powerful variance reduction technique.
  • Early Guidance: Switching experiments showed that Lookbehind’s benefits are mostly achieved early in training. It guides the model into a different, better "basin" of the loss landscape that standard SAM cannot reach.
  • A Universal Wrapper: Lookbehind isn't just for vanilla SAM; it can be plugged into ASAM (Adaptive SAM) and even meta-learning frameworks like MAML, showing consistent improvements across the board.
  • Robustness to Weight Noise: Models trained with Lookbehind are significantly more resilient to "noisy weights"—a common issue when deploying models on specialized, energy-efficient hardware (like memristor-based accelerators).

Key Results

  • Generalization: Lookbehind-SAM/ASAM consistently outperformed all baselines. On CIFAR-100 with a WRN-28-10, Lookbehind-ASAM reached 82.16% accuracy, compared to 81.67% for standard ASAM.
  • ImageNet: It was the only multi-step variant tested that successfully outperformed vanilla SAM/ASAM on the large-scale ImageNet dataset.
  • Lifelong Learning: In "Split-CIFAR100," Lookbehind-SAM achieved an average accuracy of 59.93% and reduced forgetting to 14.10%, significantly better than vanilla SAM (57.81% accuracy / 23.27% forgetting).
  • Efficiency: Lookbehind-SAM reached the same performance levels as Multistep-SAM while using only about 50% of the gradient computations.

Limitations and Future Work

  • Computational Overhead: Like all multi-step methods, Lookbehind-SAM increases training time per epoch by a factor of $k$. While the "Switching Minibatch" approach helps, it still requires more compute than a single-step optimizer.
  • Hyperparameter Tuning: Although the adaptive $\alpha$ helps, the user still needs to choose the number of inner steps $k$.
  • Future Directions: The authors suggest combining Lookbehind with "efficient SAM" variants (which aim to reduce the number of forward/backward passes) to make the method more viable for massive-scale model training.

Summary updated

BibTeX
@inproceedings{mordido2024lookbehind,
  author = {Goncalo Mordido and Pranshu Malviya and Aristide Baratin and Sarath Chandar},
  title = {{Lookbehind-SAM: k steps back, 1 step forward}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=vCN5lwcWWE},
}
Figure