Skip to content

[None][fix] Give the standalone DSpark drafter its context on KV-cache prefix hits - #21086

Closed
zheyuf wants to merge 1 commit into
NVIDIA:feat/minimax-m3.1-flashfrom
zheyuf:zheyuf/m31-dspark-reuse-ctx-pr
Closed

zheyuf wants to merge 1 commit into
NVIDIA:feat/minimax-m3.1-flashfrom
zheyuf:zheyuf/m31-dspark-reuse-ctx-pr

Conversation

@zheyuf

@zheyuf zheyuf commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

With KV-cache block reuse on (the default), a standalone DSpark drafter loses its context on every prefix-cache hit. This PR gives it that context back.

Why: the drafter builds its context K/V from target hidden states. A cache hit skips the target forward over the reused prefix, and the draft KV pool is not shared with the target's prefix cache. So a cache-hit request drafts from only the uncached tail of its prompt. DSpark also had no context_recompute_tail, the DFlash mitigation the KV cache managers already support.

A second effect makes it worse. The draft pool uses 64-token pages, and the drafter can hide a reused prefix only in whole pages. A partial hit that ends inside a page leaves up to 63 stored tail tokens unread. On a repeated prompt the drafter then starts from an empty context. Together, the two effects cut AL by ~19-21% over the first 256 tokens of a greedy cache hit.

Changes:

  • DSparkDecodingConfig.context_recompute_tail (the existing DFlash knob). None, the default, resolves from the drafter's config.json to its attention window when every layer is windowed: 4096 for MiniMax-M3.1, read through its VL-shaped config. Otherwise it resolves to 0. 0 disables the recompute; -1 re-prefills the whole prompt on a hit. The embedded DeepSeek-V4 drafter keeps 0.
  • When the drafter reads an unpaired draft pool, it has the target KVCacheManagerV2 end reuse claims on draft-page boundaries (align_reuse_claims_to_draft_pages). The target recomputes at most 63 extra prompt tokens per partial hit.
  • The drafter logs how hits are served. It warns when reuse starves it and says why: the tail is 0, or the block-reuse policy disabled it. The managers already disable the tail unless block_reuse_config.policy is all_reusable.

How to enable: nothing to set; the tail resolves automatically. A deployment that prefers TTFT on short repeated prompts can set context_recompute_tail: 0, which keeps the page alignment.

Results on GB300 TP4: MiniMax-M3.1-Flash + DSpark, K7. The sets are 80 SPEED-Bench coding prompts (T=1, top_p 0.95, c64), 70 two-turn chats and 16 prompts of 8-14K tokens. Each pass with block reuse on is compared with the same requests on a reuse-off server of the same build and settings. Pairs are matched by prompt and seed, with a bootstrap 95% CI over prompts. Measured on efa53ad:

pass, AL with reuse on vs off base, no fix (greedy drafting) this PR + #21085 (golden sampling)
same 80 prompts again (warm) -8.2% [-12.6, -4.0] -0.4% [-2.7, +1.8]
turn 2 of a two-turn chat, first 512 tokens -3.8% [-8.2, +0.9] +1.4% [-2.7, +5.7]
turn 2, full answers -2.8% [-4.7, -1.0] +0.8% [-1.3, +2.7]
8-14K-token prompts again -3.5% [-7.4, -0.2] +1.9% [-3.2, +7.9]
first pass over the 80 prompts -2.2% [-4.8, +0.6] -0.7% [-3.2, +1.8]
  • Same server, warm pass vs first pass: -7.1% on the base, +0.1% with this PR.
  • With this PR the 8-14K prompts still take 56% of their tokens from the cache; only the last ~4.2K tokens are recomputed. Prompts shorter than that are re-prefilled in full.
  • Before the rebase (greedy drafting, 2-3 servers pooled), the warm loss went from -5.8% to +0.6%. Under greedy decoding on one server, a short-prompt cache hit gave the same text and acceptance as the cold request (24/24).
  • Cost, measured before the rebase:
    • Prompts shorter than ~4.2K tokens are re-prefilled in full on a hit, so TTFT equals no reuse (+1 to +13 ms vs a plain hit).
    • Hits on 8-14K-token prompts recompute ~4.2K tokens: +12 ms TTFT on the TP4 test config and +51 ms in a 1M-MSL production recipe. That recipe keeps about half of the TTFT that reuse saves.
  • With policy: per_conversation the tail stays disabled and only the page alignment acts: warm -4.9% becomes -3.5%.
  • Also checked on other in-flight M3.1 trees: this PR, [None][feat] DSpark: ancestral draft sampling and block verification for rejection sampling #21085 and efa53ad were merged locally into [None][feat] MiniMax-M3.1 NVFP4 context (prefill) path on Rubin (SM107) #21039 + [None][feat] Add Rubin (sm_107) MiniMax-M3.1 low-latency decode targets #21038 and into brb-nv user/brb/m3.1-flash-gb300-initial, each built from source. With block reuse on, K7 golden sampling gives 4.015 and 4.009, against 4.033 and 4.068 with reuse off.

Test Coverage

  • New tests/unittest/_torch/speculative/hw_agnostic/test_dspark_recompute_tail.py:
    • Window resolution. The shipped M3.1 drafter config gives 4096, cross-checked against the runtime's per-layer windows.
    • Tail resolution: default, explicit values, unwindowed and embedded drafters, TorchLlmArgs validation.
    • The prefix-reuse hook and its warning.
  • New tests/unittest/_torch/executor/kv_cache/test_draft_page_aligned_claims.py:
    • The claim-alignment logic and the cases that skip it.
    • A real KVCacheManagerV2 on GPU: partial-reuse claims with and without the tail.
  • Unit tests on this branch, GB300 (the base's release image + this branch's Python):
    • The two new files plus test_spec_recompute_tail.py, test_kv_connector_v2_prefix.py, test_minimax_dspark_draft.py and test_kv_cache_v2_scheduler.py: 468 passed.
    • On GPU: the recompute, deferred-commit, windowed and partial-reuse cases of test_kvcm2_integration.py, plus the new claims test: 35 passed.
    • DFlash / DSpark worker regression: 161 passed. DSpark / DFlash cases of test_llm_args.py: 29 passed.
    • test_dspark_noncausal_window.py (from the base): 62 passed. api_stability: 38 passed.
  • No golden-manifest change: speculative_config.context_recompute_tail is already in the manifest (from DFlash).

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

🤖 Generated with Claude Code

…e prefix hits

A standalone DSpark drafter builds its context K/V from target hidden states
that a prefix-cache hit never produces, and its draft pool is not shared with
the target's prefix cache, so a cache-hit request drafted from only the
uncached tail of its prompt.

- DSparkDecodingConfig gains context_recompute_tail (the DFlash knob the V1/V2
  KV cache managers already honor). None, the default, resolves from the
  drafter's config.json to its attention window when every layer is windowed
  (4096 for MiniMax-M3.1, read through the VL-shaped config the way the
  drafter is built), else 0. A config without a drafter checkpoint (the
  embedded DeepSeek-V4 drafter) resolves to 0 at construction.
- On an unpaired draft pool the drafter hides the reused prefix from its reads
  only in whole pages, so a hit ending inside a page (partial reuse) left up to
  page-1 stored tail tokens unread. The drafter now has the target manager end
  its reuse claims on draft page boundaries
  (KVCacheManagerV2.align_reuse_claims_to_draft_pages); the target recomputes
  the rest of that page.
- The drafter logs how hits are served and warns when block reuse starves it,
  and why (tail 0, or a block-reuse policy that disabled it).

Signed-off-by: Zheyu Fu <[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.

1 participant