Archived
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:
1 parent
93389679e8
commit
e35052abfe
7 files changed
+70
-8
No files matched your search
@@ -56,6 +56,10 @@ struct IKVManager {
|
||||
/* A committed step: a WINDOW group gives back what no later query can read. A no-op for a
|
||||
* manager with no windowed group. See KVManager::trim_window. */
|
||||
virtual void trim_window(uint64_t seq, int64_t keep_from) { (void)seq; (void)keep_from; }
|
||||
/* The window snapshot of a prefix hit (KVManager::has_window_snapshot / seed_window). The
|
||||
* defaults are a manager with none: no hit on a windowed trunk is ever resumed. */
|
||||
virtual bool has_window_snapshot() const { return false; }
|
||||
virtual int seed_window(uint64_t seq, int64_t pos) { (void)seq; (void)pos; return -1; }
|
||||
|
||||
/* Adopt blocks a prefix-cache hit found. `n_tokens` must be a whole multiple of the group's
|
||||
* block size -- a partial block is never shared, because the next token written into it would
|
||||
@@ -294,6 +298,8 @@ struct KVBinding final : IKVManager {
|
||||
int ensure(uint64_t s, int64_t n) override { return m->ensure(s, n); }
|
||||
int ensure_from(uint64_t s, int64_t n, int64_t k) override { return m->ensure(s, n, k); }
|
||||
void trim_window(uint64_t s, int64_t k) override { m->trim_window(s, k); }
|
||||
bool has_window_snapshot() const override { return m->has_window_snapshot(); }
|
||||
int seed_window(uint64_t s, int64_t p) override { return m->seed_window(s, p); }
|
||||
int adopt(uint64_t s, int32_t g, const std::vector<int32_t>& b, int64_t n) override {
|
||||
return m->adopt(s, g, b, n);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user