Repository navigation
[None][feat] Muse Spark: TRTLLM DFlash drafter with rejection sampling: decode-step fixes and cold-page compression - #21535
Merged
zheyuf merged 11 commits intoNov 7, 2026
Conversation
zheyuf
force-pushed
the
zheyuf/dflash-trtllm-default-al-tests
branch
from
November 5, 2026 03:27
03b61b5 to
2931086
Compare
Draft
3 tasks done
…V capacity The paged drafter arena checked each context write against the block table's allocation extent by reading _ctx_block_counts back from the GPU. That D2H copy waits for every kernel queued ahead of it, i.e. the whole context forward, so every context iteration serialized the host with the GPU. Read each row's allocation from the KV cache manager's host-side capacity instead, rounded up to whole ctx pages; a manager without one keeps the device read. Covered by test_dflash_ctx_block_tables.py. Signed-off-by: zheyuf <[email protected]>
…ithout a host sync With rejection sampling, write_context_onehot_draft_probs runs on every context iteration. Its two advanced-index assignments with the device slot ids synchronize the host with the stream, so the host waited for the whole context forward twice per context iteration. index_fill_ over the basic-slice views writes the same rows without a sync. Covered by test_context_onehot_draft_probs.py. Signed-off-by: zheyuf <[email protected]>
… golden protocol and under prefix reuse - test_dflash2_speed_bench_coding_golden_acceptance: the SemiAnalysis golden protocol for this drafter (80 SPEED-Bench qualitative coding prompts, chat template, T=1.0, top_p 0.95, 4096 tokens, rejection sampling, two seeds pooled) against the K=7 golden 4.05 less 2%. - test_dflash2_acceptance_under_prefix_reuse: GSM8K few-shot prompts cold and then over their cached prefix; the warm acceptance length must stay within 5% of the cold one. - accuracy_core: gsm8k_fewshot_prompts, acceptance_length_cold_and_warm and assert_acceptance_length_survives_prefix_reuse. - The served environment adds MUSESPARK_OPEN_SM107_FUSED_KERNELS=1, which the sm107 compositions need and sm103 ignores. Covered by accuracy_core.py, test_musespark_open.py. Signed-off-by: zheyuf <[email protected]>
zheyuf
force-pushed
the
zheyuf/dflash-trtllm-default-al-tests
branch
from
November 6, 2026 21:52
806e378 to
ad1eb8c
Compare
Collaborator
Author
|
/bot run --disable-fail-fast |
Collaborator
|
PR_Github #83163 [ run ] triggered by Bot. Commit: |
…the target's KV cache manager A DFlash drafter on TRTLLM attention can now keep its KV layers in the target's KVCacheManagerV2 under cold-page NVFP4 compression. The codec encodes only the target's layers; the drafter-owned layers of the shared manager are copied byte for byte, so the drafter's context is unchanged when its pages come back from the Host or Disk tier, and a prefix-cache hit still reaches it. - KVCacheManagerV2 passes the draft-owned layer ids to the codec as lossless_layers and requires one dtype only across the encoded layers, so an FP8 target with a BF16 drafter is accepted. - The NVFP4 codec lays lossless layers out as whole-buffer copies, before uncompressed_layer_types picks among the target's layers. - The unified-KV blocker no longer names cold-page compression; other compression algorithms still keep the drafter out. - Cold-page compression admits every DFlash backend. The KV cache creator refuses a separate DFlash draft KV cache manager, whose pages the codec would encode with the target's layout, and names why the drafter could not share the target's manager. Covered by test_dflash_unified_kv_gate.py, test_kvcm2_integration.py, test_quantization_for_cold_page.py. Signed-off-by: zheyuf <[email protected]>
With rejection sampling, every decode step turns the gathered BF16 head logits into FP32 soft-capped logits for the target distribution: MuseSparkOpenLogitsProcessor (and modeling_v2's TargetHead.materialize, which reproduces it) widened the row to FP32 and applied the multiplier and the tanh cap in four more elementwise kernels, five full passes over [rows, vocab] on the step's critical path. soft_capped_logits (modules/logit_soft_cap.py) reads the row once and writes the FP32 result once, with the same three separately rounded FP32 products and the accurate tanhf, so the output is the torch chain's bit for bit; non-contiguous and CPU inputs keep the torch chain. Covered by test_logit_soft_cap.py, test_musespark_open_soft_cap.py. Signed-off-by: zheyuf <[email protected]>
…ejection target logits in place The rejection path zeroes the padding requests' target logit rows so the rejection kernel never sees their non-finite values. It did so with an out-of-place masked_fill, a full copy of the [rows, vocab] FP32 logits on every decode step, to change the few padding rows. _zero_padding_rows takes inplace=True from that caller and writes only the masked rows (one Triton program per row, which returns at once for a real request); the other callers keep the copy. Only the padding rows of the step's logits change, and no request reads them. Covered by test_rejection_buffers_guard.py. Signed-off-by: zheyuf <[email protected]>
…p in one kernel DFlashForCausalLM.apply_draft_logit_transform widened the draft logits to FP32 and applied the multiplier and the tanh soft cap in four in-place elementwise kernels: five full passes over [requests * K, vocab shard] on every decode step, before the candidate top-k. It now calls soft_capped_logits, the same chain bit for bit; an FP32 input is still transformed in place, and a drafter without a soft cap keeps the multiply. Covered by test_dflash2_semantics.py. Signed-off-by: zheyuf <[email protected]>
…get/draft KV cache manager
A TRTLLM DFlash drafter keeps its pages in the target's KVCacheManagerV2. With an FP8
target and a BF16 drafter the manager's life cycles mix page sizes, so it builds one
attention-op table per pool group. The modeling_v2 step-input stager declined the
block-offset copy for that layout ("block offsets: layout or manager mode"). Every
decode step then ran the manager's own copy: a pinned allocation, a host index_select
of every batch row's page indices, a host-to-device copy, and a conversion kernel over
all max_blocks_per_seq columns of every table.
The stager now copies the attention-op tables too: one table per pool group, from its
life cycle's host rows at the group's scale and K/V offset, keeping BAD_PAGE_INDEX as
the manager's conversion does (a bad-page word on the BLOCKS descriptor; 0 keeps the
C++ copy's semantics). A drafter in the manager reads a whole row for its extent, so
the columns past the copied ones are filled with BAD_PAGE_INDEX, as the manager's own
copy writes them.
Tests: test_modeling_v2_staged_block_offsets.py checks the staged table bit for bit
against the manager's copy over a unified FP8/BF16 cache, after a shorter request takes
a longer one's row, and the descriptor's bad-page word.
Signed-off-by: zheyuf <[email protected]>
…draft head in one launch Rejection sampling drafts each DFlash 2 block position under the token drawn before it. The draft_head fast path (the drafter LM head on vocabulary shards, the selector's lattice from a key exchange, the path walk in one launch) covered only greedy drafts: a step that samples its drafts kept the drafter's transformed FP32 shard and ran the built-in method -- a torch.topk per shard, an all-gather, a second top-k, then per position a gather, nan_to_num, the Philox offsets, the shipped fused sampler (one CTA of 1024 threads on a 16-wide row) and a clamp, then the token gather and the dense draft_probs zeroing and scatter. At one request that is about 110 launches on the decode critical path where a greedy step has 13. Fast path draft_head_sampled (on draft_head): a sampled step keeps the bf16 shard, builds the selector's lattice exactly as the greedy step does (selector_lattice, factored out of selector_draft_tokens), zeroes the draft_probs rows as the built-in does, and walks the lattice with draft_path_sample: one CTA of the shipped sampler's block per request runs every position, writing each position's row with the built-in's FP32 add and nan_to_num into scratch laid out as the built-in's tensors and calling the shipped fusedSamplingBody on it with the same parameters, Philox offsets and alignment; then it writes the draft token and scatters the distribution into draft_probs. The CUDA source is built into the head sampler's JIT library (ops/spec/_head_sampler/draft_path_sample.cuh). Tokens, distributions and draft_probs are the built-in sampled walk's bit for bit on the lattice. The candidates are torch.topk's over the full vocabulary, as on one rank; the built-in sampled path of a sharded head tops each shard first, which orders exactly tied logits differently. Rejection sampling verifies each draft against the distribution it was drawn from, so the output distribution is unchanged; TEP4 lists the path beside drafter_fc_shard rather than among the bitwise paths. Tests: test_modeling_v2_draft_path_sample.py, the op against dflash2_sample_candidate_paths with the fused sampler, bitwise over 1..129 requests, served / filtered / mixed sampling parameters and NaN / inf lattice rows; test_modeling_v2_draft_head_sampled.py, the worker step on emulated TP8 ranks against the built-in method on the gathered full-vocab logits, bitwise, and the fallbacks. Signed-off-by: zheyuf <[email protected]>
…eping into the verify fold verify_fold replaces the acceptance kernel by one launch that also writes the step's integer bookkeeping (the saved _seq_lens_cuda, the KV-length rewind and the kv_lens_cuda bump, the bonus token, the context and query positions, the drafter's input ids), which the later worker methods take instead of computing them: 18 launches less per step. It overrides only the greedy acceptance (_sample_and_accept_draft_tokens_base). A step that rejection-samples takes _sample_and_accept_draft_tokens_rejection, so every fold consumer ran the built-in bookkeeping on it. Fast path rejection_fold (on verify_fold): after the built-in rejection sampler and its forced-acceptance override, dflash_verify_fold runs in a new ACCEPTED_GIVEN mode that takes the sampler's accepted tokens and counts as given (no recount, no counter bump) and writes the same bookkeeping, which the same consumers then take. Integer results, bitwise the built-in chain. Tests: test_modeling_v2_dflash_verify_fold_given.py, the ACCEPTED_GIVEN fold against the built-in chain bitwise (1..64 requests, with and without the attention metadata's buffers, the counter untouched), and the worker folding a rejection-sampled step only under the fast path and on a step the fold takes. Signed-off-by: zheyuf <[email protected]>
…launch With a TRTLLM drafter the drafter's context K/V lives in pages, and the context-K/V fork's commit ran the worker's _commit_context: _advance_ctx_len (a gather, add and index_put, a whole-tensor clamp, the dummy slot's zero) and _drafter_context_lengths (the lengths, less the context base under TRTLLM_DFLASH_WINDOWED_CTX_ARENA; the allocation limit from the manager's block counts; the unified cache's allocation check, an _assert_async; a minimum) -- about fifteen launches on the decode critical path. The dense and windowed arenas already commit in one launch. Fast path paged_context_commit (on context_kv_fork): context_kv_commit_paged writes every element of _ctx_len once (the dummy slot 0, a batch slot min(old + n, max_ctx), any other min(old, max_ctx)) and zeroes the dummy's base, and computes each request's length from the value it wrote, so nothing is read after it is written. A length past its allocation under the check traps, which ends the CUDA context as the device assert does. Integer arithmetic, bitwise the built-in method. Tests: test_modeling_v2_context_kv_commit_paged.py, against DFlashWorker._commit_context bitwise (1..64 requests, with and without the allocation limit and the context base, int32 / int64 counts, dummy rows, lengths at max_ctx), the trap in a subprocess against the built-in's device assert, and the install's refusal of a worker class with its own commit methods. Signed-off-by: zheyuf <[email protected]>
zheyuf
force-pushed
the
zheyuf/dflash-trtllm-default-al-tests
branch
from
November 6, 2026 22:12
ad1eb8c to
d24271f
Compare
Collaborator
Author
|
/bot run --disable-fail-fast |
Collaborator
|
PR_Github #83168 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #83163 [ run ] completed with state |
Collaborator
|
PR_Github #83168 [ run ] completed with state |
zheyuf
marked this pull request as ready for review
November 7, 2026 01:58
zheyuf
requested review from
a team,
Wanli-Jiang,
WeiHaocheng and
litaotju
as code owners
November 7, 2026 01:58
zheyuf
requested review from
brnguyen2,
chienchunhung,
mikeiovine,
mzweilz,
niukuo,
reasonsolo and
zhenhuaw-me
and removed request for
a team,
Wanli-Jiang,
WeiHaocheng,
brnguyen2,
chienchunhung,
litaotju,
lowsfer,
mikeiovine,
mzweilz,
niukuo,
reasonsolo,
thorjohnsen and
zhenhuaw-me
November 7, 2026 01:59
5 tasks done
pcastonguay
added a commit
to pcastonguay/TensorRT-LLM
that referenced
this pull request
Nov 10, 2026
…ng down to one request GB300 lever for the sm_103__tep8 target, env-gated and off by default: - MUSESPARK_OPEN_DRAFTER_FUSED_PREP=1 runs the drafter context bookkeeping over the KV cache manager pages (draft page table decode, positions, per-layer K/V stores and the length commit) as a few Triton launches instead of ~50 small torch launches. MUSESPARK_OPEN_DRAFTER_FUSED_PREP_MIN_REQUESTS (default 1) sets the smallest batch that takes it. Any other layout keeps the built-in path. - Adds the paged context K/V commit kernel (NVIDIA#21535) next to the sm_103__tep copy. Tests: CPU switch / decline / geometry suite; GPU commit test. Signed-off-by: Patrice Castonguay <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Description
Muse Spark's DFlash drafter needs TRTLLM attention and rejection sampling (RS) to reach the SemiAnalysis golden acceptance length (4.05):
TRTLLM + RS used to make every decode step slower than VANILLA without RS. This PR removes that cost, makes cold-page KV compression work with the TRTLLM drafter, and adds acceptance-length tests. VANILLA still works.
[perf] DFlash: bound the paged context store by the host-side KV capacity[perf] Spec decoding: write context rows' one-hot draft probs without a host sync[test] Muse modeling_v2: DFlash2 acceptance-length tests on the golden protocol and under prefix reuse[feat] Cold-page KV cache compression with a DFlash drafter in the target's KV cache manager[perf] Muse Spark: soft-cap the head's logits in one kernel[rows, vocab], bit for bit.[perf] Spec decoding: zero the CUDA-graph padding rows of the rejection target logits in place[perf] DFlash: apply the drafter's logit multiplier and soft cap in one kernel[perf] Muse modeling_v2: stage the block-offset copy over a target/draft KV cache manager[perf] Muse modeling_v2: sample DFlash 2 drafts on the sharded draft head in one launch[perf] Muse modeling_v2: fold a rejection-sampled step's bookkeeping into the verify fold[perf] Muse modeling_v2: commit a paged drafter context in one launchTest Coverage
New unit tests, listed in
l0_gb300_musesparkunless noted. Every fused path is compared with the code it replaces, bit for bit.modules/test_logit_soft_cap.pyandmodeling/test_musespark_open_soft_cap.pyspeculative/test_rejection_buffers_guard.py(l0_h100)speculative/hw_agnostic/test_context_onehot_draft_probs.py,test_dflash_ctx_block_tables.py,test_dflash2_semantics.pykv_cache_compression/test_quantization_for_cold_page.py,executor/kv_cache/test_dflash_unified_kv_gate.py,test_kvcm2_integration.pytest_modeling_v2_staged_block_offsets.py,test_modeling_v2_draft_path_sample.py,test_modeling_v2_draft_head_sampled.py,test_modeling_v2_dflash_verify_fold_given.py,test_modeling_v2_context_kv_commit_paged.pyaccuracy/modeling_v2/test_musespark_open.py: the two acceptance-length tests. They are commented out in the list because the DFlash2 checkpoint is not in the CI model cache.Results on GB300 (sm103):
Performance on GB300
Every point of the GB300 Pareto (benchmark MR !164), AgentX 3600 s, with acceptance forced to the same 3.05 in both arms:
The two arms ran at the same time on neighbouring nodes. Changes are After vs Before. For decode step and TTFT, negative is better. Decode step is the median at the same batch size.
The decode step is faster at every point. The one exception is p11's largest batches (41-64 requests), where it is up to 1.6% slower.
Two points pay a cost that comes from the TRTLLM drafter itself, not from this PR:
Known issue, already on the base: a context server with the drafter and RS on fails its warmup at
max_seq_len1,048,576. The drafter's RoPE table is exactly that size (modeling_dflash.py_get_rope_cos_sin). The disaggregated runs above therefore use RS on the generation servers only.PR Checklist
🤖 Generated with Claude Code