Accelerated Large Batch Optimization of BERT Pretraining in 54 minutes

Shuai Zheng, Haibin Lin, Sheng Zha, Mu LiarXiv 2020

Introduction

Researchers at AWS have developed a new optimizer called LANS (Layer-wise Accelerated Non-convex Stochastic gradient descent) that slashes BERT-Large pretraining time to just 54 minutes. By combining Nesterov momentum with a novel three-stage learning rate scheduler, they successfully scaled mini-batch sizes to 96K without the accuracy loss or divergence that typically plagues large-batch training.

The Large-Batch Scaling Wall

Training state-of-the-art Language Models like BERT is notoriously computationally expensive, often taking days or weeks on standard hardware. To speed this up, researchers use "large-batch training," which allows them to distribute work across hundreds or thousands of GPUs simultaneously.

However, there is a mathematical "speed limit." To maintain efficiency as you increase the batch size, you typically must increase the learning rate (LR). But the LR is theoretically capped by the smoothness of the loss function (the inverse of the Lipschitz constant). If you push the LR past this limit to accommodate massive batches, the training often diverges or fails to reach peak accuracy. The authors set out to break through this scaling wall to achieve the fastest BERT training time in the cloud.

The LANS Optimizer and Three-Stage Scheduler

The authors introduce two primary innovations to overcome these scaling barriers:

  1. The LANS Optimizer: Building upon the LAMB optimizer, LANS incorporates per-block gradient normalization and Nesterov’s Accelerated Gradient (NAG). LANS succeeds by carefully modifying normalization factors to ensure the update for each block maintains a unit $\ell_2$-norm, making the optimizer more robust against vanishing or exploding gradients.
  2. A Three-Stage Learning Rate Scheduler: Standard schedules use a linear "warmup" followed by a decay. LANS introduces a constant learning rate stage between the warmup and decay. This allows the model to spend more time at the maximum stable learning rate, maximizing "training progress" even when the learning rate cannot be scaled any higher due to mathematical constraints.
Comparison of learning rate schedules, highlighting the three-stage approach with a constant phase.

This "Area Under the Curve" strategy effectively increases the total integrated learning rate over time without hitting the divergence threshold. By correctly integrating Nesterov momentum into a layer-wise adaptive framework, they achieved better acceleration in early training stages compared to the classic momentum used in LAMB.

Experimental Results

The model was pretrained using the standard BERT-Large recipe on Wikipedia and BooksCorpus, then fine-tuned on SQuAD v1.1 to ensure high-quality weights.

Performance comparison between LAMB and LANS optimizers for BERT-Large pretraining.

Key results include:

  • Record-Breaking Speed: BERT-Large pretraining was completed in 53.6 minutes using 1,536 NVIDIA V100 GPUs (192 AWS EC2 P3dn.24xlarge instances).
  • Superior Scaling: LANS successfully handled a mini-batch size of 96,000 in Phase 1. For comparison, the previous state-of-the-art (LAMB) diverged when attempting to scale to this batch size.
  • No Accuracy Trade-off: Despite the massive speedup, the model achieved an F1 score of 90.60 on the SQuAD v1.1 dev set, matching or slightly exceeding the baseline BERT accuracy.
  • Efficiency: The total number of iterations was reduced to 4,301, significantly lower than the ~8,600 steps required by LAMB at smaller batch sizes.

Limitations and Future Work

While 54 minutes is impressive, it requires a massive cluster of 1,536 GPUs, which is beyond the reach of most independent researchers. Additionally, the paper notes that while LANS helps, finding the "perfect" maximum learning rate still requires careful observation. Future work could explore how LANS performs on other architectures like Computer Vision models or larger Generative Pretrained Transformers (GPT).

Summary updated

BibTeX
@misc{zheng2020accelerated,
  author = {Shuai Zheng and Haibin Lin and Sheng Zha and Mu Li},
  title = {{Accelerated Large Batch Optimization of BERT Pretraining in 54 minutes}},
  year = {2020},
  eprint = {2006.13484},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2006.13484},
}
Figure