Merged
fix(moe): 加固 MoeTokenUnpermuteWithEp Tiling/InferShape 输入校验 #15936
fix(moe): 加固 MoeTokenUnpermuteWithEp Tiling/InferShape 输入校验 #15936
Merged
gylAdd on 15 days ago
gyl
gylCollaborators
15 days ago

描述

加固 MoeTokenUnpermuteWithEp 的 Host 侧输入校验与形状推导,避免非法输入静默成功或产生错误 tiling:

  • InferShape:补充 num_topk 范围 [1, 512]、permuted_tokens 2D 且非空、sorted_indices 1D 且非空、probs 2D 且非空、输出 shape 非空等校验;probs 缺省时输出 dim0 由 len(sorted_indices) / num_topk 推导,与 Tiling/文档保持一致。
  • Tiling:补充 dtype 门禁(permuted_tokens/probs 仅 float32/float16/bfloat16,sorted_indices 仅 int32)、padded_mode 仅支持 false、restore_shape 必须为空、num_topk 上界 512、range 合法性(0 <= start <= end 且跨度不超过 permuted_tokens 第 0 维)、输出 shape 一致性、platform/UB/AIV/UB 容量与 tiling 长度非零等校验;非法输入统一返回 GRAPH_FAILED。
  • 文档:更新中英文接口文档与 README 的计算公式、range 语义、参数类型与约束说明。
  • 测试:新增独立 Torch Golden tests/assets/moe_token_unpermute_with_ep.py,并同步更新 UT 期望(非法 dtype/未知 dtype 改为期望 GRAPH_FAILED,probs 缺省空 range 的 InferShape 输出改为 {1, 2})。

关联的Issue

测试

  • 已同步更新 op_host UT 期望用例。
  • 未在本次提交流程中重新执行编译与 UT;issue 记录的修复后验证结果:L0 合法 63/63 PASS、L1 随机 200 中合法 181/181 PASS、L2 22 个非法输入均被正确拒绝。

文档更新

  • 更新 README.md、docs/aclnnMoeTokenUnpermuteWithEp.md、docs/aclnnMoeTokenUnpermuteWithEp_en.md。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for gyl's contribution.)
gylgylCollaborators
15 days ago Created pull request, commit 76f8d175
gylgylCollaborators
15 days ago Associated issue: [Bug-Report|缺陷反馈]: 长尾算子质量加固-/MoeTokenUnpermuteWithEp
CANN-robot
CANN-robotCollaborators
15 days ago Comments:

Hi @guyunlong1, welcome to submitting your first PR to CANN!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.
%!(EXTRA string=https://atomgit.com/cann/community/blob/master/en/sig-infrastructure/command.md)

likedislike
atomgit-bot
atomgit-bot
15 days ago Comments:

变更摘要

本 PR 针对 MoeTokenUnpermuteWithEp 算子加固 Host 侧输入校验与形状推导:InferShapeForMoeTokenUnpermuteWithEp 与 MoeTokenUnpermuteWithEpInputParamCheck、Init、TilingHiddenSize、TilingToken、SetTilingKey 等环节补充了属性、dtype、维度、range 及平台资源的合法性检查,非法输入统一返回 GRAPH_FAILED,避免静默成功或产生错误 tiling;同时新增独立的 Torch 参考实现并同步更新 UT 期望与文档。

主要改动

  • InferShape 输入校验增强: InferShapeForMoeTokenUnpermuteWithEp 新增 num_topk 范围 [1, 512]、permuted_tokens/probs 必须为 2D 且非空、sorted_indices 必须为 1D 且非空、attrs/out_shape 空指针等校验,probs 缺省时输出 dim0 改为 len(sorted_indices) / num_topk 推导(未知维保持 -1)。
  • Tiling dtype 与属性门禁: 新增 IsSupportedFloatDtype、DtypeStr、CheckDtypes,限制 permuted_tokens/probs 仅支持 float32/float16/bfloat16、sorted_indices 仅支持 int32;padded_mode 仅支持 false,restore_shape 必须为空(识别空列表与单元素 0 的等价形式),num_topk 上界改为 MAX_NUM_TOPK。
  • range 与形状一致性校验: Init 中 range 空时按默认值处理,并校验 0 <= start <= end、跨度不超过 permuted_tokens 第 0 维;同时校验输出 shape 的 dim0/dim1 与 num_tokens、hidden_size 一致,sorted_indices 长度须为 num_topk 的正整数倍。
  • Tiling 流程返回状态化: Init、TilingHiddenSize、TilingToken、SetTilingKey 由 void 改为返回 ge::graphStatus,新增 platform、AIV 核数、UB 容量、tiling 长度非零等检查,UnpermuteWithEpTilingCompute 逐级短路返回 GRAPH_FAILED;未知 probs dtype 也不再静默继续。
  • 测试与文档同步: 新增 tests/assets/moe_token_unpermute_with_ep.py 作为独立 Torch Golden(同时注册 kernel 与 ACLNN 两条路径、空 range 视为 {0, 0} 输出全零),UT 中非法/未知 dtype 用例改为期望 GRAPH_FAILED、test_infershape_prob_none_empty_range 期望输出改为 {1, 2},并更新 README.md 及中英文接口文档的公式与参数约束说明。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
15 days ago Added label: cann-cla/yes
121 messages are collapsed here。 See more
gyl
gylCollaborators
12 days ago Comments:
likedislike
mabing
mabingCollaborators
11 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
11 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
11 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
11 days ago Merged pull request