Pull Request已成功合入, 合并人@ascend-robot
(感谢 wei-pengfei22 的贡献)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 | ✅ chenrayray, huangjingwei (2/2) | ✅ chenrayray (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wei-pengfei22, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.9.0 | ||
| v2.10.0 | ||
| v2.11.0 | ||
| v2.12.0 | ||
| v2.9.0-26.1.0 | ||
| v2.7.1-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| ci-test | ||
| sync-pr28113--to-v2.9.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


变更摘要
本次变更为 torch.jit.ignore API 补充测试覆盖,在 test/test_jit_api.py 文件中新增测试类 TestJitIgnoreNPU,包含 7 个测试用例,覆盖忽略装饰器的告警触发、导出移除、属性配置、返回值标注、方法绑定等核心场景。
主要改动
- 新增
TestJitIgnoreNPU测试类:继承JitTestCase,新增warnings、io、numpy及JitTestCase的导入,为torch.jit.ignore相关功能提供集中测试入口。 test_ignore_decorator用例:验证带drop_on_export=True参数的@torch.jit.ignore装饰器在编译时触发 "TorchScript will now drop the function" 告警,导出后忽略方法被移除且调用会触发AttributeError,同时验证导出前后前向计算结果一致。test_ignored_props用例:验证__jit_ignored_attributes__配置的忽略属性可在@torch.jit.ignore标注的方法内正常访问,模型可成功编译为ScriptModule。test_torch_ignore_conversion_to_none用例:验证被忽略方法无论是否显式标注-> None返回值类型,均能正常编译且不影响forward的计算结果。test_no_self_arg_ignore_function用例:验证缺少self参数的忽略函数在编译时会抛出包含 "does not have a self argument" 的异常。


ascend docs pipeline is running...


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


代码审查
经过全面审查,我对该 diff 中的每项变更都进行了仔细分析,包括:
- 逐行检查所有新增测试方法的逻辑正确性
- 验证
nn.Buffer、device_type、JitTestCase等依赖项的可用性 - 检查警告捕获、异常断言、张量比较等边界条件
- 与上游
test/test_jit.py中的对应测试进行交叉比对 - 检查 Python 特有的问题(可变默认参数、
isvs==、异常吞噬、资源泄漏等) - 验证导入语句的完整性和正确性
结论:该 diff 未引入任何可报告的问题。 所有测试用例逻辑正确,实现了 PR 描述中声明的验证目标(test_ignore_decorator、test_ignored_props、test_torch_ignore_conversion_to_none、test_comment_ignore_indent、test_ignored_method_binding、test_no_self_arg_ignore_function),且与上游 PyTorch 测试风格保持一致。
审查总结
- 已审查文件:
test/test_jit_api.py— 无问题 - 发现问题数量:0(P0: 0, P1: 0, P2: 0, P3: 0)
- 整体风险判定:低风险。变更仅涉及新增测试用例,不修改任何生产代码,测试逻辑正确且与上游保持一致。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线


/lgtm


/approve


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


/compile


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_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 : 停止流水线


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线




【合入来源】
【修改方案】
本次变更为重新编写部分测试, 补齐API torch.jit.ignore 的测试覆盖。
重新编写torch.jit.ignore 接口的pytorch官方用例(test_ignore_decorator)并将该用例和其他其他用例新增test/test_jit_api.py文件中
测试用例设计:
NPU适配:
torch.jit.ignore本身和底层硬件无绑定关系,是纯前端编译期装饰器逻辑;仅被忽略函数内部代码才会受硬件影响;6个用例中test_ignore_decorator涉及到张量和和自定义模型, 用例中已将这2个to到NPU device , 该用例已适配NPU; 其他用例不涉及【资料变更】
已经在 https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 的文档中进行查找与验证。该目录下的pytorch.2-7.1至pytorch.2-12-0文件夹下的torch-jit.md已经对"torch.jit.ignore"全部标注"是"。无需更改。
【接口变更】
不涉及
【功能验证】
cd pytorch/test python3 -m unittest test_jit_api.TestJitIgnoreNPU.test_ignore_decorator test_jit_api.TestJitIgnoreNPU.test_ignored_props test_jit_api.TestJitIgnoreNPU.test_torch_ignore_conversion_to_none test_jit_api.TestJitIgnoreNPU.test_comment_ignore_indent test_jit_api.TestJitIgnoreNPU.test_ignored_method_binding test_jit_api.TestJitIgnoreNPU.test_no_self_arg_ignore_function验证结果:
验证结论:
6个测试用例均通过,API 在 NPU 环境下可正常调用,状态设置与查询行为符合预期。
【CheckList】