Pull Request has been successfully merged by CANN-robot.
(Thank you for Sun's contribution.)变更摘要
本 PR 为 MoeGatingTopK 算子的 A2/A3 实现新增 norm_type 取值为 2(即 SqrtSoftPlus/softplus)的支持。核心改动包括:在 host 侧 moe_gating_top_k_tiling.cpp 与 kernel 侧 moe_gating_top_k_common.h 中统一新增常量 NORM_TYPE_SOFTPLUS = 2;在 CheckAttr() 中放开对 norm_type 取值的校验,并新增约束:当 norm_type 为 2 时 group_count 必须为 1;在无分组归一化实现 moe_gating_top_k_without_group.h 的 ComputeX() 中新增 sqrt(ln(exp(x) + 1)) 的计算分支,并在 SelectTopKExpertScore() 中将 softplus 与 sigmoid 一样视为恒做归一化的场景。
主要改动
- 新增
norm_type常量定义: 在moe_gating_top_k_tiling.cpp和moe_gating_top_k_common.h中分别加入NORM_TYPE_SOFTPLUS = 2,与既有的NORM_TYPE_SOFTMAX、NORM_TYPE_SIGMOID并列,供 tiling 与 kernel 两侧统一引用。 - 放宽并补充 tiling 属性校验:
MoeGatingTopKTilingBase::CheckAttr()允许norm_type取 0、1、2(错误提示相应更新为 "0, 1 or 2"),并新增OP_CHECK_IF校验:当norm_type为 2(softplus)时group_count必须为 1,否则报错返回GRAPH_FAILED。 - kernel 侧新增 sqrt softplus 归一化计算: 在
moe_gating_top_k_without_group.h的ComputeX()中把原有的数字字面量分支替换为具名常量判断,并为NORM_TYPE_SOFTPLUS增加 else 分支,通过Exp、Adds(+1)、Ln、Sqrt序列实现sqrt(ln(exp(x) + 1))。 - 归一化条件扩展至 softplus: 在
SelectTopKExpertScore()中,needRenorm的计算条件改为NORM_TYPE_SIGMOID || NORM_TYPE_SOFTPLUS恒为真,或NORM_TYPE_SOFTMAX && renorm_ == 1,使 softplus 路径与 sigmoid 一样固定执行归一化。 - 补充 tiling 单元测试: 在
test_moe_gating_top_k_tiling.cpp中新增moe_gating_top_k_tiling_succ_05_norm_type_softplus和moe_gating_top_k_tiling_succ_06_hash_norm_type_softplus两个用例,分别验证非 hash 与 hash 场景下norm_type=2的 tiling 数据、tilingKey(1 与 4)及 workspace 期望值。


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 | ✅ 宋恺, 於欣洁 (2/2) | ✅ 宋恺 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/approve


/approve


/lgtm


描述
为MoeGatingTopK算子的A2/A3实现补充支持SqrtSoftplus, 即norm_type=2。
normOut = sqrt(Softplus(x)) = sqrt(ln(exp(x) + 1))
增量性说明:
normType_ == 1/0改写为== NORM_TYPE_SIGMOID/SOFTMAX命名常量,数值相同,编译后等价关联的Issue
https://gitcode.com/cann/ops-transformer/issues/4870
测试
TTK测试norm_type=2已通过
文档更新
moe/moe_gating_top_k/README.md
moe/moe_gating_top_k/docs/aclnnMoeGatingTopK.md
moe/moe_gating_top_k/docs/aclnnMoeGatingTopKV2.md
类型标签