已合并
test(distributed): add test for WriteItem.tensor_storage_size #35400
Flipped创建于 5月12日
test(distributed): add test for WriteItem.tensor_storage_size #35400
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Flipped 的贡献)5月12日 关联了issue:[Usage]: API一致性说明:torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size 缺少专项验证用例
5月12日 关联了issue:[Usage]: API一致性说明:torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size 缺少专项验证用例
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 |
|---|---|---|
| test | ✅ 李伟, sunyu-xuan, huangjingwei (3/3) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
qq_65095566, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月12日 添加了label:ascend-cla/yes
ascend-robot
5月12日 评论:
5月12日 评论:
当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.9.0 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.12.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


Flipped
5月12日 评论:
5月12日 评论:
compile


ascend-robot
5月12日 评论:
5月12日 评论:
流水线 PR-pipeline_pytorch#21345 运行中
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | 🕚 | >>> |
| Build_ARM | 🕚 | >>> | |
| Build_LibTorch_x86 | 🕚 | >>> | |
| Build_LibTorch_ARM | 🕚 | >>> | |
| Build_X86_torchair | 🕚 | >>> | |
| Build_ARM_torchair | 🕚 | >>> | |
| patch_test | 🕚 | >>> | |
| 恶意代码检查 | Antipoison | 🕚 | >>> |
| 编码安全与规范检查 | CodeCheck | 🕚 | >>> |
| check_error | 🕚 | >>> | |
| 开源片段检查 | SCA | 🕚 | >>> |
| 开发者测试 | UT_X86_Part_01 | 🕚 | >>> |
| UT_X86_Part_02 | 🕚 | >>> | |
| UT_ARM_A3_Part_01 | 🕚 | >>> | |
| UT_ARM_A3_Part_02 | 🕚 | >>> | |
| UT_DIST_X86_Part_01 | 🕚 | >>> | |
| UT_DIST_X86_Part_02 | 🕚 | >>> | |
| UT_DIST_X86_Part_03 | 🕚 | >>> | |
| UT_DIST_X86_Part_04 | 🕚 | >>> | |
| UT_ARM_A2_Part_01 | 🕚 | >>> | |
| UT_ARM_A2_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_03 | 🕚 | >>> | |
| UT_inductor_Part_01_pool | 🕚 | >>> | |
| UT_inductor_Part_02_pool | 🕚 | >>> | |
| UT_inductor_Part_03_pool | 🕚 | >>> | |
| UT_inductor_Part_04_pool | 🕚 | >>> | |
| UT_DIST_ARM_Part_01 | 🕚 | >>> | |
| UT_DIST_ARM_Part_02 | 🕚 | >>> | |
| UT_DIST_ARM_Part_03 | 🕚 | >>> | |
| UT_DIST_ARM_Part_04 | 🕚 | >>> | |
| 流水线 | PR-pipeline_pytorch | 🕚 | >>> |


ascend-robot
5月12日 评论:
5月12日 评论:
5月12日 添加了label:ci-pipeline-running
ascend-robot
5月12日 评论:
5月12日 评论:
Ascend docs pipeline is running...


5月12日 添加了label:docs-ci-pipeline-running
ascend-robot
5月12日 评论:
5月12日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


5月12日 删除了label:docs-ci-pipeline-running
5月12日 添加了label:docs-ci-pipeline-success
5月12日 删除了label:ci-pipeline-running
ascend-robot
5月12日 评论:
5月12日 评论:
流水线 PR-pipeline_pytorch#21345 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | ✅ | >>> |
| UT_X86_Part_02 | ✅ | >>> | |
| UT_ARM_A3_Part_01 | ✅ | >>> | |
| UT_ARM_A3_Part_02 | ✅ | >>> | |
| UT_DIST_X86_Part_01 | ✅ | >>> | |
| UT_DIST_X86_Part_02 | ✅ | >>> | |
| UT_DIST_X86_Part_03 | ✅ | >>> | |
| UT_DIST_X86_Part_04 | ✅ | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01_pool | 🛑 | >>> | |
| UT_inductor_Part_02_pool | 🛑 | >>> | |
| UT_inductor_Part_03_pool | 🛑 | >>> | |
| UT_inductor_Part_04_pool | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


5月12日 添加了label:ci-pipeline-passed
5月13日 修改了pull request 的描述
5月13日 update merge request[project id: 7404318, iid: 35400, commit_id: 24c6105d283828cc7ae659aa5c40ecd6e995bf41] virtual merging success
5月13日 update merge request[project id: 7404318, iid: 35400, commit_id: 24c6105d283828cc7ae659aa5c40ecd6e995bf41] virtual merging success
5月13日 update merge request[project id: 7404318, iid: 35400, commit_id: 657b421a259b4c40a7aa0a4536bb369b9d6a87de] virtual merging success
5月13日 update merge request[project id: 7404318, iid: 35400, commit_id: 657b421a259b4c40a7aa0a4536bb369b9d6a87de] virtual merging success
5月13日 删除了label:ci-pipeline-passed
ascend-robot
5月13日 评论:
5月13日 评论:
5月13日 添加了label:ci-pipeline-failed
5月13日 修改了pull request 的描述
5月13日 修改了pull request 的描述
Flipped
5月13日 评论:
5月13日 评论:
compile


5月13日 删除了label:ci-pipeline-failed
5月13日 添加了label:ci-pipeline-running
ascend-robot
5月13日 评论:
5月13日 评论:
流水线 PR-pipeline_pytorch#21693 运行中
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | 🕚 | >>> |
| Build_ARM | 🕚 | >>> | |
| Build_LibTorch_x86 | 🕚 | >>> | |
| Build_LibTorch_ARM | 🕚 | >>> | |
| Build_X86_torchair | 🕚 | >>> | |
| Build_ARM_torchair | 🕚 | >>> | |
| patch_test | 🕚 | >>> | |
| 恶意代码检查 | Antipoison | 🕚 | >>> |
| 编码安全与规范检查 | CodeCheck | 🕚 | >>> |
| check_error | 🕚 | >>> | |
| 开源片段检查 | SCA | 🕚 | >>> |
| 开发者测试 | UT_X86_Part_01 | 🕚 | >>> |
| UT_X86_Part_02 | 🕚 | >>> | |
| UT_ARM_A3_Part_01 | 🕚 | >>> | |
| UT_ARM_A3_Part_02 | 🕚 | >>> | |
| UT_DIST_X86_Part_01 | 🕚 | >>> | |
| UT_DIST_X86_Part_02 | 🕚 | >>> | |
| UT_DIST_X86_Part_03 | 🕚 | >>> | |
| UT_DIST_X86_Part_04 | 🕚 | >>> | |
| UT_ARM_A2_Part_01 | 🕚 | >>> | |
| UT_ARM_A2_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_03 | 🕚 | >>> | |
| UT_inductor_Part_01_pool | 🕚 | >>> | |
| UT_inductor_Part_02_pool | 🕚 | >>> | |
| UT_inductor_Part_03_pool | 🕚 | >>> | |
| UT_inductor_Part_04_pool | 🕚 | >>> | |
| UT_DIST_ARM_Part_01 | 🕚 | >>> | |
| UT_DIST_ARM_Part_02 | 🕚 | >>> | |
| UT_DIST_ARM_Part_03 | 🕚 | >>> | |
| UT_DIST_ARM_Part_04 | 🕚 | >>> | |
| 流水线 | PR-pipeline_pytorch | 🕚 | >>> |


5月13日 删除了label:ci-pipeline-running
5月13日 添加了label:ci-pipeline-passed
5月14日 修改了pull request 的描述
5月14日 修改了pull request 的描述
5月14日 修改了pull request 的描述
sunyu-xuan
5月15日 评论:
5月15日 评论:
/lgtm


5月18日 添加了label:approved
Jingwei Huang
5月18日 评论:
5月18日 评论:
/lgtm


5月18日 添加了label:lgtm
ascend-robot
5月18日 评论:
5月18日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: 李伟.
Reviewers who wrote a comment of /lgtm are: 李伟, huangjingwei, sunyu-xuan.


5月18日 合入了pull request
【合入来源】
【修改方案】
本 PR 针对
torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size新增专项验证用例。一、API 功能说明
torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size是 distributed checkpoint planner 中WriteItem提供的元数据辅助方法,用于返回当前写入项对应 tensor 的存储大小,单位为 bytes。该 API 的核心行为如下:
WriteItem.tensor_data为None时,表示该写入项不是 tensor 写入项,例如WriteItemType.BYTE_IO,此时返回None。WriteItem.tensor_data不为None时,根据tensor_data.size计算元素数量,并结合tensor_data.properties.dtype计算单个元素字节数,最终返回 tensor 存储字节数。二、用例补齐说明
经检索,当前测试目录中未发现直接调用
WriteItem.tensor_storage_size()并断言其返回值的专项测试用例。已有 checkpoint planner 相关测试主要覆盖WriteItem、SavePlan、TensorWriteData等结构和 planner 流程,但没有单独验证tensor_storage_size的返回值行为。因此,本 PR 新增测试文件:
test/distributed/checkpoint/test_planner_api.py
该测试文件覆盖以下场景:
WriteItemType.TENSOR + tensor_data
构造普通 tensor 写入项,覆盖 torch.float32、torch.float16 和 torch.int8 三种 dtype,验证返回值等于:
tensor.numel() * tensor.element_size()
WriteItemType.SHARD + tensor_data
构造 shard 写入项,验证 tensor_storage_size 能够根据 shard 对应的 tensor metadata 返回正确的存储字节数。
WriteItemType.BYTE_IO 且 tensor_data 为 None
构造非 tensor 写入项,验证 tensor_storage_size 返回 None。
三、NPU 适配说明
torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size 本身是元数据辅助方法,不直接依赖 NPU 算子。但测试中需要基于 tensor 构造 TensorWriteData 和 TensorProperties,因此测试 tensor 需要运行在 NPU 设备上。
本 PR 使用如下方式获取当前 accelerator:
device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"
并通过如下方式将测试 tensor 迁移到当前设备:
tensor = torch.empty((2, 3), dtype=dtype).to(device_type)
因此,在 NPU 环境下,测试 tensor 会运行在 NPU 设备上,满足 NPU 适配要求。
四、涉及版本说明
本次用例补齐分别提交到以下目标分支:
v2.7.1
v2.9.0
v2.10.0
v2.11.0
v2.12.0
master
各版本均单独提交 PR,目标分支与源码分支一一对应。
【资料变更】
涉及资料支持情况检查。本 PR 不直接修改资料文件。
已检查 v2.7.1 分支
docs/zh/native_apis,当前文档中已有torch.distributed.checkpoint.planner.WriteItem,但未检索到torch.distributed.checkpoint.planner.WriteItem.tensor_storage_size的方法级支持信息。已单独提交资料补齐 PR 到 v2.7.1 分支,补充
docs/zh/native_apis中该 API 的支持情况。资料 PR 刷新以下版本目录:docs/zh/native_apis/pytorch_2-7-1/torch-distributed-checkpoint.mddocs/zh/native_apis/pytorch_2-9-0/torch-distributed-checkpoint.mddocs/zh/native_apis/pytorch_2-10-0/torch-distributed-checkpoint.mdpytorch_2-6-0和pytorch_2-8-0按要求不刷新。资料补齐 PR:https://gitcode.com/Ascend/pytorch/pull/35673
【接口变更】
不涉及
【功能验证】
新增测试用例:
test/distributed/checkpoint/test_planner_api.py
测试命令:
python test/distributed/checkpoint/test_planner_api.py -v
测试场景:
WriteItemType.TENSOR + tensor_data,验证返回 tensor 存储字节数。
WriteItemType.SHARD + tensor_data,验证返回 shard tensor 存储字节数。
WriteItemType.BYTE_IO 且 tensor_data 为 None,验证返回 None。
已在以下版本执行该用例:
v2.7.1:通过
v2.9.0:通过
v2.10.0:通过
v2.11.0:通过
v2.12.0:通过
master:通过
不同版本运行用例结果示例:
V2.7.1
V2.9.0
V2.10.0
V2.11.0
V2.12.0
master
【CheckList】