已合并
test(distributed): add ProcessGroupMPI.create tests #42950
test(distributed): add ProcessGroupMPI.create tests #42950
已合并
lgxxx创建于 24 天前
lgxxx
24 天前

【合入来源】

Issue: https://gitcode.com/Ascend/pytorch/issues/3208

【修改方案】

Add Python validation tests for torch.distributed.distributed_c10d.ProcessGroupMPI.create in test/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 -q

Result: 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 实测环境、命令和结果:

TASK 99 / PR #42950 / VALIDATION EVIDENCE
API=torch.distributed.distributed_c10d.ProcessGroupMPI.create
TARGET_BRANCH=v2.12.0
PLATFORM=Linux-5.10.0-216.0.0.115.oe2203sp4.aarch64-aarch64-with-glibc2.35
PYTHON=3.11.15
TORCH=2.12.0+cu130
TORCH_NPU=2.12.0.rc1
CANN=9.1.0.beta1
NPU=Ascend910_9382
VISIBLE_NPU=1 (PHYSICAL NPU 0)
COMMAND=scripts/run_api_python_version.sh 2.12.0
  sources/review/task99-v2.12.0/test/distributed/test_c10d_mpi.py -v
RESULT:
  Ran 18 tests in 0.181s
  OK (skipped=14)
  test_exit_code=0
NOTE=MPI is not compiled; direct create cases were skipped

说明:当前 PyTorch wheel 未编译 MPI;18 项中 14 项直接 MPI/create 用例按条件跳过。本次结果证明不可用路径及测试文件可正常执行,不表述为 ProcessGroupMPI.create 已在本机实际运行。

【合入来源】

Issue: https://gitcode.com/Ascend/pytorch/issues/3208

【修改方案】

Add Python validation tests for torch.distributed.distributed_c10d.ProcessGroupMPI.create in test/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 -q

Result: 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】

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lgxxx 的贡献)
Llgxxx
24 天前 创建了 pull request,commit fd8cf389
Llgxxx
24 天前 关联了issue:【社区任务】7月社区任务第三期-Ascend for PyTorch API 一致性开发(99)
atomgit-bot
atomgit-bot
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 返回值正确,以及 allreducebroadcastbarrier 三个集合通信原语行为符合预期。
  • 新增辅助函数 _get_process_group_mpi_is_mpi_usable:提供懒加载导入 ProcessGroupMPI 和聚合 MPI 可用性检查的能力,各测试用例依赖这两个函数决定是执行测试还是跳过。
likedislike
atomgit-bot
atomgit-bot
24 天前 评论:

代码审查

发现 5 个问题,均为中低优先级建议。

类型 数量
🔴 阻塞 0
🟡 建议 4

💬 仅评论

likedislike
此处折叠了122条消息 查看更多
li_jing_hw成员
8 天前 评论:

/approve

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