Draft
[WIP]feat(moonep): 支持 MoonEP Forward/Backward overlap #8
&NewgateAdd on 15 days ago
[WIP]feat(moonep): 支持 MoonEP Forward/Backward overlap #8
Draft
&NewgateAdd on 15 days ago
&Newgate
&NewgateCollaborators
15 days ago

What this PR does / why we need it?

为 MoonEP 接入 MindSpeed Forward/Backward overlap 调度,使专家通信、前后向计算和权重梯度计算能够按照配对执行计划重叠,减少通信等待。

主要改动:

  • 新增 moonep_fb_overlap 模块,实现执行计划编译、前向、反向及前后向配对执行,并接入已有 FB 调度框架。
  • 新增 MoonEP 与 FB 联合 Feature,统一负责联合模式的校验和注册,复用已有 Linear backward、DDP hooks 和调度入口。
  • 复用同步 MoonEP 的专家 Parameter/main_grad 绑定,通过 session 管理 FB Buffer、activation bank 和每步资源生命周期。
  • 接入异步 Dispatch、Combine、权重预取和梯度归约,维护通信完成、计算消费、bank 复用及梯度就绪之间的依赖。
  • 管理 FB 原生 GMM segment 的提交、完成和异常状态,并在 Q0 尾部批量等待 release fences,保留资源所有权、版本校验和异常保活机制。
  • 将 MoonEP 专属适配集中在联合执行路径,尽量复用原 FB 实现,缩小公共 FB/VPP 调度的改动范围。

Does this PR introduce any user-facing change?

是。在满足 MoonEP 配置要求的训练命令中,通过已有参数启用联合模式,无需新增 overlap 参数:

--moe-token-dispatcher-type flex \
--moe-flex-dispatcher-backend moonep \
--moe-fb-overlap

activation zero-copy 仍通过已有 --moonep-activation-zero-copy 参数显式开启。

当前主要配置要求:

  • BF16、CP1、expert TP1;EP大于1,专家数可被EP整除。
  • 开启 grouped GEMM、专家 GEMM 梯度累加融合、分布式优化器及 FP32 梯度累加。
  • 使用无 bias 的 SwiGLU 专家;hidden/attention dropout 为0。
  • 固定 full 重计算沿用原 FB 策略:uniform 仅允许 recompute_num_layers=1,block 按配置选择重算层数;不支持按 microbatch 选择部分重计算。
  • 不支持与参数 gather overlap、shared expert overlap、CUDA Graph 等未适配功能组合。

完整限制以联合 Feature 和 MoonEP 参数校验为准,不支持的组合在参数校验或初始化阶段拒绝。

原有 FB 使用说明位于 docs/zh/features/megatron_moe/megatron-moe-fb-overlap.md;本 PR 未新增专门的 MoonEP FB 用户文档。

How was this patch tested?

本地检查和八卡 UT

  • PR HEAD 2709a27c 对目标分支 2b975fc4 的完整差异通过本地 pre-commit。YAML 和 JSON 无适用文件。
  • tests_extend/unit_tests/features/moe/test_moonep_1f1b_overlap.py 的 9 个 CPU 用例通过。Ascend 950 单机八卡的 moe、mixed、uniform 和 updates 四个用例全部通过。测试对比同步和 FB 两臂的前向输出、输入梯度、本地优化器分片梯度及更新后的参数,逐位检查使用 rtol=0, atol=0。也检查 FB 配对次数、梯度分片覆盖及步尾 bank 释放。updates 验证连续 3 次优化器更新。

单机八卡 1000 步整网对照

2026 年 12 月 1 日完成混合传输长跑。两臂各完成 1000 次优化器更新、64,000 个样本。同步臂用 MoonEP 72674969,FB 臂用基于 7201422e 的精简版冻结源码,两臂均用 MoonEP provider b4127baa。FB 快照含当时的本地精简改动,补丁 SHA-256 前缀为 1d78b0140d3b。

项目 配置
模型 两层纯 MoE,H6144 / S4096,E48 / Top8,BF16
并行和 Batch TP1 / PP1 / CP1 / EP8 / ETP1,MBS1 / GBS64,每步 8 个 microbatch
数据和训练 C4,DeepSeek-V3 tokenizer,相同初始化 seed 1234 和数据索引,分布式 AdamW,1000 步学习率配方
执行 Activation zero-copy,专家 GEMM 梯度累加融合开启,无重计算,全程关闭 profile
通信 Dispatch / Combine 走 MTE,Prefetch / GradReduce 走 UDMA。同步臂用 mixed barrier,FB 臂用 aiv

以 abs(sync - FB) / max(abs(sync), abs(FB)) 为 loss 相对差,1000/1000 步 ≤1%。中位差 0.1229%,P90 0.2809%,最大差 0.4260%(第 435 步)。两臂均无 NaN、无跳步。Grad norm 全部有限,最大绝对差 1.323(第 221 步)。

指标 MoonEP 同步 MoonEP + FB FB 变化
第 1000 步 LM loss 5.726934 5.733913 相对差 0.1217%
中位步时,第 2–1000 步 1575.6 ms 1474.6 ms −6.41%
吞吐,由中位步时换算 166,377 tokens/s 177,773 tokens/s +6.85%
Allocated 峰值 29.85 GiB 28.80 GiB −1.05 GiB
Reserved 峰值 32.19 GiB 31.26 GiB −0.93 GiB
整卡 HBM 采样峰值 42.92 GiB 43.91 GiB +0.99 GiB

步时包含窗口内的 GC 和慢步。Allocated 和 reserved 为 PyTorch NPU allocator 的八卡最大值,整卡 HBM 为 npu-smi 采样的八卡最大值。

原生 MoE FB overlap 的 50 步确定性精度对齐

对比 Ascend 主仓 core_r0.18.0 的 3c72f231 与 PR 分支基于 7201422e 的冻结快照。两臂的原生 token 恢复均采用主仓 6fea23f2 的 scatter_add_ 累加语义。两臂均使用原生 alltoall 和 --moe-fb-overlap,开启 --deterministic-mode 和 --npu-deterministic。同配方采用单机八卡、C4、两层 MoE、H6144 / S4096、E48 / Top8、EP8、MBS1 / GBS64,关闭 FlashAttention。

验证项 结果
rank × step 的原始 FP32 LM loss 400/400 逐位一致
rank × step × microbatch 的输入指纹 3200/3200 一致
训练日志 50/50 步 LM loss 和打印的 grad norm 一致,两臂均无 NaN、无跳步
首末步 LM loss 两臂均从 13.02516 降到 7.537211
likedislike
Merge blocked
&Newgate&NewgateCollaborators
15 days ago Added label: featfixdocsstylerefactor
21 event messages are collapsed here。 See more
&Newgate&NewgateCollaborators
4 days ago Pushed 1 commits:cf6bc56c-docs(moonep): add license headers to FB overlap files
&Newgate
&NewgateCollaborators
4 days ago Comments:

compile

likedislike
&Newgate&NewgateCollaborators
3 days ago Pushed 1 commits:2709a27c-test(moonep): preserve FB schedule context in overlap UT
&Newgate&NewgateCollaborators
3 days ago Modify description of pull request
&Newgate&NewgateCollaborators
3 days ago Modify description of pull request
&Newgate&NewgateCollaborators
3 days ago Modify description of pull request
&Newgate&NewgateCollaborators
2 days ago Force-pushed 27 commits:af3d28f9-Simplify MoonEP FB setup and reuse synchronous bindings,2414a611-Move MoonEP FB Buffer lifecycle into session,360ffda4-Restore shared VPP behavior and localize MoonEP adapters,0d2e5484-Merge refactor/moonep-runtime-coordination into integrate/pr4146-fb-overlap,b4edc351-refactor(moonep): localize norm guards and restore shared FB behavior,a3f55900-refactor(fb): restore upstream norm recompute flags,e9e01354-refactor(moonep): restrict FB recompute to fixed layer policies,deebf0e7-refactor(fb): preserve the original warmup increment placement,177c2767-refactor(moonep): make joint FB feature validation explicit,439cebff-test(moonep): verify FB replay input consumption behavior,c6e5a2bf-fix(moonep): guard optional Bridge and trim FB host overhead,50be6172-refactor(moonep): unify FB module and execution naming,8aa6a224-fix(moe): avoid duplicate MoonEP FB lifecycle wrapping,d09507f8-fix(moe): detach MoonEP FB native math operands,816756fd-fix(moonep): manage FB native compute segments and paired receipts,37a6505b-Merge runtime coordination updates into MoonEP FB overlap,7a2b9fe6-refactor(moonep): simplify FB resource manifest,48a8e6cb-feat(moonep): support custom pipeline layouts in FB overlap,13398ab6-fix(moonep): shorten FB activation lifetimes,d8f1683c-perf(moonep): defer FB release at last consumer,1a5b9e39-Merge MoonEP runtime coordination into FB overlap,bfd08167-Merge MoonEP FB last-consumer release fixes,25eaafcc-perf(moonep): enable last-consumer FB release by default,d247f18d-refactor(moonep): drop FB debug controls and trim tests,3f9958a9-Merge MoonEP target license headers into FB overlap,3a0d6ee7-docs(moonep): add license headers to FB overlap files,b8e974c6-test(moonep): preserve FB schedule context in overlap UT
&Newgate
&NewgateCollaborators
2 days ago Comments:

/check-cla

likedislike
&Newgate&NewgateCollaborators
2 days ago Force-pushed 37 commits:5487f145-Integrate FB Overlap with PR4146 v10 MoonEP adapter,bcf9f987-Batch MoonEP release waits at the Q0 tail,19336f45-Simplify MoonEP FB lifecycle and admission,ce046074-Guard FB rollback and remove validation residue,f3674ea5-Simplify FB teardown and remove redundant computation wrappers,bdfda145-Simplify MoonEP FB entry state and restore eager imports,2b815076-Localize Dense identity and consolidate joint feature registration,751a1531-Reuse native call sessions and admitted forward state,7839abb7-Reuse generation keys within manifest advancement,5cd99a23-Align MoonEP FB wgrad with standard AddV2,5ec25c13-Simplify MoonEP FB setup and reuse synchronous bindings,4db66ff9-Move MoonEP FB Buffer lifecycle into session,33b06933-Restore shared VPP behavior and localize MoonEP adapters,0bd9bbc7-Merge refactor/moonep-runtime-coordination into integrate/pr4146-fb-overlap,d4a859b5-refactor(moonep): localize norm guards and restore shared FB behavior,966d8932-refactor(fb): restore upstream norm recompute flags,7fa76a6f-refactor(moonep): restrict FB recompute to fixed layer policies,e9d7fa89-refactor(fb): preserve the original warmup increment placement,ac42ccb3-refactor(moonep): make joint FB feature validation explicit,3ff4a832-test(moonep): verify FB replay input consumption behavior,ca6af27d-fix(moonep): guard optional Bridge and trim FB host overhead,7f2cb0e0-refactor(moonep): unify FB module and execution naming,de1d94be-fix(moe): avoid duplicate MoonEP FB lifecycle wrapping,5df06299-fix(moe): detach MoonEP FB native math operands,c44239ee-fix(moonep): manage FB native compute segments and paired receipts,aa8265e8-Merge runtime coordination updates into MoonEP FB overlap,58372983-refactor(moonep): simplify FB resource manifest,b5ef65a1-feat(moonep): support custom pipeline layouts in FB overlap,6ba6c534-fix(moonep): shorten FB activation lifetimes,cde55a58-perf(moonep): defer FB release at last consumer,fb3420d6-Merge MoonEP runtime coordination into FB overlap,76615ce1-Merge MoonEP FB last-consumer release fixes,41c0e01c-perf(moonep): enable last-consumer FB release by default,daa065ba-refactor(moonep): drop FB debug controls and trim tests,504522b0-Merge MoonEP target license headers into FB overlap,a7643071-docs(moonep): add license headers to FB overlap files,2998acd0-test(moonep): preserve FB schedule context in overlap UT
&Newgate&NewgateCollaborators
2 days ago Pushed commit