Skip to content

server: ensure prompt caching for SWA models#21749

Open
shipped-it wants to merge 1 commit intoggml-org:masterfrom
shipped-it:master
Open

server: ensure prompt caching for SWA models#21749
shipped-it wants to merge 1 commit intoggml-org:masterfrom
shipped-it:master

Conversation

@shipped-it
Copy link
Copy Markdown

Overview

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.

Fixed 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)

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))

  1. I've read those issues and other PRs (to no avail):
  1. But I could not find a solution to my problem, so I traced the error message to tools/server/server-context.cpp
  2. Then found pos_min_thold that determines the minimum position that must be present in cache for restoration to work. It was always calculated as pos_next - n_swa, which for Gemma 4 means pos_next - 1024. I believe this is incorrect for swa_full, as with full-size cache, ANY cached position should be valid.
  3. There was also a condition checking if checkpoint restoration was needed, but it didn't account for swa_full. With swa_full, the cache is never pruned so checkpoint restoration is unnecessary.

Requirements

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)
@shipped-it shipped-it requested a review from a team as a code owner April 10, 2026 22:27
Copy link
Copy Markdown

@elektricM elektricM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, also fixed my issue on swa models on my amd card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache reuse is not supported for Gemma 4 models despite -fa enabled and --swa-full

2 participants