arXiv(opens in a new tab)cs.LGJan 2025Cited by 4 papers on PaperVantage

Manuscript Offprint

arXiv:2501.11873

Demons in the Detail: On Implementing Load Balancing Loss for Training Specialized Mixture-of-Expert Models

Zihan Qiu, Zeyu Huang, Bo Zheng, Kaiyue Wen, Zekun Wang, Rui Men, Ivan Titov, Dayiheng Liu, Jingren Zhou, Junyang Lin

Abstract

This paper revisits the implementation of Load-balancing Loss (LBL) when training Mixture-of-Experts (MoEs) models. Specifically, LBL for MoEs is defined as NE∑i=1NEfipiN_E \sum_{i=1}^{N_E} f_i p_i, where NEN_E is the total number of experts, fif_i represents the frequency of expert ii being selected, and pip_i denotes the average gating score of the expert ii. Existing MoE training frameworks usually employ the parallel training strategy so that fif_i and the LBL are calculated within a micro-batch and then averaged across parallel groups. In essence, a micro-batch for training billion-scale LLMs normally contains very few sequences. So, the micro-batch LBL is almost at the sequence level, and the router is pushed to distribute the token evenly within each sequence. Under this strict constraint, even tokens from a domain-specific sequence (e.g., code) are uniformly routed to all experts, thereby inhibiting expert specialization. In this work, we propose calculating LBL using a global-batch to loose this constraint. Because a global-batch contains much more diverse sequences than a micro-batch, which will encourage load balance at the corpus level. Specifically, we introduce an extra communication step to synchronize fif_i across micro-batches and then use it to calculate the LBL. Through experiments on training MoEs-based LLMs (up to 42.8B total parameters and 400B tokens), we surprisingly find that the global-batch LBL strategy yields excellent performance gains in both pre-training perplexity and downstream tasks. Our analysis reveals that the global-batch LBL also greatly improves the domain specialization of MoE experts.

1 Introduction

In recent years, the Mixture-of-Experts (MoE) framework (Szymanski & Lemmon, 1993; Shazeer et al., 2017) has become a popular technique to scale the model parameters up (Jiang et al., 2024; Dai et al., 2024; Liu et al., 2024a; Yang et al., 2024). For instance, Mixtral-8x22B (Jiang et al., 2024) (141B), Deepseek-v3 (Liu et al., 2024a) (671B) and MiniMax-01 (Li et al., 2025) (456B) reach a scale of hundreds of billion parameters while maintaining affordable training and inference efficiency. Typically, standard MoE comprises a router network and a group of parallel expert modules. Given a set of inputs, the router distributes each input to its corresponding experts conditionally and sparsely. Then, the outputs from individual experts are aggregated based on the importance weight that the router assigned to the expert.

One critical factor for training MoE-based models is encouraging the router to assign input to experts in a balanced manner (Shazeer et al., 2017; Fedus et al., 2022; Zoph et al., 2022; Qiu et al., 2024a). The reasons are twofold: (1) effectiveness: if the router continually prioritizes some experts during training, these experts will get more updates than others and will soon dominate that MoE layer, finally resulting in parameter redundancy issue (Shazeer et al., 2017; Wang et al., 2024); (2) efficiency: training and deploying large-scale MoE-based models often requires the Expert Parallel, where different experts will be in different parallel groups to process their inputs. Then, their outputs will be gathered and aggregated. In this case, the imbalanced expert utilization would heavily slow the forward process. Therefore, previous works training MoE-based LLMs generally employ an auxiliary loss, called Load-balancing Loss (LBL), to encourage the balanced routing decision (Shazeer et al., 2017).

Nevertheless, in most open-source MoE training frameworks like Deepspeed-MoE (Liu et al., 2024a), Tutel (Hwang et al., 2023), Megablocks (Gale et al., 2023) and Megatron-Core (Shoeybi et al., 2019), the LBL is calculated at the micro-batch level, which, as we will soon empirically demonstrate, negatively affects the performance and expert specialization of MoE-based LLMs. Specifically, during large-scale MoE training, each micro-batch usually contains only up to thousands of tokens and, thus, only a handful of sequences. Therefore, the micro-batch LBL is almost calculated at the sequence level. Suppose

∗^{*}Equal Contribution

Corresponding authors

Figure

(a) Ablation of Balance Scope

(b) Expert Frequency for Micro-Batch Balance (Left) and Global-Batch Balance (Right)

Figure 1: The impact of the Balance BSZ on (a) model performance and (b) expert specialization. (a) When employing micro-batch level load balance, methods based on LBL and based on auxiliary-loss-free (Wang et al., 2024) approaches perform worse than employing the global-batch balance. (b) When employing micro-batch balance, there is no significant difference in the selection frequency of different domain-specific data, and the selection frequency of different experts within the same domain is approximately the same. With global-batch balance, there is a noticeable difference in the selection frequency of experts on different domain data, and within the same domain, there are experts with high selection frequency (marked in blue).

a micro-batch contains some domain-specific sequences (i.e. code and math); the micro-batch LBL still pushes routers to distribute these domain-specific tokens to all experts evenly, introducing an overly strict constraint and may hurt the model performance.

Consequently, we propose calculating the LBL at the global-batch level by synchronizing the expert selection frequency across parallel groups and then computing the LBL. According to the Fig. 1 (a), the global-batch LBL significantly enhances model performance (approximately 0.1 in pre-training PPL and 2 in benchmark scores). Additionally, Fig. 1 (b) showcases that the domain specialization only clearly emerges when trained with the global-batch LBL. We demonstrate that the model performance effectively increases with the global batch size (Section 4.2). We conducted further ablation studies to verify that introducing more diverse training tokens instead of more training token numbers is the main contributor to performance gains (Section 5). Because the expert selection frequency is just an expert-number-dimensional vector, our method introduces less than 3% latency under appropriate configurations and achieves more performant and interpretable models.

In summary, we investigate the challenges associated with the LBL in training MoEs models. By introducing global-batch LBL, we achieve improved performance and foster expert specialization within the MoE model. We believe this advancement addresses an essential limitation in existing MoE training, offering a novel perspective for MoEs model optimization. Though mainly experimenting with language-based tasks, we hope our work could pave the way for training stronger and more specialised MoE models in various domains, e.g., Computer Vision and Multi-Modality.

References (41)