已合并
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39484
yulin520创建于 6月27日
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39484
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 yulin520 的贡献)ascend-robot
6月27日 评论:
6月27日 评论:
6月27日 添加了label:ascend-cla/yes
ascend-robot
6月27日 评论:
6月27日 评论:
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_upstream | ✅ chenrayray, renyujin (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
weixin_65332823, thanks for your pull request. All authors of the commits have signed the CLA. 👍


6月27日 添加了label:needs-issue
此处折叠了113条消息 查看更多
ascend-robot
7月6日 评论:
7月6日 评论:
流水线 PR-pipeline_pytorch#41380 [ commitID:d3d61eaf ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线


chenrayray
7月7日 评论:
7月7日 评论:
/approve


7月7日 添加了label:approvedlgtm
7月7日 合入了pull request
【合入来源】
关联 Issue:https://gitcode.com/Ascend/pytorch/issues/2529
关联 Issue:#2529
关联任务:
torch.overrides.is_tensor_like、torch.utils.checkpoint.checkpoint、torch.utils.checkpoint.checkpoint_sequentialAPI 一致性验证。本 PR 对
v2.10.0分支补充上述 API 在 NPU 场景下的上游测试适配。【修改方案】
本 PR 仅涉及
test_upstream上游测试 patch 适配,不修改torch_npu功能实现代码,不改变已有 API 行为。修改文件:
test_upstream/test/test_autograd.py.patchtest_upstream/test/dynamo/test_misc.py.patch具体修改如下:
在
test_upstream/test/test_autograd.py.patch中补充torch.utils.checkpoint.checkpoint_sequential相关用例的 NPU 适配:torch.utils.checkpoint.checkpoint_sequential相关测试输入 Tensor 从 CPU 放置到 NPU;torch.utils.checkpoint.checkpoint_sequential测试中使用的torch.nn.Linear模块迁移到 NPU;torch.utils.checkpoint.checkpoint_sequential在 NPU Tensor 输入下能够正常前向、反向传播。在
test_upstream/test/dynamo/test_misc.py.patch中补充torch.overrides.is_tensor_like相关用例的 NPU 适配:torch.overrides.is_tensor_like测试输入 Tensor 放置到 NPU;torch.overrides.is_tensor_like返回结果正确。保留现有
torch.utils.checkpoint.checkpoint相关 NPU 适配内容:torch.utils.checkpoint.checkpointAPI 的功能实现;torch.utils.checkpoint.checkpoint、torch.utils.checkpoint.checkpoint_sequential和torch.overrides.is_tensor_like,确保三类目标 API 在 NPU 场景下均可正常运行。【资料变更】
不涉及。
本 PR 仅补充上游测试用例在 NPU 场景下的适配,不新增或修改用户可见资料。相关 API 在目标版本资料中已有说明,因此本任务不需要新增 doc PR。
【接口变更】
不涉及。
本 PR 不新增、删除或修改客户可见接口,不涉及跨代码仓接口变更,不改变
torch.utils.checkpoint.checkpoint、torch.utils.checkpoint.checkpoint_sequential或torch.overrides.is_tensor_like的调用方式和返回语义。【功能验证】
已在 Ascend 910B4 NPU 环境完成
v2.10.0对应分支的本地运行验证。验证环境:
v2.10.0test-checkpoint-overrides-npu-v2102.10.02.10.0torch.npu.is_available() == True验证内容:
torch.utils.checkpoint.checkpoint_sequentialtorch.overrides.is_tensor_liketorch.overrides.is_tensor_like返回结果为 True。torch.utils.checkpoint.checkpoint本地验证结果:
torch.utils.checkpoint.checkpoint_sequential NPU validation PASSEDtorch.overrides.is_tensor_like NPU validation PASSEDtorch.utils.checkpoint.checkpoint NPU validation PASSEDRUNTIME VALIDATION PASSED测试自验证截图:

Patch 生成与检查说明:
本 PR 中的 patch 基于对应版本的 PyTorch 社区源码生成。已有 patch 时,先在对应版本 PyTorch 社区源码中应用原 patch,再根据代码审查意见修改社区源码文件,将
torch.ones(10)调整为torch.ones(10).npu(),避免默认生成 CPU Tensor 后与 NPU Tensorx相加导致设备不一致。修改完成后,通过git diff重新生成 patch 文件,未在生成后直接编辑 patch 文件。已完成以下检查:
torch.ones(10)已在社区源码中迁移至 NPU,并通过git diff重新生成对应 patch;torch/torch_npu运行时环境中完成本地 NPU 复验。【CheckList】