Merged
MoeInitRoutingV3 支持 expertIdx=-1(无效专家) #9708
MoeInitRoutingV3 支持 expertIdx=-1(无效专家) #9708
Merged
tujun6Add on Aug 6
tujun6
tujun6Collaborators
Aug 6

描述

MoeInitRoutingV3 算子支持 expertIdx = -1(无效专家)特性:-1 表示该位置不参与路由,算子正确过滤 -1,不影响有效专家的排序、gather 和统计结果。

核心修改(kernel 侧)

  1. 4 个 SIMT 函数补充 < expertStart 下界守卫(moe_v3_full_load_base.h、moe_v3_expert_tokens_count.h):避免排序后末尾无效元素溢出为负值导致越界写。
  2. CopyOutRowIdx 无效位置显式填充 -1(moe_v3_full_load_base.h):确保 rowIdxType 为 0 时无效数据由 -1 填充,符合 README 约定。

测试

  1. expertIdx=-1 专项测试用例(32 条,新 TTK 框架 kernel 模式):覆盖 -1 比例(0%/10%/50%/100%)、量化模式(-1/1/2/3)、gather/scatter、bf16/fp16/fp32、cumsum/count/key_value、全载/非全载、DropPad、边界场景(-1 恰小于 expertStart、全在 range 外、K=1/K=64)。
  2. UT 用例:3 个含 -1 的用例(gen_data.py 支持生成 -1 数据)。

文档更新

  1. README 和 aclnnMoeInitRoutingV3.md 补充 expertIdx=-1 无效专家语义说明。

关联的Issue

关联 Issue #4615:https://gitcode.com/cann/ops-transformer/issues/4615

测试

  • 功能验证:含 -1 的输入经 kernel 模式执行,与 golden 对比通过。
  • 专项用例覆盖各类 -1 比例与算子场景组合。
  • UT:3 个含 -1 的 UT 用例 + 存量 UT 回归。

文档更新

  • README.md:expertIdx 参数及 availableIdxNum 公式补充 -1 语义。
  • docs/aclnnMoeInitRoutingV3.md:expertIdx 参数及 availableIdxNum 公式补充 -1 语义。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for tujun6's contribution.)
tujun6tujun6Collaborators
Aug 6 Created pull request, commit f79ee5b6
CANN-robotCANN-robotCollaborators
Aug 6 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 6 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.
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 ✅ 蔡雯雯, 杜慧萍 (2/2) ✅ 蔡雯雯 (1/1)
*/*/docs/acl*.md ✅ 蔡雯雯, 杜慧萍 (2/2) ✅ 蔡雯雯 (1/1)
moe ✅ cpy_123456, guoqiuhao (2/2) ✅ cpy_123456 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

tujun6, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Aug 6 Set cpy_123456,juyangokok,monologue815,chen-linxin4,yu-xinjie62,jiang-lirui,Allan_Yu,songkai111,liudan12,cc-z,mabing1118,guoqiuhao as approver
CANN-robotCANN-robotCollaborators
Aug 6 Set cpy_123456,juyangokok,monologue815,chen-linxin4,yu-xinjie62,jiang-lirui,Allan_Yu,songkai111,liudan12,cc-z,mabing1118,guoqiuhao as approver
220 messages are collapsed here。 See more
gitee-duhuiping
gitee-duhuipingCollaborators
Aug 27 Comments:

/lgtm

likedislike
Guoqh
GuoqhCollaborators
Aug 27 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 27 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 27 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 27 Merged pull request