Repository navigation
[Bugfix][MRV2] Dispatch uniform decode to a padded FULL cudagraph - #53407
Conversation
c4124da to
21958d7
Compare
LucasWilkinson
left a comment
There was a problem hiding this comment.
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? |
|
/ci run |
|
✅ Triggered Buildkite CI #85255 for commit |
|
/ci retry |
|
✅ Queued 1 failed job(s) for retry in Buildkite CI #85255. |
|
This pull request has merge conflicts that must be resolved before it can be |
af4179e to
677536b
Compare
|
✅ Triggered Buildkite CI #85318 for commit |
LucasWilkinson
left a comment
There was a problem hiding this comment.
Overall this LGTM now; thanks! left one more suggestion on how we could tighten up the implementation a bit more
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>
5d4cbe8 to
3235aa8
Compare
|
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-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: Xiaohu Guo <Xiaohu.Guo@amd.com>
|
/ci run |
|
✅ Triggered Buildkite CI #85408 for commit |
|
/ci retry |
|
✅ Queued 4 failed job(s) for retry in Buildkite CI #85408. |
…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>
…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>
…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>
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 kindsof graph, staged at different sizes:
round_up(capture_size, decode_query_len).The problem. When
decode_query_lendoes not divide the capture ladder, those two setsinterleave 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=Noneand_is_compatibleaccepts anything against it. So the batchtakes 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 landon 3, 6, 9, 18, 24 tokens; PIECEWISE stays on the raw sizes:
This is not a corner case. On the stock default config — default ladder,
max_cudagraph_capture_size=512,max_num_seqs=128, EAGLE/MTP withnum_speculative_tokens=2sodecode_query_len=3: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/PIECEWISEfallback.
dispatch()then picks the smallest FULL decode graph that fits, and only fallsback to PIECEWISE when none does.
dispatch()or_is_compatible()— only the contents and order of thecandidate lists built in
_init_candidates.satisfies
num_tokens >= num_reqs * query_len, and a decode graph staged atTtokensholds
T / query_lenrequests — so the smallest graph at or above the batch's token countalready 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.
uniform_token_count=None, and_is_compatiblerejects any descriptor that has one.varlen_decode=True: those graphs are captured at every raw size, sothey 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 onCUDA 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 decodebatch 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 patchescurrent_platform.is_rocmviamonkeypatch— the idiom used intests/test_config.pyandtests/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_seqsanddecode_query_len(query lengths 1, 2, 3, 8), against both this change andits parent commit, and the decision sets diffed. Reachability accounts for the data-parallel
path, where
sync_cudagraph_and_dp_paddingpasses the synced (max-across-ranks)num_tokenswith the local
num_reqs, sonum_tokens > num_reqs * query_lenis 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 replacingcurrent_platform.is_rocm()withTruefailstest_pad_up_is_rocm_gated. Fulltests/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 atdecode_query_len=3, theonly tested query length that does not divide its ladder — query lengths 1, 2 and 8 are
completely unchanged.
decode_query_len=1covers every deployment not running speculativedecoding, 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(souniform_decode_query_len=3),FULL_AND_PIECEWISE, 68k-ISL / 350-OSL long-context sweep. Both arms are the same containerand the same stock capture ladder; the only difference is this patch. With
decode_query_len=3, FULL decode graphs stage atround_up(size, 3), so M = 3xconc lands on acaptured 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):
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: Claudetrailer.