sched: a prefix hit on a sliding-window model resumes from a snapshot of the window behind it

The prefix cache cannot index a windowed group, so every hit on a windowed
trunk re-prefilled the whole prompt (73620ef). Gemma 4 31B (50 of 60 layers
windowed at 1024) paid that on every chat and agent turn: 17-48 s to the
first token at 25-49k tokens.

A model with a window and no linear state now takes one checkpoint per
prompt, a block short of its end -- the next turn re-renders the last few
tokens -- if the prompt is --checkpoint-interval tokens or longer, and does
not split chunks at the interval. The prefix cache treats the window like
linear state: a hit is reusable at a checkpoint only. admit_one adopts the
full-attention blocks as before, seeds the windowed groups at the window's
floor, and the entry's restore fills them from the slot; anything else
re-prefills as before. A model with both linear state and a window keeps
refusing the hit.

Measured on Gemma 4 31B, TP 2, agent transcripts: a follow-up turn's first
token in 0.8-3.4 s instead of 17-48 s; greedy output byte-identical to a
cold prefill with the same chunk boundaries (32 turns, chains five hits
deep, thinking on and off).
This commit is contained in:
keptn42 committed 2026-10-12 09:04:43 +00:00
1 parent 93389679e8
commit e35052abfe
7 files changed
+70 -8

No files matched your search

+1
View File
@@ -226,6 +226,7 @@ private:
/* Scratch for the checkpoint copies: the state slots of one sequence, reused so the step path
* does not allocate. See state_slots_of. */
std::vector<int32_t> ckpt_slots_;
std::vector<int32_t> ckpt_win_; /* KVManager::window_rows, same reuse */
bool state_slots_of(uint64_t seq, std::vector<int32_t>* out) const;
int load_vocab();