Skip to content

[HIP] [CustomAR] Keep CUDA-graph buffer registration in step across ranks - #6819

Merged
TennyWang1223 merged 1 commit into
ROCm:mainfrom
okorzh-amd:okorzh/car-graph-output-rank-divergence
Oct 26, 2026
Merged

TennyWang1223 merged 1 commit into
ROCm:mainfrom
okorzh-amd:okorzh/car-graph-output-rank-divergence

Conversation

@okorzh-amd

Copy link
Copy Markdown
Contributor

Motivation

vLLM on ROCm crashes at startup with DSpark speculative decoding at TP8 when custom all-reduce is on. It reproduces on stock vLLM. During the third CUDA-graph capture round (the DSpark verify/draft graphs), the ranks record different numbers of graph buffers:

Capture round Buffers per rank
1st (target graphs) 1996 on all 8 ranks
2nd 99 on all 8 ranks
3rd (DSpark graphs) 3492 on 7 ranks, 3488 on 1

flush_graph_buffers pairs buffer i with every peer's buffer i, so the lists end up misaligned and hipIpcOpenMemHandle fails with "invalid argument" / "invalid device pointer". The current workaround is --disable-custom-all-reduce, which falls back to RCCL and slows the all-reduces down.

Root cause

On the registered capture path, register_graph_buffers added every captured output to output_buffers_, the map of eagerly registered outputs. get_output_buffer_RD checks that map before recording. So when the allocator gave a rank an address that an earlier capture had already used, only that rank:

  • reused the stale entry and skipped recording the buffer, which leaves its list shorter than its peers' (the crash above);
  • or, if the totals still matched by chance, pointed its kernel at its peers' old buffers, which corrupts data with no error.

Only fp32/fp16 all-reduces record outputs; the bf16 dispatch never passes is_broadcast_reg_outptr. Muse Spark's MoE does its TP reduction in fp32, which is what exposes the bug. Inputs were never cached this way, so they are unaffected.

Changes

  • csrc/include/custom_all_reduce.cuh: stop adding graph-captured outputs to output_buffers_. Their RankData slots are already baked into the captured kernels, so nothing reads the map entry after flush. A later capture now records the buffer on every rank. The map keeps only eagerly registered buffers, and a comment states that rule.
  • csrc/include/custom_all_reduce_gfx1250.cuh: the same change, for consistency only. gfx1250 never registers graph buffers, so it has no runtime effect there.
  • IPCBufferPool.flush_graph_buffers: before exchanging handles, the ranks all-gather their counts. If the counts differ, every rank raises the same RuntimeError, instead of opening the wrong peer handles. This also fixes a hang: a rank with 0 recorded buffers used to return early while the other ranks waited for its handles.
  • New op_tests/multigpu_tests/test_custom_allreduce_graph_buffer_reuse.py (fp32), run at TP 2/4/8:
    • reuse: in the second capture, rank 0 writes into the first capture's output and the other ranks into a fresh tensor. Every rank must record 2 buffers per capture, and both graphs must replay to the exact sum.
    • extra / none: rank 0 captures one extra all-reduce, or none at all. Every rank must raise, and none may hang.
  • op_tests/multigpu_tests/test_custom_allreduce.py: remove the docstring warning about stale peer pointers on address reuse, which no longer applies.

Test plan

  • python op_tests/multigpu_tests/test_custom_allreduce_graph_buffer_reuse.py fails on main and passes on this branch (MI355X, TP 2/4/8)
  • python op_tests/multigpu_tests/test_custom_allreduce.py and test_custom_allreduce_capture_registration.py still pass
  • vLLM + Muse Spark + DSpark at TP8 with custom all-reduce on: the server starts and every rank registers the same count in every capture round

@okorzh-amd
okorzh-amd requested a review from a team October 22, 2026 04:48
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6819 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [CustomAR] Keep CUDA-graph buffer registration in step across ranks [HIP] [CustomAR] Keep CUDA-graph buffer registration in step across ranks Oct 22, 2026
@github-actions github-actions Bot added the HIP label Oct 22, 2026
On the registered capture path, register_graph_buffers added every captured
output to output_buffers_, the map of eagerly registered outputs. A later
capture looks that map up before recording, so when the allocator handed a
rank the same address again, that rank reused the stale entry and skipped
the buffer while the other ranks recorded theirs. flush_graph_buffers pairs
buffer i with every peer's buffer i, so the shifted lists made peers open
the wrong IPC handles; with matching counts the rank would instead have
pointed at its peers' old buffers, silently.

vLLM hit this with DSpark on Muse Spark (TP8, fp32 MoE reduce): the draft
graphs, captured after the target graphs, recorded 3488 buffers on one rank
and 3492 on the other seven, and hipIpcOpenMemHandle failed with "invalid
argument". Only fp32/fp16 all-reduces record outputs; bf16 does not.

- Do not add graph-captured outputs to output_buffers_. Their RankData
  slots are baked into the captured kernels, so nothing reads the map entry
  after flush; a later capture now records the buffer on every rank. The
  gfx1250 header gets the same change for consistency only: that transport
  never registers graph buffers.
- flush_graph_buffers agrees on the per-rank count before exchanging
  handles and raises the same error on every rank when they differ. This
  also stops a rank with nothing recorded from returning early and leaving
  the others blocked on its handles.
- Add test_custom_allreduce_graph_buffer_reuse.py (address reuse on rank 0
  only, plus rank-divergent captures that must raise on every rank), and
  drop the stale-pointer warning from test_custom_allreduce.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Oxana Korzh <[email protected]>
@okorzh-amd

Copy link
Copy Markdown
Contributor Author

@TennyWang1223 could you please help to review? CI is passing

@TennyWang1223 TennyWang1223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants