Skip to content

feat(megamoe): add MXFP8 Token Wave and streamline device routing - #4

Merged
davidhe91 merged 5 commits into
davidhe91:megamoe-ascend950-integrationfrom
forever-moe:feat/megamoe-token-wave-integration
Dec 2, 2026
Merged

davidhe91 merged 5 commits into
davidhe91:megamoe-ascend950-integrationfrom
forever-moe:feat/megamoe-token-wave-integration

Conversation

@forever-moe

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

Copy link
Copy Markdown

/kind feature

接口变更

 tuning = MegaMoeTuningOptions(
     dispatch_mode="pull",
     dispatch_split=128,
     combine_split=128,
-    scheduler=MegaMoeSchedulerOptions(policy="two_expert_pipeline"),
+    scheduler=MegaMoeSchedulerOptions(policy="token_wave"),
+    compute_split=256,
 )

-with profiler.mega_kernel_profile() as capture:
+with profiler.mega_kernel_profile(granularity="wave") as capture:
     train_step()

compute_split 支持 256 和 512,启用 Token Wave 时默认 256。Wave 采集只用于 Token Wave。当前支持 Ascend950、32 个 AIC、EP8、MXFP8 UDMA Pull、t6、hidden_size=7168、intermediate_size=3072 和 FC2 后概率加权。共享专家和选择性重算各自走整专家路径。开启设备路由时,同一 EP 组要求等长输入,并使用平均接收量作为容量上界。

Token Wave 调度

执行位置 正向 反向
AIV1 Dispatch 按 peer/专家切成 128 行,向重叠的计算 Tile 累积实际到达行数 按片分发 dY 并累积行数
AIV0 从两张就绪位图选取 QuantX 和 SwiGLUQuant,优先做激活量化 同样调度 QuantDY 和 SwiGLUGradQuant
AIC 每个 Wave 最多合批 3 个同阶段就绪 Tile,执行 GMM1 或 GMM2 优先执行 dA、dX,在可用空档执行已就绪的整专家权重梯度
AIV1 Combine 的每个 PUT 等待它覆盖的所有输出 Tile 完成 FIX 写回 dX 对应分片写回即可开始 Combine

计算 Tile 从专家行起点切分。AIC0 发布 Wave,AIC 滚动分配 M×N 块。512 行 Tile 最多由两个 256 行 M 块组成。完整行块的 Wave 复用 Blaze batch,含短尾的 Wave 走通用 GMM。AIV 收到最后一次相关 FIX 信用才发布就绪。本地 MTE 拷贝在 Scalar 发布 GET 信用前增加 MTE3→Scalar 完成同步。

整专家的 builder_order 和 two_expert_pipeline 在本 rank 所有路由专家完成 dX 后执行权重梯度。各专家的 Combine 按自己的 dX 就绪时刻启动。

设备路由

稳态的纯路由专家按「提交计数交换 → 排列 token → 等待计数交换 → 生成元数据」在调用流上执行。设备路由 kernel 同时清零 Token Wave 的正向 scratch,省去一次单独的清零提交。共享专家在元数据提交后准备前向缓冲区,并复用本次调用已验证的权重视图。涉及容量增长时,流间顺序先保证元数据校验,再进入集体扩容。

本次 rebase 后的短测

实测提交为 6b06122,基底为 40a66d4。环境为 Ascend950、CANN 9.2、MXFP8 UDMA Pull,使用 t6 配置并关闭 Profiling。每组预热 4 步、计时 12 步,关闭设备路由的用例运行两组。每步取最慢 Rank,再统计 P50。

场景 基线端到端 P50 设备路由关闭 P50 设备路由开启 P50 Host 正向提交 P50,路由关闭 → 开启
EP2 共享专家,4096 token/Rank,以独立 CANN 串行为基线 20.711 ms 17.444 ms 17.396 ms 1.330 → 1.117 ms
EP8 Token Wave,256 token/Rank,以整专家为基线 2.443 ms 2.463 ms 2.131 ms 1.492 → 1.107 ms
  • EP8 Token Wave 在设备路由关闭和开启时,正向输出及四组梯度均与整专家逐字节一致,覆盖 8/8 Rank。
  • EP2 共享专家融合在开关设备路由以及 rebase 前后,正向输出及六组梯度逐字节一致,覆盖 2/2 Rank。独立 CANN 参考在 dX 和共享专家 dW1 有逐字节差异,rebase 前的 c325528 使用同一输入复现了这两项差异。
  • 设备路由开启的两个用例均通过显式 .cpu() 和 .tolist() 回读拦截检查。短测的端到端和 Host 提交数字适用于表中的输入规模。
  • 6b06122 修正了 MXFP8 量化描述符的输入列表引用。正反向 CANN 内核和 Torch 桥接均已重编,设备短测加载 ABI 9。

Rank 2 正反向 Profiling

下列时间线来自首轮 EP8 全尺寸验收 18febd7。每 rank 7 专家、3584 token、TopK=6、UDMA 双 QP。两图都从首个有效 Dispatch 对齐,分别列出 AIC、AIV0 和 AIV1。

正向

GMM1 提前 204 µs,首片 Combine 提前 680 µs。GMM2 最后完成时刻相差约 5 µs,末片 Combine 提前 87 µs。

Rank 2 正向 Profiling

反向

dA 提前 391 µs,首片 Combine 提前 1.29 ms,末片 Combine 提前 3.68 ms。Tile 版最后一次权重梯度比末片 Combine 晚 3.36 ms。

Rank 2 反向 Profiling

首轮关闭 Profiling,每组预热 7 步并保留 55 步,逐步取 8 rank 的最大值。端到端 P50 从 15.501 ms 降到 15.206 ms,AB 和 BA 两组分别下降 2.72% 和 0.44%。

首轮正反向与端到端耗时

回退与影响

Token Wave 和设备路由均可通过配置关闭。本分支的 MXFP8 路径需要配套构建 ABI 9 原生包。回退提交时,Python 与原生包须一起回到同一版本。

@forever-moe
forever-moe force-pushed the feat/megamoe-token-wave-integration branch 2 times, most recently from 9ae1daa to c325528 Compare December 2, 2026 10:43
The double-buffer events only order MTE2 reuse. Join the final MTE3 write to the scalar pipe before a completed copy may publish a credit. Token Wave can otherwise consume an unfinished self GET.
Add forward and backward row-tile scheduling for UDMA Pull. Use the existing policy selector with configurable compute_split, and publish Dispatch and first-GMM readiness to AIV0 through per-invocation bitmaps.

Add sparse Wave profiling and enforce the matching runtime and native ABI contracts.
Apply the routed backward dependency rules across policies. Whole-expert policies wait for all local dX before weight gradients. Token Wave prioritizes dA and dX while allowing ready weight gradients in gaps.
Clear Token Wave forward scratch in bounded route metadata and use device validation for shared expert preflight errors.

Allocate shared buffers on the caller stream after submitting metadata and reuse validated forward weight views within each invocation.
@forever-moe
forever-moe force-pushed the feat/megamoe-token-wave-integration branch from c325528 to d44048b Compare December 2, 2026 10:58
Use the merged input-list parameter when loading the quantization descriptor. The old parameter name prevents Ascend C compilation after the rebase.
@forever-moe forever-moe changed the title feat(megamoe): add MXFP8 Token Wave pipelines and sparse profiling feat(megamoe): add MXFP8 Token Wave and streamline device routing Dec 2, 2026
@davidhe91
davidhe91 merged commit def37a6 into davidhe91:megamoe-ascend950-integration Dec 2, 2026
1 check failed
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