server: ensure prompt caching for SWA models#21749
Open
shipped-it wants to merge 1 commit intoggml-org:masterfrom
Open
server: ensure prompt caching for SWA models#21749shipped-it wants to merge 1 commit intoggml-org:masterfrom
shipped-it wants to merge 1 commit intoggml-org:masterfrom
Conversation
When using --swa-full with Gemma 4 and other SWA models, the server can sometimes incorrectly force full prompt re-processing on every request, even though --swa-full allocates a full-size SWA cache where tokens are not pruned. Fix by: - Setting pos_min_thold = 0 when swa_full is enabled (any cached position is useful) - Skipping checkpoint restoration logic when swa_full is enabled (unnecessary since cache is full-size)
elektricM
approved these changes
Apr 11, 2026
elektricM
left a comment
There was a problem hiding this comment.
Looks good to me, also fixed my issue on swa models on my amd card.
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.
Overview
When using
--swa-fullwith Gemma 4 and other SWA models, the server can sometimes incorrectly force full prompt re-processing on every request, even though--swa-fullallocates a full-size SWA cache where tokens are not pruned.Fixed by:
In short, this makes inference faster for SWA models when using prompt caching.
Closes #21468
Additional information
I was trying to debug a prompt caching issue: slot update_slots: id 0 | task 76 | forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory, see #13194 (comment))
tools/server/server-context.cpppos_next - n_swa, which for Gemma 4 meanspos_next - 1024. I believe this is incorrect for swa_full, as with full-size cache, ANY cached position should be valid.Requirements