已合并
test(distributed): add ProcessGroupMPI.create tests #42950
lgxxx创建于 24 天前
test(distributed): add ProcessGroupMPI.create tests #42950
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lgxxx 的贡献)atomgit-bot
24 天前 评论:
24 天前 评论:
变更摘要
该 PR 为 torch.distributed.distributed_c10d.ProcessGroupMPI.create 新增了 Python 层面的验证测试文件 test/distributed/test_c10d_mpi.py(+203 行)。社区此前仅有 C++ 覆盖,缺少对该 API 的直接 Python 测试。新增的测试覆盖了 MPI 可用性检查与导入守卫、ProcessGroupMPI.create 工厂方法的创建与属性验证、非成员行为、以及通过 dist.init_process_group 初始化后的 allreduce/broadcast/barrier 等集合通信操作。当 MPI 运行时不可用时,大部分测试用例会被自动跳过。
主要改动
- 新增
TestProcessGroupMPIAvailability测试类:验证dist.is_mpi_available()和dist.is_available()返回布尔值、MPI 不可用时dist.init_process_group(backend="mpi")抛出RuntimeError,以及ProcessGroupMPI导入受 MPI 可用性守卫控制。 - 新增
TestProcessGroupMPICreate测试类:验证ProcessGroupMPI.create工厂方法返回正确的进程组实例(name()为"mpi")、单 rank 下size()和rank()属性正确、全量 ranks 下属性匹配dist.get_world_size(),以及当前 rank 不在给定 ranks 列表中时返回None。 - 新增
TestProcessGroupMPIInitGroup测试类:通过dist.init_process_group(backend="mpi")初始化后,验证dist.get_backend()返回"mpi"、get_rank/get_world_size/is_initialized返回值正确,以及allreduce、broadcast、barrier三个集合通信原语行为符合预期。 - 新增辅助函数
_get_process_group_mpi与_is_mpi_usable:提供懒加载导入ProcessGroupMPI和聚合 MPI 可用性检查的能力,各测试用例依赖这两个函数决定是执行测试还是跳过。


atomgit-bot
24 天前 评论:
24 天前 评论:
ascend-robot
24 天前 评论:
24 天前 评论:
此处折叠了122条消息 查看更多
li_jing_hw
8 天前 评论:
8 天前 评论:
/approve


8 天前 添加了label:approved, lgtm
8 天前 删除了label:ci-pipeline-passed
8 天前 合入了pull request
ascend-robot
8 天前 评论:
8 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13946 [ commitID:0aa6a99f ] 已完成


【合入来源】
Issue: https://gitcode.com/Ascend/pytorch/issues/3208
【修改方案】
Add Python validation tests for
torch.distributed.distributed_c10d.ProcessGroupMPI.createintest/distributed/test_c10d_mpi.py.The PyTorch community has C++ coverage for the MPI process group but no direct Python tests for this API. The tests cover MPI availability and import guards, factory creation and properties, non-member behavior, process-group initialization, and allreduce/broadcast/barrier operations.
【资料变更】
不涉及。This is a backend control API and no native API documentation update is required.
【接口变更】
不涉及。
【功能验证】
The test was run with an absolute path outside the source tree:
python -m pytest test/distributed/test_c10d_mpi.py -qResult:
4 passed, 14 skipped. The skipped cases require an MPI runtime and a PyTorch build compiled with MPI support; this is expected in the current environment. ProcessGroupMPI is a backend/control API, so the test does not require NPU tensors.【CheckList】
NPU 功能验证补充
以下为当前 PR head commit 对应的单卡 NPU 实测环境、命令和结果:
【合入来源】
Issue: https://gitcode.com/Ascend/pytorch/issues/3208
【修改方案】
Add Python validation tests for
torch.distributed.distributed_c10d.ProcessGroupMPI.createintest/distributed/test_c10d_mpi.py.The PyTorch community has C++ coverage for the MPI process group but no direct Python tests for this API. The tests cover MPI availability and import guards, factory creation and properties, non-member behavior, process-group initialization, and allreduce/broadcast/barrier operations.
【资料变更】
不涉及。This is a backend control API and no native API documentation update is required.
【接口变更】
不涉及。
【功能验证】
The test was run with an absolute path outside the source tree:
python -m pytest test/distributed/test_c10d_mpi.py -qResult:
4 passed, 14 skipped. The skipped cases require an MPI runtime and a PyTorch build compiled with MPI support; this is expected in the current environment. ProcessGroupMPI is a backend/control API, so the test does not require NPU tensors.CI validation is pending.
【CheckList】