llama : add position-relocatable KV range save/load#25133
Open
Anyesh wants to merge 1 commit into
Open
Conversation
Anyesh
marked this pull request as ready for review
June 29, 2026 21:11
Anyesh
force-pushed
the
anyesh/kv-block-primitives
branch
from
July 3, 2026 23:48
8e026b0 to
b23c0b7
Compare
Anyesh
force-pushed
the
anyesh/kv-block-primitives
branch
from
July 18, 2026 05:39
b23c0b7 to
8101749
Compare
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
Adds
llama_state_seq_get_range/llama_state_seq_set_range: serialize a contiguous KV range[p0, p1)of a sequence and restore it at a different position, re-anchoring K via the existing deferred RoPE shift (no forward pass on restore).get_data/set_dataonly restore a sequence at its original positions; there is no way to relocate a sub-range. This enables cache schemes that drop spans and later splice them back at a new offset without recompute. Works for plain, iSWA, and hybrid attention caches; no change to existing formats or public APIs.Additional information
range_readplaces the saved cells at their original positions, then appliespos_add(new_pos - original_pos)to queue the same K rotationseq_adduses.tests/test-state-seq-range.cpp(added to CTest) covers round-trip, partial restore, and positive/negative/offset relocation. Relocation cases assert the result is bit-identical to an in-placellama_memory_seq_addshift rather than a from-scratch decode: the K-shift is not bit-exact versus a fresh rope, so greedy tokens can differ on near-tied logits even when relocation is correct.Requirements