已关闭
【API一致性任务】torch.UntypedStorage.tolist NPU 测试适配方案 #4040
Wo150创建于  8月15日关闭于  24 天前
Wo150
8月15日 创建

torch.UntypedStorage.tolist NPU 测试适配方案

一、API 功能说明

适用版本:v2.7.1、v2.11.0、v2.12.0、master

当前状态: 有效。

可见性: 公开。

功能: torch.UntypedStorage.tolist() 将当前无类型存储中的元素转换为 Python 列表,并按存储中的元素顺序返回。

参数: 该方法不接收业务参数。

返回: 返回包含当前存储元素的 Python list

设备约束: 未发现 Python 层显式设备限制;设备能力跟随输入张量并由底层实现决定。

二、PyTorch 社区测试用例情况

适用版本:v2.7.1、v2.11.0、v2.12.0、master

PyTorch 社区测试中检索到以下与 torch.UntypedStorage.tolist 相关的用例:

测试文件 测试用例 覆盖情况
test/test_torch.py test_bytes_to_scalar 覆盖存储字节转换为标量的相关路径,并直接使用存储列表结果进行验证。
test/test_torch.py test_storage_byteswap 覆盖存储字节序交换场景,并直接使用存储列表结果检查交换后的内容。

现有社区测试覆盖了字节转换和字节序交换相关路径,但未形成面向 NPU 设备的空存储、完整字节边界、存储切片及非法参数专项验证。

结论:PyTorch社区已有测试用例,但是测试用例覆盖不全

三、API 测试用例补齐及适配方案

适配方案所属版本:v2.7.1、v2.11.0、v2.12.0、master

新增测试文件 test/test_untyped_storage_tolist.py,补充以下测试用例:

测试用例 验证场景
test_tolist_empty_storage 在目标设备上构造空的 uint8 张量并取得无类型存储,验证 tolist() 返回空列表。
test_tolist_byte_boundaries 使用 0、1、127、128、254、255 等典型字节边界值,验证无类型存储转换后的列表内容与输入一致。
test_tolist_all_byte_values 构造覆盖完整字节取值范围的输入,验证 tolist() 能完整、按序返回存储字节。
test_tolist_storage_slice 对无类型存储进行切片,验证切片结果仍为 torch.UntypedStorage,且 tolist() 返回对应区间内容。
test_tolist_invalid_arguments 向无参数方法传入非法关键字参数,验证抛出 TypeError

测试内容: 测试围绕空存储、典型字节边界、完整字节取值、存储切片和非法参数五类场景,在目标设备上调用 torch.UntypedStorage.tolist,并通过列表相等、对象类型和异常断言验证返回内容、顺序、切片行为及参数约束。

新增原因及必要性: PyTorch 社区现有相关用例主要覆盖字节转换和字节序交换路径,未直接覆盖上述 NPU 专项场景。新增测试用于确认该公开存储接口在 NPU 上的基本功能、边界数据、视图切片和错误处理行为,降低后续底层存储实现变化造成行为回归的风险。

四、资料变更

适用版本:v2.7.1、v2.11.0、v2.12.0

结论:不涉及。

TorchNPU 文档树的对应独立版本资料目录中已检索到 torch-Storage.md 资料,本次提交仅新增 NPU 测试文件,未修改资料,也未引入需要同步更新的接口能力说明。

五、接口变更

适用版本:v2.7.1、v2.11.0、v2.12.0、master

结论:不涉及。

本次提交仅新增 test/test_untyped_storage_tolist.py 测试文件,未修改 API 实现、声明、注册或跨仓依赖,也未改变客户可见的参数、返回值和运行行为,因此不涉及接口变更。

六、功能验证

v2.7.1

执行命令:

python test_untyped_storage_tolist.py -v

结果:

test_tolist_all_byte_values (__main__.TestUntypedStorageToList.test_tolist_all_byte_values) ... [W815 03:26:02.920477846 NPUCachingAllocator.cpp:198] Warning: The current CANN and Soc Version require processing for 32 padding size, with memory allocation. (function operator())
ok
test_tolist_byte_boundaries (__main__.TestUntypedStorageToList.test_tolist_byte_boundaries) ... ok
test_tolist_empty_storage (__main__.TestUntypedStorageToList.test_tolist_empty_storage) ... ok
test_tolist_invalid_arguments (__main__.TestUntypedStorageToList.test_tolist_invalid_arguments) ... ok
test_tolist_storage_slice (__main__.TestUntypedStorageToList.test_tolist_storage_slice) ... ok

----------------------------------------------------------------------
Ran 5 tests in 1.139s

OK

v2.11.0

执行命令:

python test_untyped_storage_tolist.py -v

结果:

test_tolist_all_byte_values (__main__.TestUntypedStorageToList.test_tolist_all_byte_values) ... [W815 03:26:14.204852357 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok
test_tolist_byte_boundaries (__main__.TestUntypedStorageToList.test_tolist_byte_boundaries) ... ok
test_tolist_empty_storage (__main__.TestUntypedStorageToList.test_tolist_empty_storage) ... ok
test_tolist_invalid_arguments (__main__.TestUntypedStorageToList.test_tolist_invalid_arguments) ... ok
test_tolist_storage_slice (__main__.TestUntypedStorageToList.test_tolist_storage_slice) ... ok

----------------------------------------------------------------------
Ran 5 tests in 1.148s

OK

v2.12.0

执行命令:

python test_untyped_storage_tolist.py -v

结果:

W0815 03:26:24.557000 359368 <absolute-path>/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages `nvidia-cutlass-dsl` and `apache-tvm-ffi`; missing optional dependency `nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed)
test_tolist_all_byte_values (__main__.TestUntypedStorageToList.test_tolist_all_byte_values) ... [W815 03:26:25.688292968 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok
test_tolist_byte_boundaries (__main__.TestUntypedStorageToList.test_tolist_byte_boundaries) ... ok
test_tolist_empty_storage (__main__.TestUntypedStorageToList.test_tolist_empty_storage) ... ok
test_tolist_invalid_arguments (__main__.TestUntypedStorageToList.test_tolist_invalid_arguments) ... ok
test_tolist_storage_slice (__main__.TestUntypedStorageToList.test_tolist_storage_slice) ... ok

----------------------------------------------------------------------
Ran 5 tests in 1.134s

OK

master

执行命令:

python test_untyped_storage_tolist.py -v

结果:

W0815 03:26:37.202000 359457 <absolute-path>/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages `nvidia-cutlass-dsl` and `apache-tvm-ffi`; missing optional dependency `nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed)
test_tolist_all_byte_values (__main__.TestUntypedStorageToList.test_tolist_all_byte_values) ... [W815 03:26:38.340855850 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok
test_tolist_byte_boundaries (__main__.TestUntypedStorageToList.test_tolist_byte_boundaries) ... ok
test_tolist_empty_storage (__main__.TestUntypedStorageToList.test_tolist_empty_storage) ... ok
test_tolist_invalid_arguments (__main__.TestUntypedStorageToList.test_tolist_invalid_arguments) ... ok
test_tolist_storage_slice (__main__.TestUntypedStorageToList.test_tolist_storage_slice) ... ok

----------------------------------------------------------------------
Ran 5 tests in 1.139s

OK
likedislike
WWo150
8月15日 关联了看板:FrameworkPTAdapter 版本issue看板
WWo150
8月15日 关联了pull request:test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added.
WWo150
8月15日 关联了pull request:test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added.
WWo150
8月15日 关联了pull request:test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added.
WWo150
8月15日 关联了pull request:test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added.
WWo150
8月16日 修改了issue 的描述
TorchNPU-BotTorchNPU-Bot成员
8月17日 添加了label:bot-triaged
TorchNPU-Bot
TorchNPU-Bot成员
8月17日 评论:

检测到当前 issue 已关联 PR !44643,自动添加标签:bot-triaged

likedislike
WWo150
8月18日 修改标题为 “【API一致性任务】torch.UntypedStorage.tolist NPU 测试适配方案”,原标题为“torch.UntypedStorage.tolist NPU 测试适配方案”
TorchNPU-BotTorchNPU-Bot成员
8月18日 添加了label:help-wantedevent: api-consistency
TorchNPU-Bot
TorchNPU-Bot成员
8月18日 评论:

检测到社区任务相关 issue,自动添加标签:event: api-consistencyhelp-wanted

likedislike
ascend-robotascend-robot成员
24 天前 关闭了 issue
ascend-robotascend-robot成员
24 天前 添加了label:resolved