Demons in the Detail: On Implementing Load Balancing Loss for Training Specialized Mixture-of-Expert Models
本文提出了一种基于全局批次的负载均衡损失(LBL)计算方法,用于训练混合专家模型(MoE),从而提高模型性能和专家的领域专业化。
更新于 2025-01-22。作者:Zihan Qiu、Zeyu Huang、Bo Zheng、Kaiyue Wen、Zekun Wang、Rui Men、Ivan Titov、Dayiheng Liu、Jingren Zhou、Junyang Lin。
中文摘要
本文重新审视了在训练混合专家(MoEs)模型时实现负载均衡损失(LBL)的方法。具体而言,MoEs中的LBL定义为 N_E ∑_{i=1}^{N_E} f_i p_i,其中 N_E 是专家的总数,f_i 表示专家 i 被选中的频率,p_i 表示专家 i 的平均门控得分。现有的MoE训练框架通常采用并行训练策略,以便在微批次内计算 f_i 和 LBL,然后在整个并行组中进行平均。本质上,用于训练百亿规模的大型语言模型(LLMs)的微批次通常包含非常少的序列。因此,微批次LBL几乎处于序列级别,路由器被推向在每一序列内均匀分配令牌。在这种严格的约束下,即使是特定领域序列(例如代码)的令牌也会被统一路由到所有专家,从而抑制专家的专业化。在这项工作中,我们提出使用全局批次来计算LBL以放宽这一约束。因为全局批次包含比微批次更多样化的序列,这将鼓励在语料库级别上的负载均衡。具体来说,我们引入了一个额外的通信步骤来同步微批次间的 f_i,然后使用它来计算LBL。通过在基于MoEs的LLMs训练上的实验(总参数量高达42.8B,令牌量高达400B),我们惊人地发现,全局批次LBL策略在预训练困惑度和下游任务中均取得了显著的性能提升。我们的分析揭示,全局批次LBL也极大地提高了MoE专家的领域专业化程度。
英文摘要
This paper revisits the implementation of Load-balancing Loss (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 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 f_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.
解读
一句话总结
本文提出了一种基于全局批次的负载均衡损失(LBL)计算方法,用于训练混合专家模型(MoE),从而提高模型性能和专家的领域专业化。
问题1:这篇论文想要解决什么具体问题?
• 问题背景:在训练大规模混合专家模型(MoE)时,现有的负载均衡损失(LBL)计算方法通常在微批次级别进行,这限制了专家的领域专业化并可能影响模型性能。 • 现有方案不足:微批次级别的LBL计算导致路由器在序列级别上均匀分布标记,从而抑制了专家的专业化。 • 研究目标:通过引入全局批次的LBL计算方法,放松微批次平衡的限制,提高模型性能和专家的领域专业化。
问题2:论文的核心创新点是什么?
• 技术创新:提出了一种基于全局批次的LBL计算方法,通过同步微批次之间的专家选择频率来计算LBL。 • 方法改进:引入了额外的通信步骤来同步fi,然后使用它来计算LBL。 • 优势:与微批次LBL相比,全局批次LBL能够更有效地平衡负载,并促进专家的领域专业化。
问题3:实验结果如何验证了方法的有效性?
• 关键实验:在基于MoE的大规模语言模型(LLM)训练上进行了实验,包括高达42.8B参数和400B标记的模型。 • 性能提升:全局批次LBL策略在预训练困惑度和下游任务中取得了优异的性能提升。 • 对比结果:与基线方法相比,全局批次LBL在预训练困惑度上提高了约0.1,在基准测试分数上提高了2。
问题4:这个研究的实际应用价值是什么?
• 应用场景:该方法可以应用于训练各种领域的大规模MoE模型,例如计算机视觉和多模态。 • 实施建议:建议在MoE训练中使用全局批次LBL,以提高模型性能和专家的领域专业化。 • 局限与展望:该方法主要针对语言任务,未来可以扩展到视觉和多模态领域,并考虑在微批次中包含更多样化的序列以减轻局部不平衡问题。