已合并
【API一致性任务】test: add Partial placement test for compute_local_shape_and_global_offset #45657
m0_53076416创建于 9月1日
【API一致性任务】test: add Partial placement test for compute_local_shape_and_global_offset #45657
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 m0_53076416 的贡献)9月1日 创建了 pull request,commit 86fd23da
9月1日 关联了issue:【API一致性任务】8月社区任务第三期-Ascend for PyTorch API 一致性开发(136)
atomgit-bot
9月1日 评论:
9月1日 评论:
变更摘要
本 PR 属于 API 一致性任务下的纯测试补充,针对 DTensor 内部元数据工具函数 torch.distributed._tensor._utils.compute_local_shape_and_global_offset 补齐 Partial 放置策略的测试覆盖。官方原有 1D/2D 测试仅覆盖 Shard 与 Replicate 策略,遗漏了合法核心策略 Partial;本 PR 在 test/distributed/_tensor/test_utils.py 中新增测试用例,验证在 Partial 策略下局部张量未发生物理切分(local_size 等于全局形状),且全局偏移坐标全为 0。
主要改动
- 扩展
Partial策略导入: 在test/distributed/_tensor/test_utils.py中,将导入语句由from torch.distributed._tensor.placement_types import Replicate, Shard扩展为同时导入Partial,为新增用例提供策略类支持。 - 新增
test_compute_local_shape_and_global_offset_partial测试用例: 使用@skipIfUnsupportMultiNPU(4)与@with_comms装饰,在分布式环境下构造Partial()放置策略及DeviceMesh,调用compute_local_shape_and_global_offset(global_shape, device_mesh, placements)。 - 断言验证
Partial策略推导结果: 断言local_size与全局形状global_shape相等(未切分),并断言global_offset为长度等于全局形状维度的全 0 元组,验证偏移量推导逻辑。


不准确?
atomgit-bot
9月1日 评论:
9月1日 评论:
9月1日 添加了label:ascend-cla/yes
此处折叠了143条消息 查看更多
AtlasAccount
26 天前 评论:
26 天前 评论:
流水线 PR-pipeline_pytorch#67338 [ commitID:79011655 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ COMPLETED | >>> |
| Build_ARM | ✅ COMPLETED | >>> | |
| Build_X86_torchair | ⚪ IGNORED | >>> | |
| Build_ARM_torchair | ⚪ IGNORED | >>> | |
| patch_test | ⚪ IGNORED | >>> | |
| Build_X86_213 | ⚪ IGNORED | >>> | |
| Build_ARM_213 | ⚪ IGNORED | >>> | |
| 恶意代码检查 | Antipoison | ✅ COMPLETED | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ COMPLETED | >>> |
| check_error | ✅ COMPLETED | >>> | |
| lintrunner | ✅ COMPLETED | >>> | |
| 开源片段检查 | SCA | ✅ COMPLETED | >>> |
| 开发者测试 | UT_ARM_A3_Part_01 | ✅ COMPLETED | >>> |
| UT_ARM_A3_Part_02 | ✅ COMPLETED | >>> | |
| UT_ARM_A2_Part_01 | ✅ COMPLETED | >>> | |
| UT_ARM_A2_Part_02 | ✅ COMPLETED | >>> | |
| UT_ARM_A2_Part_03 | ✅ COMPLETED | >>> | |
| UT_inductor_Part_01 | ⚪ IGNORED | >>> | |
| UT_inductor_Part_02 | ⚪ IGNORED | >>> | |
| UT_inductor_Part_03 | ⚪ IGNORED | >>> | |
| UT_inductor_Part_04 | ⚪ IGNORED | >>> | |
| UT_DIST_ARM_Part_01 | ✅ COMPLETED | >>> | |
| UT_DIST_ARM_Part_02 | ✅ COMPLETED | >>> | |
| UT_DIST_ARM_Part_03 | ✅ COMPLETED | >>> | |
| UT_DIST_ARM_Part_04 | ✅ COMPLETED | >>> | |
| UT_ARM_A2_Select_Part_01 | ⚪ IGNORED | >>> | |
| UT_ARM_A2_Select_Part_02 | ⚪ IGNORED | >>> | |
| UT_inductor_Part_213 | ⚪ IGNORED | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ COMPLETED | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


chengpeng25
24 天前 评论:
24 天前 评论:
/approve


24 天前 添加了label:approvedlgtm
24 天前 合入了pull request
AtlasAccount
24 天前 评论:
24 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#15249 [ commitID:79011655 ] 已完成


【合入来源】
【修改方案】
torch.distributed.tensor._utils.compute_local_shape_and_global_offset是 DTensor 模块下一个纯 Python 实现的内部元数据工具函数。其功能为:给定全局张量的形状、设备网格(DeviceMesh)以及放置策略(placements),计算并推导出当前 rank 对应的局部张量形状(local_shape)以及该数据块在全局张量中的绝对偏移量(global_offset)。Shard(切分)和Replicate(复制)策略,客观上遗漏了对另一合法核心策略Partial(部分状态)的入参验证。为了保证该 API 在 NPU 环境下的参数完备性与逻辑全覆盖,必须进行用例补齐。test_compute_local_shape_and_global_offset_partial测试用例,显式导入Partial策略类,并断言验证其推导结果:在Partial策略下,局部张量尺寸未发生物理切分(保持等于全局尺寸),且全局偏移坐标全为 0。具体的bug:
经过检查原第5行中的
torch.distributed._tensor._utils.compute_local_shape已不存在,其已被替换成torch.distributed._tensor._utils.compute_local_shape.compute_local_shape_and_global_offset。检查结果如下,
compute_local_shape已不存在:torch.distributed._tensor._utils.compute_local_shape.compute_local_shape_and_global_offset函数返回一个元组 (local_shape, global_offset),其中第一个元素 local_shape 与原torch.distributed._tensor._utils.compute_local_shape的返回值完全一致。因此通过元组解包 local_shape, _ = compute_local_shape_and_global_offset(...) 丢弃第二个返回值即可。原来代码:
修改为:
【资料变更】
不涉及。
原因说明:本次测试的目标接口
torch.distributed.tensor._utils.compute_local_shape_and_global_offset属于带有_utils前缀的内部私有 API。上游 PyTorch 官方未对其开放公开的原生独立文档。且该 API 逻辑为纯 Python 的坐标数学推导,不涉及 NPU 底层内存操作或算子调用,无特殊硬件约束,故不涉及对外公开资料的编写与变更。【接口变更】
不涉及。本次提交仅为纯测试层面的用例补充。
【功能验证】
测试场景与方法:在分布式环境下(世界大小为 8),测试传入
Partial策略时的尺寸和偏移量推导是否正确。执行步骤:
测试结果:8 个通信进程均正常计算完毕并匹配正确断言,结果为 OK。
910B3的4卡测试自验证截图,无A5多卡环境,无法验证A5支持情况,不再进行A5多卡验证测试:

修改bug之后的函数测试:
执行步骤:
验证截图:

【CheckList】