已合并
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39483
yulin520创建于 6月27日
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39483
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 yulin520 的贡献)ascend-robot
6月27日 评论:
6月27日 评论:
6月27日 添加了label:ascend-cla/yes
ascend-robot
6月27日 评论:
6月27日 评论:
6月27日 添加了label:needs-issue
此处折叠了121条消息 查看更多
7月7日 合入了pull request
ascend-robot
7月7日 评论:
7月7日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
7月7日 评论:
7月7日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
7月7日 评论:
7月7日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
7月7日 评论:
7月7日 评论:
流水线 pytorch_gitcode_PR_multiVersion#12082 [ commitID:7ab19c53 ] 已完成


【合入来源】
关联 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.9.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.9.0对应分支的本地运行验证。验证环境:
v2.9.0test-checkpoint-overrides-npu-v2902.9.02.9.0.post2torch.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】