合并受阻
变更摘要
本 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 补充可融合的反向分解,从而消除编译期 CompilationError、MissingOperatorWithDecomp、MissingOperatorWithoutDecomp 等错误。
主要改动
- 新增
_npu_print_RoundToIntcodegen 实现: 在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/3d与upsample_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()之后生效,使显式分解得以保留。


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


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 .


当前仓库存在以下 保护分支 :
| 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,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


ascend docs pipeline is running...


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


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


ascend docs pipeline is running...


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


【合入来源】
【修改方案】
修复 triton_experimental 后端(
TORCHINDUCTOR_NPU_BACKEND=triton_experimental)下 4 个 UT 用例失败,所有改动严格限定在torch_npu/_inductor/triton_experimental/目录内,未触碰通用 mutation / RNG / 分解框架路径:codegen/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,语义一致)。lowering_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 缺失时后端照常加载)。overrides.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 等已通过用例。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
ir_nodes_pre_fusion = 2,CPU fallback 警告消失三处修复影响面均严格限定在各自那一个(或一组)算子:realize 为 inductor 测试专用 op(真实模型不用);其余两处均为单条指令/单算子级替换,无性能劣化。
【CheckList】