Repository navigation
[Spec] Reuse K3 auxiliary outputs across decode CUDA graph sizes - #40159
Merged
hnyls2002 merged 5 commits intoSep 29, 2026
Merged
Conversation
AuxHiddenStatePacker gains an optional `out=` destination. The decode CUDA graph runner owns one [max_num_token, width] buffer per stream and hands each captured size a row slice through ForwardBatch.aux_hidden_states_buffer, so DFlash/DSpark target graphs no longer each pin their own packed aux output. Models opt in through the SupportsSharedAuxHiddenStates protocol. Kimi K3 now captures through AuxHiddenStatePacker (PP stages keep the list path) and is the first opt-in; EAGLE3, draft runners, PP and models without the interface are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chromecast56
force-pushed
the
codex/shared-aux-graph-upstream
branch
from
September 22, 2026 21:23
f2be651 to
91fa6ad
Compare
chromecast56
marked this pull request as ready for review
September 22, 2026 21:37
chromecast56
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ch-wan,
hnyls2002,
ispobock and
merrymercy
as code owners
September 22, 2026 21:37
Collaborator
Author
|
/tag-and-rerun-ci |
# Conflicts: # python/sglang/srt/layers/aux_hidden_states.py # python/sglang/srt/models/kimi_k3.py
Collaborator
|
/rerun-test test_kimi_k3_b300.py test_kimi_k3_b300_low_latency.py test_basic_sanity_dflash.py test_basic_sanity_dspark.py |
Contributor
|
Results for 🚀 🚀 🚀 |
Collaborator
|
Pushed fixes for:
|
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
With DFlash/DSpark, every captured decode CUDA graph keeps its own packed aux hidden-state output alive, so reserved graph memory grows with the sum of captured sizes. One buffer sized for the largest graph is enough: the worker writes target hidden states into draft KV before the next target forward on that stream.
Modifications
AuxHiddenStatePacker(Improve CUDA graph and speculative execution output handling #37329) takes an optionalout=buffer, checks its shape and dtype on the firstappend, and writes captures into it.DecodeCudaGraphRunnerkeeps one[max_num_token, K * hidden]buffer per stream (so PD-multiplexed streams don't alias) and gives each captured size a row slice throughForwardBatch.aux_hidden_states_buffer. The buffer is used only for DFlash-family target runners withpp_size == 1, and only for models implementingSupportsSharedAuxHiddenStates.get_packed_aux_hidden_size().AuxHiddenStatePacker(PP stages keep the list, since inherited captures arrive already concatenated) and is the first model to opt in. Other packer users (DeepSeek V2, MiMo V2) and EAGLE3 are unchanged.Tests
test_spec_aux_hidden_state.py: packing into an external buffer gives the same result as the list-path concat, lands in the caller's storage, and raises on a buffer that doesn't fit.test_decode_cuda_graph_runner.py: graph sizes 64/8/32 share one buffer; a second stream gets its own; non-DFlash, draft, PP and non-opt-in models get no shared buffer.GPU check, Kimi K3 colocated TP8 on 8xB300 with DFLASH (block size 8), GSM8K 5-shot on all 1,319 questions. The comparison is main + #40794 (K3 DFLASH) with and without this PR. Target-verify CUDA-graph memory per GPU goes from 2.215 GB to 1.756 GB (−0.46 GB, −21%), and startup free memory rises by the same amount. Accuracy and acceptance are unchanged: 95.0% / average accept length 5.07 without this PR, 95.6% / 5.06 with it.
CI States
Latest PR Test (Base): ⏳ Run #36628674548
Latest PR Test (Extra): ❌ Run #36628673923
Latest PR Test (AMD ROCm 10): ⏳ Run #36628674234