Skip to content

kv-cache: Fix state restore fragmented cache - #17982

Merged
ggerganov merged 6 commits into
ggml-org:masterfrom
ssweens:fix-state-restore-fragmented-cache
Dec 15, 2025
Merged

ggerganov merged 6 commits into
ggml-org:masterfrom
ssweens:fix-state-restore-fragmented-cache

Conversation

@ssweens

@ssweens ssweens commented Dec 13, 2025

Copy link
Copy Markdown
Contributor

Fix #17527

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.
@ssweens
ssweens requested a review from ggerganov as a code owner December 13, 2025 01:27
@ssweens

ssweens commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

PS - aimed to implement the direction given by @ggerganov (#17527 (comment))

@ggerganov

Copy link
Copy Markdown
Member

Looking good - will do some testing to confirm 👍

Comment thread src/llama-kv-cache.h Resolved
@ggerganov

ggerganov commented Dec 15, 2025 •

Copy link
Copy Markdown
Member

I updated the test to do a proper verification:

  • It requires kv_unified == true
  • It interleaves the sequences to create large fragmentation
  • Uses total context size of 256 tokens and 3 sequences with 70 tokens each

@ssweens After you address the comments, we can merge.

Comment thread src/llama-kv-cache.h Resolved
@ssweens

ssweens commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @ggerganov. Comments addressed and committed.

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. This is a good improvement.

@ggerganov
ggerganov merged commit 4529c66 into ggml-org:master Dec 15, 2025
@ssweens

ssweens commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

Happy to help where/when I can. Hat tip to you and team on the great project.

blime4 referenced this pull request in blime4/llama.cpp Feb 5, 2026
* kv-cache : fix state restore with fragmented cache (#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* kv-cache : fix state restore with fragmented cache (ggml-org#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* kv-cache : fix state restore with fragmented cache (ggml-org#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* kv-cache : fix state restore with fragmented cache (ggml-org#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
MrLordCat referenced this pull request in MrLordCat/llama.cpp-rdna-lab Jul 16, 2026
* kv-cache : fix state restore with fragmented cache (#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
* kv-cache : fix state restore with fragmented cache (ggml-org#17527)

Change find_slot to allow non-contiguous allocation during state restore. Fixes 'failed to find available cells in kv cache' error when restoring state to fragmented cache.

* tests : update logic

* cleanup: tightened state_read_meta sig, added is_contiguous case

* fix: state_read_meta arg reorder loose ends

---------

Co-authored-by: Georgi Gerganov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: failed to restore kv cache on gpt-oss:120b with parallel processing

2 participants