Skip to content

perf(megamoe): prioritize routed backward with Pull input replay - #8

Merged
davidhe91 merged 1 commit into
davidhe91:megamoe-ascend950-integrationfrom
forever-moe:feat/megamoe-backward-optimization
Dec 3, 2026
Merged

davidhe91 merged 1 commit into
davidhe91:megamoe-ascend950-integrationfrom
forever-moe:feat/megamoe-backward-optimization

Conversation

@forever-moe

@forever-moe forever-moe commented Dec 3, 2026 •

Copy link
Copy Markdown

Summary

 class MegaMoeSchedulerOptions:
     prioritize_shared: Mapping[Literal["forward", "backward"], str] | None = None
+    prioritize_routed: bool = True

prioritize_routed 默认允许 ascend950 MXFP8 逐专家反向的路由调度优化。实际生效需要同时使用 Pull 分发、输入重算(permute=True)和窗口 8。
prioritize_shared 继续按阶段前缀控制共享任务能否提前参与。
输入重算可单独使用或与激活重算组合。其他配置按关闭路径编排。显式设置 prioritize_routed=False 可关闭优化。

Cube  主窗口 → 为候选 AIV0 供数的共享 Cube 任务 → 路由 dW1/dW2 → 其余共享候选队首
AIV0  主窗口 → Pull 输入恢复量化 → 共享候选队首
AIV1  dY Dispatch → 恢复 GET → Combine

Cube 主窗口内就绪的路由 dA/dX 优先。候选窗口根据数据依赖识别为共享 AIV0 供数的 Cube 任务,
让其后续 Vector 计算与路由权重梯度重叠。例如共享 dA 先产出 SwiGLU 梯度量化的输入,
Cube 随后执行就绪的路由 dW1/dW2。任务仍需满足自身依赖和共享候选范围。

适配目标基线 e8167ff 的融合反向收尾。BF16 路由权重梯度回写等待实际发布的 rank 级 Cube 汇合事件,
融合 token 梯度恢复在共享 dX 和 Combine 都就绪后才能被选中。

Evidence

  • 当前默认策略通过 636 项 Host 回归。Host 编译任务图验证仅输入重算和双项重算启用路由 Cube 汇合,激活重算和无重算的默认计划与显式关闭一致。
  • 既有 Ascend950 设备对照使用 ABI 11 制品。EP2 仅激活重算下,关闭策略的 profiling 任务编排一致,14 项输出和梯度逐位一致。
  • EP2 同时开启路由优先和融合反向收尾,BF16 回写与 FP32 直出分别通过 14 项逐位对照。
  • EP2 65 tokens 命中 Stream-K,trace 覆盖 Cube partial 和 AIV0 归并,路由开关前后 14 项逐位一致。
  • EP8 4K Pull,固定 prioritize_shared={"backward": "dx"}、窗口 8、设备路由及 FP32 partial dW。
    三种重算组合各测 FC2 前、后加权,路由开关前后共 336 项输出和梯度逐位一致。

下表保留制定默认策略前的六组开关对照。仅激活重算的两组用于说明关闭依据,当前默认生效范围为两种包含输入重算的组合。
每档 12 步独立计时。表内为关 → 开,单位 ms。Cube、AIV0 和 AIV1 间隙按 rank 0、2 的每核首末有效任务之间的空闲取平均。
Combine 收尾取两个采样 rank 中较晚者。单次 trace 和未打点计时分别采集。

重算 FC2 加权 整步 P50 整步 P95 反向 P50 反向主 kernel · rank 0 Cube 间隙 AIV0 间隙 AIV1 间隙 Combine 收尾
输入重算 后 19.77 → 19.45 21.63 → 21.14 11.92 → 11.64 10.51 → 10.30 0.47 → 0.20 2.22 → 1.54 5.12 → 4.46 7.26 → 7.02
输入重算 前 19.65 → 19.12 21.38 → 20.49 11.71 → 11.62 10.78 → 10.27 0.74 → 0.20 1.94 → 1.11 5.38 → 4.45 7.89 → 7.35
激活重算 后 18.97 → 19.16 20.55 → 20.58 11.27 → 11.31 10.22 → 10.34 0.17 → 0.16 1.91 → 1.67 4.62 → 4.38 5.66 → 5.42
激活重算 前 18.58 → 18.78 19.91 → 19.98 10.99 → 11.08 10.26 → 10.24 0.19 → 0.19 1.33 → 1.31 4.59 → 4.58 5.72 → 5.72
输入 + 激活重算 后 20.24 → 19.23 21.40 → 21.03 12.26 → 11.73 10.67 → 10.40 0.63 → 0.17 1.86 → 0.94 5.32 → 4.39 7.60 → 7.04
输入 + 激活重算 前 19.86 → 19.58 21.83 → 20.83 12.49 → 12.21 11.00 → 10.32 0.93 → 0.19 1.72 → 0.62 5.63 → 4.61 8.31 → 7.39

整步 P50 有 4/6 组下降,最大降幅为双项重算、FC2 后加权的 1.02 ms(5.03%)。仅激活重算时,FC2 后加权上升 0.19 ms(1.01%),FC2 前加权上升 0.21 ms(1.11%)。百分比按各组关闭路由优先时的整步 P50 计算。

双项重算、FC2 后加权时,Cube 平均间隙为 0.63 → 0.17 ms。rank 0 首个路由 dW2 在 6.19 → 5.18 ms 启动。
共享 dA 与 SwiGLU 梯度量化分别在 0.36 → 0.69 ms 和 0.57 → 2.03 ms 启动。
开启后,共享 SwiGLU 梯度量化仍与路由 dA 重叠,共享 dX 留在主反向 kernel 尾部。
Combine 与共享 dX 分别在 7.60 → 7.04 ms 和 2.63 → 10.40 ms 收尾。

双项重算的开关对照

输入重算与激活重算

输入重算的开关对照

激活重算的开关对照

六组计时与阶段数据

Merge Danger

双向门。符合条件的 Pull 输入重算层可用 prioritize_routed=False 逐层关闭优化。MXFP8 运行需要配套 ABI 11 制品。两类候选同时存在时使用 worker 队列布局 5。

@forever-moe
forever-moe marked this pull request as ready for review December 3, 2026 10:59
@forever-moe
forever-moe force-pushed the feat/megamoe-backward-optimization branch 3 times, most recently from ee7b7b5 to b5f9569 Compare December 3, 2026 11:58
@forever-moe
forever-moe force-pushed the feat/megamoe-backward-optimization branch from b5f9569 to 410ceb1 Compare December 3, 2026 12:35
@forever-moe forever-moe changed the title perf(megamoe): make routed backward priority opt-in perf(megamoe): prioritize routed backward with Pull input replay Dec 3, 2026
@forever-moe
forever-moe force-pushed the feat/megamoe-backward-optimization branch 2 times, most recently from 651b546 to 410ceb1 Compare December 3, 2026 12:40
@davidhe91
davidhe91 merged commit 8701a75 into davidhe91:megamoe-ascend950-integration Dec 3, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants