Merged
fix(operation): Add viewshape check for GatherMask last axis #5626
fix(operation): Add viewshape check for GatherMask last axis #5626
Merged
Wang XuAdd on Aug 24
Wang Xu
Wang Xu
Aug 24

为 GatherMask 动态场景的最后一个轴添加viewshape不可切分约束检查

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Wang Xu's contribution.)
Wang XuWang Xu
Aug 24 Created pull request, commit f4af1bdb
atomgit-bot
atomgit-bot
Aug 24 Comments:

变更摘要

该 PR 为 GatherMask 操作增加了"最后一维不允许被 View 拆分"的约束校验:当 patternMode 处于 1~6 时,若输入张量的最后一维经 View 拆分后变小,则在编译/执行阶段直接报错,避免生成错误结果。改动同时覆盖 C++ 后端、pypto Python 前端以及单元/系统测试。

主要改动

  • View 记录原始形状属性(framework/src/interface/operation/operation_impl.cpp):在 View 的三条实现路径中,为结果存储写入 ORIGINAL_SHAPE 属性,并在操作数存在动态有效形状时写入 ORIGINAL_DYN_VALID_SHAPE,供后续校验使用。
  • 后端执行期校验(framework/src/interface/operation/vector/indexing.cpp):在 GatherMaskBuildInOperationTileFunc 中,当 patternMode 为 1~6 时读取 ORIGINAL_SHAPE,若 viewShape 最后一维小于原始最后一维,则通过 CHECK 抛出 ERR_PARAM_INVALID 错误,提示 "GatherMask requires the last axis of self.shape not to be split by view"。
  • pypto 前端跟踪 View 与校验(python/pypto/operation.py、python/pypto/op/indexing.py、python/pypto/frontend/parser/entry.py):view 通过 _view_original_shapes、_view_input_ids、_view_input_names 记录视图的原始形状及输入张量信息;gathermask 在 pattern_mode 为 1~6 时将校验信息追加到 _gathermask_checks;JitCallableWrapper 新增 _check_gathermask_view_constraint,在编译时用实际张量形状核对,若 viewshape_last 小于实际最后一维则抛出 FeError。
  • 单元测试补充(framework/tests/ut/operator/src/test_operation_impl.cpp):新增 4 个用例,覆盖 2D/4D 张量经 View 拆分最后一维后调用 GatherMask 期望抛错(含 mode 3 场景),以及 View 与输入形状相同时正常通过的场景。
  • ST 测试与 golden 适配(framework/tests/st/operation/src/test_gathermask_operation.cpp、framework/tests/st/operation/python/vector_operator_golden.py):ST 参数化用例补充单次切分执行函数;golden 生成逻辑对 uint16/uint32 输入先转 int16/int32 参与 torch 计算,再转回原始 dtype 输出,避免无符号整型运算出错。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 24 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 24 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 24 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
repo-cann/pypto ✅ ym-HW, DCGDDD (2/2) ✅ ym-HW (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
55 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 24 Added label: ci-pipeline-passed
杨旭
杨旭Collaborators
Aug 25 Comments:

/lgtm

likedislike
yumeng_27
yumeng_27Collaborators
Aug 25 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 25 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Aug 25 Merged pull request