Repository navigation
[CustomAllreduce] Re-take the expandable_segments decision at capture time - #5799
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
d2b901d to
bbd272a
Compare
Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which cannot be exported with `hipIpcGetMemHandle`. AITER's custom all-reduce therefore declines to register its buffers for IPC and stages every input through a device-to-device copy instead. On an 8x MI355X Kimi-K3 decode that is one `__amd_rocclr_copyBuffer` per all-reduce: with ROCm/aiter#5799, 1160 fewer copies per 4 captured passes on rank 0. The activations feeding those all-reduces are allocated inside CUDA graph capture from the graph's private pool, so disabling expandable segments for the duration of capture is enough to make them exportable and let AITER take its registered, copy-free path. Weights, KV cache and eager allocations keep expandable segments. Off by default behind VLLM_ROCM_NON_EXPANDABLE_CUDAGRAPH_POOL, and inert unless it can actually pay off: the flag is ignored, with a warning, off ROCm and on an AITER that still decides whether to register its buffers once at start-up rather than when capture begins (every release up to v0.1.22.post1; the capture-time decision is ROCm/aiter#5799). That capability is probed via `AiterCustomAllreduce.build_defers_capture_registration`, following the existing `build_supports_per_group_quant` pattern. The guard also rewrites the PYTORCH_*_ALLOC_CONF variables for the duration of capture. Consumers fall back to parsing those when they cannot read the allocator; a consumer that read a stale `expandable_segments:True` while the allocator said False would pick a different all-reduce path from its peers, which across ranks of one job is a collective mismatch rather than a local inefficiency. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
581c81d to
bb100fa
Compare
|
@TennyWang1223 could please help to review this PR ? |
Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which cannot be exported with `hipIpcGetMemHandle`. AITER's custom all-reduce therefore declines to register its buffers for IPC and stages every input through a device-to-device copy instead. On an 8x MI355X Kimi-K3 decode that is one `__amd_rocclr_copyBuffer` per all-reduce: with ROCm/aiter#5799, 1160 fewer copies per 4 captured passes on rank 0. The activations feeding those all-reduces are allocated inside CUDA graph capture from the graph's private pool, so disabling expandable segments for the duration of capture is enough to make them exportable and let AITER take its registered, copy-free path. Weights, KV cache and eager allocations keep expandable segments. Off by default behind VLLM_ROCM_NON_EXPANDABLE_CUDAGRAPH_POOL, and inert unless it can actually pay off: the flag is ignored, with a warning, off ROCm and on an AITER that still decides whether to register its buffers once at start-up rather than when capture begins (every release up to v0.1.22.post1; the capture-time decision is ROCm/aiter#5799). That capability is probed via `AiterCustomAllreduce.build_defers_capture_registration`, following the existing `build_supports_per_group_quant` pattern. The guard also rewrites the PYTORCH_*_ALLOC_CONF variables for the duration of capture. Consumers fall back to parsing those when they cannot read the allocator; a consumer that read a stale `expandable_segments:True` while the allocator said False would pick a different all-reduce path from its peers, which across ranks of one job is a collective mismatch rather than a local inefficiency. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which cannot be exported with `hipIpcGetMemHandle`. AITER's custom all-reduce therefore declines to register its buffers for IPC and stages every input through a device-to-device copy instead. On an 8x MI355X Kimi-K3 decode that is one `__amd_rocclr_copyBuffer` per all-reduce: with ROCm/aiter#5799, 1160 fewer copies per 4 captured passes on rank 0. The activations feeding those all-reduces are allocated inside CUDA graph capture from the graph's private pool, so disabling expandable segments for the duration of capture is enough to make them exportable and let AITER take its registered, copy-free path. Weights, KV cache and eager allocations keep expandable segments. Off by default behind VLLM_ROCM_NON_EXPANDABLE_CUDAGRAPH_POOL, and inert unless it can actually pay off: the flag is ignored, with a warning, off ROCm and on an AITER that still decides whether to register its buffers once at start-up rather than when capture begins (every release up to v0.1.22.post1; the capture-time decision is ROCm/aiter#5799). That capability is probed via `AiterCustomAllreduce.build_defers_capture_registration`, following the existing `build_supports_per_group_quant` pattern. The guard also rewrites the PYTORCH_*_ALLOC_CONF variables for the duration of capture. Consumers fall back to parsing those when they cannot read the allocator; a consumer that read a stale `expandable_segments:True` while the allocator said False would pick a different all-reduce path from its peers, which across ranks of one job is a collective mismatch rather than a local inefficiency. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
108cc51 to
5947b83
Compare
|
waiting for CI |
e0af2d4 to
06f267f
Compare
|
@gyohuangxin Could you please help check the MI350X multi-GPU CI environment? The only real failure is |
@zufayu @gyohuangxin I believe non of this PR changes are causing test failures.
can this PR be merged? |
|
FYI, #6571 has been merged into Please update/rebase this branch onto the latest |
… time CustomAllreduce refuses the registered (copy-free) CUDA-graph capture path while PyTorch expandable_segments is on, because VMM-backed pointers cannot be exported with hipIpcGetMemHandle (ROCm#4174). It then stages every all-reduce input through a device-to-device copy. That decision is taken once, in __init__. A host that disables expandable segments only for the duration of graph capture -- precisely so that the graph pool's activations are exportable -- gets nothing from it, because the veto has already latched by the time capture() runs. Remember what the caller asked for before the veto, and re-evaluate it in capture() against the live allocator state (_expandable_segments_enabled() already reads the allocator snapshot, so no new plumbing). The flag is restored on exit, so the change is scoped to the capture window. The gfx1250 veto is architectural and is deliberately not re-evaluated. Measured with vLLM on 8x MI355X running Kimi-K3 decode: __amd_rocclr_copyBuffer launches per 4 captured passes drop 1396 -> 236, i.e. -1160, exactly one staging copy per collective (792 two-stage + 368 one-stage all-reduce calls). Both attributes are set before __init__ can return early, since graph_capture() still enters capture() on a disabled communicator (unsupported world size, multi-node group, no custom_ar library), and the flag is restored even if flush_graph_buffers raises. `defers_capture_registration` is a class-level marker so hosts can feature-detect this rather than infer it from a version number. Hosts must allocate every all-reduce input captured in the window inside it. Adds op_tests/multigpu_tests/test_custom_allreduce_capture_registration.py. Neither existing test covers both axes: test_init_dist_env.py sets expandable segments but captures no graph, and test_custom_allreduce.py captures a graph but never touches the allocator config. The new test also asserts that all ranks agree on the capture path, since the registered/unregistered choice changes the kernel algorithm and the graph-buffer count, and covers a disabled communicator with -t 3. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…portable inputs Addresses two review questions on the capture-time re-check. Cross-rank agreement. capture() used to re-read each rank's own allocator state. Ranks that disagreed (config drift, a rank whose snapshot read failed) would pick different kernel input sources and graph-buffer counts: a collective mismatch, not a local inefficiency. capture() now exchanges each rank's local decision through the pool's TCP store and uses the registered path only if every rank can; otherwise every rank uses copy-in, which is always safe, and a warning lists the per-rank decisions. The exchange is skipped when registration was never requested, since that is rank-uniform. The decision is also taken in both directions now: off at __init__ but on at capture falls back to copy-in instead of registering VMM-backed pointers. Unexportable inputs. The registered path requires every captured collective buffer to be allocated inside the window. A buffer allocated while expandable_segments were on is VMM-backed, and flush_graph_buffers' export of it failed through HIP_CALL, i.e. SIGABRT with no traceback. Each captured collective now checks its buffer the way flush will export it (hipPointerGetAttribute RANGE_START_ADDR, then hipIpcGetMemHandle on the base, about 1 us, legal during capture) and raises a RuntimeError at the call site. The check binds the HIP runtime torch already loaded, and clears the sticky error a failed call leaves behind; without that, the next kernel launch reports "invalid argument". The registered all_reduce also exports its output, so a caller-provided output is checked too. A capture whose body raised is no longer flushed: the graph is discarded, and exchanging a partial set of buffers could mismatch ranks. The test now sweeps TP 2/3/4/8 (capped at the visible GPU count) by default, which is what CI runs, and adds three scenarios: "mixed" (only rank 0 turns expandable segments off; every rank must fall back to copy-in), "reverse" (off at __init__, on at capture; copy-in), and "stale" (input allocated before the toggle; every rank must raise the new error and stay usable for an eager all-reduce afterwards). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…n test The test gave each of its 20 runs (TP 2/3/4/8 x 5 scenarios) a fixed, consecutive MASTER_PORT starting at 49375. Those ports sit inside the Linux ephemeral range, so on a busy CI runner another connection can already hold one: both multi-GPU CI runs failed with EADDRINUSE, at a different port each time (49382 and 49392), after every scenario that had run passed. Ask the OS for a free port per run with get_open_port(), as the other multi-GPU tests do. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ATOM turns the registered capture path off for PIECEWISE CUDA graphs: before capture it sets enable_register_for_capturing = False on its TP/DP/EP communicators, because under PIECEWISE a fast rank can overwrite a pool-recycled input while a slow peer still reads it. capture() re-derived the path from the constructor argument and the live allocator state, and turned registration back on. In aiter CI, the DeepSeek-V4-Pro DSpark job on this branch (DP attention, so only the DP/EP communicators are live) logs ATOM's "forced aiter ca_comm ... to unreg" for both groups and then "Registering 2322 cuda graph addresses" on every rank, where the same job on other PRs registers none. enable_register_for_capturing is now a property. Assigning False records an opt-out that capture() keeps. The opt-out is a vote in the existing all-rank agreement, not a reason to skip it: whether the exchange runs still depends only on the constructor argument and the arch. ATOM opts out only where the flag reads True, and that value comes from each rank's own expandable_segments check at __init__, so ranks that disagree there all fall back to copy-in instead of leaving their peers blocked in the store exchange. Assigning True only withdraws an opt-out: the flag reads the __init__ decision again and capture() decides as before. Unlike a direct write on main, it no longer turns registration on where __init__ ruled it out, e.g. on the gfx1250 VMM transport, which cannot register. Assigning inside the capture window raises, since it would switch one rank's path without the others. The test adds four scenarios: the opt-out with expandable_segments off throughout (ATOM's case), the opt-out combined with the capture-time toggle, an opt-out on rank 0 only, and an opt-out that is withdrawn. Every scenario also checks that a write inside the capture window is refused, and asserts the all-reduce result exactly: checkAllclose only logs a mismatch, so a wrong result could not fail the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
06f267f to
b9bbeab
Compare
rebased. Thanks! |
Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which cannot be exported with `hipIpcGetMemHandle`. AITER's custom all-reduce therefore declines to register its buffers for IPC and stages every input through a device-to-device copy instead. On an 8x MI355X Kimi-K3 decode that is one `__amd_rocclr_copyBuffer` per all-reduce: with ROCm/aiter#5799, 1160 fewer copies per 4 captured passes on rank 0. The activations feeding those all-reduces are allocated inside CUDA graph capture from the graph's private pool, so disabling expandable segments for the duration of capture is enough to make them exportable and let AITER take its registered, copy-free path. Weights, KV cache and eager allocations keep expandable segments. Off by default behind VLLM_ROCM_NON_EXPANDABLE_CUDAGRAPH_POOL. The flag is ignored, with a warning, off ROCm and on an AITER that still decides whether to register its buffers once at start-up rather than when capture begins: every release up to v0.1.25. The capture-time decision is ROCm/aiter#5799, first released in v0.1.26. That capability is probed via `AiterCustomAllreduce.build_defers_capture_registration`, following the existing `build_supports_per_group_quant` pattern. The guard also rewrites the PYTORCH_*_ALLOC_CONF variables for the duration of capture. AITER falls back to parsing those when it cannot read the allocator; a rank that read a stale `expandable_segments:True` would vote against the registered path, and AITER's all-rank agreement would then drop every rank to copy-in, silently losing the win. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ROCm/aiter#5799 merged and first ships in AITER v0.1.26; vLLM still pins v0.1.25, so the flag stays a warned no-op on stock images until the pin moves. Name the release instead of the PR in the warning, the env-var comment and the probe docstring, and add a TODO to drop the probe once the pin reaches it. Read the `defers_capture_registration` marker's value rather than only its presence. On the registered path, merged AITER checks that every captured collective input can be IPC-exported and raises a RuntimeError if not; before, such an input aborted the process in `hipIpcGetMemHandle` when the graph buffers were flushed. Its own wrappers go through that check, but the per-group fused AR+RMSNorm+FP8-quant ops in `_aiter_ops` pass `registered=` to the AITER kernel themselves and skipped it. Route them through a new `AiterCustomAllreduce.capture_registered()`, which uses AITER's check when it exists and the old expression otherwise. Like AITER's own wrappers, it also answers False for a stream captured outside AITER's capture(), which would never flush and register the inputs. Run the CPU step that covers these tests when aiter_custom_all_reduce.py changes. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which `hipIpcGetMemHandle` cannot export, so AITER's custom all-reduce stages every captured input through a device-to-device copy. On an 8x MI355X Kimi-K3 MTP decode that is 1160 extra copies per 4 captured passes on rank 0 and costs 4% TPOT at conc 1 and 2.3% at conc 8. The activations feeding those all-reduces are allocated inside graph capture from the graph's private pool, so turning expandable segments off for the duration of graph_capture() makes them exportable and lets AITER take its registered, copy-free path. Weights, KV cache and allocations made outside graph_capture() keep expandable segments. Off by default behind VLLM_ROCM_NON_EXPANDABLE_CUDAGRAPH_POOL. Needs AITER >= v0.1.26, which re-takes the decision when capture begins (ROCm/aiter#5799). On older AITER, including vLLM's current v0.1.25 pin, the flag gives no speed-up and only changes how allocations inside graph_capture() are made. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-reduce Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which `hipIpcGetMemHandle` cannot export, so AITER's custom all-reduce stages every captured input through a device-to-device copy. The activations feeding those all-reduces are allocated inside graph capture from the graph's private pool, so turning expandable segments off for the duration of graph_capture() makes them exportable and lets AITER take its registered, copy-free path. Weights, KV cache and allocations made outside graph_capture() keep expandable segments. This happens automatically on ROCm when the TP group's AITER custom all-reduce requested graph-buffer registration, which AITER exposes from v0.1.26 (ROCm/aiter#5799, which re-takes the decision when capture begins). It is skipped when the DP group also runs AITER collectives: under DP+EP the MoE combine reduce-scatters a persistent workspace allocated before capture, which the registered path cannot export. On older AITER, without AITER custom all-reduce, with the cuMem graph pool, or when expandable segments are already off, nothing changes. DeepSeek-V4.1-Flash TP8 on MI355X with expandable segments on: decode step -2.6% at concurrency 1 and -2.0% at concurrency 8, the same as with expandable segments off; the graph pool grows by ~0.5 GiB per GPU (its size with expandable segments off) and the KV cache shrinks by 0.2%. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-reduce Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which `hipIpcGetMemHandle` cannot export, so AITER's custom all-reduce stages every captured input through a device-to-device copy. The activations feeding those all-reduces are allocated inside graph capture from the graph's private pool, so turning expandable segments off for the duration of graph_capture() makes them exportable and lets AITER take its registered, copy-free path. Weights, KV cache and allocations made outside graph_capture() keep expandable segments. This happens automatically on ROCm when the TP group's AITER custom all-reduce requested graph-buffer registration, which AITER exposes from v0.1.26 (ROCm/aiter#5799, which re-takes the decision when capture begins). It is skipped when the DP group also runs AITER collectives: under DP+EP the MoE combine reduce-scatters a persistent workspace allocated before capture, which the registered path cannot export. On older AITER, without AITER custom all-reduce, with the cuMem graph pool, or when expandable segments are already off, nothing changes. DeepSeek-V4.1-Flash TP8 on MI355X with expandable segments on: decode step -2.6% at concurrency 1 and -2.0% at concurrency 8, the same as with expandable segments off; the graph pool grows by ~0.5 GiB per GPU (its size with expandable segments off) and the KV cache shrinks by 0.2%. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-reduce Under `expandable_segments:True` the caching allocator hands out VMM-backed pointers, which `hipIpcGetMemHandle` cannot export, so AITER's custom all-reduce stages every captured input through a device-to-device copy. The activations feeding those all-reduces are allocated inside graph capture from the graph's private pool, so turning expandable segments off for the duration of graph_capture() makes them exportable and lets AITER take its registered, copy-free path. Weights, KV cache and allocations made outside graph_capture() keep expandable segments. This happens automatically on ROCm when the TP group's AITER custom all-reduce registers graph buffers (vLLM did not turn that off, not gfx1250) and AITER decides it when capture begins, which AITER advertises with the `defers_capture_registration` class marker from v0.1.26 (ROCm/aiter#5799). It is skipped when the DP group also runs AITER collectives: under DP+EP the MoE combine reduce-scatters a persistent workspace allocated before capture, which the registered path cannot export. On older AITER, without AITER custom all-reduce, with the cuMem graph pool, or when expandable segments are already off, nothing changes. DeepSeek-V4.1-Flash TP8 on MI355X with expandable segments on: decode step -2.6% at concurrency 1 and -2.0% at concurrency 8, the same as with expandable segments off; the graph pool grows by ~0.5 GiB per GPU (its size with expandable segments off) and the KV cache shrinks by 0.2%. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
CustomAllreducerefuses its registered (copy-free) CUDA-graph capture path while PyTorchexpandable_segmentsis on, because VMM-backed pointers cannot be exported withhipIpcGetMemHandle(#4174). It then stages every all-reduce input through a device-to-device copy (__amd_rocclr_copyBuffer) into the pre-registered input pool.That veto is decided once, in
__init__:A host that wants the registered path has one clean way to get it: keep expandable segments for weights, KV cache and eager allocations, and turn them off only for the duration of graph capture, so the graph pool's activations are ordinary
hipMallocmemory and are exportable. Today that does nothing. By the timecapture()runs the veto has already latched, and the copy-in path is taken regardless of what the allocator is doing.The fix
_register_for_capturing_requested) before theexpandable_segmentsveto.capture(), decide the path from the live allocator state._expandable_segments_enabled()already reads the allocator snapshot, so no new plumbing. The decision goes both ways: off at capture uses the registered path, on at capture uses copy-in, whatever__init__decided.IPCBufferPool.all_gather_object, factored out of_gather_ipc_meta). The registered path is used only if every rank can take it. Otherwise every rank uses copy-in, which is always safe, and a warning lists the per-rank decisions. The exchange is skipped when registration was never requested, since that is the same on every rank.flush_graph_bufferswill export it (hipPointerGetAttribute(RANGE_START_ADDR), thenhipIpcGetMemHandleon the base), through the HIP runtime torch already loaded. A buffer that fails raises aRuntimeErrorat the call site. Before, the export failed insideHIP_CALLat flush, whichstd::abort()s the process with no traceback. The check clears the sticky error a failed HIP call leaves, which the next kernel launch would otherwise report as its own. A caller-provided output on the registeredall_reduceis checked too, since flush exports it as well.capture()'sfinally, so the decision is scoped to the capture window and never leaks into eager calls.CustomAllreduce.defers_capture_registration = True, so hosts can feature-detect this instead of inferring it from a version number. vLLM's side ([ROCm] Capture CUDA graphs with expandable segments off for AITER all-reduce vllm-project/vllm#57481) probes for it and stays inert without it.Disabled communicators (unsupported world size, multi-node group, no
custom_arlibrary) are still entered bygraph_capture(). Both new attributes are set before__init__can return early, andcapture()skips the exchange there.What changes for existing callers
capture()than at__init__. On at both: copy-in, as before. Off at both: registered, as before.__init__, on at capture now uses copy-in. Before, the latched registered path was kept and flush aborted the process atcustom_all_reduce.cuh:4071(hipIpcGetMemHandle ... invalid argument). Measured on this PR's first revision (bbd272ae8), which handled this case likemain.capture()when registration was requested, and the export check (about 1 us) per collective captured on the registered path.flush_graph_buffersalready exchanges graph-buffer handles through the same store at the end ofcapture(). Eager calls and graph replay are unchanged.__init__warning now says the decision is re-checked at capture instead of saying it forces copy-in.Precondition for hosts: on the registered path, every collective buffer captured in the window must be allocated inside it. A tensor allocated earlier, while expandable segments were on, is still VMM-backed and cannot be IPC-exported. A graph-capturing host normally meets this, because the graph pool's activations feed the all-reduces. This is now enforced: a violation raises the
RuntimeErrorabove at the offending collective, and the process stays usable.Impact
Measured with vLLM on 8x MI355X, Kimi-K3 decode (conc 1, 131k context, MTP K=6), rank 0, 4 captured passes. The host turns expandable segments off for capture on every rank (vllm-project/vllm#57481). The aiter side was applied as a runtime overlay of this PR's first revision. The second revision adds the cross-rank exchange and the export check, neither of which changes the path when every rank turns expandable segments off.
__amd_rocclr_copyBufferlaunchesThe drop is exactly -1160 copies = 792 two-stage + 368 one-stage all-reduce calls, i.e. one staging copy per collective, all gone. To confirm a host is getting the registered path, look for
expandable_segments is off at capture time; using the registered custom-allreduce capture path(logged at INFO on each capture).Test plan
New
op_tests/multigpu_tests/test_custom_allreduce_capture_registration.py. Neither existing test covers both axes:test_init_dist_env.pysets expandable segments but captures no graph, andtest_custom_allreduce.pycaptures a graph but never touches the allocator config. Each run builds the communicator, then captures one all-reduce under one of five scenarios:__init__keeptogglemixedreversestaleRuntimeErrorat the collective on every rankIt asserts that:
__init__veto still fires exactly when expandable segments are on at construction;capture(), every rank is on the expected path (formixed, rank 0 alone could have registered);capture();stale, every rank raises the new error, and an eager all-reduce afterwards is correct, so no sticky HIP error is left behind.With no arguments the test sweeps TP 2/3/4/8 (capped at the visible GPU count), which is what CI runs. TP=3 covers a disabled communicator. On platforms where the veto cannot happen (gfx1250, the VMM transport, or a build that ignores
expandable_segments), the flag assertions are skipped with a warning and only the result is checked, astest_init_dist_env.pydoes.Test result
New test: 20/20 pass (TP 2/3/4/8 x 5 scenarios) in both environments:
vllm/vllm-openai-rocm:nightly-rocm100-3df4ae15(torch 2.12.0+rocm10.0.0), aiter built from source on this PR's basec8325e00c.This PR's first revision, which re-checked only each rank's own state and only ever relaxed the veto, is the control for the new scenarios (TP=2):
bbd272ae8)keeptogglemixed[True, False]reversecustom_all_reduce.cuh:4071On
main(1ec3cf48e),togglefails at every TP size withexpected enable_register_for_capturing=True inside capture(), saw False, so the test catches the latched veto.