已合并
test(distributed): add ProcessGroupMPI.create tests #42948
test(distributed): add ProcessGroupMPI.create tests #42948
已合并
lgxxx创建于 23 天前
lgxxx
23 天前
# 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 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, 12 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】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 ## NPU 功能验证补充 以下为当前 PR head commit 对应的单卡 NPU 实测环境、命令和结果: ```text TASK 99 / PR #42948 / VALIDATION EVIDENCE API=torch.distributed.distributed_c10d.ProcessGroupMPI.create TARGET_BRANCH=v2.7.1 PLATFORM=Linux-5.10.0-216.0.0.115.oe2203sp4.aarch64-aarch64-with-glibc2.35 PYTHON=3.11.15 TORCH=2.7.1+cpu TORCH_NPU=2.7.1.post4 CANN=9.1.0.beta1 NPU=Ascend910_9382 VISIBLE_NPU=1 (PHYSICAL NPU 0) COMMAND=scripts/run_api_python_version.sh 2.7.1 sources/review/task99-v2.7.1/test/distributed/test_c10d_mpi.py -v RESULT: Ran 18 tests in 0.237s 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` 已在本机实际运行。 # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 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】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lgxxx 的贡献)
Llgxxx
23 天前 创建了 pull request,commit e692452e
Llgxxx
23 天前 关联了issue:【社区任务】7月社区任务第三期-Ascend for PyTorch API 一致性开发(99)
atomgit-bot
atomgit-bot
23 天前 评论:

变更摘要

本 PR 新增了 test/distributed/test_c10d_mpi.py 测试文件,为 torch.distributed.distributed_c10d.ProcessGroupMPI.create 静态工厂方法及 MPI 后端的进程组初始化流程补充 Python 层验证用例。社区此前仅有 C++ 覆盖,缺少直接面向该 API 的 Python 测试。新增的测试涵盖 MPI 可用性检查与导入守卫、ProcessGroupMPI.create 工厂创建及属性验证、非成员行为、以及通过 dist.init_process_group 初始化后的 allreduce/broadcast/barrier 等集合通信操作。

主要改动

  • 新增 TestProcessGroupMPIAvailability:验证 dist.is_mpi_available()dist.is_available() 返回布尔值、MPI 不可用时 dist.init_process_group(backend="mpi") 抛出 RuntimeError、以及 ProcessGroupMPI 的导入受可用性守卫控制。
  • 新增 TestProcessGroupMPICreate:验证 ProcessGroupMPI.create 返回实例的 name()size()rank() 属性是否正确;覆盖单 rank、全量 world size ranks、以及当前 rank 不在指定列表中时返回 None 的非成员场景。
  • 新增 TestProcessGroupMPIInitGroup:通过 dist.init_process_group(backend="mpi") 初始化后验证 get_backendget_rankget_world_sizeis_initialized 等 API,并覆盖 all_reducebroadcastbarrier 三个集合通信操作的端到端测试。
  • 新增辅助函数_get_process_group_mpi() 实现惰性导入并安全返回 None_is_mpi_usable() 组合检查 dist.is_available()dist.is_mpi_available(),各测试用例依赖这些函数进行灵活跳过(skip)以适配无 MPI 运行时的环境。
likedislike
atomgit-bot
atomgit-bot
23 天前 评论:

代码审查

审查总结

共发现 3 个问题

优先级 数量 说明
P1 1 dist.get_world_size()/dist.get_rank() 在默认进程组未初始化时被调用,MPI 可用时将直接崩溃
P3 2 环境变量未恢复的测试隔离性缺陷;多处硬编码 [0] 导致非 rank 0 进程测试失败

整体风险判断:中等。P1 问题在 MPI 环境可用时会直接导致 TestProcessGroupMPICreate 中 2 个测试用例崩溃;当前测试环境无 MPI 支持所以未被触发。建议在合入前修复 P1 问题(补充 setUp/tearDown 或改用环境变量),P3 项作为可选改进。

已审查文件

  • test/distributed/test_c10d_mpi.py:发现 3 个问题(1 × P1, 2 × P3)
类型 数量
🔴 阻塞 1
🟡 建议 0

⛔ 需要修改

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

/approve

likedislike
ascend-robotascend-robot成员
6 天前 添加了label:approvedlgtm
ascend-robotascend-robot成员
6 天前 删除了label:ci-pipeline-passed
ascend-robotascend-robot成员
6 天前 合入了pull request
ascend-robot
ascend-robot成员
6 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13944 [ commitID:7ac28e4c ] 已完成
likedislike