Merged
feat(npu): add prepared L+B bindings and async communication APIs #20
&NewgateAdd on 23 days ago
feat(npu): add prepared L+B bindings and async communication APIs #20
Merged
Pull Request has been successfully merged by ascend-robot.
(Thank you for &Newgate's contribution.)23 days ago Added label: ascend-cla/no
23 days ago Added label: stat/needs-squash
ascend-robot
23 days ago Comments:
23 days ago Comments:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/MoonEP | ✅ weixin_49096267, gcw_CXpJWhGA (2/2) | ✅ weixin_49096267 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhangguobiao, thanks for your pull request. All authors of the commits have signed the CLA. 👍


80 messages are collapsed here。 See more
16 days ago Added label: approvedlgtm
16 days ago Merged pull request
ascend-robot
16 days ago Comments:
16 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
16 days ago Comments:
16 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
16 days ago Comments:
16 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


PR功能描述 / 为什么需要这个合入
为 MoonEP 增加“本地 L 个专家 + B 个 SHMEM 对称通信槽”的存储布局,并扩展对应的专家通信、zero-copy 存储和同步接口。调用方可以保留本地权重与梯度地址,预先准备通信存储,再按数据生命周期安排计算通信交叠。
主要改动:
CommBuffers和ExpertPointerBinding,在 setup 阶段准备通信视图、专家地址表及必要 workspace;bank 数量、调度和复用顺序由调用方管理。GradReduceTargets,从对称梯度槽读取贡献,通过地址表直接累加到本地 FP32 梯度 Tensor,保留原 dense 接口及归约、核内同步和清槽语义。num_sms参数;UDMA 保持原有调度。barrier_mode/ASCEND_MOONEP_BARRIER_MODE,在公共流上屏障入口选择 mixed 或单 AIV 实现,独立于 payload 后端,保留完整 barrier 的 quiet 与 team sync 语义。A5验证结果
使用脚本与运行方式
npu_patch/benchmarks/bench_comm.pydispatch_fwdnpu_patch/benchmarks/bench_comm.pycombine_fwdnpu_patch/benchmarks/bench_prefetch.pynpu_patch/benchmarks/bench_prefetch_push.pynpu_patch/benchmarks/bench_grad_reduce.pynpu_patch/benchmarks/bench_grad_reduce_targets.py在 27.1 A5 上以 EP8 独立启动,MTE、URMA 分开,各组按 A1 → B1 → B2 → A2 执行,每次预热 10 轮、计时 50 轮,关闭 cudagraph。各臂取两次独立启动结果的几何均值,耗时变化为
(B/A−1)×100%。以下时延单位均为 ms。Dispatch/Combine 历史实验
两项来自同一次
bench_comm.py运行,指定以下参数:实际形状为 S=8192、H=7168、K=8、E=48。Dispatch 前向计时包含 Planning;Combine 为 hidden 前向。计时沿原脚本的迭代平均、跨 rank 均值口径。
Prefetch/GradReduce 最新实验
GET、PUSH、dense、targets 使用以下共同主配置:
PUSH 另加
--barrier-mode mixed。实际外层通过torch.distributed.run+runpy执行仓内脚本,保留原计划、输入和计时函数。四个投影 benchmark 使用原
_bench_common.time_kernel(..., agg="max"):各 rank 对连续 50 次调用整体计时后除以 50,再取 rank 最大值。原接口 GET/GradReduce 回归:A 为目的分支
6fcf256,B 为 PR0f5be48;GET/PUSH、dense/targets 对照均固定在 PR0f5be48。各表使用各自完整 ABBA,不跨批拼接单臂。原接口:PR 对比目标分支
† Dispatch/Combine 本轮未重跑,保留 2026-11-16 的
f407f0b对6fcf256历史结果。其余四行使用 2026-11-19 完成的原接口 ABBA。Prefetch:旧 GET 对比新 PUSH
GradReduce:dense 对比 targets
* URMA 配置下 GET 实际仍启动 MTE kernel,PUSH 为 UDMA,因此该对照包含实际后端差异,不能将全部收益归因于 GET/PUSH 方向。
A3 验证结果
验证版本:
pr20 / 1542f994。环境:Ascend910_93、CANN 9.2.0、Python 3.12.15、torch/torch_npu 2.10.0。本轮使用 EP2/EP8。编译
npu_patch/scripts/build_a3.sh编译成功(rc=0);import npu_patch和from npu_patch import _C均通过。_C导出 29 个符号,两项 SHMEM 描述符 ABI 大小均为 64 字节。测试
既有套件
run_test.sh --soc_type Ascend910_93共执行 17 条命令,结果为 16 PASS / 1 FAIL。失败项为
test_buffer_grouped_e2e.py,报错为rank does not match the active CANN-SHMEM PE,涉及测试工具对子通信组的处理。在目标分支dev_npu上以相同错误签名复现,涉及测试工具将子组覆盖为 WORLD,不是本 PR 引入的回归。两版本全部 17 条命令的退出码一致。本 PR 新增、适用于 A3 的 4 个测试文件,在 EP2 和 EP8 下均通过:
buffer_test/test_buffer_comm_buffers.pybuffer_test/test_buffer_grad_reduce_targets.pybuffer_test/test_buffer_prefetch_push.pymte/test_grad_reduce_targets.pyBenchmark
使用 8 rank、
engine=ubmem,9 个 benchmark 脚本均完成运行;新增两个脚本修复运行问题后,各完成 14/14 case。bench_barrierbench_dispatch_maxviobench_prefetchbench_prefetch_push(新增)bench_grad_reducebench_grad_reduce_targets(新增)bench_grad_reduce_maxviobench_vsbench_vs_all2all上述耗时对应本次运行配置。GradReduce dense/targets 存在工作量配置差异,不用于计算接口间加速比;Prefetch 和 barrier 的跨轮次波动较大。
希望检视人员了解:
_C、rank/server kernel 库,不能混用旧构建产物。num_sms控制。目标分支原来固定使用 32 个 AIV 核,复现原有核数时应显式设置num_sms=32。