Pull Request已成功合入, 合并人@CANN-robot
(感谢 lidongsheng 的贡献)变更摘要
此 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完成 Pythondict到 C++ 属性列表的转换;printer.cpp新增属性键值对的格式化输出逻辑,支持int/double/bool/string等常见类型。


代码审查
审查总结
审查结果
| 优先级 | 数量 | 说明 |
|---|---|---|
| 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 |
💬 仅评论


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


🟡 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 中完成。


compile


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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 | >>>>> | >>>>> |


流水线任务触发成功
任务链接 [ac1270455dbb4edaa364372eba4fe211][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| get_pr_file | ✅ SUCCESS | ||
| static-check | ❌ FAILED | ||
| compile | ✅ SUCCESS |


compile


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [2ccb9f9e529a47ecb4fc5498a929e1c9][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| get_pr_file | ✅ SUCCESS | ||
| static-check | ✅ SUCCESS | ||
| compile | ✅ SUCCESS |
[2026-07-08 11:47:22] CI执行结束


/lgtm


/approve


TypeEquasl should not based on valid-shape
Related Issue: #1185