Pull Request has been successfully merged by CANN-robot.
(Thank you for luobq's contribution.)变更摘要
本次 PR 为 MegaMoE 内核新增逐 expert 权重 TensorList 布局支持。原有实现将多个 expert 的权重堆叠在单个 3D/4D tensor 中(TensorList 长度为 1),现同时兼容每个 expert 独立一个 2D/3D tensor 的逐 expert 布局(TensorList 长度等于 expert 数)。tiling 阶段通过权重张量维数自动识别布局,kernel 阶段通过新增的 GetExpertWeightAddr 辅助函数统一解析地址,MoE 与 shared expert 的四组权重输入(weight1/weightScales1/weight2/weightScales2)均已适配。
主要改动
-
新增
ExpertWeightTensorListAddrs结构与GetExpertWeightAddr辅助函数:在mega_moe_base.h中定义结构体保存四组权重的 TensorList 入口地址,通过GetExpertWeightAddr根据isPerExpertWeightTensor标志决定是按 expert 下标直接取 tensor 地址(新布局),还是取TensorList[0]后叠加元素偏移量(旧布局)。 -
MegaMoeTilingData新增isPerExpertWeightTensor字段:tiling 阶段根据 weight 张量维数(2D 为逐 expert,3D 为堆叠)判定布局,结果通过该字段下发到 kernel,MoE 与 shared expert 共用同一布局标志。 -
MegaMoe与MegaMoeWave的UpdateGlobalBuffer和UpdateSharedGlobalBuffer签名变更:两个函数新增expertIdx/sharedExpertIdx参数,内部将对params_.bGmAddr等成员的直接偏移替换为调用GetExpertWeightAddr,实现布局透明的权重地址解析。 -
Init 阶段改为保存原始 TensorList 地址:
MegaMoe::Init和MegaMoeWave::Init不再在初始化时提前解析TensorList[0]存入params_,改为将四组权重 TensorList 地址存入moeWeightTensorListAddrs_和sharedWeightTensorListAddrs_成员变量。 -
调用点适配:所有
UpdateGlobalBuffer和UpdateSharedGlobalBuffer的调用点(如Process、ProcessGmm1Wave、ProcessGmm2Wave、ProcessCombineExperts、ProcessSharedExpertGmm1、ProcessSharedExpertGmm2等)均新增传递当前 expert 或 shared expert 下标。


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| mc2 | ✅ yangzeheng, macech (2/2) | ✅ yangzeheng (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
luobaiqing, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/compile


流水线任务触发成功
任务链接 [40c87c65b63c4506aac51fb0ce100ca4][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-transformer | ✅ SUCCESS | ||
| UT_Test_harmony-infer-cpro-transformer | ✅ SUCCESS | ||
| UT_Test_report_lcov | ⚠️ WARNING | >>>>> |
[2026-08-03 21:12:55] CI执行结束


流水线任务触发成功
任务链接 [aba3e2822dbb45fb9e738016eebd90af][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ❌ FAILED | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_style | ✅ SUCCESS | >>>>> | |
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_checkpr | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |


为什么要放到这个位置?


/compile


流水线任务触发成功
任务链接 [b69c24d2174547438526eb3b28ff27c2][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-transformer | ✅ SUCCESS | ||
| UT_Test_harmony-infer-cpro-transformer | ✅ SUCCESS | ||
| UT_Test_report_lcov | ⚠️ WARNING | >>>>> |
[2026-08-04 09:30:41] CI执行结束


流水线任务触发成功
任务链接 [953da6ed00074ce0885d28f82de6d92e][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_style | ✅ SUCCESS | >>>>> | |
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_checkpr | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-08-04 09:16:28] CI执行结束


/approve


/lgtm


描述
背景
原来 MoE 权重以单元素 TensorList 承载三维/四维堆叠 tensor(weight 为 3D、scale 为 4D),不符合逐 expert TensorList 的常规表达方式。本 PR 在保持旧堆叠布局完全兼容的同时,新增逐 expert weight tensor 布局支持。
改动内容
1. 支持两种兼容布局
2. Tiling 改动(
mega_moe_tiling.cpp/mega_moe_tiling.h)isPerExpertWeightTensortiling 字段,随MegaMoeTilingData下发到 Kernel。3. Kernel 改动(
mega_moe.h/mega_moe_wave.h)MegaMoe与MegaMoeWave保存原始 TensorList 地址(不再在 Init 阶段提前解析TensorList[0]);TensorList[0]后叠加累计元素 offset;TensorList[expertIdx],不叠加专家间 offset。4. 输入适配范围
weight1 / weightScales1 / weight2 / weightScales2均已适配;5. 公共能力收敛(
mega_moe_base.h)ExpertWeightTensorListAddrs结构体与模板函数GetExpertWeightAddr<ElementType>收敛到mega_moe_base.h,避免普通路径与 Wave 路径重复实现。6. 兼容性
mega_moe_layered.h,layered 路径不在本 PR 支持范围。7. 建议后续用例覆盖
关联的Issue
无
测试
git diff --check均已通过;文档更新
无
类型标签