已开启
fix(inductor): fix triton_experimental UT failures #44742
fix(inductor): fix triton_experimental UT failures #44742
已开启
liuyutong创建于 21 天前
liuyutong
liuyutong成员
21 天前

【合入来源】

【修改方案】

修复 triton_experimental 后端(TORCHINDUCTOR_NPU_BACKEND=triton_experimental)下 4 个 UT 用例失败,所有改动严格限定在 torch_npu/_inductor/triton_experimental/ 目录内,未触碰通用 mutation / RNG / 分解框架路径:

  1. test_builtins_roundcodegen/triton.py):round() 内建在 triton codegen 里被打印成 libdevice.llrint(...),该 op 是 SIMT-only、返回 int64,NPU 的 SIMD/AI Vector Core 不支持,编译期报 CompilationError。新增 _npu_print_RoundToInt,改用 SIMD 支持的 libdevice.nearbyint(round-half-to-even,语义一致)。
  2. test_forced_buffer_realize_npulowering_override_list.py):_register_npu_inductor_fallbacks()torch.ops._inductor_test.realize 的上游 lowering(纯 IR 记账、不发 kernel)误砸成 CPU fallback,导致 ir_nodes_pre_fusion 断言 2 实际得 4。将其加入 KEEP_UPSTREAM_LOWERING(带 ImportError 兜底,测试专用 op 缺失时后端照常加载)。
  3. test_inductor_sequence_nroverrides.py):torch_npu 的 l1_loss autograd 公式向反向 FX 图发 torch.ops.npu.l1_loss_backward.default,后端既无 lowering 也无分解,反向编译期抛 MissingOperatorWithoutDecomp。新增 _register_l1_loss_backward_decomposition(),分解为 grad * sign(self - target)(Mean 再除 numel);sign 刻意用比较运算 (diff>0)-(diff<0) 实现,避免引入不在 GENERATE_LIST 中的 aten.sign 而打断融合、牵连 test_sign_dtype_npu / test_bool_npu 等已通过用例。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

用例 验证结果
test_builtins_round_npu(含 dynamic 版本) 通过;scalar 索引计算,无性能劣化
test_forced_buffer_realize_npu 通过;ir_nodes_pre_fusion = 2,CPU fallback 警告消失
test_inductor_sequence_nr 通过;数值与 CPU autograd 逐位一致(max diff = 0.0,三种 reduction),前/反向均为单个 triton kernel、无 aten.sign fallback、无 extern 调用

三处修复影响面均严格限定在各自那一个(或一组)算子:realize 为 inductor 测试专用 op(真实模型不用);其余两处均为单条指令/单算子级替换,无性能劣化。

【CheckList】

likedislike
合并受阻
liuyutongliuyutong成员
21 天前 创建了 pull request,commit 095700fa
atomgit-bot
atomgit-bot
21 天前 评论:

变更摘要

本 PR 用于修复 TORCHINDUCTOR_NPU_BACKEND=triton_experimental 后端下 4 个 UT 用例的失败,所有改动均限定在 torch_npu/_inductor/triton_experimental/ 目录内。主要围绕三类问题展开:在 codegen/triton.py 中为 round() 内建新增 SIMD 可用的 codegen 实现;在 lowering_override_list.py 中保护 torch.ops._inductor_test.realize 的上游 lowering 不被错误降级为 CPU fallback;在 overrides.py 中显式注册 upsample 系列算子的分解,并为 torch.ops.npu.l1_loss_backward 补充可融合的反向分解,从而消除编译期 CompilationErrorMissingOperatorWithDecompMissingOperatorWithoutDecomp 等错误。

主要改动

  • 新增 _npu_print_RoundToInt codegen 实现: 在 codegen/triton.py 中新增 _npu_print_RoundToInt 并注册为 _TritonPrinter._print_RoundToInt,将 round() 从 SIMT-only 的 libdevice.llrint 改为 SIMD 支持的 libdevice.nearbyint(...).to(...),保持 round-half-to-even 语义并修复 test_builtins_round
  • _inductor_test.realize 加入 KEEP_UPSTREAM_LOWERING: 在 lowering_override_list.py 中通过 try/except ImportError 导入 torch._inductor.test_operators 并将 torch.ops._inductor_test.realize 追加到 KEEP_UPSTREAM_LOWERING,避免其纯 IR 记账的上游 lowering 被降级为 CPU fallback,从而修复 test_forced_buffer_realize_npu
  • 新增 _register_upsample_decompositions(): 在 overrides.py 中显式注册 8 个 upsample op(upsample_nearest1d/2d/3dupsample_bilinear2d.vec.default 形式)的 Inductor 规范分解,以在 disable_implicit_decomposition() 摘除 CompositeImplicitAutograd kernel 后补足缺失的 NPU lowering,修复 test_optimize_indexing_dtype
  • 新增 _register_l1_loss_backward_decomposition(): 在 overrides.py 中为 torch.ops.npu.l1_loss_backward.default 注册分解为 grad * sign(self - target)(Mean 时再除以 numel),并刻意用 (diff>0)-(diff<0) 实现 sign 以避开不在 GENERATE_LIST 中的 aten.sign,从而保持融合并修复 test_inductor_sequence_nr
  • apply_npu_overrides() 中接入两组新分解: 在 apply_npu_overrides() 中调用 _register_upsample_decompositions()_register_l1_loss_backward_decomposition(),确保其在该后端 loader 应用 disable_implicit_decomposition() 之后生效,使显式分解得以保留。
likedislike
不准确?
atomgit-bot
atomgit-bot
21 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
ascend-robotascend-robot成员
21 天前 添加了label:ascend-cla/yes
ascend-robotascend-robot成员
21 天前 添加了label:needs-issue
ascend-robot
ascend-robot成员
21 天前 评论:

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

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
torch_npu/_inductor ❌ (0/2)(You can also ask: chujinjin, 杨开昕, wangmin0104, wangqiang160, zichun_ye) ❌ (0/1)(You can also ask: wasd1111222, wangqiang160, guoqi1024, zqwenn, zichun_ye)

💡 Tip:

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

CLA Signature Pass

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

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

CLA Signature Pass

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

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

Linking Issue Notice

@liuyutong_bury , 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成员
21 天前 评论:

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

Protected Branch Version Release
master
v2.12.0
v2.10.0
v2.11.0
v2.9.0
v2.7.1-26.1.0
v2.7.1
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成员
21 天前 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
21 天前 评论:

ascend docs pipeline is running...

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

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

likedislike
ascend-robotascend-robot成员
21 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
21 天前 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
21 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
21 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
21 天前 评论:
流水线 PR-pipeline_pytorch#61667 [ commitID:823c6b3a ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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
rmch成员
18 天前 评论:

增加decompose,建议测试一下性能

likedislike
liuyutongliuyutong成员
17 天前 update merge request[project id: 7404318, iid: 44742, commit_id: cdf47dbed24e42765e78094e831639404af76770] virtual merging success
liuyutongliuyutong成员
17 天前 强制推送  1 个提交:2211adff-[inductor] fix 3 triton_experimental UT failures: RoundToInt codegen, l1_loss_backward decomp, realize lowering
liuyutongliuyutong成员
17 天前 update merge request[project id: 7404318, iid: 44742, commit_id: cd1835b7c53015d2a8c7099acc99814b5383f10f] virtual merging success
ascend-robotascend-robot成员
17 天前 删除了label:ci-pipeline-passed
ascend-robotascend-robot成员
17 天前 删除了label:ascend-cla/yes
ascend-robotascend-robot成员
17 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
17 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
17 天前 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
17 天前 添加了label:docs-ci-pipeline-running
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
liuyutongliuyutong成员
14 天前 修改了pull request 的描述
liuyutongliuyutong成员
14 天前 关联了里程碑:v26.2.0