已合并
【inductor】bugfix for noinear codegen, sync from pr39111 #39768
【inductor】bugfix for noinear codegen, sync from pr39111 #39768
已合并
stonexxx创建于 7月1日
stonexxx
stonexxx
7月1日

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

【修改方案】

https://gitcode.com/Ascend/pytorch/issues/2571

【资料变更】

请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

【接口变更】

请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

【功能验证】

说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤
新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 stonexxx 的贡献)
stonexxxstonexxx
7月1日 创建了 pull request,commit 76952d49
ascend-robotascend-robot成员
7月1日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
7月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
test crazyDannyBoy, TonyYA (2/2) crazyDannyBoy (1/1)
torch_npu/_inductor crazyDannyBoy, TonyYA (2/2) crazyDannyBoy (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
ascend-robotascend-robot成员
7月1日 添加了label:needs-issue
ascend-robot
ascend-robot成员
7月1日 评论:

Linking Issue Notice

@stonexxx , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .

likedislike
ascend-robot
ascend-robot成员
7月1日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.9.0
v2.10.0
v2.7.1
v2.11.0
v2.12.0
v2.7.1-26.1.0
v2.9.0-26.1.0
v2.11.0-26.1.0
v2.10.0-26.1.0
v2.12.0-26.1.0
ci-test
sync-pr28113--to-v2.9.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robotascend-robot成员
7月1日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
7月1日 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
7月1日 添加了label:docs-ci-pipeline-running
stonexxxstonexxx
7月1日 修改标题为 “【inductor】bugfix for noinear codegen, sync from pr39111”,原标题为“bugfix for noinear codegen, sync from pr39111”
ascend-robot
ascend-robot成员
7月1日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
7月1日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
7月1日 添加了label:docs-ci-pipeline-success
atomgit-bot
atomgit-bot
7月1日 评论:

变更摘要

此 PR 修复了 Ascend 线性代码生成(linear codegen)中 no_linear 模式相关的多个问题,主要纠正了 inductor_ascend_linear_mode 配置值与内核类型、调度策略之间的映射关系,改进了 TTIR 测试配置的选择逻辑,并调整了编译选项和日志行为。

主要改动

  • NPUNoLinearTritonScheduling 默认内核类型与条件反转:将默认 kernel_typeNPUTritonKernelWithLoop 改为 NPUTritonKernel,同时将触发 NPUTritonKernelWithLoop 的条件由 'no_linear' 改为 'no_linear_loop',使 no_linear 模式使用无循环内核、no_linear_loop 模式使用带循环内核。

  • NPUTritonKernel 中 linear 回退目标修正:当 inductor_ascend_linear_mode == "linear" 时,回退写入的 inductor_meta 值从 "no_linear_loop" 改为 "no_linear";同时 npu_kernel_type 由硬编码字符串 "simt_only" 改为 NPUKernelType.SIMD_SIMT_MIX 的字符串形式。

  • 新增 _select_ttir_test_config 方法:在 NPUCachingAutotuner 中新增该方法,从所有配置中选择 SUB tiling 乘积最小的配置作为 TTIR 测试配置(替代原来直接取 self.configs[0]),以降低编译开销。

  • no_linear 模式启用 enable_auto_blockify:在 NPUCachingAutotuner 的编译选项设置中,当 inductor_ascend_linear_mode == "no_linear" 时,自动设置 options['enable_auto_blockify'] = True

  • 移除 SIMD 内核类型的 tile 配置生成:在 triton_config_npu_index 中删除了 NPUKernelType.SIMD 对应的 descend_split_tiling() 调用;同时在 no_linear 模式下处理 tiling 参数时,改为从 kwargs 中弹出原始 _SUB 后缀键(pop)而非仅添加新键,避免重复键残留。

likedislike
atomgit-bot
atomgit-bot
7月1日 评论:

代码审查

I've completed my thorough review. Let me provide the closing summary.


审查总结

已审查全部 5 个变更文件:

文件 状态
test/_inductor/test_exceptions.py 无问题(仅测试 meta 新增 inductor_ascend_linear_mode: 'linear',匹配内核的 SUB tiling 模式)
torch_npu/_inductor/codegen/npu_combined_scheduling.py 发现问题 P2:日志级别从 ERROR 降为 DEBUG
torch_npu/_inductor/codegen/scheduling.py 无问题(NPUNoLinearTritonScheduling 的 kernel_type 默认值/条件交换与整体 bugfix 方向一致)
torch_npu/_inductor/codegen/triton.py 发现问题 P3:注释与代码不一致
torch_npu/_inductor/runtime/triton_heuristics.py 无问题(新增 _select_ttir_test_configenable_auto_blockify、移除 SIMD 配置生成、pop SUB key 均为功能性改动,逻辑自洽)

问题统计:P2 × 1,P3 × 1

整体风险评估:此变更是一个有意的行为修正(bugfix),核心逻辑变更(mode 字符串从 no_linear_loopno_linear,kernel_type 默认值交换,npu_kernel_type 从 simt_onlysimd_simt_mix)在多处保持一致性。主要风险在于 linear codegen 失败时的 fallback 路径现在完全静默(日志降级为 DEBUG),可能导致生产环境中问题难以排查。建议将日志级别至少恢复为 log.warning

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

💬 仅评论

likedislike
atomgit-bot
atomgit-bot7月1日进行代码检视1
torch_npu/_inductor/codegen/npu_combined_scheduling.py
@@ -94,3 +94,4 @@
9494 "linear codegen for node %s raise error, fallback to origin codegen",
9595 node,
96+ exc_info=True,
9697 )
atomgit-bot
atomgit-bot7月1日评论:

🟡 Medium Priority

变更行:npu_combined_scheduling.py 第92-97行。原代码在 linear codegen 失败时使用 log.exception(...) 记录异常(ERROR 级别,自动附带 traceback),新代码改为 log.debug(..., exc_info=True)(DEBUG 级别)。

影响:当用户配置 inductor_ascend_linear_mode = "linear"(也是默认值)且 linear codegen 因任何原因失败时,原代码会在默认日志级别(WARNING)下输出完整的异常信息,开发者可以感知到 fallback 的发生。新代码将日志降级为 DEBUG,在生产环境的默认日志级别下,这些 fallback 完全不可见。如果 linear codegen 存在持续性问题(如某个算子始终无法走 linear 路径),故障排查将变得更加困难——异常被静默吞掉,只留下 fallback 行为生效,开发者可能完全不知道 linear codegen 已经失败了。

虽然 fallback 本身是预期行为(注释写 "fallback to origin codegen"),但用 DEBUG 级别记录异常会丢失可观测性。建议至少使用 log.warninglog.info,或者在降级的同时增加一个 counter/metrics 来统计 fallback 次数,便于运维监控。

建议:将 log.debug 至少提升为 log.warninglog.info,确保 linear codegen 的静默 fallback 在默认日志级别下可被观测。或者保持 debug 但额外增加一个 metric/counter 来记录 fallback 次数。

likedislike
stonexxxstonexxx
7月1日 修改了pull request 的描述
此处折叠了16条事件消息 查看更多
ascend-robotascend-robot成员
7月2日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
7月2日 评论:
流水线 PR-pipeline_pytorch#40440 (重试第3次) [ commitID:11d5f412 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_LibTorch_x86 >>>
Build_LibTorch_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
check_error >>>
CodeCheck_lintrunner >>>
开源片段检查 SCA >>>
开发者测试 UT_X86_Part_01 🛑 >>>
UT_X86_Part_02 🛑 >>>
UT_ARM_A3_Part_01 🛑 >>>
UT_ARM_A3_Part_02 🛑 >>>
UT_ARM_A2_Part_01 >>>
UT_ARM_A2_Part_02 >>>
UT_ARM_A2_Part_03 >>>
UT_inductor_Part_01 >>>
UT_inductor_Part_02 >>>
UT_inductor_Part_03 >>>
UT_inductor_Part_04 >>>
UT_DIST_ARM_Part_01 🛑 >>>
UT_DIST_ARM_Part_02 🛑 >>>
UT_DIST_ARM_Part_03 🛑 >>>
UT_DIST_ARM_Part_04 🛑 >>>
UT_ARM_A2_Select_Part_01 >>>
UT_ARM_A2_Select_Part_02 >>>
流水线 PR-pipeline_pytorch >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
pangjiayi
pangjiayi
7月2日 评论:

/lgtm

likedislike
zhucehw
7月2日 评论:

/lgtm

likedislike
ascend-robot
ascend-robot成员
7月2日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
zhucehw

likedislike
dezheng889成员
7月2日 评论:

/lgtm
/approve

likedislike
ascend-robot
ascend-robot成员
7月2日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
zhucehw

likedislike
ascend-robotascend-robot成员
7月2日 添加了label:approvedlgtm
ascend-robotascend-robot成员
7月2日 解决了最后一个问题
ascend-robotascend-robot成员
7月2日 合入了pull request
ascend-robot
ascend-robot成员
7月2日 评论:

The MR is merging by another one

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
7月2日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
7月2日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
7月2日 评论:
流水线 pytorch_gitcode_PR_multiVersion#11738 [ commitID:11d5f412 ] 已完成
likedislike