已合并
test(jit): add ScriptModule API alignment test cases [v2.12.0] #37637
TensorLake创建于 6月4日
test(jit): add ScriptModule API alignment test cases [v2.12.0] #37637
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 TensorLake 的贡献)6月4日 创建了 pull request,commit a9c5745f
6月4日 关联了issue:【Ascend for PyTorch训练营 API一致性任务】补齐测试用例、API功能对齐、补齐文档(9)
ascend-robot
6月4日 评论:
6月4日 评论:
6月4日 添加了label:ascend-cla/yes
ascend-robot
6月4日 评论:
6月4日 评论:
ascend-robot
6月4日 评论:
6月4日 评论:
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 | ✅ sunyu-xuan, 李伟 (2/2) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


ascend-robot
6月4日 评论:
6月4日 评论:
当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.12.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| v2.11.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 命令关闭


ascend-robot
6月4日 评论:
6月4日 评论:
Ascend docs pipeline is running...


6月4日 添加了label:docs-ci-pipeline-running
ascend-robot
6月4日 评论:
6月4日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


6月4日 删除了label:docs-ci-pipeline-running
6月4日 添加了label:docs-ci-pipeline-success
6月4日 修改了pull request 的描述
6月4日 修改了pull request 的描述
6月4日 修改了pull request 的描述
TensorLake
6月4日 评论:
6月4日 评论:
compile


TensorLake
6月4日 评论:
6月4日 评论:
compile


6月4日 添加了label:ci-pipeline-running
ascend-robot
6月4日 评论:
6月4日 评论:
Ascend docs pipeline is running...


6月4日 删除了label:docs-ci-pipeline-success
6月4日 添加了label:docs-ci-pipeline-running
ascend-robot
6月4日 评论:
6月4日 评论:
Ascend docs pipeline is running...


ascend-robot
6月4日 评论:
6月4日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


6月4日 删除了label:docs-ci-pipeline-running
6月4日 添加了label:docs-ci-pipeline-success
ascend-robot
6月4日 评论:
6月4日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


6月4日 删除了label:ci-pipeline-running
6月4日 添加了label:ci-pipeline-passed
ascend-robot
6月4日 评论:
6月4日 评论:
流水线 PR-pipeline_pytorch#29805 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |


TensorLake
6月8日 评论:
6月8日 评论:
compile


6月8日 删除了label:ci-pipeline-passed
6月8日 添加了label:ci-pipeline-running
ascend-robot
6月8日 评论:
6月8日 评论:
Ascend docs pipeline is running...


6月8日 删除了label:docs-ci-pipeline-success
6月8日 添加了label:docs-ci-pipeline-running
ascend-robot
6月8日 评论:
6月8日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


6月8日 删除了label:docs-ci-pipeline-running
6月8日 添加了label:docs-ci-pipeline-success
6月8日 删除了label:ci-pipeline-running
6月8日 添加了label:ci-pipeline-passed
ascend-robot
6月8日 评论:
6月8日 评论:
流水线 PR-pipeline_pytorch#30259 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |


sunyu-xuan
6月8日 评论:
6月8日 评论:
/lgtm


sunyu-xuan
6月8日 评论:
6月8日 评论:
/lgtm


6月9日 添加了label:approvedlgtm
6月9日 合入了pull request
ascend-robot
6月9日 评论:
6月9日 评论:
流水线 pytorch_gitcode_PR_multiVersion#10329 [ commitID:40e380fc ] 已完成


【合入来源】
Fork: TensorLake/torch-npu
分支:
test/script-module-npu-v2-12-0→ Ascend/pytorch:v2.12.0【修改方案】
本 PR 为 #1861 的交付。社区用例情况:已在 PyTorch 官方社区
pytorch/test/jit/下搜索ScriptModule相关测试,无针对这 19 个 API 的独立测试用例,因此自行编写测试用例。一、API 功能说明及行为分类
torch.jit.ScriptModule通过torch.jit.script()创建,返回RecursiveScriptModule实例。其方法可见性由双层机制控制:RecursiveScriptModule自己定义的方法(如save()、extra_repr())_compiled_methods_allowlist白名单中的nn.Module方法(如train()、to()、state_dict())_make_fail替换,调用即抛RuntimeError("xxx is not supported on ScriptModules")本测试使用
torch.jit.script()作为 canonical 创建方式,正确验证 allowlist 机制的行为。按实测行为将 19 个 API 分为 4 类:第一类:allowlist 内正常工作(11 个)
train(mode)eval()train(False),返回 selfzero_grad(set_to_none)float()double()to(dtype/device)type(dst_type)state_dict(...)prefix=、destination=、keep_vars=参数save(f, _extra_files)_extra_files附加文件save_to_buffer()extra_repr()"original_name=..."格式字符串第二类:
_make_fail封杀(5 个,与 CPU/GPU 行为一致)assertRaisesRegex匹配)requires_grad_()"requires_grad_ is not supported on ScriptModules"to_empty()"to_empty is not supported on ScriptModules"xpu()"xpu is not supported on ScriptModules"get_buffer()"get_buffer is not supported on ScriptModules"set_submodule()"set_submodule is not supported on ScriptModules"第三类:torch-npu 拦截(3 个)
share_memory()register_module()register_parameter()注:
share_memory在 GPU/CUDA 上为 no-op(官方文档明确),NPU 行为与 GPU 不一致。第四类:PyTorch 内部未完成实现(1 个)
set_extra_state()二、测试文件说明
新增文件:
test/jit/test_script_module.py,共 67 个测试用例,按功能语义分为 10 个测试类:TestScriptModuleTrainEval(11 个):train/eval 默认状态、显式设置、返回值验证、往返切换、NPU 验证、子模块递归传播TestScriptModuleZeroGrad(5 个):无梯度不报错、梯度清零、set_to_none 语义、set_to_none=False 清零、backward→zero_grad→backward 链路TestScriptModuleTo(9 个):dtype/device/device+dtype/dtype_keyword/string_device/no_args 多形式、返回值验证、子模块传播TestScriptModuleFloatDouble(7 个):float 转换/传播、double 转换/NPU float64 降级 float32/传播TestScriptModuleType(4 个):float32 正常路径、float64 降级路径、NPU 验证、int32 异常TestScriptModuleStateDict(7 个):参数/buffer 包含、值匹配、NPU 设备验证、prefix/destination/keep_vars 参数形式TestScriptModuleSave(6 个):save/load 往返、参数保留、返回 None、NPU 验证、_extra_files、save_to_bufferTestScriptModuleExtraRepr(3 个):返回字符串、original_name 模式、NPU 验证TestScriptModuleShareMemory(4 个):CPU 返回 self/makes_shared/幂等、NPU assertRaisesRegex 拦截TestScriptModuleMetadata(7 个):register_module/register_parameter NPU 拦截、set_submodule _make_fail、get_buffer _make_failTestScriptModuleUnsupported(4 个):requires_grad_/to_empty/xpu _make_fail、set_extra_state 未完成实现所有可预测异常的 API 均使用
assertRaisesRegex精确匹配异常信息内容。三、NPU 适配说明
double()/to(torch.float64)/type(torch.float64)自动降级为 float32share_memory在 NPU 上被拦截(GPU 为 no-op,行为不一致,已在测试中标注)_make_fail封杀的 5 个 API 在所有设备上行为一致【资料变更】
经检查
docs/zh/native_apis/下各版本路径,已有记录的 API 18/19。set_submodule缺失,已通过独立文档 PR 提交。【接口变更】
不涉及
【功能验证】
测试文件:
test/jit/test_script_module.py测试环境:
torch 2.12.0+torch_npu 2.12.0+ NPU 910B3(CANN 8.5.0)结果:67 passed,0 failed。
【CheckList】