已合并
fix(inductor): deliver auto_blockify_size via the Config.extra_options slot #44846
fix(inductor): deliver auto_blockify_size via the Config.extra_options slot #44846
已合并
AllenGuan创建于 17 天前
AllenGuan成员
17 天前

【合入来源】

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

社区 issue 链接待创建后补充。

【修改方案】

请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列
如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

背景:auto_blockify_size 是 triton-ascend 的编译选项(NPUOptions 字段,经 options 通道生效于 AutoBlockify pass),不是 kernel constexpr。此前前端把它注入 Config.kwargs_precompile_config 将全部 cfg kwargs 灌进 ASTSource 的 constants,triton 核心 ast_to_ttirfn.arg_names.index(key) 解析键名——kernel 签名无此参数,导致 grid>65535 的 kernel(默认 1D 路径 _pw1d_formula_configs 生成 auto_blockify_size∈{2,4,8} 候选时)编译必崩 ValueError: 'auto_blockify_size' is not in list,且 options 通道从未被喂值,该选项此前不存在送达后端的通路。

  1. 注入npu_triton_config):auto_blockify_size 不再写入 cfg.kwargs,改设上游第三方后端官方槽位 Config.extra_optionsAutotuneCache.save 原生序列化、read_best 原生恢复);kwargs 恢复纯 constexpr,constants 通道因构造正确而安全,无需过滤逻辑。
  2. 送达_precompile_config):options.update(getattr(cfg, "extra_options", None) or {}) 将槽位转发进 triton.compile 的 options dict → NPUOptions.auto_blockify_size → 编译 metadata → add_auto_blockify pass → bishengir。转发不感知具体键名,后续新增后端选项自动走通。
  3. 候选身份cached_autotune):上游去重/hash 键只含 kwargs+num_warps+num_stages,看不到 extra_options,{2,4,8} 三候选会被折叠为一个;改用 _npu_config_key/_npu_unique_configs/_npu_hash_configs(键扩展 extra_options),save/read 同经本文件,hash 前后自洽。
  4. 兜底透传_compile_small_block_fallback):小方块回退重建 Config 时显式携带 template 的 extra_options(缓存命中路径 configs=[winner] 时 template 即带槽位的 winner)。

gate 语义零变更:all_blocks_parallel=True 且 ceildiv(numel, cap_XBLOCK)>65535 时在 cap tile 上追加 {2,4,8} 候选,与原行为一致。

【资料变更】

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

不涉及

【接口变更】

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

不涉及(Config.extra_options 为上游既有第三方后端槽位,本 PR 仅使用,未新增对外接口)

【功能验证】

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

  • 新增 UT 看护test/_inductor/test_triton_experimental_autotune.py 新增 TestAutoBlockify 7 用例——槽位正确性(extra_options 位置/kwargs 零泄漏/仅 cap tile 携带)、gate 开关矩阵(65535 严格边界、all_blocks_parallel 开关、小 kernel)、候选身份与去重、序列化 round-trip 形态。
  • 存量回归:清缓存(TORCHINDUCTOR_CACHE_DIR 等缓存目录清空)后全量 test_triton_experimental_autotune.py 66 passed(存量 59 + 新增 7)。
  • e2e 验证:最小复现 kernel(5 个 fp32 load × 2²⁸ 元素,UB 预算封顶 XBLOCK=4096 → grid=65536,精确复现原崩溃形态)torch.compile 编译通过、输出数值正确。
  • 送达取证:triton 编译缓存出现 auto_blockify_size∈{2,4,8} 三个独立 hash 的编译产物(options 参与缓存 key,三候选真实参与 autotune 竞速)。
  • 模型级验证:修复前编译崩溃的 timm mobilevit_s(bs=128)与 mobilenetv3_large_100(bs=512)可正常编译运行,实测 speedup 分别为 0.210× / 0.803×,运行日志零报错。

【CheckList】

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

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 AllenGuan 的贡献)
AAllenGuan成员
17 天前 创建了 pull request,commit adbe6787
AAllenGuan成员
17 天前 关联了issue:[Bug]: torch.compile 大 grid kernel 编译报错 "ValueError: 'auto_blockify_size' is not in list"(mobilevit_s / mobilenetv3_large_100 等大 batch 模型触发
atomgit-bot
atomgit-bot
17 天前 评论:

变更摘要

本 PR 修复了 auto_blockify_size 传递通路缺失导致的编译崩溃:此前该 triton-ascend 编译选项(NPUOptions 字段,非 kernel constexpr)被写入 Config.kwargs_precompile_config 会把 kwargs 灌入 ASTSource 的 constants,ast_to_ttir 按 kernel 签名解析键名失败,导致 grid>65535 的 kernel 编译必崩 ValueError: 'auto_blockify_size' is not in list。本 PR 将其改经上游第三方后端槽位 Config.extra_options 注入,并在 _precompile_config 中转发进 triton.compile 的 options dict 送达 NPUOptions.auto_blockify_size,同时扩展 autotune 去重/hash 身份键以保留 {2,4,8} 三个候选的独立性,并新增 7 个 UT 用例看护。

主要改动

  • 注入槽位切换(npu_triton_config: auto_blockify_size 不再写入 cfg.kwargs,改为设置 config.extra_options = {"auto_blockify_size": ...},kwargs 恢复为纯 constexpr,constants 通道不再携带后端选项。
  • 选项送达(_precompile_config: 在 triton.compile 前新增 options.update(getattr(cfg, "extra_options", None) or {}),将槽位内容转发进 options dict(NPUOptions.parse_options 按需映射),转发不感知具体键名。
  • 候选身份与去重(cached_autotune: 新增 _npu_config_key/_npu_unique_configs/_npu_hash_configs,将 extra_options 并入身份/hash 键,替换上游仅含 kwargs+num_warps+num_stages 的 unique_configs/hash_configs,避免 {2,4,8} 三候选被折叠为一个。
  • 兜底透传(_compile_small_block_fallback: 小方块回退重建 Config 时,将 template 的 extra_options 显式拷贝到 fallback_cfg.extra_options,保证缓存命中路径下槽位不丢失。
  • 测试看护(test/_inductor/test_triton_experimental_autotune.py: 新增 TestAutoBlockify 7 个用例,覆盖槽位放置/kwargs 零泄漏、gate 开关矩阵(65535 严格边界、all_blocks_parallel 开关、小 kernel)、候选身份去重及序列化 round-trip。
likedislike
atomgit-bot
atomgit-bot
17 天前 评论:

代码审查

✅ 未发现问题

likedislike
ascend-robotascend-robot成员
17 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
17 天前 评论:

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 liangsongwei, 楚浩田 (2/2) liangsongwei (1/1)
torch_npu/_inductor liangsongwei, 楚浩田, rmch (3/2) liangsongwei (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
ascend-robot
ascend-robot成员
17 天前 评论:

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

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

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

注意:

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

compile

likedislike
ascend-robotascend-robot成员
17 天前 删除了label:ci-pipeline-running
ascend-robot
ascend-robot成员
17 天前 评论:
流水线 PR-pipeline_pytorch#62006 [ commitID:1b855d5c ] 已终止运行
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 🕚 >>>
Build_ARM 🕚 >>>
Build_LibTorch_x86 🕚 >>>
Build_LibTorch_ARM 🕚 >>>
Build_X86_torchair 🕚 >>>
Build_ARM_torchair 🕚 >>>
patch_test 🕚 >>>
恶意代码检查 Antipoison 🟨 >>>
编码安全与规范检查 codecheck_pre-commit 🟨 >>>
check_error 🟨 >>>
lintrunner 🟨 >>>
开源片段检查 SCA 🟨 >>>
开发者测试 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, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
ascend-robot
ascend-robot成员
17 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
17 天前 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
17 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robot
ascend-robot成员
17 天前 评论:

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

likedislike
ascend-robotascend-robot成员
17 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
17 天前 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
17 天前 评论:

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

likedislike
ascend-robotascend-robot成员
17 天前 添加了label:ci-pipeline-failed
ascend-robot
ascend-robot成员
17 天前 评论:
流水线 PR-pipeline_pytorch#62007 [ commitID:1b855d5c ] 运行失败
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_LibTorch_x86 >>>
Build_LibTorch_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 codecheck_pre-commit >>>
check_error >>>
lintrunner >>>
开源片段检查 SCA >>>
开发者测试 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, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
AllenGuan成员
17 天前 评论:

retry

likedislike
ascend-robotascend-robot成员
17 天前 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
17 天前 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
17 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
17 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
17 天前 评论:
流水线 PR-pipeline_pytorch#62007 (重试第1次) [ commitID:1b855d5c ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_LibTorch_x86 >>>
Build_LibTorch_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 codecheck_pre-commit >>>
check_error >>>
lintrunner >>>
开源片段检查 SCA >>>
开发者测试 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, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
htchu成员
17 天前 评论:

/lgtm

likedislike
rmch成员
16 天前 评论:

/lgtm

likedislike
AAllenGuan成员
16 天前 修改了pull request 的描述
梁松伟
梁松伟成员
16 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
16 天前 添加了label:approvedlgtm
梁松伟梁松伟成员
16 天前 关联了里程碑:TorchNPU-v2.14.0
梁松伟梁松伟成员
16 天前 关联了里程碑:v26.2.0
ascend-robotascend-robot成员
16 天前 关闭了关联的issue
ascend-robotascend-robot成员
16 天前 合入了pull request
ascend-robot
ascend-robot成员
16 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14267 [ commitID:1b855d5c ] 运行失败
likedislike