Merged
fix(ir): Disable check of valid-shape #4706
lidongshengAdd on Jul 7
fix(ir): Disable check of valid-shape #4706
Merged
lidongshengAdd on Jul 7
lidongsheng
lidongshengCollaborators
Jul 7

TypeEquasl should not based on valid-shape

Related Issue: #1185

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for lidongsheng's contribution.)
lidongshenglidongshengCollaborators
Jul 7 Created pull request, commit bcd887c9
lidongshenglidongshengCollaborators
Jul 7 Associated issue: [Requirement|需求建议]: 基于scf+token 的IR-1.3
atomgit-bot
atomgit-bot
Jul 7 Comments:

变更摘要

此 PR 主要做了两件事:一是修复 — 从 TypeEqual 函数中移除了对 dynValidShape_ 的比较逻辑,使类型相等判断不再依赖 valid-shape;二是扩展 — 为 ForStmt IR 节点新增了 attrs_ 通用属性字典,支持在循环语句上携带键值对元数据(如 parallel、submit_before_loop),并贯穿编译器各层(Python API、IRBuilder、各 Pass、Printer、Python 绑定)完成完整传播与打印。

主要改动

  • 移除 TypeEqual 中的 dynValidShape_ 比较: 在 framework/src/interface/tensor/logical_tensor.cpp 中删除了遍历 dynValidShape_ 逐维比较的循环体,TypeEqual 不再将 valid-shape 作为类型等价的判断依据。
  • ForStmt 新增 attrs_ 字段及 GetAttr/HasAttr 方法: framework/include/ir/stmt.h 中为 ForStmt 添加了 std::vector<std::pair<std::string, std::any>> attrs_ 成员与相应的模板化取值/存在性检测方法,构造函数签名同步增加该参数。
  • Python 端 loop API 重构: python/pypto/pil/ops.py 中 _pypto_loop 改为 batch, *args, **kwargs 签名以接收 parallel 和 submit_before_loop 控制参数;LoopRange 数据类新增 parallel 和 submit_before_loop 字段并在循环展开逻辑中通过 attrs 字典传递到 ForStmt。
  • 各 IR Pass 传递 attrs_: convert_to_ssa_pass、infer_token_pass、lower_break_continue_pass、merge_stmts_pass 四个 Pass 在重建 ForStmt 时均将原始节点的 op->attrs_ 转发到新构造的节点,确保属性不丢失。
  • IRBuilder / Python 绑定层与 Printer 适配 attrs: IRBuilder::CreateForStmt 及 Python 绑定(builder.cpp、ir.cpp)新增 attrs 参数,通过 ConvertAttrDict 完成 Python dict 到 C++ 属性列表的转换;printer.cpp 新增属性键值对的格式化输出逻辑,支持 int/double/bool/string 等常见类型。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 7 Comments:

代码审查

审查总结

审查结果

优先级 数量 说明
P0 0 无构建/编译/崩溃问题
P1 0 无运行时错误或安全风险
P2 1 _loop_unroll batch 模式下 varmap 宽度计算错误(step≠1 时触发)
P3 0 无

各文件确认

文件 审查结果
framework/include/ir/stmt.h ✅ 无问题 — 新增 attrs_ 字段、GetAttr/HasAttr 方法及反射描述符,实现正确
framework/src/interface/ir/transforms/convert_to_ssa_pass.cpp ✅ 无问题 — 透传 op->attrs_
framework/src/interface/ir/transforms/infer_token_pass.cpp ✅ 无问题 — 透传 op->attrs_
framework/src/interface/ir/transforms/lower_break_continue_pass.cpp ✅ 无问题 — 多处理传 attrs_
framework/src/interface/ir/transforms/merge_stmts_pass.cpp ✅ 无问题 — 多处理传 attrs_
framework/src/interface/ir/transforms/printer.cpp ✅ 无问题 — attrs 打印逻辑类型覆盖完整
framework/src/interface/tensor/irbuilder.cpp ✅ 无问题 — 正确使用 std::move
framework/src/interface/tensor/irbuilder.h ✅ 无问题 — 临时变量前缀 %→$ 且 attrs 参数有默认值
framework/src/interface/tensor/logical_tensor.cpp ✅ 无问题 — TypeEqual 移除 valid-shape 检查,符合 PR 目标
python/pypto/pil/ops.py ⚠️ 1 个 P2 问题 — _loop_unroll batch 宽度错误
python/pypto/pil/pir.py ✅ 无问题 — LoopRange 新增 parallel/submit_before_loop 字段
python/pypto/pypto_impl/ir.pyi ✅ 无问题 — 类型桩更新与 C++ 实现一致
python/src/bindings/ir/builder.cpp ✅ 无问题 — lambda 封装正确调用 ConvertAttrDict
python/src/bindings/ir/ir.cpp ✅ 无问题 — py::isinstance<bool>→py::isinstance<py::bool_> 是正确的 bool/int 区分修复
python/tests/ut/ir/test_ir.py ✅ 无问题 — 测试 attrs 打印输出

整体风险评估

中等。虽然只有一个 P2 问题,但该问题涉及 IR 生成正确性:当 pypto.loop_unroll 使用非单位步长(step ≠ 1)时,循环体中的批次元素计数会被错误放大,可能导致生成错误的张量操作(越界访问或处理多余元素)。当前所有测试均使用 step=1,故未被发现。修复简单(将 loop.step * factor 改为 factor),风险可控。其余变更(ForStmt attrs 支持、TypeEqual 简化、ConvertAttr bool 修复)实现正确。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 7 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Jul 7 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 7 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


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/pypto ✅ 尹杰, DCGDDD (2/2) ✅ 尹杰 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Jul 7 Set xinweiliu,cam_bxh,dai-zhentao,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,gaoxingwang,zhiweiyuan,zhoubotcam,linjiashu,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Jul 7 Set xinweiliu,cam_bxh,dai-zhentao,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,gaoxingwang,zhiweiyuan,zhoubotcam,linjiashu,WenboCodes as approver
atomgit-bot
atomgit-botJul 7Start code review1
python/src/bindings/ir/builder.cpp
@@ -513,2 +525,2 @@
513- "create_while_stmt", &IRBuilder::CreateWhileStmt, py::arg("cond"), py::arg("iterArgs"), py::arg("body"),
514- py::arg("returnVars"), py::arg("span"),
525+ "create_while_stmt", &IRBuilder::CreateWhileStmt, py::arg("cond"), py::arg("iter_args"), py::arg("body"),
526+ py::arg("return_vars"), py::arg("span"),
atomgit-bot
atomgit-botJul 7Comments:

🟡 Medium Priority

在 builder.cpp 中,create_for_stmt 和 create_while_stmt 的 Python 绑定关键字参数名从驼峰命名(loopVar、iterArgs、returnVars)改为蛇形命名(loop_var、iter_args、return_vars)。

任何使用关键字参数调用这些方法的现有 Python 代码都将因参数名不匹配而抛出 TypeError。PR 描述中未提及此重命名,且它不属于添加 attrs 功能的一部分。

建议:如果是有意做出的破坏性变更,请在 PR 描述或 CHANGELOG 中记录它。或者,恢复原来的关键字参数名以保持向后兼容。蛇形命名对齐可以单独在一个专注于重命名的 PR 中完成。

likedislike
Incorrect?
lidongshenglidongshengCollaborators
Jul 8 Pre merge succeeded (commit_id: 6962e462108dc7d8f543b8e6af7b6b234b1fdbdb)
lidongshenglidongshengCollaborators
Jul 8 Pushed 2 commits:0d5a36fc-fix(ir): Remove redundant span field in Operation,485f4bf0-fix(ir): Fix span not correct
lidongshenglidongshengCollaborators
Jul 8 Pre merge succeeded (commit_id: 697f05b9e4df1acee206efb3bb7e4fc45e6063ba)
lidongsheng
lidongshengCollaborators
Jul 8 Comments:

compile

likedislike
lidongshenglidongshengCollaborators
Jul 8 Pre merge succeeded (commit_id: 5cc2e6225696c965616d7c031830d109a206ac90)
CANN-robotCANN-robotCollaborators
Jul 8 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [9ae4e7e49e844450a9db870ace0122db][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
UT_Test_Py3_ninja_simulation ✅ SUCCESS
UT_Test_Py3_ninja ✅ SUCCESS
UT_Test_Cpp_make_clang ✅ SUCCESS
UT_Test_Cpp_make_gnu ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_1 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_2 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_3 ✅ SUCCESS
UT_Test_report ✅ SUCCESS >>>>>
PreSmoke_A900 ✅ SUCCESS >>>>>

[2026-07-08 10:33:16]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [94c855acf88b4761846554ff341e82a8][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ❌ FAILED >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>
likedislike
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [ac1270455dbb4edaa364372eba4fe211][流水线指导]

任务名称状态日志下载链接
get_pr_file ✅ SUCCESS
static-check ❌ FAILED
compile ✅ SUCCESS
likedislike
CANN-robotCANN-robotCollaborators
Jul 8 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Jul 8 Added label: ci-pipeline-failed
lidongsheng
lidongshengCollaborators
Jul 8 Comments:

compile

likedislike
lidongshenglidongshengCollaborators
Jul 8 Pre merge succeeded (commit_id: 5d03df6a00a46a94207d8a3b6da6036e75cc362f)
CANN-robotCANN-robotCollaborators
Jul 8 Removed label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
Jul 8 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [7ce06a2108b044bf9e6e61e4f19addba][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
UT_Test_Py3_ninja_simulation ✅ SUCCESS
UT_Test_Py3_ninja ✅ SUCCESS
UT_Test_Cpp_make_clang ✅ SUCCESS
UT_Test_Cpp_make_gnu ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_1 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_2 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_3 ✅ SUCCESS
UT_Test_report ✅ SUCCESS >>>>>
PreSmoke_A900 ✅ SUCCESS >>>>>

[2026-07-08 11:46:44]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [cd274e1c23a24aaf8f6824f4c1324e2a][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-07-08 11:17:15]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Jul 8 Comments:

流水线任务触发成功
任务链接 [2ccb9f9e529a47ecb4fc5498a929e1c9][流水线指导]

任务名称状态日志下载链接
get_pr_file ✅ SUCCESS
static-check ✅ SUCCESS
compile ✅ SUCCESS

[2026-07-08 11:47:22]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Jul 8 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Jul 8 Added label: ci-pipeline-passed
杨旭
杨旭Collaborators
Jul 8 Comments:

/lgtm

likedislike
Jie Yin
Jie YinCollaborators
Jul 8 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 8 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Jul 8 Resolved final issue
CANN-robotCANN-robotCollaborators
Jul 8 Merged pull request