Pull Request已成功合入, 合并人@ascend-robot
(感谢 cuiduo 的贡献)变更摘要
此 PR 主要对 TYPE_CHECKING 导入语句的位置进行了调整,将 torch_npu/utils/_dynamo.py 中模块级别的 from torch._dynamo.symbolic_convert import InstructionTranslator 导入移入 patch_npu_stream_context 函数内部,以缩小该类型检查导入的作用范围。同时清理了测试文件 test/_inductor/test_add.py 中多余的 import torch_npu。
主要改动
- 将
InstructionTranslator的类型检查导入移至函数内部:在torch_npu/utils/_dynamo.py中,将原本位于模块顶层的if TYPE_CHECKING: from torch._dynamo.symbolic_convert import InstructionTranslator移动到patch_npu_stream_context函数体内,使其仅在函数局部作用域生效。 - 移除测试文件中多余的
import torch_npu:从test/_inductor/test_add.py中删除了未使用的import torch_npu语句,保持测试代码整洁。


代码审查
我已经仔细审查了两个变更文件。以下是我的分析:
文件 1:test/_inductor/test_add.py
移除了 import torch_npu。经过检查:
testutils.py(同目录下的测试工具模块)在第 7 行已经import torch_npu,而test_add.py通过from testutils import TestUtils间接导入了torch_npu。test_add.py文件中没有任何对torch_npu的直接引用。- 所有同目录下的其他测试文件也都保持
import torch_npu,但它们的testutils导入同样会触发该模块的初始化。移除这个冗余导入不会影响测试行为。
结论:无问题。
文件 2:torch_npu/utils/_dynamo.py
将 if TYPE_CHECKING: from torch._dynamo.symbolic_convert import InstructionTranslator 从模块顶层移至 patch_npu_stream_context() 函数内部。经过检查:
InstructionTranslator在整个文件中仅被patch_npu_stream_context()函数使用(在类型注解字符串"InstructionTranslator"中作为前向引用)。TYPE_CHECKING已在模块顶层从typing导入,在函数内部可正常访问。- 没有任何外部模块从
torch_npu.utils._dynamo导入InstructionTranslator。 - 运行时
TYPE_CHECKING为False,该导入块不会被执行,因此无性能影响。
结论:无问题。
总结
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 0 |
| P3 | 0 |
整体风险评估:此变更是安全的代码清理重构,无功能影响,无回归风险。
审核文件清单:
test/_inductor/test_add.py— 无问题torch_npu/utils/_dynamo.py— 无问题
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


compile


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, renyujin (2/2) | ✅ zichun_ye (1/1) |
| torch_npu/utils | ✅ zichun_ye, renyujin (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-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.7.1-26.1.0 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.12.0 | ||
| v2.9.0 | ||
| v2.7.1 | ||
| v2.12.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| ci-test |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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_X86_Part_01 | 🕚 | >>> |
| UT_X86_Part_02 | 🕚 | >>> | |
| 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...


ascend docs pipeline is running...


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


✅ 跳过 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_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| 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 : 停止流水线


Linking Issue Notice
@cuiduo , 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 .


/approve




【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】