[Paper Review] TorchScale: Transformers at Scale
TorchScale is an open-source PyTorch toolkit that enables efficient and stable scaling of Transformers to large sizes by integrating advanced modeling techniques such as Magneto architecture, DeepNorm initialization, and X-MoE with a novel gradient clipping method (SparseClip). It achieves stable training and improved performance across language modeling and neural machine translation tasks, even at 96-layer depths and 256-expert MoE configurations.
Large Transformers have achieved state-of-the-art performance across many tasks. Most open-source libraries on scaling Transformers focus on improving training or inference with better parallelization. In this work, we present TorchScale, an open-source toolkit that allows researchers and developers to scale up Transformers efficiently and effectively. TorchScale has the implementation of several modeling techniques, which can improve modeling generality and capability, as well as training stability and efficiency. Experimental results on language modeling and neural machine translation demonstrate that TorchScale can successfully scale Transformers to different sizes without tears. The library is available at https://aka.ms/torchscale.
Motivation & Objective
- To address the instability and inefficiency challenges in scaling Transformers beyond standard sizes.
- To improve training stability during deep and wide Transformer scaling, especially with sparse MoE architectures.
- To enable effective scaling of model depth, width, and expert count without compromising convergence or performance.
- To provide a unified, general-purpose framework supporting diverse tasks including language modeling, machine translation, and multimodal pretraining.
- To introduce a novel gradient clipping method (SparseClip) tailored for sparse MoE models to mitigate gradient dominance and improve training stability.
Proposed method
- Adopts the Magneto architecture as the default backbone, which uses Sub-LN initialization and a unified encoder-decoder structure for general-purpose modeling.
- Implements Sub-LN initialization based on DeepNet theory to enhance optimization stability in deep Transformers.
- Integrates X-MoE (eXtended Mixture of Experts) with top-1 and top-2 routing to enable parameter-efficient scaling via sparsity.
- Proposes SparseClip, a re-weighted gradient clipping method that scales MoE gradients by $ \kappa = 1/\sqrt{E} $ to balance gradient norms across dense and MoE components.
- Uses L2 norm-based gradient clipping with modified norm computation: $ ||g||_2 = ||(g_d, \kappa g_s)||_2 $, where $ E $ is the number of experts.
- Supports both dense and sparse MoE models across encoder, decoder, and encoder-decoder architectures with consistent training and inference pipelines.
Experimental results
Research questions
- RQ1Can Transformers be scaled stably to 96 layers and 256 experts without training divergence?
- RQ2How does the proposed SparseClip method improve training stability and convergence in sparse MoE models compared to vanilla gradient clipping?
- RQ3To what extent does the X-MoE architecture with top-2 routing preserve model performance while enabling efficient scaling?
- RQ4Does the Magneto architecture with Sub-LN initialization enable better generalization and training stability across diverse tasks like language modeling and machine translation?
- RQ5Can the combination of advanced modeling techniques in TorchScale achieve consistent performance gains across different model sizes and tasks?
Key findings
- TorchScale successfully trains a 96-layer decoder model on language modeling with stable convergence and a validation perplexity (PPL) that improves with depth.
- The 256-expert X-MoE model with top-2 routing achieves better PPL than smaller models despite over 100x more parameters, demonstrating effective scaling.
- SparseClip significantly improves training stability and convergence of sparse MoE models, reducing PPL by a notable margin compared to vanilla gradient clipping.
- The number of gradient clipping triggers is reduced over time with SparseClip, indicating more consistent and accurate gradient updates.
- Routing entropy is lower under SparseClip, suggesting improved expert utilization and more stable routing behavior during training.
- Training FLOPs remain nearly constant across models with increasing expert count, confirming the efficiency of the sparse MoE approach in TorchScale.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.