Repository navigation
Fix server prompt cache reuse with speculative decoding - #2104
Closed
cassieliang6709 wants to merge 1 commit into
Closed
cassieliang6709 wants to merge 1 commit into
cassieliang6709 wants to merge 1 commit into
Conversation
LRUPromptCache trims a reused cache by len(key) - prefix, so it assumes the cache holds one entry per token in its key. After speculative decoding the last yielded token is never fed back, and the draft cache can lag the main cache, so the cache is shorter than the key. The next request that shares a prefix then gets a cache trimmed one token too far, and the model sees a prompt with a token missing. With Qwen3 this drops the token before "assistant", so the model answers as if a new user turn started and echoes the input. Before inserting the cache, trim every layer to the shortest cache and cut the key to the same length. Only the draft-model path changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Closing as a duplicate of #2083, which fixes the same bug and was opened earlier. It aligns the caches inside speculative_generate_step, so it also covers EOS and early-disconnect exits and callers outside the server. |
This was referenced Nov 25, 2026
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.
Symptom
--draft-model, sending the same request twice gives a correct answer the first time. The second time, the model echoes the input back, starting withuser\n.Cause
LRUPromptCache.fetch_nearest_cachereuses a cache, it trimslen(key) - prefixtokens. This assumes the cache has one entry per token in the key.assistant, so the model thinks a new user turn has started.Fix
server.py, before saving the cache, trim every layer to the length of the shortest layer, and cut the key to the same length.Tests
TestAlignCacheToTokens(2 tests).tests/test_server.pyandtests/test_prompt_cache.pypass.