已合并
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39484
test(utils): adapt torch.utils.checkpoint.checkpoint, torch.utils.checkpoint.checkpoint_sequential and torch.overrides.is_tensor_like on NPU #39484
已合并
yulin520创建于 6月27日
yulin520
yulin520
6月27日

【合入来源】

如有社区issue,请关联issue链接 请勿携带内部流程信息(需求链接、问题单、内部issue等)

关联 Issue:https://gitcode.com/Ascend/pytorch/issues/2529
关联 Issue:#2529

关联任务:torch.overrides.is_tensor_like、torch.utils.checkpoint.checkpoint、torch.utils.checkpoint.checkpoint_sequential API 一致性验证。

本 PR 对 v2.10.0 分支补充上述 API 在 NPU 场景下的上游测试适配。

【修改方案】

本 PR 仅涉及 test_upstream 上游测试 patch 适配,不修改 torch_npu 功能实现代码,不改变已有 API 行为。

修改文件:

  • test_upstream/test/test_autograd.py.patch
  • test_upstream/test/dynamo/test_misc.py.patch

具体修改如下:

  1. 在 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 输入下能够正常前向、反向传播。
  2. 在 test_upstream/test/dynamo/test_misc.py.patch 中补充 torch.overrides.is_tensor_like 相关用例的 NPU 适配:

    • 将 torch.overrides.is_tensor_like 测试输入 Tensor 放置到 NPU;
    • 验证 NPU Tensor 场景下 torch.overrides.is_tensor_like 返回结果正确。
  3. 保留现有 torch.utils.checkpoint.checkpoint 相关 NPU 适配内容:

    • 本次修改未改变 torch.utils.checkpoint.checkpoint API 的功能实现;
    • 仅在本地验证中同时覆盖 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 对应分支的本地运行验证。

验证环境:

  • 操作系统:Ubuntu 22.04.5 LTS / aarch64
  • CANN:cann-9.1.0-beta.1
  • NPU 设备:Ascend910B4
  • 目标分支:v2.10.0
  • 测试分支:test-checkpoint-overrides-npu-v210
  • torch 版本:2.10.0
  • torch_npu 版本:2.10.0
  • NPU 可用性:torch.npu.is_available() == True

验证内容:

  1. torch.utils.checkpoint.checkpoint_sequential

    • NPU Tensor 输入;
    • NPU Linear 模块;
    • 前向计算和反向传播均通过。
  2. torch.overrides.is_tensor_like

    • NPU Tensor 输入;
    • torch.overrides.is_tensor_like 返回结果为 True。
  3. torch.utils.checkpoint.checkpoint

    • NPU Tensor 输入;
    • 前向计算和反向传播均通过。

本地验证结果:

  • torch.utils.checkpoint.checkpoint_sequential NPU validation PASSED
  • torch.overrides.is_tensor_like NPU validation PASSED
  • torch.utils.checkpoint.checkpoint NPU validation PASSED
  • RUNTIME VALIDATION PASSED

测试自验证截图:
2.10.0.png

Patch 生成与检查说明:

本 PR 中的 patch 基于对应版本的 PyTorch 社区源码生成。已有 patch 时,先在对应版本 PyTorch 社区源码中应用原 patch,再根据代码审查意见修改社区源码文件,将 torch.ones(10) 调整为 torch.ones(10).npu(),避免默认生成 CPU Tensor 后与 NPU Tensor x 相加导致设备不一致。修改完成后,通过 git diff 重新生成 patch 文件,未在生成后直接编辑 patch 文件。

已完成以下检查:

  • 已执行 patch 应用检查;
  • 已检查 patch 不包含整文件删除;
  • 已检查 patch 不包含冲突标记;
  • 已检查本 PR 仅包含目标 patch 文件修改;
  • 已确认 torch.ones(10) 已在社区源码中迁移至 NPU,并通过 git diff 重新生成对应 patch;
  • 已在匹配版本的 torch / torch_npu 运行时环境中完成本地 NPU 复验。

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 yulin520 的贡献)
yulin520yulin520
6月27日 创建了 pull request,commit b3819954
ascend-robotascend-robot成员
6月27日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
ascend-robotascend-robot成员
6月27日 添加了label:needs-issue
此处折叠了113条消息 查看更多
ascend-robot
ascend-robot成员
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 ✅ >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
renyujin成员
7月7日 评论:

/lgtm

likedislike
chenrayray
chenrayray成员
7月7日 评论:

/approve

likedislike
ascend-robotascend-robot成员
7月7日 添加了label:approvedlgtm
ascend-robotascend-robot成员
7月7日 合入了pull request