TorchScale: Transformers at Scale

Shuming Ma, Hongyu Wang, Shaohan Huang, Wenhui Wang, Zewen Chi, Li Dong, Alon Benhaim, Barun Patra, Vishrav Chaudhary, Xia Song, Furu WeiarXiv 2022

TL;DR

This paper introduces TorchScale, an open-source toolkit designed to make scaling Transformers to larger sizes more efficient and stable. It addresses the challenges of training massive Transformer models by incorporating advanced modeling techniques and a novel gradient clipping method, enabling researchers to build and train larger, more capable models without encountering common pitfalls.

What Problem Does This Paper Address?

The Transformer architecture has become the dominant force in many AI tasks, from language to vision. As these models grow larger, they exhibit emergent abilities and faster convergence. However, scaling Transformers presents significant challenges: training becomes unstable, requiring extensive hyperparameter tuning and computational resources. Existing toolkits primarily focus on system-level parallelization (model, pipeline, or expert parallelism). This paper tackles the problem of modeling-level scalability, aiming to improve the inherent stability and efficiency of training larger Transformer models directly through architectural and algorithmic innovations.

Methods

TorchScale offers a suite of techniques to enhance Transformer scalability:

  • Magneto Backbone: The toolkit uses Magneto as its default backbone. Magneto is a foundation Transformer architecture designed for general-purpose modeling, incorporating an extra LayerNorm in each sublayer for improved stability. This unified architecture supports various tasks and modalities.
  • DeepNet Initialization (Sub-LN): To combat optimization instability in large models, TorchScale implements the Sub-LN initialization method from DeepNet. This technique helps stabilize training, allowing for larger learning rates and more diverse data.
  • Mixture-of-Experts (MoE) Integration: The toolkit supports sparse MoE models, specifically implementing X-MoE. This approach introduces sparsity for efficiency while mitigating representation collapse issues common in sparse MoE models. It supports both Top-1 and Top-2 routing algorithms.
  • SparseClip: A novel gradient clipping method is proposed to address the instability of sparse MoE models. Unlike vanilla gradient clipping, which can distort gradient directions in large MoE models, SparseClip re-weights MoE gradients before computing the norm, ensuring more stable training and better performance.

Datasets

The paper evaluates TorchScale on the following datasets:

  • Language Modeling: A subset of data from Liu et al. (2019) and the English portion of the CC100 corpus (Conneau et al., 2020).
  • Neural Machine Translation: A combination of CCMatrix (Schwenk et al., 2021), CCAligned (El-Kishky et al., 2020), OPUS (Zhang et al., 2020), and Tatoeba. This dataset comprises 102 languages, 1932 directions, and 12 billion sentence pairs.

Key Insights and Ideas

  • Modeling Stability is Key to Scaling: The paper strongly emphasizes that improving the inherent modeling stability of Transformers is crucial for effective scaling, complementing existing system-level parallelization efforts.
  • Emergent Abilities at Scale: The experiments demonstrate that as Transformer models scale up in depth and width, their performance (measured by perplexity) improves, highlighting the benefits of larger model capacities.
  • Sparse MoE Models Benefit from Specialized Clipping: Vanilla gradient clipping can hinder the performance of large sparse MoE models. The proposed SparseClip method offers a significant improvement by stabilizing training and leading to better results.
  • TorchScale Enables "Scaling Without Tears": The toolkit's design and implemented techniques allow for scaling Transformers to much larger sizes (billions of parameters) with improved stability and efficiency, making large-scale Transformer research more accessible.

Key Results

  • Language Modeling: TorchScale successfully scaled dense Transformer models up to 96 layers, showing smooth convergence and improved perplexity with increased depth. Sparse MoE models with up to 256 experts and 13 billion parameters were trained, outperforming smaller models.
  • Neural Machine Translation: Dense encoder-decoder models were scaled up to 96-layer depths, demonstrating stable training and performance gains. Sparse X-MoE models with up to 256 experts also showed significant improvements, with training FLOPs remaining comparable to smaller models, underscoring efficiency.
  • SparseClip Performance: Figure 3 shows that SparseClip significantly improves the convergence of sparse MoE models on neural machine translation, leading to lower perplexity compared to vanilla gradient clipping. Figure 4 further visualizes that SparseClip leads to lower routing entropy and fewer gradient clipping events.

Limitations and Future Work

  • Limitations: The paper does not explicitly detail limitations of TorchScale itself, but the inherent challenges of training extremely large models (e.g., computational cost, memory requirements) are implicitly acknowledged. The effectiveness of SparseClip is demonstrated, but its theoretical underpinnings might require further exploration.
  • Future Work: The authors suggest further research into the impact of SparseClip, particularly its effect on training dynamics and the number of gradient clipping triggers. The potential for TorchScale to support even larger models and more diverse applications is also implied.

Summary updated

BibTeX
@misc{ma2022torchscale,
  author = {Shuming Ma and Hongyu Wang and Shaohan Huang and Wenhui Wang and Zewen Chi and Li Dong and Alon Benhaim and Barun Patra and Vishrav Chaudhary and Xia Song and Furu Wei},
  title = {{TorchScale: Transformers at Scale}},
  year = {2022},
  eprint = {2211.13184},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.13184},
}
Figure