Pull Request已成功合入, 合并人@ascend-robot
(感谢 cuiduo 的贡献)变更摘要
该 PR 将 has_triton() 函数从 torch_npu/_inductor/utils.py 迁移至 torch_npu/utils/_dynamo.py,使其成为模块级函数并保留 @functools.lru_cache(None) 缓存装饰器。同时调整了 patching 的分工:_dynamo.py 中的 patch_has_triton 负责将 has_triton 注入 torch.utils._triton.has_triton,而 _inductor/utils.py 中的 patch_has_triton 则从 _dynamo 导入并注入到 torch._inductor.scheduler 和 torch._inductor.compile_fx。此外,测试用例中移除了 transfer_to_npu 场景下对 has_triton() 的 assertFalse 断言。
主要改动
has_triton函数迁移至torch_npu/utils/_dynamo.py:将原来内嵌在patch_has_triton内部的has_triton闭包提升为_dynamo.py的模块级函数,保留@functools.lru_cache(None)及完整的设备兼容性检查逻辑(cuda/xpu/cpu/npu)。- Patching 职责拆分:在
_dynamo.py中新增patch_has_triton函数,仅负责将has_triton赋值给torch.utils._triton.has_triton,并在add_dynamo_methods()中调用它;_inductor/utils.py中的patch_has_triton改为从_dynamo导入has_triton并注入到torch._inductor.scheduler.has_triton和torch._inductor.compile_fx.has_triton。 - 测试断言调整:在
test/_inductor/test_triton.py的TestHasTriton类中删除了self.assertFalse(has_triton())断言(原用于验证transfer_to_npu后 triton 不可用),仅保留对has_triton_tma和has_triton_tma_device的assertFalse检查。


代码审查
审查总结
本次审查覆盖了全部 3 个变更文件:
| 文件 | 审查结果 |
|---|---|
test/_inductor/test_triton.py |
无问题 — 移除了 transfer_to_npu 前冗余的 assertFalse(has_triton()) 断言,符合预期 |
torch_npu/_inductor/utils.py |
发现 1 个 P3 不一致问题(见下方),另有 1 个无影响的观察记录 |
torch_npu/utils/_dynamo.py |
无问题 — has_triton() 函数逻辑与原实现完全一致,patch_has_triton() 正确接入 add_dynamo_methods() |
发现统计
- P0: 0
- P1: 0
- P2: 0
- P3: 1(
torch._inductor.scheduler.has_triton未被transfer_to_npu覆盖导致的不一致)
整体风险评估
低风险。此次变更是一次合理的代码重构:将 has_triton() 从 utils.py 的闭包中提升到 _dynamo.py 模块级别,并拆分了 patch_has_triton 的职责(_dynamo.py 负责 torch.utils._triton.has_triton,utils.py 负责 inductor 内部模块)。核心逻辑未变,测试行为未变。唯一需关注的是调度器模块新增的 has_triton 打补丁与 transfer_to_npu 之间的覆盖缺口,建议后续在 transfer_to_npu._init() 中补充覆盖以保持一致性。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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 | ✅ zichun_ye, daifu1234567 (2/2) | ✅ zichun_ye (1/1) |
| torch_npu/_inductor | ✅ zichun_ye, daifu1234567 (2/2) | ✅ zichun_ye (1/1) |
| torch_npu/utils | ✅ zichun_ye, daifu1234567 (2/2) | ✅ zichun_ye (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
cuiduo, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.10.0 | ||
| v2.10.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.7.1 | ||
| v2.12.0-26.1.0 | ||
| v2.7.1-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.12.0 | ||
| v2.11.0 | ||
| v2.9.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 | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_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 检查,没有需要检查的文档文件


compile


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 | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_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 : 停止流水线


/approve


/lgtm




【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】
Related: https://gitcode.com/Ascend/pytorch/issues/1978