[None][test] reuse conftest mpi_pool_executor in MoE routing multi-GPU test#15868
Conversation
…U test Migrate test_perfect_router_load_balanced_multi_gpu off a per-case MPIPoolExecutor onto the shared module-scoped conftest mpi_pool_executor (world_size=4, indirect), so the 4 worker processes are spawned once for the whole module instead of being re-created for every parametrized case. A per-case _reset_perfect_router_comm_state() clears the perfect-router logits cache and NVLink one-sided workspace singletons between reused-pool cases to match the fresh-process semantics of the previous per-case executor. Validated on GB200 (sm100) with the origin/main matching container: 72 passed in 381s. Signed-off-by: xxi <xxi@nvidia.com>
📝 WalkthroughWalkthroughThe test module for MoE perfect-router now uses a shared, parametrized ChangesPerfect-Router Multi-GPU Test Refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unittest/_torch/modules/test_moe_routing.py (1)
891-944: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd explicit return annotations for the new functions.
The new helpers/test return
None; annotate that and avoid returning the worker expression from_perfect_router_worker_entry. As per coding guidelines, “Always annotate functions. Make the return typeNoneif the function does not return.”Proposed annotation fix
-def _reset_perfect_router_comm_state(): +def _reset_perfect_router_comm_state() -> None: @@ -def _perfect_router_worker_entry(*worker_args): +def _perfect_router_worker_entry(*worker_args) -> None: """Run one perfect-router case, then reset state for the reused worker.""" try: - return _perfect_router_worker(*worker_args) + _perfect_router_worker(*worker_args) finally: _reset_perfect_router_comm_state() @@ def test_perfect_router_load_balanced_multi_gpu(parallel_mode, routing_name, num_tokens, dtype, - mpi_pool_executor): + mpi_pool_executor) -> None:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unittest/_torch/modules/test_moe_routing.py` around lines 891 - 944, The new helpers in test_moe_routing should have explicit return type annotations because they do not return a value. Update _reset_perfect_router_comm_state and _perfect_router_worker_entry to be annotated as returning None, and change _perfect_router_worker_entry so it does not return the result of _perfect_router_worker but only runs it and then resets state in the finally block. Keep the fix localized to these helper functions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unittest/_torch/modules/test_moe_routing.py`:
- Around line 906-922: Synchronize the GPU before clearing shared routing state
in the cleanup path. In the test teardown around _perfect_router_worker, move
torch.cuda.synchronize() ahead of clearing _PERFECT_ROUTER_LOGITS_CACHE and
NVLinkOneSided workspace state, then keep the cache/workspace reset and
torch.cuda.empty_cache() afterward. Use the _PERFECT_ROUTER_LOGITS_CACHE and
NVLinkOneSided symbols to locate the cleanup block.
---
Nitpick comments:
In `@tests/unittest/_torch/modules/test_moe_routing.py`:
- Around line 891-944: The new helpers in test_moe_routing should have explicit
return type annotations because they do not return a value. Update
_reset_perfect_router_comm_state and _perfect_router_worker_entry to be
annotated as returning None, and change _perfect_router_worker_entry so it does
not return the result of _perfect_router_worker but only runs it and then resets
state in the finally block. Keep the fix localized to these helper functions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fa2f8ad0-1e66-4075-ba4b-83acea0fd59e
📒 Files selected for processing (1)
tests/unittest/_torch/modules/test_moe_routing.py
…tations Move torch.cuda.synchronize() ahead of the cache/NVLink-workspace clear in _reset_perfect_router_comm_state so the error-path teardown does not free GPU memory that is still in flight; keep empty_cache last. Add -> None return annotations to the new helpers/test and drop the returned value from _perfect_router_worker_entry. Signed-off-by: xxi <xxi@nvidia.com>
|
/bot run --disable-fail-fast |
|
PR_Github #57136 [ run ] triggered by Bot. Commit: |
|
PR_Github #57136 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
/bot run --disable-fail-fast |
|
PR_Github #57272 [ run ] triggered by Bot. Commit: |
|
PR_Github #57272 [ run ] completed with state |
…U test (NVIDIA#15868) Signed-off-by: xxi <xxi@nvidia.com>
Summary
Migrate the perfect-router multi-GPU routing test (test_perfect_router_load_balanced_multi_gpu) off a per-case MPIPoolExecutor onto the shared, module-scoped conftest
mpi_pool_executorfixture (world_size=4 via indirect parametrization), the same pool other multi-GPU tests (test_moe_a2a / test_moe_comm) already use.Details
Before: each parametrized case did
with MPIPoolExecutor(max_workers=4), re-spawning 4 worker processes (re-import + CUDA/NCCL/comm init) per case.After: the 4 workers are spawned once for the whole module and reused across all cases; a per-case
_reset_perfect_router_comm_state()clears the perfect-router logits cache and NVLink one-sided workspace singletons between cases to match the fresh-process semantics of the previous per-case executor.The unused
from mpi4py.futures import MPIPoolExecutorimport is removed;@pytest.mark.threadleak(enabled=False)is added (the module-scoped pool manager thread persists by design).Test plan
pytest test_moe_routing.py::test_perfect_router_load_balanced_multi_gpu-> 72 passed in 381.26s.Summary by CodeRabbit