Skip to content

[Bugfix][MRV2] Dispatch uniform decode to a padded FULL cudagraph - #53407

Merged
LucasWilkinson merged 6 commits into
vllm-project:mainfrom
xiaohuguo2023:xiaohuguo/cudagraph-dispatch-pad-uniform-decode-fix
Aug 25, 2026
Merged

LucasWilkinson merged 6 commits into
vllm-project:mainfrom
xiaohuguo2023:xiaohuguo/cudagraph-dispatch-pad-uniform-decode-fix

Conversation

@xiaohuguo2023

@xiaohuguo2023 xiaohuguo2023 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Under speculative decoding, half of all decode batch sizes silently fall back to running
attention eagerly every decode step instead of replaying a captured CUDA graph. This makes
them dispatch to a captured graph instead.

Current state. With a separate decode routine (FULL_AND_PIECEWISE) there are two kinds
of graph, staged at different sizes:

  • FULL decode — the whole decode step, attention included, is captured. Staged only at
    round_up(capture_size, decode_query_len).
  • PIECEWISE — attention runs eagerly. Staged at the raw capture sizes.

The problem. When decode_query_len does not divide the capture ladder, those two sets
interleave and leave gaps. A batch landing in a gap finds that the smallest graph that fits
is a PIECEWISE one, even though a slightly larger FULL decode graph exists and could serve it
by padding a few dummy requests. PIECEWISE always matches, because its descriptor has
uniform_token_count=None and _is_compatible accepts anything against it. So the batch
takes it and pays the eager-attention cost — metadata build and kernels on the host critical
path — every single decode step.

Example (decode_query_len=3, capture sizes [1, 2, 4, 8, 16, 24]). FULL decode graphs land
on 3, 6, 9, 18, 24 tokens; PIECEWISE stays on the raw sizes:

batch tokens smallest graph that fits result
4 requests 12 size-16 PIECEWISE eager attention ❌
4 requests (this PR) 12 size-18 FULL decode (pad 4→6 reqs) captured ✅

This is not a corner case. On the stock default config — default ladder,
max_cudagraph_capture_size=512, max_num_seqs=128, EAGLE/MTP with
num_speculative_tokens=2 so decode_query_len=3:

on a FULL decode graph falling back to eager PIECEWISE
before 64 / 128 64 / 128
after 128 / 128 0

Affected request counts are 4, 5, 9, 10, 12, 13, 17, 18, 20, 21, 25, 26, … continuing in that
pattern. The issue was originally found in profiling traces on MI355X.

Fix. In _init_candidates, offer the FULL decode graphs ahead of the mixed/PIECEWISE
fallback. dispatch() then picks the smallest FULL decode graph that fits, and only falls
back to PIECEWISE when none does.

  • No change to dispatch() or _is_compatible() — only the contents and order of the
    candidate lists built in _init_candidates.
  • Zero extra captured graphs: no additional capture time or memory.
  • One candidate per query length, not every larger graph. A uniform-decode batch always
    satisfies num_tokens >= num_reqs * query_len, and a decode graph staged at T tokens
    holds T / query_len requests — so the smallest graph at or above the batch's token count
    already has enough request slots, and larger graphs of the same query length are
    unreachable. On the default ladder this is 2 candidates per token count instead of 43.
  • Inert for non-uniform batches: a mixed batch passes uniform_token_count=None, and
    _is_compatible rejects any descriptor that has one.
  • Strict no-op when varlen_decode=True: those graphs are captured at every raw size, so
    they have no gaps, and they are excluded by the filter.

Platform. The change is gated behind current_platform.is_rocm(), so it is zero-diff on
CUDA by construction — the end-to-end numbers below were taken on MI355X.

Test Plan

1. Unit tests — six new tests in tests/v1/cudagraph/test_cudagraph_manager.py: a decode
batch in a gap now runs on the next size up (regression test for the fix); the same batch off
ROCm keeps the old behaviour (pins the gate); an exact-size match is not over-padded; a mixed
batch never lands on a decode-only graph; a batch beyond the ladder still falls back to eager;
and, parametrized over query lengths 1, 2 and 8, dispatch is unchanged whenever the query
length divides the ladder.

This file runs on a non-ROCm CI runner (.buildkite/test_areas/misc.yaml, device: cpu-small), so rather than skip there, the helper patches current_platform.is_rocm via
monkeypatch — the idiom used in tests/test_config.py and
tests/kernels/test_gate_linear_rocm_dispatch.py — and both sides of the gate stay covered.

2. Exhaustive dispatch differential — dispatch() replayed over every reachable
(num_tokens, num_reqs, uniform_token_count) triple for seven combinations of capture ladder,
max_num_seqs and decode_query_len (query lengths 1, 2, 3, 8), against both this change and
its parent commit, and the decision sets diffed. Reachability accounts for the data-parallel
path, where sync_cudagraph_and_dp_padding passes the synced (max-across-ranks) num_tokens
with the local num_reqs, so num_tokens > num_reqs * query_len is possible.

3. Candidate-list narrowing differential — the "one candidate per query length"
restriction diffed separately against the unrestricted version over the same harness.

4. End-to-end — Kimi-K3 TP8 on MI355X, num_spec=2 (decode_query_len=3),
FULL_AND_PIECEWISE, long-context (68k ISL / 350 OSL).

Test Result

1. Unit tests. All six pass, and both halves of the change are pinned: reverting the
dispatch change fails test_uniform_decode_pads_up_to_full_graph
(assert <CUDAGraphMode.PIECEWISE: 1> == <CUDAGraphMode.FULL: 2>), and replacing
current_platform.is_rocm() with True fails test_pad_up_is_rocm_gated. Full
tests/v1/cudagraph/ suite: 98 passed, 5 skipped (103 collected).

2. Dispatch differential. Of 4440 reachable batches, 52 dispatch differently. All
52 are PIECEWISE -> FULL; none move the other way. All 52 are at decode_query_len=3, the
only tested query length that does not divide its ladder — query lengths 1, 2 and 8 are
completely unchanged. decode_query_len=1 covers every deployment not running speculative
decoding, so those configurations are provably unaffected.

Three safety properties hold across all 4440 batches with the fix applied: no mixed batch is
given a uniform-decode graph, no batch is given a graph smaller than its token count, and no
batch is given a graph smaller than its request count. The cost on the stock default config is
a mean of 1.27 extra padded requests, at most 5.

3. Candidate-list narrowing. Over 105576 reachable batches the narrowed and
unrestricted versions make identical decisions (0 differences), confirming the larger
same-query-length graphs are unreachable rather than merely unlikely. This was a readability
change, not a performance one: a uniform decode batch hits the first candidate in 0.11 µs,
unchanged either way
. Only mixed/prefill dispatch differed (0.14 → 1.70 µs unnarrowed),
negligible against a prefill step.

4. End-to-end. Kimi-K3 TP8 on MI355X, num_spec=2 (so uniform_decode_query_len=3),
FULL_AND_PIECEWISE, 68k-ISL / 350-OSL long-context sweep. Both arms are the same container
and the same stock capture ladder; the only difference is this patch. With
decode_query_len=3, FULL decode graphs stage at round_up(size, 3), so M = 3xconc lands on a
captured size at every concurrency except conc-4 (M=12) and conc-12 (M=36), which fall into a
gap and dispatch to PIECEWISE. Those two are the batches this PR pads onto the next FULL graph
(18 and 42); every other concurrency is a control.

Decode ITL p50 (ms):

conc M before after delta
1 3 8.98 9.05 +0.8%
2 6 10.11 10.15 +0.4%
4 12 (gap) 62.14 12.15 -80.4%
8 24 13.94 13.77 -1.2%
12 36 (gap) 64.94 15.96 -75.4%

AI assistance disclosure

Per docs/contributing/README.md: this change was developed with AI assistance (Claude Code).
I identified the bug from profiling traces on MI355X, reviewed and validated the change and
the tests myself, and ran the test suites and the end-to-end benchmark above. The commit
carries a Co-authored-by: Claude trailer.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added nvidia rocm Related to AMD ROCm mrv2 Model Runner V2 specific labels Aug 22, 2026
@mergify mergify Bot added the bug Something isn't working label Aug 22, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Aug 22, 2026
@ChuanLi1101 ChuanLi1101 added the verified Run pre-commit for new contributors without triggering other tests label Aug 22, 2026
@xiaohuguo2023
xiaohuguo2023 force-pushed the xiaohuguo/cudagraph-dispatch-pad-uniform-decode-fix branch from c4124da to 21958d7 Compare August 22, 2026 23:06

@LucasWilkinson LucasWilkinson 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.

Thanks for the contribution! I think we should just do this generally (and simplify it) proposed simpler version here: xiaohuguo2023#1

@github-project-automation github-project-automation Bot moved this to In review in NVIDIA Aug 23, 2026
@shen-shanshan shen-shanshan self-assigned this Aug 23, 2026
@xiaohuguo2023 xiaohuguo2023 changed the title [Bugfix][MRV2][ROCm] Dispatch uniform decode to a padded FULL cudagraph [Bugfix][MRV2] Dispatch uniform decode to a padded FULL cudagraph Aug 23, 2026
@xiaohuguo2023

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution! I think we should just do this generally (and simplify it) proposed simpler version here: xiaohuguo2023#1

@LucasWilkinson Thanks, this is nicer than what I had, merged it in my PR branch, and I'll take [ROCm] off the title.

added one fix: current_range_start advances once per descriptor, which assumes no two share a num_tokens — but under dynamic spec decode round_up collapses several query lengths onto the same token count, and every descriptor after the first then gets an empty range and never enters a candidate list at all. I grouped the range fill by num_tokens (details in the comment); that takes decode_query_lens=[1, 2, 3, 4] from 113 batches losing a FULL graph versus main down to none

Also worth flagging: your version fixes a bug I'd missed. Token counts above the largest PIECEWISE graph but at or below the largest FULL one only get FULL descriptors as candidates today, so a mixed batch there matches nothing and runs fully eager. Building the PIECEWISE ranges independently gives them a graph — a straight improvement over both main and my original patch.

I am doing Mi355X e2e test, will post before/after. Could a maintainer kick off the CUDA CI, as I don't have the access to CUDA machine?

@njhill

njhill commented Aug 23, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85255 for commit af4179ee7fa9.

@shen-shanshan shen-shanshan removed their assignment Aug 24, 2026
@shen-shanshan

Copy link
Copy Markdown
Member

/ci retry

@github-actions

Copy link
Copy Markdown

✅ Queued 1 failed job(s) for retry in Buildkite CI #85255.

@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @xiaohuguo2023.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Aug 24, 2026
@xiaohuguo2023
xiaohuguo2023 force-pushed the xiaohuguo/cudagraph-dispatch-pad-uniform-decode-fix branch from af4179e to 677536b Compare August 24, 2026 08:54
@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85318 for commit 82417785edf9.

Comment thread vllm/v1/worker/gpu/cudagraph_utils.py Resolved

@LucasWilkinson LucasWilkinson 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.

Overall this LGTM now; thanks! left one more suggestion on how we could tighten up the implementation a bit more

@github-project-automation github-project-automation Bot moved this from In review to Ready in NVIDIA Aug 24, 2026
xiaohuguo2023 and others added 5 commits August 24, 2026 23:10
With speculative decoding, half of all decode batch sizes run attention
eagerly every step instead of replaying a captured graph.

FULL decode graphs are staged at round_up(capture_size, decode_query_len)
while PIECEWISE graphs stay on the raw capture sizes. When the query length
does not divide the capture ladder the two sets come apart and leave gaps.
A batch landing in a gap finds that the smallest graph big enough for it is
a PIECEWISE one, so it takes that and pays for eager attention on every
decode step -- even though a slightly larger FULL decode graph exists and
could serve it by padding in a few dummy requests. PIECEWISE always matches
because its descriptor has uniform_token_count=None.

On the stock default config with num_speculative_tokens=2, that is 64 of
the 128 possible decode batch sizes.

Offer the FULL decode graphs ahead of the mixed fallback in the candidate
lists, so dispatch() picks the smallest FULL decode graph that fits and
only falls back to PIECEWISE when there is none. dispatch() and
_is_compatible() are unchanged, and no extra graphs are captured.

Only one candidate is offered per query length. dispatch() returns the
first graph in the list that fits and the list is sorted smallest first,
so the smallest always wins. A bigger graph would only be needed if the
smallest had too few request slots, and that cannot happen: a decode batch
never holds more requests than its token count divided by the query length,
which is exactly how many slots the graph has. That takes the list from 43
entries to 2, and every batch the engine can actually produce still gets
the same graph -- checked by replaying dispatch() over all 105576 of them.

Gated on ROCm, where the end-to-end numbers were taken.

Co-authored-by: Claude
Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
Co-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
  descriptor is left with an empty range. Order within a group does not
  matter: those descriptors differ only in uniform_token_count, and a
  batch matches at most one of them. No batch then loses a FULL graph
  relative to main in any of the five configurations checked, and the
  gains from the preceding commit are preserved.

  Also add a regression test: tests/v1/cudagraph/ had no dynamic
  spec-decode manager -- the helper hardcoded speculative_config = None --
  so nothing covered the multi-query-length staging path.

  Co-Authored-By: Claude
  Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
  The candidate ranges are now built per mode, so each mode's ladder covers
  the full token range on its own. This commit pins the behaviour that
  change buys, which was previously untested.

  round_up(capture_size, decode_query_len) lands FULL decode graphs on token
  counts the PIECEWISE ladder never uses. With capture sizes
  [1, 2, 4, 8, 16, 24] and decode_query_len=3, FULL is staged at 3, 6, 9, 18
  and 24 while PIECEWISE stays on the raw sizes. At 3, 6, 9 and 18 tokens the
  only staged descriptors are decode ones, and a mixed batch passes
  uniform_token_count=None, which _is_compatible can never match against
  them -- so deriving one shared range set from the union of staged sizes
  leaves that batch nothing to dispatch to and it runs fully eager.

  Building each mode's ranges independently keeps the next PIECEWISE graph
  reachable there. The test derives the decode-only token counts from the
  staged descriptors rather than hard-coding them, and asserts the premise is
  non-empty first so it cannot silently degrade into covering nothing.

  Fails on the parent of "Simplify cudagraph candidate construction"
  (CUDAGraphMode.NONE at 3, 6, 9 and 18); passes here.

  Co-authored-by: Claude
  Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
Signed-off-by: xiaohuguo2023 <149615094+xiaohuguo2023@users.noreply.github.com>
@xiaohuguo2023
xiaohuguo2023 force-pushed the xiaohuguo/cudagraph-dispatch-pad-uniform-decode-fix branch from 5d4cbe8 to 3235aa8 Compare August 24, 2026 22:10
@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Hi @xiaohuguo2023, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
@LucasWilkinson
LucasWilkinson enabled auto-merge (squash) August 25, 2026 00:03
@LucasWilkinson

Copy link
Copy Markdown
Contributor

/ci run

@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 25, 2026
@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85408 for commit 39fdaece9c29.

@shen-shanshan

Copy link
Copy Markdown
Member

/ci retry

@github-actions

Copy link
Copy Markdown

✅ Queued 4 failed job(s) for retry in Buildkite CI #85408.

@LucasWilkinson
LucasWilkinson merged commit c74dd2d into vllm-project:main Aug 25, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Aug 25, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Aug 25, 2026
am-cohere pushed a commit to am-cohere/vllm that referenced this pull request Sep 1, 2026
…lm-project#53407)

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: xiaohuguo2023 <149615094+xiaohuguo2023@users.noreply.github.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
mikeshawcode pushed a commit to mikeshawcode/vllm that referenced this pull request Sep 1, 2026
…lm-project#53407)

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: xiaohuguo2023 <149615094+xiaohuguo2023@users.noreply.github.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
Signed-off-by: mikeshawcode <michaelwshaw2@gmail.com>
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…lm-project#53407)

Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: xiaohuguo2023 <149615094+xiaohuguo2023@users.noreply.github.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mrv2 Model Runner V2 specific nvidia ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm verified Run pre-commit for new contributors without triggering other tests

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants