Pull Request has been successfully merged by CANN-robot.
(Thank you for zhang_xin_yu's contribution.)变更摘要
本 PR 针对 mc2/common/torch_extension/moe_distribute_buffer.py 中的 MoeDistributeBuffer 缓冲区核算逻辑,补充了 A5(Ascend950)平台非量化 scales 的窗口占用与 CCL buffer 核算。改动在原有 A3 参数上限的基础上按设备类型区分上限值,并在 Dispatch/Combine 的 token 尺寸计算中纳入 scales 数据长度与对齐规则。
主要改动
- 接口参数扩展:
MoeDistributeBuffer相关核算方法的入参新增scales_col与scales_type_size,用于将scales的列数与元素字节数纳入缓冲区估算。 - 设备差异化参数上限:新增基于
torch_npu.npu.get_device_name()判断是否含Ascend950的is_a5标识,并据此将world_size、num_moe_expert、local_moe_expert_num * world_size的上限分别放宽到 1024、2048、4096,非 A5 保持 768、1024、2048;相应torch._check校验与报错文案改为引用这些上限变量。 - Dispatch 侧 token 长度核算:在 A5 场景下新增
dispatch_token_bytes,按inline_align(token_align + scales_col * scales_type_size, ub_align) + 3 * 4 + 4计算,并与原token_actual_len取较大值,使scales占用被计入窗口需求。 - Combine 侧对齐规则调整:引入
combine_data_align(A5 取full_mesh_data_align,否则取win_addr_align),先按该对齐粒度对齐hidden * max_out_dtype_size,再折算为win_addr_align的整数倍,从而影响token_need_size_combine及最终minimum_buffer_size的估算。
🧩 本次 Review 已使用自定义 Skill:


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.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| */*/README.md | ✅ zzzzzzyf_, wang-minbo, 刘丹, macech (4/2) | ✅ zzzzzzyf_ (1/1) |
| */*/docs/acl*.md | ✅ zzzzzzyf_, wang-minbo, 刘丹, macech (4/2) | ✅ zzzzzzyf_ (1/1) |
| mc2 | ✅ 刘丹, macech, wang-minbo (3/2) | ✅ 刘丹, macech, wang-minbo (3/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhang_xin_yu, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/lgtm
/approve


The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


描述
关联的Issue
测试
文档更新
类型标签
PR #15295 全量代码检视报告
docs/mc2-a5-nonquant-scales-winb8c0ed98f(用户指定5b5719750,该提交已被 amend 为b8c0ed98f)origin/master一、结论
核心逻辑与 host 侧口径一致,未发现会导致 A5 窗口少算的功能性错误。主要剩余问题集中在测试覆盖、保守预留策略和文档同步,均不阻塞合入,但建议处理。
二、问题与建议
1. [P2] Python helper 新增逻辑没有单元测试
mc2/common/torch_extension/moe_distribute_buffer.pyget_device_name()的单测,覆盖 A3/A5、fullmesh_v1/v2、有无 scales、rank offset 边界。2. [P2] A5 所有场景都按 scales 最大值预留,量化场景会偏大
mc2/common/torch_extension/moe_distribute_buffer.py:153-160max_scale_bytes = hidden * 4对所有 A5 调用生效;host 侧只在NON_QUANT + scales时增加该占位。quant_mode/scales参数区分。3. [P3] 英文文档未同步
mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2_en.md、V3_en、V4_en,以及 combine V2/V3/V4 的_en.md。4. [P3][历史遗留] Dispatch V2 950 的
commAlg参数约束仍写不支持mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2.md:500fullmesh_v1/fullmesh_v2,但参数约束仍写“commAlg当前版本不支持”。49af78d0a(2026-02-03,MR !1234),不是本 PR 引入。5. [P3][文档清晰度] Combine 950 的 HCCL 公式使用了
commAlg,但参数约束写不支持mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV2.md、V3、V4 的 950 段。commAlg的 fullmesh_v1/v2 展开,但 combine 的commAlg参数约束写不支持。三、核对通过项
max_scale_bytes = hidden * 4,与 hostCalcA5DispatchTokenBytes的上界一致。fullmesh_v1用 512、fullmesh_v2用 480,与 hosttokenDataAlign一致。combineDataAlign一致。world_size * 1024,与 hostEP_RANK_OFFSET_STEP=1024一致。480Align512(2 * H)。_is_a5_device()已消除重复判定;注释与常量命名已整理。四、验证建议
fullmesh_v1/fullmesh_v2、NON_QUANT + scales、量化无 scales 三类场景。H=7168、较大world_size和local_moe_expert_num的边界组合,确认 rank offset 和 2MB 对齐没有少算。pre-commit run --files ...。