SPAM: Spike-Aware Adam with Momentum Reset for Stable LLM Training

Tianjin Huang, Ziquan Zhu, Gaojie Jin, Lu Liu, Zhangyang Wang, Shiwei Liu

Abstract

Large Language Models (LLMs) have demonstrated exceptional performance across diverse tasks, yet their training remains highly resource-intensive and susceptible to critical challenges such as training instability. A predominant source of this instability stems from gradient and loss spikes, which disrupt the learning process, often leading to costly interventions like checkpoint recovery and experiment restarts. This paper presents a comprehensive investigation into gradient spikes observed during LLM training, revealing their prevalence across multiple architectures and datasets. Our analysis shows that these spikes can be up to $1000\times$ larger than typical gradients, substantially deteriorating model performance. To address this issue, we propose Spike-Aware Adam with Momentum Reset (SPAM), a novel optimizer designed to counteract gradient spikes through momentum reset and spike-aware gradient clipping. Extensive experiments demonstrate that SPAM consistently surpasses Adam and its variants across various tasks, including LLM pre-training from 60M to 1B and memory-efficient fine-tuning.

Introduction

Training Large Language Models (LLMs) is a notoriously finicky process. Even with massive compute budgets, researchers often find their training runs derailed by sudden "loss spikes"—moments where the model's error shoots up, potentially ruining weeks of work. Traditionally, the industry standard fix has been manual: researchers monitor logs and manually restart training from an earlier checkpoint if a spike occurs. This process is both expensive and exhausting. This paper introduces SPAM (Spike-Aware Adam with Momentum Reset), a new optimizer designed to make LLM training more stable, efficient, and resilient to these sudden shocks.

The Problem: Gradient Spikes and Momentum Poisoning

The "Edge of Stability" in LLM training is a precarious place. During training, gradients occasionally explode, reaching magnitudes up to 1000x larger than normal. These "gradient spikes" are not just transient errors; they have a lasting impact due to the momentum mechanisms in popular optimizers like Adam.

Adam keeps a running average of past gradients (the "first moment") and their squared values (the "second moment"). When a massive spike occurs, it "poisons" these averages. Because the second moment typically uses a very slow decay rate (0.999), the ghost of a single bad gradient can haunt the optimizer for hundreds of steps, leading to prolonged instability or total divergence.

Figure 4: Visualization of the correlation between gradient spikes and training loss spikes across LLaMA models of various sizes. The red circles highlight how sudden gradient bursts directly trigger instability in the loss curve.

Methods: The SPAM Optimizer

To address these challenges, SPAM integrates two primary mechanisms into the Adam framework:

  1. Momentum Reset: Every few hundred steps, the optimizer wipes its memory of the first and second moments. This "reboot" clears out any poisoned state. To prevent the reset itself from shocking the system, a short cosine warmup period is implemented after each reboot.
  2. Spike-Aware Clipping: Instead of traditional global norm clipping, SPAM identifies specific "spiked" parameters on-the-fly using a Gradient Spike Score (GSS). If a gradient is too large relative to its historical average, it is scaled down, preserving its directional information rather than simply zeroing it out.
  3. Sparse Momentum: By resetting momentum periodically, the authors realized they didn't need to track every parameter all the time. SPAM introduces a version that only updates a random subset of momentum terms, significantly reducing the memory footprint—a critical feature for training massive models on limited hardware.

Key Results and Insights

Experimental evaluations across LLaMA, Pythia, and OPT architectures show that spikes are universal, occurring regardless of dataset quality or architectural tricks like LayerNorm scaling.

In pre-training LLaMA models (from 60M to 1B parameters), SPAM consistently achieved lower perplexity than Adam, Adafactor, and Adam-mini. For a 60M model, SPAM reached a perplexity of 30.46 compared to Adam's 34.09.

Figure 1: Performance comparison showing perplexity versus update steps for LLaMA models. SPAM (red dashed line) consistently achieves superior convergence and lower final perplexity compared to standard Adam and other baseline optimizers.

Furthermore, SPAM demonstrated exceptional memory efficiency. When operating under strict memory constraints, it outperformed GaLore, a leading memory-efficient optimizer. In fine-tuning LLaMA2-7B, SPAM achieved an average score of 66.7 across downstream tasks, beating Adam's 63.4. Importantly, the computational overhead is negligible; the wall-clock time per iteration remains nearly identical to standard Adam.

Conclusion

SPAM offers a robust solution to the pervasive problem of training instability in LLMs. By combining periodic momentum resets with intelligent, spike-aware gradient clipping, it provides a more stable and memory-efficient path to scaling billion-parameter models. Future work will focus on bridging the theoretical gap for non-convex optimization and investigating the ultimate root causes of these gradient spikes.

Summary updated

Abstract

Large Language Models (LLMs) have demonstrated exceptional performance across diverse tasks, yet their training remains highly resource-intensive and susceptible to critical challenges such as training instability. A predominant source of this instability stems from gradient and loss spikes, which disrupt the learning process, often leading to costly interventions like checkpoint recovery and experiment restarts, further amplifying inefficiencies. This paper presents a comprehensive investigation into gradient spikes observed during LLM training, revealing their prevalence across multiple architectures and datasets. Our analysis shows that these spikes can be up to $1000\times$ larger than typical gradients, substantially deteriorating model performance. To address this issue, we propose Spike-Aware Adam with Momentum Reset SPAM, a novel optimizer designed to counteract gradient spikes through momentum reset and spike-aware gradient clipping. Extensive experiments, including both pre-training and fine-tuning, demonstrate that SPAM consistently surpasses Adam and its variants across various tasks, including (1) LLM pre-training from 60M to 1B, (2) 4-bit LLM pre-training,(3) reinforcement learning, and (4) Time Series Forecasting. Additionally, SPAM facilitates memory-efficient training by enabling sparse momentum, where only a subset of momentum terms are maintained and updated. When operating under memory constraints, SPAM outperforms state-of-the-art memory-efficient optimizers such as GaLore and Adam-Mini. Our work underscores the importance of mitigating gradient spikes in LLM training and introduces an effective optimization strategy that enhances both training stability and resource efficiency at scale. Code is available at https://github.com/TianjinYellow/SPAM-Optimizer.git
BibTeX
@inproceedings{huang2025spam,
  author = {Tianjin Huang and Ziquan Zhu and Gaojie Jin and Lu Liu and Zhangyang Wang and Shiwei Liu},
  title = {{SPAM: Spike-Aware Adam with Momentum Reset for Stable LLM Training}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=L9eBxTCpQG},
}
Figure