已合并
fix: [910B/910_93] fall back to aclop for view tensors in format cast #45058
fix: [910B/910_93] fall back to aclop for view tensors in format cast #45058
已合并
wuyouqi1创建于 15 天前
wuyouqi1
wuyouqi1成员
15 天前

【合入来源】

【修改方案】

  1. MaybeUseAclnnNpuFormatCast 非 aclnn-only 分支(910B/910_93)中,新增文件内 IsViewTensor 判定(张量逻辑形状 sizes 与存储 desc 的 base_sizes 不一致即为 view),将原 ND->NZ N×1 列向量窄守卫泛化为通用 sizes 守卫:view(reshape/transpose/slice)直接回退 aclop,恢复 PR 前行为。
  2. 非连续 internal 守卫保持原样;同形异构 stride view(shape 一致、stride 不一致)经实测 aclnn 可正确且位级保值处理,不改变其原有路径。
  3. aclnn-only(950)分支保持现状,不做未经验证的改动。
  4. 回退安全性: aclop 路径尺寸由 torch_npu 侧确定性公式计算(check_size_nonnegative / GuessStorageFormat / GetMemorySize),无垃圾值输入来源。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

  • 10×10 格式矩阵(view 场景,100 组合): 修复前 35 个 OOM 组合修复后全部回退 aclop 成功;28 个 aclnn 正常组合不受影响。
  • 同形异构 stride view 修复前环境实测: 走 aclnn 正确处理,data_ptr 共享存储,数值位级一致(max_err=0),故守卫仅按 sizes 判定、不改变 stride 场景行为。
  • 新增 UT(test_npu_format_cast.py Group 8,5 个用例): reshape / transpose / as_strided 三类 view,覆盖回退行为与数值正确性,适配 910B/910_93。

【CheckList】

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wuyouqi1 的贡献)
wuyouqi1wuyouqi1成员
15 天前 创建了 pull request,commit 90683299
atomgit-bot
atomgit-bot
15 天前 评论:

变更摘要

本 PR 修复 910B/910_93 设备上 npu_format_cast 对 view 张量(reshape/transpose/slice 产生的逻辑形状与存储描述不一致的张量)的格式转换问题:在 MaybeUseAclnnNpuFormatCast 的非 aclnn-only 分支中,新增文件内 IsViewTensor 判定,将原先仅针对 ND->NZ N×1 列向量的窄守卫泛化为通用的 sizes 守卫,使 view 张量统一回退 aclop 路径,避免 aclnn 路径可能导致的 OOM/精度问题并恢复 PR 前行为;同形异构的 stride view(shape 一致、stride 不一致)经实测可被 aclnn 正确处理,故守卫仅按 sizes 判定、不改变其原有路径。同时新增 UT 用例(test_npu_format_cast.py Group 8,5 个用例)覆盖 reshape/transpose/as_strided 三类 view 的回退行为与数值正确性。

主要改动

  • 新增 IsViewTensor 判定函数: 在 FormatCastKernelNpu.cpp 中新增 IsViewTensor,通过比较 src.sizes() 与存储描述 npu_desc_.base_sizes_ 的维度数和各维度大小,判定张量是否为 view(维度不一致或任一维 sizes 不一致即视为 view)。
  • 守卫由窄条件泛化为通用 sizes 守卫: 删除原先仅针对 2D contiguous ND->NZ 且 sizes()[1] == 1 的列向量特判,替换为 if (IsViewTensor(src)) 回退 aclop,使 910B/910_93 非 aclnn-only 分支上所有 view 张量统一回退、恢复 PR 前行为。
  • stride view 路径保持不变: 守卫仅按 sizes 判定、不涉及 stride 比较,同形异构 stride view(shape 一致、stride 不一致)仍走 aclnn 路径,行为不受影响。
  • 新增 Group 8 UT 用例: 在 test_npu_format_cast.py 中新增 5 个用例(test_view_reshape_internal_to_base_fallbacktest_view_reshape_nd_to_nz_fallbacktest_view_transpose_nd_to_nz_fallbacktest_view_strided_same_shape_nd_to_nztest_view_strided_same_shape_internal_to_base),覆盖 reshape/transpose/as_strided 三类 view 的回退与数值正确性,通过 @SupportedDevices(['Ascend910B', 'Ascend910_93']) 限定适配设备。
  • 补充格式常量定义: 在测试文件中新增 ACL_FORMAT_NCHWACL_FORMAT_NC1HWC0 常量,供新用例引用内部格式转换场景。
likedislike
atomgit-bot
atomgit-bot
15 天前 评论:

代码审查

✅ 未发现问题

likedislike
ascend-robotascend-robot成员
15 天前 添加了label:ascend-cla/yes
ascend-robotascend-robot成员
15 天前 添加了label:needs-issue
ascend-robot
ascend-robot成员
15 天前 评论:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/pytorch wanglijun55, chengpeng25 (2/2) chengpeng25 (1/1)
test chengpeng25, wanglijun55 (2/2) chengpeng25 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

wuyouqi1, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robot成员
15 天前 评论:

Linking Issue Notice

@wuyouqi1 , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .

likedislike
ascend-robot
ascend-robot成员
15 天前 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.7.1
v2.12.0
v2.11.0
v2.10.0
v2.9.0
v2.7.1-26.1.0
v2.12.0-26.1.0
v2.10.0-26.1.0
v2.11.0-26.1.0
v2.9.0-26.1.0
ci-test

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robotascend-robot成员
15 天前 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
15 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
15 天前 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
15 天前 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
15 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
15 天前 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
15 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
15 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
15 天前 评论:
流水线 PR-pipeline_pytorch#62797 [ commitID:ff9e21c4 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
Build_X86_213 🛑 >>>
Build_ARM_213 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 codecheck_pre-commit >>>
check_error >>>
lintrunner >>>
开源片段检查 SCA >>>
开发者测试 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 >>>
UT_ARM_A2_Part_01_213 🛑 >>>
UT_ARM_A2_Part_02_213 🛑 >>>
UT_ARM_A2_Part_03_213 🛑 >>>
UT_inductor_Part_01_213 🛑 >>>
UT_inductor_Part_02_213 🛑 >>>
UT_inductor_Part_03_213 🛑 >>>
UT_inductor_Part_04_213 🛑 >>>
UT_DIST_ARM_Part_01_213 🛑 >>>
UT_DIST_ARM_Part_02_213 🛑 >>>
UT_DIST_ARM_Part_03_213 🛑 >>>
UT_DIST_ARM_Part_04_213 🛑 >>>
UT_ARM_A2_Select_Part_01_213 🛑 >>>
UT_ARM_A2_Select_Part_02_213 🛑 >>>
流水线 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, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
wuyouqi1wuyouqi1成员
15 天前 关联了issue:[Bug]:npu_format_cast 对 view 张量在 aclnn 路径分配 1EB 内存 OOM
ascend-robotascend-robot成员
15 天前 删除了label:needs-issue
wuyouqi1wuyouqi1成员
15 天前 关联了里程碑:v26.2.0
chengpeng25成员
14 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:approved
wanglijun55成员
14 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:lgtm
ascend-robotascend-robot成员
14 天前 合入了pull request
ascend-robot
ascend-robot成员
14 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14388 [ commitID:ff9e21c4 ] 已完成
likedislike