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.10.0 | ||
| v2.7.1 | ||
| v2.9.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 命令关闭


变更摘要
本次变更在 test/test_jit_api.py 中新增测试类 TestJitIgnoreNPU,补充了 torch.jit.ignore API 的测试覆盖,包括带 drop_on_export 参数的忽略装饰器、忽略属性配置、返回值标注兼容性、方法绑定等多个验证场景。
主要改动
- 新增
TestJitIgnoreNPU测试类:继承自JitTestCase,并添加了辅助方法getExportImportCopy用于模型的保存/加载导出验证,同时新增import warnings、import io、import numpy等必要依赖导入。 - 新增
test_ignore_decorator方法:验证@torch.jit.ignore(drop_on_export=True)的功能——编译时触发告警,导出后忽略方法被移除且调用会触发AttributeError,同时验证导出前后模型的前向推理结果一致。 - 新增
test_ignored_props方法:验证__jit_ignored_attributes__配置生效,确保被忽略属性可在@torch.jit.ignore修饰的方法内正常调用,模型编译无异常。 - 新增
test_torch_ignore_conversion_to_none方法:验证忽略方法无论是否有显式-> None返回值标注,均能正常编译且不影响模型主前向推理结果。 - 新增
test_ignored_method_binding与test_no_self_arg_ignore_function方法:分别验证被忽略方法在脚本模块上的正常绑定调用,以及缺少self参数的忽略函数在编译时正确抛出异常。


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


代码审查
经过对 test/test_jit_api.py 新增内容(第 528–684 行,共 161 行)的逐行审查,包括:
- 语法与导入:
warnings,io,numpy,JitTestCase均正确导入并使用,无语法错误。 - 测试逻辑正确性:共 6 个测试方法(
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.py)改写或精简,覆盖了@torch.jit.ignore/drop_on_export/__jit_ignored_attributes__/@torch.jit.export等核心能力,断言与预期行为一致。 - 设备一致性:
test_ignore_decorator中所有张量均通过device_type移至正确设备,其他测试用例无需显式指定设备且逻辑自洽。 - 资源与安全:使用
io.BytesIO进行内存序列化/反序列化,无外部文件读写、无命令注入、无硬编码密钥等安全隐患。 - 并发与竞态:纯单线程测试,无共享可变状态或锁竞争风险。
- 边界值与热点:无量级/阈值/循环内 I/O 等性能或边界缺陷。
结论:该 diff 未引入任何可确认的正确性、安全性、可靠性或破坏性变更问题。
审查关闭摘要
- 已审查文件:
test/test_jit_api.py— 无问题。 - 发现问题数:P0: 0, P1: 0, P2: 0, P3: 0。
- 整体风险评估:低风险。变更为纯测试补充,代码逻辑清晰,与上游测试模式一致,预期可稳定运行在目标 NPU 环境。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


/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】