消除长上下文混合专家训练中的每个内存峰值
研究论文 · 2026/09/17
训练长上下文或大batch size的混合专家(MoE)模型时,只要任一组件峰值分配超过设备内存就会失败,因此目标是同时控制所有峰值,而非平均占用。常用并行方案中四个峰值未受限制且增长方式各异:专家分发随路由矩阵增长,词汇投影随token数乘以词汇量增长,梯度检查点边界随深度乘以序列长度增长,优化器状态随参数量增长。哪个先耗尽取决于模型、上下文长度和设备数量,因此仅降低最大峰值只会暴露下一个。我们通过调度将这四个峰值在GPU工作集启动时固定:PipelinedLLEP扩展最少负载专家并行,限制每个源向分发块贡献的token数;Ring-DTP在词汇投影处环形传递激活或权重分片,并将每个logits块折叠为在线log-sum-exp;选择性检查点卸载(SCO)将每个检查点边界的一个长生命周期张量保留在CPU内存;OffloadStreamAdamW将优化器卸载的串行CPU Adam更新转为桶流水线。四者仅改变计算和数据移动的顺序与粒度,因此损失和梯度保持精确。在匹配组件测试中,它们将MoE分发峰值降低高达59.3%且不损失吞吐量,词汇投影峰值降低86.6%,卸载优化器步骤加速2.05倍。在120B至667B参数的MoE模型上组合使用,可在1M上下文长度下训练,达到调优FSDP2基线的8-32倍,吞吐量高达其10.4倍。
该工作系统性地解决了长上下文MoE训练中多个内存峰值同时超限的难题,通过仅改变计算与数据移动顺序和粒度,在保持损失和梯度精确的同时,显著降低峰值内存并提升训练规模与吞吐量,对大规模模型训练具有重要实践价值。
Training a Mixture-of-Experts (MoE) model at long context or large batch size fails as soon as any one component's peak allocation exceeds device memory, so the target is every peak at once, not the average footprint. Four are left unbounded by the parallelism plans in common use, and each grows differently: expert dispatch with the routing matrix, the vocabulary projection with tokens times vocabulary, gradient checkpoint boundaries with depth times sequence length, and optimizer state with parameter count. Which one runs out first changes with the model, the context length, and the device count, so lowering the largest only exposes the next. We bound all four with schedules whose GPU working set is fixed at launch: PipelinedLLEP extends least-loaded expert parallelism with a cap on the tokens each source contributes to a dispatch chunk, Ring-DTP circulates activations or weight shards around a ring at the vocabulary projection and folds each block of logits into an online log-sum-exp, Selective checkpoint offload (SCO) keeps the one long-lived tensor of each checkpoint boundary in CPU memory, and OffloadStreamAdamW turns the serial CPU Adam update of optimizer offload into a bucket pipeline. All four change only the order and granularity of computation and data movement, so the loss and gradients stay exact. In matched component tests, they cut the MoE dispatch peak by up to 59.3% without losing throughput, the vocabulary projection peak by 86.6%, and the offloaded optimizer step by 2.05times faster. Composed on MoE models from 120B to 667B parameters, they train at 1M context length, 8--32times the reach of a tuned FSDP2 baseline, and up to 10.4times its throughput.