Repository navigation
Conversation
…fix loads and long-prompt re-save Let the mooncake-store KV connector serve models that mix sliding-window and full-attention layers, with a hidden-state drafter: - Save a window group's pages once per prompt, at its last chunk (the window's sinks and tail at the prompt end). Look up the longest full-attention hit, walk back up to swa_endpoint_rewind_tokens for a prompt end whose window is stored, and optionally fall back to an earlier one. kv_cache_layout carries each group's num_sink_tokens. - Load stored prefixes through V2 prefix reservations on loader threads, each with its own staging pool and stream, while the request waits outside the batch (TRTLLM_MOONCAKE_STORE_LOAD_THREADS, _SYNC_LOAD). - Under speculative decoding save only prompt blocks, and admit mooncake-store through the executor's connector/speculation gate. - Cap a context request's saves at its chunk's end, and save only the window pages the request still holds. - Optionally re-list a long prompt's full-attention blocks at its last chunk, refreshing the chain's head in the pool (TRTLLM_MOONCAKE_STORE_RESAVE_MIN_TOKENS). - Build lookup hashes and keys with one struct.pack per chunk and per-namespace key columns (byte-identical), and split long existence probes into concurrent chunks. - Queue window pages ahead of full-attention blocks, log lookup, save and load statistics, refuse enable_swa_scratch_reuse and a nonzero context_recompute_tail, and document the connector's window support and environment variables. Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Member
Author
|
/bot run |
Collaborator
|
PR_Github #81591 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #81591 [ run ] completed with state |
This branch has not been deployed
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
The Mooncake store connector (#19235, #19171) shares context KV through a Mooncake pool, but only for full-attention layouts, and it refuses speculative decoding. A model that mixes sliding-window (SWA) and full-attention layers, served with a hidden-state drafter, can't use it. On long multi-turn prompts, it also blocks the executor while a reused prefix loads.
This PR makes the connector work for such models:
swa_endpoint_rewind_tokens.TRTLLM_MOONCAKE_STORE_WINDOW_FALLBACK, on by default), it probes further back for an earlier prompt end with a complete window.kv_cache_layoutnow carries each group'snum_sink_tokens.validate_layoutaccepts window groups. Registration refuses a window layout without prefix-aware scheduling, which window loads need.validate_llm_argsrefuseskv_cache_config.enable_swa_scratch_reuseand a nonzerospeculative_config.context_recompute_tail. With either, the connector could save or load a window page it never verified.reserve_prefix/release_prefix_reservation).TRTLLM_MOONCAKE_STORE_LOAD_THREADSsets the thread count (default 2).TRTLLM_MOONCAKE_STORE_SYNC_LOAD=1restores synchronous loads.mooncake-store.TRTLLM_MOONCAKE_STORE_RESAVE_MIN_TOKENS, off by default). A prompt that computed at least that many tokens lists its full-attention blocks again at its last chunk. That refreshes the chain's head in the pool and rewrites blocks the pool evicted during a long prefill. Otherwise one evicted head block makes the whole stored chain unreachable, and the next turn re-prefills all of it.struct.packand slices it per block. Keys are built column-wise per namespace.TRTLLM_MOONCAKE_STORE_PROBE_CHUNK, default 4096 keys).TRTLLM_MOONCAKE_STORE_WINDOW_FIRST, on by default). Window pages are queued ahead of a prompt's full-attention blocks, so a stored chain's window lands first.The changes are in one PR because they are interdependent: SWA lookups need the reservation path to load asynchronously, and the save fixes and re-save are all on the SWA save path.
Impact
scheduler_config.enable_prefix_aware_schedulingis on.Test Coverage
tests/unittest/_torch/executor/test_mooncake_store_connector.py: window saves, rewind and fallback lookups, window-first ordering, reservation loads (async and sync), loader threads, chunked probes, the chunk-end save cap, re-save, hash-chain and key equivalence with the per-token encoding, and the speculative-decoding prompt-only saves.test_mooncake_store_{cli,common,settings,real_pool}.py,test_kv_cache_layout.py,test_kv_connector_reservations.pyandtest_kv_connector_v2_prefix.py.PR Checklist