[Hybrid KV Cache][Kimi K3] Retain two committed decode checkpoints - #50506
Closed
qianlihuang wants to merge 1 commit into
Closed
qianlihuang wants to merge 1 commit into
qianlihuang wants to merge 1 commit into
Conversation
Under sparse retention, keep at most two additional committed decode checkpoints for Mamba align mode. Validate the opt-in configuration, exclude rejected speculative tokens, and withdraw older local hashes without freeing referenced blocks. Assisted-by: OpenAI Codex Signed-off-by: Yiliu Dong <91178480+qianlihuang@users.noreply.github.com>
qianlihuang
force-pushed
the
agent/kimi-k3-response-end
branch
from
July 31, 2026 03:43
b0430a6 to
23a3f6d
Compare
4 tasks
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.
Purpose
This is an extraction from #49574 for the Kimi K3 preserved-thinking case.
With sparse hybrid-cache retention enabled, this PR lets Mamba
aligngroups admit scheduler-aligned states from the committed decode prefix. It keeps at most two additional checkpoints per request in the local prefix-cache hashmap; when a third additional checkpoint is materialized, the oldest local hash is withdrawn without freeing a block that is still referenced.
Periodic checkpoints selected by a positive retention interval remain governed by that interval. Copies already exported to an external KV store remain governed by that store's eviction policy.
Enable the policy with prefix caching and Mamba align mode:
Reuse examples
Kimi K3 preserves and re-renders complete assistant thinking/tool-call history (model card, reference encoding). An exact next-turn request can therefore reuse tokens decoded by the previous request:
... assistant(reasoning_content + content) <|end_of_msg|> | user ...can hit through the latest aligned assistant prefix instead of stopping at the earlier prompt boundary.... assistant(reasoning_content + tool_calls) <|end_of_msg|> | tool ...can hit through the latest aligned assistant tool-call prefix before the tool input/result.The final non-aligned tail is still recomputed. Exact block hashes remain the correctness gate, so modified rendering or dropped thinking safely misses. Rejected speculative tokens are excluded by the existing committed-token cap, and a checkpoint is recorded only when the corresponding Mamba state was actually materialized.
In a P/D deployment, these admitted states are eligible for the existing Decode-side export/offload path and can be matched by Prefill workers using the same backing pool.
Why not exact response-end retention
Keeping exactly one semantic response-end state involves chat renderer/parser and request protocol.
Test plan
Test results
and environment-default validation.
(4, 4)tokens; enabled locally retains the latest two decode points andhits
(16, 20)tokens for an earlier branch and the full assistant replay.SWA-only configurations.
materialized tokens.
than model computation, tokenization, logits, or output accuracy.
Connector-specific Kimi K3 P/D hit-rate and memory validation remains
deployment follow-up work.
AI assistance
AI was used to analyze the cache/offload paths, implement the change, and run the checks above.