Pull Request已成功合入, 合并人@ascend-robot
(感谢 王刚 的贡献)变更摘要
本 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_contiguouslowering: 在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 等值校验。


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


当前仓库存在以下 保护分支 :
评论 /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 | ✅ 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 | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/lgtm


/approve


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


compile


ascend docs pipeline is running...


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


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




【合入来源】
【修改方案】
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 两处配套落地:
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 设备外往返。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 变体)。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
【CheckList】