Repository navigation
[Dist] GroupCoordinator: run the NCCL path on PyNccl, fix send/recv - #8095
Conversation
all_gather's NCCL path and reduce_scatter_tensor(use_custom=False) called torch.distributed directly, so a caller that wanted the group's PyNccl had to reach into device_communicator itself (ROCm/ATOM#3429). send/recv read self.pynccl_comm, which GroupCoordinator never sets, so every call raised AttributeError. - GroupCoordinator._pynccl_comm(dtype) decides for all four: the device communicator's PyNccl when it is usable and carries the dtype, else torch.distributed, which is also kept while dynamo traces. - ncclDataTypeEnum.supports(dtype) answers from the table from_torch uses. - all_gather's NCCL output is allocated concatenated along dim 0, so dim 0 needs no movedim/reshape; reduce_scatter_tensor allocates with new_empty. Tests: tests/test_group_coordinator_all_gather.py (CPU) covers the routing, each fallback and the dim layouts; the multi-GPU test_allgather, test_reduce_scatter and test_parallel_groups check exactness, the path taken, CUDA-graph capture, torch.compile(fullgraph=True) and send/recv. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
The focused suite runs tests/ in one process, and an earlier module sets the default device to cuda, so torch.full() landed on the GPU while recv allocates on the group's (CPU) device. Co-authored-by: Cursor <[email protected]>
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
CI status at
All other jobs passed, including the focused cc @valarLip |
|
LGTM code-wise. Just waiting for the multi-GPU CI to actually run and pass test_allgather, test_reduce_scatter and test_parallel_groups (they're currently blocked by the unrelated Mori smoke failure), and then I'll approve. |
|
@TennyWang1223 Thanks, and thanks for merging main. That merge brings in #8172, which moved the multi-GPU tests from |
|
@TennyWang1223 The multi-GPU job at
A plain re-run would hit the same limit, since the order is the same. Could you either run Meanwhile I'm running the three tests locally on 4× MI308X at the CI defaults where 4 GPUs allow: |
|
@TennyWang1223 I reran the three multi-GPU tests locally at the current head. All three pass at TP4, and the TP2 controls pass too. Setup
Results
The TP2 numbers match the earlier TP2 run in the PR description (allgather 31 s then). On the CI timeout: test_reduce_scatter takes about 40 s at TP4 here, and test_allgather took 39 s on the MI350X runner. So it looks like the step's 120-minute budget ran out (the 43 tests before it used 118.7 min) rather than reduce_scatter hanging. Caveat: reduce_scatter was only verified up to TP4, not at the CI default of TP8. |
|
@TennyWang1223 A CI note on It is not from this PR:
The multi-GPU results are in my comments above. |
|
@TennyWang1223 The current-head MI350X multi-GPU CI has now completed all three requested tests. At
The three completion records are at 06:25:25, 07:52:04 and 07:57:23 UTC on November 20. The job and Aiter Test Gate are successful. This supersedes the earlier timeout report: reduce-scatter reached completion on this run. These are existing CI results; no new local GPU run or code change was needed for this update. cc @valarLip |
Summary
GroupCoordinator's NCCL path now runs on the group's PyNccl communicator:all_gatherwhen it does not take the custom kernel (including everyuse_custom=Falsecall),reduce_scatter_tensor(use_custom=False), andsend/recv.send/recvread aself.pynccl_commthatGroupCoordinatornever sets, so they raisedAttributeErroron every call; they work now. torch.distributed stays the fallback for groups without a usable PyNccl communicator, for dtypes PyNccl does not carry, and while dynamo traces.Motivation
ATOM's Qwen4Exp sequence parallelism all-gathers and reduce-scatters with
GroupCoordinator.all_gather/reduce_scatter_tensor(use_custom=False), which called torch.distributed directly. ROCm/ATOM#3429 made those two calls take the TP group's PyNccl communicator itself (group.device_communicator.pynccl_comm): the same RCCL collective, on the current stream, at about half the host time per call. ATOM's maintainer asked for the routing to live in aiter instead, so ATOM can go back to the group's two calls and delete its PyNccl lookup (review: "The root cause is in aiter:GroupCoordinator.all_gather/reduce_scatter_tensor(use_custom=False)calltorch.distributeddirectly and skipCudaCommunicator's PyNccl path. Also,GroupCoordinator.send/recvread aself.pynccl_commthat is never set.").Changes
GroupCoordinator._pynccl_comm(dtype)makes the choice once for all four calls. It returns the device communicator's PyNccl communicator, or None to keep torch.distributed when:The answer depends only on the group and the dtype, so every rank takes the same path.
ncclDataTypeEnum.supports(dtype):from_torchandsupportsnow read one table.all_gatherallocates its NCCL output concatenated along dim 0 (both PyNccl andall_gather_into_tensortake that form), so a dim-0 gather needs nomovedim/reshape. Other dims are transposed as before.reduce_scatter_tensorallocates withnew_empty. Together these remove about 6 us of host time per dim-0 gather (measured below).send/recvuse_pynccl_comm; the stalepynccl_commclass annotation is removed..contiguous()inputs. The torch.distributed calls are unchanged.Not changed:
CudaCommunicator's own collectives, the custom kernels, anduse_custom=Truecalls that the custom kernel takes. Seen while reading and left alone, since this PR's paths do not reach them:CudaCommunicator.reduce_scatterasserts that PyNccl exists but does not checkdisabled;CudaCommunicator.all_gatherpasses a non-contiguous input to PyNccl as is;all_gather(use_custom=True, dim=0)on a group without a custom all-reduce (ca_comm is None) still picks_all_gather_out_place, which asserts.Callers on these paths in ATOM main (
b7b5ec3f2):recv_tensor_dict(bf16);embed_head.pyanddspark_markov_argmax.pywhenuse_customis False;get_tp_group().all_gather(hidden_states);dcp_ops.py, the indexer's FP4 planes);linear.py,moe.py,attention_mla.py).bf16, fp32, int32 and uint8 tensors now take PyNccl; fp8, e8m0 and fp4 tensors keep torch.distributed. ATOM's simulated TP replaces these methods on the group instance and is not affected. The SGLang and vLLM plugin code that uses the host framework's own groups is not affected either.
Performance
MI308X (gfx942), TP2, ROCm 7.2.4, torch 2.10.0+rocm7.2.4, RCCL 2.27.7. Host time per call, the median of 5 rounds of 16-call bursts (the GPU queue is drained between bursts); "cold" walks 8 MiB and runs unrelated Python between two calls. The shapes are ATOM's sequence-parallel prefill shapes for 2112 tokens. Same process, same group, same inputs; the three paths are bitwise identical on these shapes.
[1056, 2560], dim 0[2112, 2560], dim 0[1056, 512], dim 0Rank 0; rank 1 is within 2.5 us. This PR costs 1.5-2.3 us (hot) more than ATOM#3429's direct call: the generic argument checks, the
use_customdispatch and_pynccl_comm(torch.compiler.is_compiling()0.18 us,supports0.19 us). Of the allocation change, skippingmovedim+reshapeon a dim-0 gather saves 4.5 us andnew_empty1.3 us overtorch.empty(..., dtype=, device=)(measured in isolation).End to end on ATOM (Qwen4Exp, TP2 on two MI308X, SGLang
baa9befa38(v0.5.22) and Native ATOM, MTP on, the issue-#576 prefix-hit TTFT protocol at c=1: input_ids, the hit prefix filled before every wave, a new tail salt per wave, the hit checked every wave, round 0 dropped). One server at a time on the same two GPUs, 2-5 sessions per path alternating between the paths, 3 or 6 counted rounds per session. The TTFT is the median over all counted rounds of a path (n rounds). Sessions of one path differ by 6-8 ms, more under load (load average 4-25; other jobs share the box). One Native ATOM#3429 session is left out: it overlapped a CPU-heavy test run of mine on the same host._pyncclreverted (the group's calls)fa5ebfe15(direct PyNccl)_pyncclrevertedb7b5ec3f2_pyncclrevertedfa5ebfe15(direct PyNccl)_pyncclrevertedb7b5ec3f2_pyncclreverted" is the follow-up ATOM change:_SequenceParallelback ongroup.all_gather/reduce_scatter_tensor(use_custom=False), which leaves those two files identical to ATOM main. With this PR it matches ATOM#3429's direct calls (-4.0 to +0.2 ms, inside the spread between sessions of one path); without it, it is 10-23 ms slower. ATOM main gets the same gain with no ATOM change.max_gen_toks=4096,until=<|im_end|>, temperature 0, concurrency 16. 0.980-0.985 everywhere; the run-to-run noise at limit 200 is about one or two questions. MTP acceptance is 0.710-0.725.Testing
Documentation
No document describes which communicator these calls use.
Dependencies
Breaking Changes
None in values or signatures. Behavior a caller can notice:
ProcessGroupNCCL, so its watchdog, flight recorder and the profiler'srecord_param_commsevents do not see them (the same holds today for the all-reduces aiter runs on PyNccl).PR Self-Review
Reviewed revision
e276fe4
Behavior and intent
Behavior change:
GroupCoordinator.all_gatheron its NCCL path (everyuse_custom=Falsecall, anduse_custom=Truecalls the custom kernel does not take),reduce_scatter_tensor(use_custom=False),sendandrecvrun on the device communicator's PyNccl communicator when it is usable and carries the dtype. They keep torch.distributed for groups without one, for dtypes PyNccl does not carry, and while dynamo traces. Values are unchanged.send/recvraisedAttributeErroron every call before; they work now. A dim-0 all-gather returns its concatenated output directly.Why the existing behavior is insufficient: torch.distributed takes about twice the host time per call (a c10d work object, events and a side stream), which shows in host-bound eager prefill. ATOM#3429 worked around it by taking the PyNccl communicator out of
device_communicatorin the model; ATOM's maintainer asked for the routing to be fixed in aiter, so ATOM can delete that.Validation and unverified scope
Validated at e7dd5f1 on MI308X (gfx942), ROCm 7.2.4, torch 2.10.0+rocm7.2.4, RCCL 2.27.7. The image's aiter build (95d2112) is overlaid with the changed files:
parallel_state.pythere differs from main 03f9f37 only by the unrelateddcp_lse_mergemethod; the other changed files are identical. Reverting the change was checked by running the new tests against the unmodified 95d2112 build.python3 -m pytest -q tests(the focused suite, as CI runs it): 413 passed, 2 skipped, 1 failed:test_mega_moe_gfx1250_recipe.py::test_layout, which fails the same way on the unmodified build.tests/test_group_coordinator_all_gather.pyalone: 11 passed. Against the unmodified build: 9 failed, the 2 existing cases pass. All 11 mutations of the change fail at least one case: dropping the dynamo / disabled / dtype check, dropping each.contiguous(), sending the global rank to PyNccl, putting all-gather / reduce-scatter / recv back on torch.distributed, and skipping the dim != 0 transpose.python3 op_tests/multigpu_tests/test_allgather.py -t 2: 58 rows, 18 of them CUDA-graph cases; everyuse_custom=Falserow is exact and never calls torch.distributed. Against the unmodified build it fails at once withNCCL path not exact or not on PyNccl.python3 op_tests/multigpu_tests/test_reduce_scatter.py -t 2: custom 5, fallback 3 and nccl 3 cases, all with error 0; the nccl cases' compiled results match. Against the unmodified build, all 3 nccl cases fail:went through torch.distributed=True.python3 op_tests/multigpu_tests/test_parallel_groups.py --tp 2 --dp 1: passes, including the send/recv ring. Against the unmodified build:AttributeError: 'GroupCoordinator' object has no attribute 'pynccl_comm'.use_custom=Truegather on the middle dim that the custom kernel does not take;graph_capture();torch.compile(fullgraph=True)of both collectives;fp8 and bool took torch.distributed; every other case took PyNccl. On the unmodified build, 5 cases fail: the non-contiguous input ("Tensors must be contiguous"), the compiled all-gather (a fake-tensor error from dynamo's
all_gather_into_tensorrewrite into a(world, ...)output), and the 3 send/recv cases (AttributeError).use_custom=Falsecollective happens inside capture, c10d creates its communicator during capture and fails withhipErrorStreamCaptureInvalidated.blackandruff check(ruff 0.16.0) are clean on the six files.Unverified:
test_allgather, TP8 fortest_reduce_scatter, tp2 x dp2 fortest_parallel_groups) were not run here; they needci:multi-gpu.PR-specific question
The most important failure mode is ranks of one group taking different paths for the same collective, PyNccl on some and torch.distributed on others: the group would hang. A second one is a dtype PyNccl cannot carry reaching PyNccl (
ValueError), which would break callers that gather fp8 or bool tensors today.Evidence:
_pynccl_commdepends only on the group (its device communicator and that communicator's PyNccl state, the same on every rank), the dtype (the same on every rank for one collective) and dynamo tracing (a property of the code being compiled, the same on every rank).ncclDataTypeEnum.from_torch, so it cannot disagree with what PyNccl accepts.The output layout is the third boundary: a dim-0 gather now returns the concatenated buffer, and dims 1, 2 and -1 are still transposed. Both are checked against torch.distributed on GPUs, and dims 0, 1 and -1 against an independent expectation on CPU.
Changed op tests
op_tests/multigpu_tests/test_allgather.py: each case now records whether it issued a torch.distributed all-gather and whether the result equals the reference exactly. Theuse_custom=Falsecases run a second time captured in a CUDA graph. The test asserts that those cases are exact and never call torch.distributed; the eager sweep is checked before the graph sweep, since a live graph that captured a torch.distributed all-gather hangs the group's teardown. Not redundant: the file checked the custom kernel's accuracy, never asserted on the NCCL path and never ran graph mode.op_tests/multigpu_tests/test_reduce_scatter.py: a newncclsuite (use_custom=False) on the fallback suite's shapes (dims 0, 1, 2) with the exact integer reference, a check that it never calls torch.distributed, and atorch.compile(fullgraph=True, backend="eager")run that must still trace and match. Not redundant: the custom and fallback suites reachCudaCommunicator.reduce_scatter, notGroupCoordinator's ownuse_custom=Falsepath.op_tests/multigpu_tests/test_parallel_groups.py: a send/recv ring over the TP group; each rank must hold its predecessor's input. Not redundant: nothing calledGroupCoordinator.send/recv(every call raised).The three files run with the
ci:multi-gpulabel.tests/test_group_coordinator_all_gather.py(not underop_tests/) runs in the focused pytest step.cc @valarLip