[sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356)
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !46545 merge fix/narrow-aclnn-nc1hwc0-3d-fallback-master into master [sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356) Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/4356 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间是如何交互的,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 本 MR 为 !45502(已合入 v2.7.1:`test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356)`)向 **master** 分支的同步合入,代码内容与 v2.7.1 合入版本一致。 1. 背景:issue 4356 中 `allow_internal_format=True` 时,非视图 3D NC1HWC0 张量经 `npu_format_cast(src, NCHW)`(如 `to("cpu")` 触发)在 aclnn 路径报 161001 且毒化进程,导致 `test_single_reshape_copy_to_contiguous` 类 4 个用例被 `@unittest.skip` 临时跳过。 2. 该问题的根因在 CANN 侧(`aclnnNpuFormatCast` 对 3D NC1HWC0 → NCHW 的支持性判定与执行不一致),**CANN 已在 9.2.0 修复**;torch_npu 侧无需 workaround。 3. 本 MR 仅恢复测试看护:解除 `test/trans_contiguous/test_single_reshape_copy_to_contiguous.py` 中 4 个用例的 `@unittest.skip`(view/unsqueeze/flatten/narrow,issue 4356)。 4. 头注释补充说明:设置 `allow_internal_format = True` 走真实内部格式路径时,3D NC1HWC0 在 aclnn 路径上的正确转换需要 CANN >= 9.2.0。 5. 相对 v2.7.1 合入版本的差异:额外删除了该测试文件中解除 skip 后不再使用的 `import unittest`。master 分支的 `.lintrunner.toml` 启用了 flake8 检查(发布分支中该项被注释),机器人同步 MR !46509 因 F401('unittest' imported but unused)CI 失败;本 MR 基于最新 master 重新提交并已修复该 lint 问题(本地 `flake8 --config=.flake8` 验证通过)。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 与 !45502(v2.7.1)验证结论一致,本 MR 为同一变更的分支同步: 1. 环境:910B2 / CANN 9.2.0 / torch_npu(v2.7.1 构建)。 2. 默认配置(`allow_internal_format` 保持注释,走 aclnn 降级路径):`python test_single_reshape_copy_to_contiguous.py -v SingleViewCopyToContiguous`,5 个用例全部通过。 3. 解开 `torch.npu.config.allow_internal_format = True`(CANN 9.2.0 修复生效后):整类用例通过,`test_narrow_at_first_axis_copy` 的 `[fp16, NC1HWC0, [20,16,16]]` item(原 161001 失败点)恢复正常。 4. 本 MR 不修改框架代码,无新增 UT;由恢复的 4 个用例看护原失败路径。 5. **Lint 自验证**:`python -m flake8 --config=.flake8 test/trans_contiguous/test_single_reshape_copy_to_contiguous.py` 通过(修复机器人 MR !46509 的 F401 失败项)。 See merge request: Ascend/pytorch!46545
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import unittest
|
||||
import os
|
||||
import torch
|
||||
import numpy as np
|
||||
@@ -9,19 +8,18 @@ from torch_npu.testing.common_utils import create_common_tensor, check_operators
|
||||
|
||||
os.environ["COMBINED_ENABLE"] = "1" # Open combined-view cases optimization
|
||||
|
||||
SKIP_REASON = "Temporarily skipped; see https://gitcode.com/Ascend/pytorch/issues/4356"
|
||||
|
||||
# Optimized view Ops contains Transpose, permute, narrow, strideslice, select, unfold
|
||||
|
||||
# The test case is a continuous optimization test case for aclop
|
||||
# By default, we will use aclnn in the following steps. To ensure the test case passes, we have added the path to aclnn
|
||||
# If the primary function is to maintain the original functionality, you can configure jit_compile and internal formats
|
||||
# NOTE: set allow_internal_format = True to exercise real internal-format paths; correct
|
||||
# 3D NC1HWC0 conversion on the aclnn path requires CANN >= 9.2.0
|
||||
# torch_npu.npu.set_compile_mode(jit_compile=True)
|
||||
# torch.npu.config.allow_internal_format = True
|
||||
|
||||
|
||||
class SingleViewCopyToContiguous(TestCase):
|
||||
@unittest.skip(SKIP_REASON)
|
||||
def test_view_copy(self, device="npu"):
|
||||
dtype_list1 = [np.float16, np.float32]
|
||||
format_list1 = [0, 3, 29]
|
||||
@@ -69,7 +67,6 @@ class SingleViewCopyToContiguous(TestCase):
|
||||
cpu_out2 = cpu_input.view(1, 6, cpu_input.size(2) * cpu_input.size(3), 1).clone()
|
||||
self.assertRtolEqual(npu_out2.to("cpu").numpy(), cpu_out2.numpy())
|
||||
|
||||
@unittest.skip(SKIP_REASON)
|
||||
def test_unsqueeze_copy(self, device="npu"):
|
||||
dtype_list2 = [np.float16, np.float32]
|
||||
format_list2 = [2, 3, 29]
|
||||
@@ -102,7 +99,6 @@ class SingleViewCopyToContiguous(TestCase):
|
||||
cpu_out = cpu_input.unsqueeze(i).clone()
|
||||
self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy())
|
||||
|
||||
@unittest.skip(SKIP_REASON)
|
||||
def test_flatten_copy(self, device="npu"):
|
||||
dtype_list3 = [np.float16, np.float32]
|
||||
format_list3 = [0, 3, 29]
|
||||
@@ -132,7 +128,6 @@ class SingleViewCopyToContiguous(TestCase):
|
||||
cpu_out = torch.flatten(cpu_input, 0, 1).clone()
|
||||
self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy())
|
||||
|
||||
@unittest.skip(SKIP_REASON)
|
||||
def test_narrow_at_first_axis_copy(self, device="npu"):
|
||||
# this case: slice at the first dim, tensor with offset remains contiguous
|
||||
dtype_list4 = [np.float16, np.float32]
|
||||
|
||||
Reference in New Issue
Block a user