已合并
[feat]TensorTo support preserve_format consistent with GPU #35351
culechan创建于 5月12日
[feat]TensorTo support preserve_format consistent with GPU #35351
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 culechan 的贡献)ascend-robot
5月12日 评论:
5月12日 评论:
5月12日 添加了label:stat/needs-squash
ascend-robot
5月12日 评论:
5月12日 评论:
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 |
|---|---|---|
| repo-Ascend/pytorch | ✅ htchu, ffmh (2/2) | ✅ htchu (1/1) |
| test | ✅ htchu, probiotics_53, ffmh (3/2) | ✅ htchu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
culechan, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月12日 添加了label:ascend-cla/yes
此处折叠了66条消息 查看更多
5月13日 添加了label:approvedlgtm
openLiBingCI
5月13日 评论:
5月13日 评论:
本PR中共发现代码检查告警抑制8处,请Committer检视合理性
本评论自动扫描PR中使用的开源代码检查工具(ruff、clang-tidy、CodeQL等)的屏蔽注释。
这些屏蔽注释会阻止开源代码检查工具对特定代码区域的检测,可能导致潜在问题被忽略。
| 文件路径 | 行号 | 屏蔽类型 | 代码片段 | 工具名称 |
|---|---|---|---|---|
| test/npu/test_npu.py | 605 | 行级屏蔽 | 601: # check that the allocation is not reused if it's in-use by a copy 602: npu_tensor = torch.npu.FloatTensor([0]) 603: npu_tensor.copy_(t, non_blocking=True) 604: del t 605: t = torch.FloatTensor([1]).pin_memory() # noqa: F841 606: self.assertEqual(list(npu_tensor), [1]) 608: def test_function_torch_empty_and_to(self): 609: x = torch.empty((2, 3), dtype=torch.float16, device="npu") 610: x_int32 = x.to(torch.int32) 611: res = x_int32 + 1 # noqa: F841 |
flake8 |
| test/npu/test_npu.py | 611 | 行级屏蔽 | 606: self.assertEqual(list(npu_tensor), [1]) 608: def test_function_torch_empty_and_to(self): 609: x = torch.empty((2, 3), dtype=torch.float16, device="npu") 610: x_int32 = x.to(torch.int32) 611: res = x_int32 + 1 # noqa: F841 613: def test_function_npu(self): 614: x = torch.empty((2, 3), dtype=torch.float16, device="cpu") 615: x_npu = x.npu() 616: res = x_npu + 1 # noqa: F841 618: def test_function_torch_empty_with_format(self): |
flake8 |
| test/npu/test_npu.py | 616 | 行级屏蔽 | 611: res = x_int32 + 1 # noqa: F841 613: def test_function_npu(self): 614: x = torch.empty((2, 3), dtype=torch.float16, device="cpu") 615: x_npu = x.npu() 616: res = x_npu + 1 # noqa: F841 618: def test_function_torch_empty_with_format(self): 619: x = torch_npu.empty_with_format((2, 3), dtype=torch.float32, device="npu") 620: res = x + 1 # noqa: F841 622: def test_function_torch_empty_like(self): 623: x = torch.empty((2, 3), dtype=torch.float32, device="npu") |
flake8 |
| test/npu/test_npu.py | 620 | 行级屏蔽 | 615: x_npu = x.npu() 616: res = x_npu + 1 # noqa: F841 618: def test_function_torch_empty_with_format(self): 619: x = torch_npu.empty_with_format((2, 3), dtype=torch.float32, device="npu") 620: res = x + 1 # noqa: F841 622: def test_function_torch_empty_like(self): 623: x = torch.empty((2, 3), dtype=torch.float32, device="npu") 624: x_like = torch.empty_like(x) 625: res = x_like + 1 # noqa: F841 627: def test_function_torch_empty_like_with_stride(self): |
flake8 |
| test/npu/test_npu.py | 625 | 行级屏蔽 | 620: res = x + 1 # noqa: F841 622: def test_function_torch_empty_like(self): 623: x = torch.empty((2, 3), dtype=torch.float32, device="npu") 624: x_like = torch.empty_like(x) 625: res = x_like + 1 # noqa: F841 627: def test_function_torch_empty_like_with_stride(self): 628: # if a is contiguous, stride of b should be same as a 629: a = torch.empty([16, 32], device="npu") 630: self.assertTrue(a.is_contiguous()) 631: self.assertEqual(a.stride(), (32, 1)) |
flake8 |
| test/npu/test_npu.py | 911 | 行级屏蔽 | 906: npu_t = cpu_t.npu() 907: self.assertFalse(cpu_t.is_contiguous()) 908: self._compare_with_cpu(cpu_t, npu_t, memory_format=torch.preserve_format) 910: def test_function_torch_empty_strided(self): 911: x = torch.empty_strided((2, 3), (1, 2), dtype=torch.int8, device="npu") # noqa: F841 913: def test_function_tensor_new_empty(self): 914: x = torch.ones(()).npu() 915: x_new_empty = x.new_empty((2, 3), dtype=torch.float16, device="npu") 916: res = x_new_empty + 1 917: x_new_empty = x.new_empty(size=(2, 3), dtype=torch.float16, device="npu") |
flake8 |
| test/npu/test_npu.py | 918 | 行级屏蔽 | 914: x = torch.ones(()).npu() 915: x_new_empty = x.new_empty((2, 3), dtype=torch.float16, device="npu") 916: res = x_new_empty + 1 917: x_new_empty = x.new_empty(size=(2, 3), dtype=torch.float16, device="npu") 918: res = x_new_empty + 1 # noqa: F841 920: def test_function_tensor_new_empty_strided(self): 921: x = torch.ones(()).npu() 922: x_new = x.new_empty_strided([2, 3], [3, 1], dtype=torch.float32, device="npu") 923: res = x_new + 1 # noqa: F841 925: def test_function_tensor_data_npu(self): |
flake8 |
| test/npu/test_npu.py | 923 | 行级屏蔽 | 918: res = x_new_empty + 1 # noqa: F841 920: def test_function_tensor_new_empty_strided(self): 921: x = torch.ones(()).npu() 922: x_new = x.new_empty_strided([2, 3], [3, 1], dtype=torch.float32, device="npu") 923: res = x_new + 1 # noqa: F841 925: def test_function_tensor_data_npu(self): 926: x = torch.ones(()) 927: x.data = x.data.npu() 929: def test_function_tensor_new_full(self): 930: x_cpu = torch.tensor((), dtype=torch.float32) |
flake8 |


ascend-robot
5月13日 评论:
5月13日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: htchu.
Reviewers who wrote a comment of /lgtm are: ffmh, probiotics_53, htchu.


5月13日 合入了pull request
【合入来源】
【修改方案】
1、NPU上tensorto支持preserve_format模式。行为逻辑上对齐pytorch原生框架
2、增加preserve_format模式相关的测试用例
【资料变更】
不涉及,原生API表格中未体现这部分内容
【接口变更】
Tensor.to默认使用且支持preserve_format模式
【功能验证】
【CheckList】