arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2501.11873cs.LGcs.CL
收藏

细节中的魔鬼:论训练专用混合专家模型时负载均衡损失的实现

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

Alibaba Group(阿里巴巴集团);University of Edinburgh(爱丁堡大学);Stanford University(斯坦福大学)

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

AI总结:

本文针对混合专家模型训练中微批次负载均衡损失限制专家专业化的问题,提出基于全局批次计算负载均衡损失的方法,并通过大规模实验证明其能显著提升预训练困惑度、下游任务性能和专家领域专业化。

摘要:

本文重新审视了训练混合专家(Mixture-of-Experts, MoEs)模型时负载均衡损失(Load-balancing Loss, LBL)的实现方式。具体而言,MoEs 的 LBL 定义为 $N_E \sum_{i=1}^{N_E} f_i p_i$,其中 $N_E$ 是专家总数,$f_i$ 表示专家 $i$ 被选中的频率,$p_i$ 表示专家 $i$ 的平均门控分数。现有的 MoE 训练框架通常采用并行训练策略,因此 $f_i$ 和 LBL 是在一个微批次(micro-batch)内计算,然后在并行组之间取平均。本质上,用于训练十亿级大语言模型(LLMs)的微批次通常只包含极少量的序列。因此,微批次 LBL 几乎处于序列级别,路由器被迫在每个序列内均匀分配 token。在这种严格约束下,即使是来自特定领域序列(例如代码)的 token 也会被均匀路由到所有专家,从而抑制了专家专业化。在这项工作中,我们提出使用全局批次(global-batch)来计算 LBL,以放宽这一约束。由于全局批次比微批次包含更多样化的序列,这将鼓励在语料库级别实现负载均衡。具体来说,我们引入了一个额外的通信步骤来在微批次之间同步 $f_i$,然后用它来计算 LBL。通过在训练基于 MoE 的大语言模型(总参数量高达 42.8B,训练 token 数高达 400B)上的实验,我们惊讶地发现,全局批次 LBL 策略在预训练困惑度和下游任务上都取得了优异的性能提升。我们的分析表明,全局批次 LBL 还极大地改善了 MoE 专家的领域专业化。

英文摘要:

This paper revisits the implementation of $\textbf{L}$oad-$\textbf{b}$alancing $\textbf{L}$oss (LBL) when training Mixture-of-Experts (MoEs) models. Specifically, LBL for MoEs is defined as $N_E \sum_{i=1}^{N_E} f_i p_i$, where $N_E$ is the total number of experts, $f_i$ represents the frequency of expert $i$ being selected, and $p_i$ denotes the average gating score of the expert $i$. Existing MoE training frameworks usually employ the parallel training strategy so that $f_i$ and the LBL are calculated within a $\textbf{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 ($\textit{e.g.}$, code) are uniformly routed to all experts, thereby inhibiting expert specialization. In this work, we propose calculating LBL using a $\textbf{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 $f_i$ across micro-batches and then use it to calculate the LBL. Through experiments on training MoEs-based LLMs (up to $\textbf{42.8B}$ total parameters and $\textbf{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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑