Skip to content

feat: make shared GMM and EP collectives traceable - #1267

Merged
yu-chen-code merged 1 commit into
mindspore-ai:masterfrom
yu-chen-code:feat-ep-gmm-primitives
Oct 26, 2026
Merged

yu-chen-code merged 1 commit into
mindspore-ai:masterfrom
yu-chen-code:feat-ep-gmm-primitives

Conversation

@yu-chen-code

@yu-chen-code yu-chen-code commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Paired: GitHub #1267 ↔ GitCode !1819

What type of PR is this?

/kind feature
/kind refactor

What does this PR do / why do we need it:

让基础同步 EP 的真实变长路由能够被捕获,同时沿用现有动态图的计算和参数布局。本 PR 提供 #1221 所需的公共 EP/GMM 能力,不包含编译器改动。

现有执行顺序保持为:模型 EP adapter 完成专家分片和 forward 绑定 → Router 产生专家编号与权重 → 按目标 rank/专家排序 token → 交换 counts 和 payload → 本地 GMM 专家计算 → 回传并按原 token 位置加权合并。

  • ep_exchange_counts:eager 继续使用同步 dist.all_to_all_single;捕获时记录 functional count A2A,并显式等待 counts 可读。
  • ep_split_sizes:eager 读取具体 split;捕获时从 counts 形成数据相关的符号长度,约束长度非负,并在已知发送行数时检查 split 总和。路由变化对应的收包长度仍由每次运行的 counts 决定。
  • ep_all_to_all:捕获时使用带 autograd 的 functional payload A2A,由消费者插入等待;eager 继续走原有后端分支。正常的变长 dispatch 只把 count 交换和 split 提取改为调用上述 helper。
  • grouped_matmul 和 SwiGLU 的 _get_npu_grouped_matmul 缓存 autograd wrapper 均保留。两者只在非 compile、numel 为 int 且等于零时使用零权重梯度;其他情况执行原生 split-K GMM,避免对数据相关形状做 Python 布尔判断。
  • 专家前向、输入梯度和权重梯度仍使用原生 NPU GMM,设备端 token counts 累积为 group list;不改成逐专家 linear,也不增加逐专家 split。V4.1 继续使用原有 clamped SwiGLU。
  • CPU 用例共用一套独立梯度参考校验两个 GMM wrapper,并校验通信/符号 split 契约;两项 NPU 用例分别在 FP32/BF16 下捕获两个 wrapper 的前反向图,重放不同专家负载。

本 PR 不修改 hyper_parallel/compile/ 或 EP 指南。ShapeEnv、图内运行约束、dense/EDP 分组及 GraphCompiler 接入由 #1221 完成。重计算和 EP overlap 本阶段不开发。

Which issue(s) this PR fixes:

Part of #1112;为 #1221 提供公共 EP/GMM 前置能力,不单独关闭整图 EP 总需求。

Test Plan and Test result:What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):

验证环境:Ascend 910B2,Python 3.12.13,PyTorch 2.9.1+cpu / torch_npu 2.9.1,CANN 9.3。以下为当前提交 b9350695 的本地验证结果。

  • python -m pytest -q tests/ut/core/expert_parallel tests/ut/auto_models/distributed tests/ut/components/functional/test_grouped_matmul.py:252 passed;生产代码增量覆盖率 29/29(100%)。独立 tests/安装包目录布局下的新增 GMM UT 也通过。
  • python -m pytest -q -s tests/torch/expert_parallel/test_grouped_matmul_graph.py:2 passed。两个 GMM wrapper 均保留 forward/dgrad/wgrad 三个原生节点;同图重放全零、单专家及混合负载,与 eager 逐张量零误差。
  • 动态图完整一层 DeepSeek V4.1:EP2、FP32/BF16,相同初始权重和输入,十次 SGD 更新、每次两次累积。相对冻结 master 原始 GMM/EP/adapter 的独立参考,loss、logits、全部梯度和更新参数均零误差。覆盖 learned Router、clamped SwiGLU、共享专家、attention/mHC 和 LM head/loss;mHC 两端使用仓库已有 Torch 回退。
  • 通用 packed SwiGLU:FP32/BF16 各十次更新、两次累积,覆盖零总 token、部分空专家和混合负载,输出、梯度及更新参数均零误差。
  • 动态图性能回归:同一完整一层 V4.1、BF16、EP2、序列 128、累积 2,三轮交错对照,每轮预热 10 步、测量 50 步,取每步最慢 rank。候选相对参考的均值耗时变化为 −4.53%、+1.33%、−0.14%,均满足原定不退化超过 3% 的标准;每轮 loss 一致,不据此宣称性能收益。
  • 仓内与服务端归档规则双配置 Pylint 无新增诊断,AGENTS catalog、diff 及执行源码快照核对通过。

上述结果对应当前代码;正式门禁请查看该提交的构建 1038,不沿用旧提交的通过结果。

Code review checklist [illustration]:

  • whether to verify the function's return value (It is forbidden to use void to mask the return values of security functions and self-developed functions. C++ STL functions can be masked if there is no problem)
  • Whether to comply with SOLID principle / Demeter's law
  • Whether there is UT test case && the test case is a valid (if there is no test case, please explain the reason)
  • Whether the API change is involved
  • Whether official document modification is involved

Special notes for your reviewers:

公共前置的审阅重点是:eager 通信和计算语义是否保持,以及同一 GMM 图能否处理专家负载从非零到全零的切换。这里不单独完成 GraphCompiler 接入。

动态 split 提取仍包含 CPU/host 读取;functional 节点可被 FX 捕获不等于训练 step 没有 host 同步,也不代表设备图编译后端已完成。与 #1221 的公共文件保持一致,后者在此基础上接入基础 EP 联合图训练。

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/check-pr

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1026 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 68%/62% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1026
coverage FAILURE 1026
UT_TEST FAILURE 1026

@yu-chen-code
yu-chen-code force-pushed the feat-ep-gmm-primitives branch 2 times, most recently from b111b4c to aff3f4d Compare October 21, 2026 18:23
@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/check-pr

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/check-pr

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1027 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 68%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- multicore 106.36075s 120.0s
- pipeline_parallel 788.892s 600.0s
- optimizer 325.281s 300.0s
- accuracy 117.788s 120.0s
- shard 199.576s 300.0s
- clip_grad 118.203s 120.0s
- tensor_parallel 259.404s 300.0s
- auto_models 111.214s 150.0s
- distributed_checkpoint 107.616s 120.0s
- context_parallel 74.561s 120.0s
- llama3_examples 107.288s 120.0s
- fully_shard 386.756s 600.0s
- swap_optimizer 284.238s 300.0s
- process_group 91.683s 90.0s
- activation_memory 109.33275s 120.0s
- expert_parallel 151.229s 120.0s
- dtensor 86.826s 120.0s
- init_weights 81.583s 118.75s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1027

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1028 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 68%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- fully_shard 405.555s 600.0s
- optimizer 351.983s 300.0s
- pipeline_parallel 723.247s 600.0s
- swap_optimizer 274.866s 300.0s
- shard 221.419s 300.0s
- clip_grad 142.783s 120.0s
- auto_models 148.13s 150.0s
- activation_memory 116.26087s 120.0s
- multicore 122.52212s 120.0s
- accuracy 95.05s 120.0s
- context_parallel 85.635s 120.0s
- dtensor 97.06s 120.0s
- expert_parallel 190.201s 120.0s
- process_group 102.195s 90.0s
- tensor_parallel 291.254s 300.0s
- llama3_examples 112.596s 120.0s
- init_weights 87.016s 118.75s
- distributed_checkpoint 92.898s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1038

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

Gate trigger failed: please fix the /check-pr findings and obtain the pr-check-pass label before retrying.

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/check-pr

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1050 is running. Please wait a moment... (Link)

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/check-pr

@yu-chen-code

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1056 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ✅ SUCCESS 68%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- activation_memory 122.38625s 120.0s
- shard 158.788s 300.0s
- pipeline_parallel 518.241s 600.0s
- auto_models 90.909s 150.0s
- multicore 104.65613s 120.0s
- swap_optimizer 216.647s 300.0s
- optimizer 224.182s 300.0s
- accuracy 76.838s 120.0s
- fully_shard 275.277s 600.0s
- context_parallel 69.387s 120.0s
- dtensor 66.727s 120.0s
- clip_grad 72.792s 120.0s
- init_weights 65.232s 118.75s
- tensor_parallel 202.511s 300.0s
- distributed_checkpoint 74.847s 120.0s
- expert_parallel 138.79s 120.0s
- llama3_examples 58.071s 120.0s
- process_group 57.922s 90.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ✅ SUCCESS 1056

@liuchongming74 liuchongming74 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants