Repository navigation
kv-cache : iSWA seq_rm returns false when the SWA cache cannot satisfy the cut - #31483
Open
kukirin-ui wants to merge 1 commit into
Open
kukirin-ui wants to merge 1 commit into
kukirin-ui wants to merge 1 commit into
Conversation
…y the cut With swa_full = false the SWA cache reuses the cells of masked positions. A tail removal at p0 needs the positions [p0 - n_swa + 1, p0) to still be present, otherwise the next decode silently runs without them. Return false in that case (before touching either cache), as documented in llama.h. Fixes ggml-org#31457
|
Hi @kukirin-ui, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
1 task done
|
Tested it against my repro at every cut point and it refuses exactly the broken ones. Thanks |
Contributor
Author
|
:) |
kukirin-ui
marked this pull request as draft
November 14, 2026 15:02
kukirin-ui
marked this pull request as ready for review
November 15, 2026 06:48
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.
Overview
Fixes #31457
With swa_full=false,
llama_kv_cache_iswa::seq_rmreturned true for a tail cut even when the SWA cache had already overwritten the rows needed after the cut. The caller then thinks the cache is still valid and keeps going with broken SWA state.Now, before touching either cache, seq_rm checks if the SWA cache still has positions [p0 - n_swa + 1, p0). If not, it returns false and leaves the sequence untouched, so the caller can reprocess. The check is skipped when swa_full=true, seq_id < 0 or p0 <= 0. This is the same threshold the server already uses (pos_min_thold), so the server path does not change.
Additional information
Added tests/test-memory-iswa-seq-rm.cpp. It uses the random gemma3 model from test-llama-archs (generate-models fixture). It fails on master (seq_rm returns true) and passes with the fix. test-llama-context still passes for all 139 models.
Related: #29480 touches the same file (seq_pos_max) but does not overlap, #28007 is a server side fallback and works together with this.
Requirements