The Stability-Efficiency Dilemma: Investigating Sequence Length Warmup for Training GPT Models

Conglong Li, Minjia Zhang, Yuxiong He · DOI

Abstract

Recent works have demonstrated great success in pre-training large-scale autoregressive language models on massive GPUs. To reduce the wall-clock training time, a common practice is to increase the batch size and learning rate. However, such practice is often brittle and leads to a so-called stability-efficiency dilemma: increasing the batch sizes and learning rates leads to better training efficiency but can also result in training instability, leading to poor generalization accuracy or failed runs. To better understand this phenomenon, we conduct an in-depth analysis on large-scale pre-training experiments replicating the GPT-2 model. We find that there is a strong correlation between training instability and extreme values of gradient variance, and that samples with long sequence lengths contribute to these extreme gradient variance values, especially at the beginning of the training, indicating that long sequence length can be a main source of training instability. Based on the analysis, we present a Sequence Length Warmup method that aims to solve the training stability-efficiency dilemma. Experiments replicating GPT-2 models show that our approach enables stable training with 8x larger batch size and 4x larger learning rate, whereas the baseline approach struggles with training instability. To achieve the same or better zero-shot evaluation results, our method reduces the required number of training tokens and wall clock time by up to 2.2x and 3.7x, respectively. Experiments replicating GPT-3 model (125M) show that our approach enables stable training with 8x larger batch size and 40x larger learning rate, and retains 99% of the zero-shot accuracy on 11 tasks using 10x less data and 17x less time compared to the original GPT-3 training recipe, while the baseline diverges under the same settings and only retain 95% of accuracy under lower learning rate.

Introduction

Pre-training massive autoregressive models like GPT-3 is a monumental computational task, often requiring thousands of GPUs and weeks of execution time. To improve throughput and reduce wall-clock time, researchers typically scale up batch sizes and learning rates. However, this scaling is frequently hindered by the "stability-efficiency dilemma": aggressive hyperparameter settings often trigger catastrophic training instabilities, such as loss spikes or total model divergence. Conversely, conservative settings ensure stability but result in prohibitively slow training cycles.

This work investigates the root causes of these instabilities and introduces Sequence Length Warmup (SLW), a simple yet powerful technique to bypass the dilemma, enabling significantly faster training without sacrificing stability.

Identifying the Source of Instability

Through an extensive analysis of GPT-2 training runs, we identified a critical correlation between training instability and extreme outliers in gradient variance. Specifically, the $l_1$ norm and the maximum element of Adam’s variance state serve as leading indicators for impending loss spikes.

Correlation between loss spikes (red) and gradient variance outliers (blue) during 1.5B GPT-2 training.

Further investigation revealed that long sequence lengths are a primary driver of these variance spikes, particularly during the early stages of training when model weights are near-random. As shown in the figure below, increasing the sequence length or the batch size significantly elevates the peak gradient variance norm, explaining why large-scale training with full-length sequences is so prone to failure at the start.

Gradient variance norm across different batch sizes and sequence lengths. Longer sequences (orange) and larger batch sizes (blue) lead to higher variance peaks.

Sequence Length Warmup (SLW)

To mitigate these early-stage variance spikes, we propose Sequence Length Warmup (SLW). Instead of training on full-length sequences from step zero, SLW gradually increases the sequence length from a small initial value (e.g., 8 or 64 tokens) to the target length (e.g., 1024 or 2048) over a warmup period $T$.

Key features of SLW include:

  • Truncation-based Implementation: To maintain efficiency, we simply truncate full-length sequences from the dataloader on the fly, avoiding complex dataset re-indexing.
  • Quadratic Speedup: Due to the $O(L^2)$ complexity of self-attention, processing shorter sequences at the start provides a massive wall-clock speedup that exceeds the reduction in token count.
  • Heuristic Tuning: The optimal warmup duration $T$ can be determined by monitoring validation perplexity fluctuations during the first few thousand steps, making it easy to integrate into existing pipelines.

Experimental Results

We evaluated SLW across multiple model scales with impressive results:

  • GPT-2 (1.5B): SLW enabled stable training with an 8x larger batch size and 4x larger learning rate. It reached target zero-shot accuracy using 2.2x fewer tokens and 3.7x less wall-clock time compared to the baseline.
  • GPT-3 (125M): In a data-constrained setting, SLW allowed for a 40x larger learning rate than the original GPT-3 recipe. It achieved 99% of the original model's accuracy while training 17x faster.

By "squashing" the initial variance spikes, SLW allows the model to stabilize its weights on simpler, shorter contexts before tackling long-range dependencies, effectively decoupling stability from hyperparameter aggressiveness.

Conclusion

Sequence Length Warmup offers a robust solution to the stability-efficiency dilemma in large-scale language model pre-training. By addressing the root cause of early-training instability—noisy gradients from long sequences—SLW enables the use of much more efficient training configurations. The implementation is now available as part of the DeepSpeed library to facilitate broader adoption in the research community.

Summary updated

BibTeX
@inproceedings{li2022stability,
  author = {Conglong Li and Minjia Zhang and Yuxiong He},
  title = {{The Stability-Efficiency Dilemma: Investigating Sequence Length Warmup for Training GPT Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=JpZ5du_Kdh},
}
Figure