Skip to content

[None][feat] Muse Spark: TRTLLM DFlash drafter with rejection sampling: decode-step fixes and cold-page compression - #21535

Merged
zheyuf merged 11 commits into
NVIDIA:feat/musespark-open-agentxfrom
zheyuf:zheyuf/dflash-trtllm-default-al-tests
Nov 7, 2026
Merged

zheyuf merged 11 commits into
NVIDIA:feat/musespark-open-agentxfrom
zheyuf:zheyuf/dflash-trtllm-default-al-tests

Conversation

@zheyuf

@zheyuf zheyuf commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Muse Spark's DFlash drafter needs TRTLLM attention and rejection sampling (RS) to reach the SemiAnalysis golden acceptance length (4.05):

  • With VANILLA attention, the drafter keeps its context K/V outside the KV cache manager. Prefix-cache hits and disaggregated transfers lose that context, so acceptance drops.
  • Without RS, acceptance is about 3.5.

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.

# Commit What it does
1 [perf] DFlash: bound the paged context store by the host-side KV capacity Removes a GPU-to-host sync on every context step.
2 [perf] Spec decoding: write context rows' one-hot draft probs without a host sync Removes two more host syncs per context step under RS.
3 [test] Muse modeling_v2: DFlash2 acceptance-length tests on the golden protocol and under prefix reuse Acceptance-length tests: golden 4.05 (floor 3.969), and no drop on a prefix hit.
4 [feat] Cold-page KV cache compression with a DFlash drafter in the target's KV cache manager Cold-page compression now works when the drafter shares the target's KV cache manager.
5 [perf] Muse Spark: soft-cap the head's logits in one kernel One kernel instead of five passes over [rows, vocab], bit for bit.
6 [perf] Spec decoding: zero the CUDA-graph padding rows of the rejection target logits in place Zeroes only the padding rows instead of copying all target logits.
7 [perf] DFlash: apply the drafter's logit multiplier and soft cap in one kernel Same one-kernel soft cap for the drafter, bit for bit.
8 [perf] Muse modeling_v2: stage the block-offset copy over a target/draft KV cache manager The fast block-table copy now works when the drafter shares the manager.
9 [perf] Muse modeling_v2: sample DFlash 2 drafts on the sharded draft head in one launch RS drafts in one launch instead of about 110.
10 [perf] Muse modeling_v2: fold a rejection-sampled step's bookkeeping into the verify fold RS steps get the same one-launch bookkeeping as greedy steps.
11 [perf] Muse modeling_v2: commit a paged drafter context in one launch One launch instead of about 15 to commit the drafter's context.

Test Coverage

New unit tests, listed in l0_gb300_musespark unless noted. Every fused path is compared with the code it replaces, bit for bit.

  • modules/test_logit_soft_cap.py and modeling/test_musespark_open_soft_cap.py
  • speculative/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.py
  • kv_cache_compression/test_quantization_for_cold_page.py, executor/kv_cache/test_dflash_unified_kv_gate.py, test_kvcm2_integration.py
  • Muse modeling_v2: test_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.py
  • accuracy/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):

Check Result
sm103 target test directory 906 / 906
New Muse tests 189 / 189
Acceptance length, golden protocol 4.091 (golden 4.05)
Acceptance length under prefix reuse -2.6% (limit -5%)

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:

  • Before: VANILLA drafter, no RS (the base).
  • After: this PR, TRTLLM drafter + RS.

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.

Point Decode step x (tok/s/user, p10) y (tok/s/GPU) TTFT p90
p01 agg TEP8, 1 user -3.1% +1.8% +0.5% -5%
p02 disagg, 4 TEP8 gens, batch 1 -2.2% +0.7% +0.8% -7%
p03 disagg, 5 TEP4 gens, batch 1 -2.2% +0.2% +0.3% -6%
p04 disagg, 6 gens, batch 2 -1.8% to -2.7% +1.8% -1.0% -7%
p05 agg TEP4, 14 users, batch 3 -1.6% to -3.7% +2.2% +1.5% -2%
p06 agg TEP4, 14 users, batch 4 -0.7% to -3.2% +1.8% +1.1% -4%
p07 disagg, 3 gens, batch 4 -2.0% to -3.1% +2.3% +0.9% -12%
p08 disagg, 1 TEP8 gen, batch 20 -1.7% to -3.6% +3.8% +1.6% -8%
p09 disagg, 3 ctx + 4 gens, batch 24 -0.1% to -5.3% +3.3% -4.5% +2%
p10 agg TEP4, 48 users -2.1% to -2.8% +1.1% to +1.9% +1.1% -6%
p11 agg TEP4, 72 users -2.8% to +1.6% +0.2% (two runs) -0.2% (two runs) +24% to +46%

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:

  • p09 (y -4.5%): in disaggregated serving the context servers also run the drafter, so each 8K-token prefill chunk takes about 50 ms longer. p09 is the only point limited by its context servers. We are profiling this.
  • p11 (TTFT p90 +24% to +46%): the drafter's K/V (5.4 GiB per GPU) shares the KV cache budget, so the cache holds about 5% fewer blocks. p11 runs right at the cache's limit, so requests wait longer to start. x and y are unchanged. Storing the drafter's K/V in FP8 and running RS on each GPU's vocabulary shard would win most of it back; both are follow-ups.

Known issue, already on the base: a context server with the drafter and RS on fails its warmup at max_seq_len 1,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

  • PR title and description follow the guidelines.
  • Tests are added and listed in CI test lists.
  • Rationale is in this description, not in code comments.

🤖 Generated with Claude Code

@zheyuf
zheyuf force-pushed the zheyuf/dflash-trtllm-default-al-tests branch from 03b61b5 to 2931086 Compare November 5, 2026 03:27
@zheyuf zheyuf changed the title [None][feat] DFlash: TRTLLM drafter attention by default wherever it runs, cold-page compression with a TRTLLM drafter, and acceptance-length tests [None][feat] Muse Spark: TRTLLM DFlash drafter with rejection sampling only, cold-page compression with it, and its decode-step fixes Nov 5, 2026
…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
zheyuf force-pushed the zheyuf/dflash-trtllm-default-al-tests branch from 806e378 to ad1eb8c Compare November 6, 2026 21:52
@zheyuf

zheyuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83163 [ run ] triggered by Bot. Commit: ad1eb8c Link to invocation

…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
zheyuf force-pushed the zheyuf/dflash-trtllm-default-al-tests branch from ad1eb8c to d24271f Compare November 6, 2026 22:12
@zheyuf

zheyuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83168 [ run ] triggered by Bot. Commit: d24271f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83163 [ run ] completed with state ABORTED. Commit: ad1eb8c

Link to invocation

@zheyuf zheyuf changed the title [None][feat] Muse Spark: TRTLLM DFlash drafter with rejection sampling only, cold-page compression with it, and its decode-step fixes [None][feat] Muse Spark: TRTLLM DFlash drafter with rejection sampling: decode-step fixes and cold-page compression Nov 7, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83168 [ run ] completed with state SUCCESS. Commit: d24271f
/LLM/main/L0_MergeRequest_PR pipeline #68717 completed with status: 'SUCCESS'

CI Report

Link to invocation

@zheyuf
zheyuf marked this pull request as ready for review November 7, 2026 01:58
@zheyuf
zheyuf merged commit aaba1de into NVIDIA:feat/musespark-open-agentx Nov 7, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants