Merged
【硬件解耦任务】fix(inductor-TE): 生成 aten.contiguous 拷贝 lowering #4933 #47274
【硬件解耦任务】fix(inductor-TE): 生成 aten.contiguous 拷贝 lowering #4933 #47274
Merged
王刚Add on Sep 28
王刚
王刚Collaborators
Sep 28

【合入来源】

关联 issue:fixes #4933 https://gitcode.com/Ascend/pytorch/issues/4933

【修改方案】

issue #4933:triton_experimental 后端下 diag_embed 全部 6 个 dtype 变体在严格模式(implicit_fallbacks=False)编译期失败,缺失 target 为 aten.contiguous.default。

机制:与 as_strided 不同,aten.contiguous 在上游 lowerings 表中没有任何既有条目(纯布局 op,上游历来在 IR 层由 lazy clone 处理)。_register_npu_inductor_fallbacks() 的批量回退 pass 遍历的是 for op in lowerings,因此根本扫不到 contiguous 节点(diag_embed 分解链末端 mask_tensor(...).contiguous() 发出);单独将其列入 GENERATE_LIST 也是空操作。

按评审意见(GENERATE_LIST 路线,即生成设备内 kernel 而非回退),本 PR 两处配套落地:

  1. torch_npu/_inductor/triton_experimental/lowering.py:新增 npu_contiguous,委托既有 npu_clone(clone-fold 契约:输入已行主序则折叠为零拷贝视图,否则按判定走一次设备内拷贝——生成的 triton Pointwise 或 vendor strided copy),并以 overwrite_lowering(aten.contiguous, npu_contiguous) 注册。相比 make_fallback,拷贝保持 on-device 且参与 scheduler 融合,无 FallbackKernel 设备外往返。
  2. torch_npu/_inductor/triton_experimental/lowering_override_list.py:GENERATE_LIST 紧邻 aten.clone 增加 aten.contiguous。此步为必需:op 一旦进入 lowerings,批量 pass 会将其 make_fallback 反盖,GENERATE_LIST 豁免保证新注册的 lowering 生效。

新增 UT:test/_inductor/triton_experimental/test_te_contiguous_lowering.py(注册钉扎 3 例 + diag_embed 严格模式编译与 eager 逐 dtype 等值 6 变体)。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

  • 环境:Ascend 910B2 ×8,PyTorch 2.14.0+cpu / torch_npu 2.14.0 / CANN 9.1.0,后端 triton_experimental。
  • 新增 UT 4 例真机全绿(约 76s);去除修复后其中注册断言 2 例 FAIL(双向验证)。
  • 验证证据:
    $ python test/_inductor/triton_experimental/test_te_contiguous_lowering.py
    Ran 4 tests in 77.4s
    OK
    
  • 反向族(diag_embed backward)与 default 后端路径不涉及本改动(仅新增 TE lowering 与 GENERATE_LIST 条目,无既有用例行为变更)。

【CheckList】

likedislike
Pull Request has been successfully merged by ascend-robot.
(Thank you for 王刚's contribution.)
王刚王刚Collaborators
Sep 28 Created pull request, commit b6e86253
王刚王刚Collaborators
Sep 28 Associated issue: 【硬件解耦任务】triton_experimental 缺 contiguous lowering(6 例)
atomgit-bot
atomgit-bot
Sep 28 Comments:

变更摘要

本 PR 针对 triton_experimental 后端在严格模式(implicit_fallbacks=False)下编译 diag_embed 失败的问题(缺失 target 为 aten.contiguous.default),采用「生成设备内 kernel」而非回退的路线进行修复。由于 aten.contiguous 在上游 lowerings 表中没有既有条目,批量回退 pass 无法扫到该节点,因此本 PR 新增 npu_contiguous(委托既有 npu_clone)并注册为 aten.contiguous 的 lowering,同时在 GENERATE_LIST 中列出 aten.contiguous,避免新 lowering 被批量 pass 反盖为 fallback,并补充相应的单元测试。

主要改动

  • 新增 npu_contiguous lowering: 在 torch_npu/_inductor/triton_experimental/lowering.py 新增 npu_contiguous(x, memory_format=torch.contiguous_format),直接委托 npu_clone,利用 clone-fold 契约在输入已行主序时折叠为无拷贝视图,否则执行一次设备内拷贝。
  • 注册 aten.contiguous 的 lowering: 通过 overwrite_lowering(aten.contiguous, npu_contiguous, type_promotion_kind=None) 将上述实现注册为 aten.contiguous 的 lowering,使拷贝保持 on-device 并参与 scheduler 融合,替代设备外往返的 FallbackKernel。
  • GENERATE_LIST 新增 aten.contiguous: 在 torch_npu/_inductor/triton_experimental/lowering_override_list.py 的 GENERATE_LIST 中紧邻 aten.clone 加入 aten.contiguous,使批量回退 pass 豁免该 op,保证新注册的 lowering 生效。
  • 新增单元测试: 新增 test/_inductor/triton_experimental/test_te_contiguous_lowering.py,覆盖注册钉扎(GENERATE_LIST 包含、lowerings 已注册、不被 FALLBACK_LIST 覆盖)以及 diag_embed 在严格模式下对 issue #4933 涉及的 6 个 dtype 的编译与 eager 等值校验。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 28 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
ascend-robotascend-robotCollaborators
Sep 28 Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
Sep 28 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.


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
test ✅ 楚浩田, rmch (2/2) ✅ 楚浩田 (1/1)
torch_npu/_inductor ✅ 楚浩田, rmch (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

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

likedislike
ascend-robot
ascend-robotCollaborators
Sep 28 Comments:

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

Protected Branch Version Release
master
v2.10.0
v2.11.0
v2.12.0
v2.9.0
v2.7.1
v2.7.1-26.2.0
v2.9.0-26.2.0
v2.14.0-26.2.0
v2.13.0-26.2.0
v2.10.0-26.2.0
v2.11.0-26.2.0
v2.12.0-26.2.0
v2.7.1-26.1.0
v2.9.0-26.1.0
v2.11.0-26.1.0
v2.12.0-26.1.0
v2.10.0-26.1.0
ci-test
fix/te-rnumel-autoblockify-prea5

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

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
AtlasAccountAtlasAccountCollaborators
Sep 28 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Sep 28 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Sep 28 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Sep 28 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Sep 28 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Sep 28 Added label: docs-ci-pipeline-success
AtlasAccountAtlasAccountCollaborators
Sep 28 Removed label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
Sep 28 Added label: ci-pipeline-passed
AtlasAccount
AtlasAccountCollaborators
Sep 28 Comments:
流水线 PR-pipeline_pytorch#70441 [ commitID:91c91079 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 ✅ COMPLETED >>>
Build_ARM ✅ COMPLETED >>>
Build_X86_torchair ⚪ IGNORED >>>
Build_ARM_torchair ⚪ IGNORED >>>
patch_test ⚪ IGNORED >>>
Build_X86_213 ✅ COMPLETED >>>
Build_ARM_213 ✅ COMPLETED >>>
恶意代码检查 Antipoison ✅ COMPLETED >>>
编码安全与规范检查 codecheck_pre-commit ✅ COMPLETED >>>
check_error ✅ COMPLETED >>>
lintrunner ✅ COMPLETED >>>
开源片段检查 SCA ✅ COMPLETED >>>
开发者测试 UT_ARM_A3_Part_01 ⚪ IGNORED >>>
UT_ARM_A3_Part_02 ⚪ IGNORED >>>
UT_ARM_A2_Part_01 ✅ COMPLETED >>>
UT_ARM_A2_Part_02 ✅ COMPLETED >>>
UT_ARM_A2_Part_03 ✅ COMPLETED >>>
UT_inductor_Part_01 ⚪ IGNORED >>>
UT_inductor_Part_02 ⚪ IGNORED >>>
UT_inductor_Part_03 ⚪ IGNORED >>>
UT_inductor_Part_04 ⚪ IGNORED >>>
UT_DIST_ARM_Part_01 ⚪ IGNORED >>>
UT_DIST_ARM_Part_02 ⚪ IGNORED >>>
UT_DIST_ARM_Part_03 ⚪ IGNORED >>>
UT_DIST_ARM_Part_04 ⚪ IGNORED >>>
UT_ARM_A2_Select_Part_01 ✅ COMPLETED >>>
UT_ARM_A2_Select_Part_02 ⚪ IGNORED >>>
UT_inductor_Part1_213 ✅ COMPLETED >>>
流水线 PR-pipeline_pytorch ✅ COMPLETED >>>
此流水线已支持下列评论快捷指令,仅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, SCh_zx, lvjiangdong, TonyYA, shi-yufeng99, qiaoyaodan, stonexxx, jimmycao9929, zzll, qindong0, luqichao, xinyuzhuo, liujm2001, dezheng889, zhucehw, HinPeng, rain-666, lsy_0111, a_knight]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
王刚王刚Collaborators
Sep 29 Modify description of pull request
rmch
rmchCollaborators
Oct 8 Comments:

/lgtm

likedislike
htchu
htchuCollaborators
Oct 8 Comments:

/approve

likedislike
ascend-robotascend-robotCollaborators
Oct 8 Added label: approvedlgtm
ascend-robotascend-robotCollaborators
Oct 8 Removed label: ci-pipeline-passed
ascend-robot
ascend-robotCollaborators
Oct 8 Comments:

The following label is not ready.

ci-pipeline-passed: The ci-pipeline-passed label is expired. Please compile again.

likedislike
王刚
王刚Collaborators
Oct 8 Comments:

compile

likedislike
王刚王刚Collaborators
Oct 8 Pre merge succeeded (commit_id: a732a62f81ac90bb2d46b5c98a2d69046456fca2)
AtlasAccountAtlasAccountCollaborators
Oct 8 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Oct 8 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Oct 8 Removed label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Oct 8 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Oct 8 Comments:

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

likedislike
ascend-robotascend-robotCollaborators
Oct 8 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Oct 8 Added label: docs-ci-pipeline-success
AtlasAccountAtlasAccountCollaborators
Oct 8 Removed label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
Oct 8 Added label: ci-pipeline-passed
AtlasAccount
AtlasAccountCollaborators
Oct 8 Comments:
流水线 PR-pipeline_pytorch#71585 [ commitID:91c91079 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 ✅ COMPLETED >>>
Build_ARM ✅ COMPLETED >>>
Build_X86_torchair ⚪ IGNORED >>>
Build_ARM_torchair ⚪ IGNORED >>>
patch_test ⚪ IGNORED >>>
Build_X86_213 ✅ COMPLETED >>>
Build_ARM_213 ✅ COMPLETED >>>
恶意代码检查 Antipoison ✅ COMPLETED >>>
编码安全与规范检查 codecheck_pre-commit ✅ COMPLETED >>>
check_error ✅ COMPLETED >>>
lintrunner ✅ COMPLETED >>>
开源片段检查 SCA ✅ COMPLETED >>>
开发者测试 UT_ARM_A2_Part_01 ✅ COMPLETED >>>
UT_ARM_A2_Part_02 ✅ COMPLETED >>>
UT_ARM_A2_Part_03 ✅ COMPLETED >>>
UT_inductor_Part_01 ⚪ IGNORED >>>
UT_inductor_Part_02 ⚪ IGNORED >>>
UT_inductor_Part_03 ⚪ IGNORED >>>
UT_inductor_Part_04 ⚪ IGNORED >>>
UT_DIST_ARM_Part_01 ⚪ IGNORED >>>
UT_DIST_ARM_Part_02 ⚪ IGNORED >>>
UT_DIST_ARM_Part_03 ⚪ IGNORED >>>
UT_DIST_ARM_Part_04 ⚪ IGNORED >>>
UT_ARM_A2_Select_Part_01 ✅ COMPLETED >>>
UT_ARM_A2_Select_Part_02 ⚪ IGNORED >>>
UT_inductor_Part1_213 ✅ COMPLETED >>>
流水线 PR-pipeline_pytorch ✅ COMPLETED >>>
此流水线已支持下列评论快捷指令,仅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, SCh_zx, lvjiangdong, TonyYA, shi-yufeng99, qiaoyaodan, stonexxx, jimmycao9929, zzll, qindong0, luqichao, xinyuzhuo, liujm2001, dezheng889, zhucehw, HinPeng, rain-666, lsy_0111, a_knight, glf2016]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
ascend-robotascend-robotCollaborators
Oct 8 Merged pull request
AtlasAccount
AtlasAccountCollaborators
Oct 8 Comments:
流水线 pytorch_gitcode_PR_multiVersion-onetrack#274 [ commitID:91c91079 ] 已完成
likedislike