Archived
kv tiers: a restore makes room the way pressure does, and a chain the pool cannot hold stops at a snapshot
A restore reserved only from the free list. The reserve's trim leaves a quarter of the pool free
after every publish, so a returning conversation larger than that came back as far as the free
list reached, and the lookup stopped at the first block still on the host. On GLM-5.3-Flash at
eight ranks, two conversations of 314K tokens in a 446,832-token pool: the second turn of the
first brought back exactly the 27,930 free blocks, hit 111,772 tokens, and on its hybrid state
resumed at the snapshot at 1,024, since geometric backoff keeps nothing between 1,024 and 131,072.
Its prefill took 84 s instead of under one.
PCBinding::restore_plan now makes room before the engine plans the restore, the same way
PCBinding::evict does for an admission: PrefixCache::trim_for drops entries whose host copy has
landed, the engine lands pending copies (flush_fn), and it drops again. It never erases one,
spares the restoring chain itself and every chain a waiting request holds, and like trim never
touches one a running sequence reads. The free quarter may go; the reserve's trim after the next
publish frees it again. One block table serves every rank, so the room rank 0's cache makes is
room on every rank, as with evict.
When the pool still cannot hold the chain, PrefixCache::restorable_from cuts it at the deepest
valid snapshot the shorter prefix reaches, so no block comes back past the point the hit resumes
from; without recurrent state it cuts where the room ends. TierExec::issue_restore keeps its own
cut as the backstop.
Both cuts are counted: radiance:prefix_restore_cuts_total for restores the pool could not hold
whole (/sessions moved.restore_cuts), and radiance:prefix_hit_cuts_total{reason="resumed_below"}
for admissions that resumed more than one checkpoint interval below their attention hit, which
hit_cut_tokens alone did not tell apart from many small tails (/stats and /sessions hit_cuts).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7d392b0400
commit
4be0a34791
16 files changed
+205
-39
No files matched your search
@@ -170,6 +170,8 @@ struct IPrefixCache {
|
||||
virtual CkptCounts ckpt_counts() const { return {}; }
|
||||
/* Entries expired by --prefix-cache-ttl; not counted as evictions. */
|
||||
virtual int64_t expired() const { return 0; }
|
||||
/* Restores the pool could not hold whole (PrefixCache::Stats::restore_cuts). */
|
||||
virtual int64_t restore_cuts() const { return 0; }
|
||||
virtual int64_t ckpt_expired() const { return 0; }
|
||||
|
||||
/* Tokens of context held only by the cache right now. Blocks a running sequence also reads
|
||||
@@ -346,6 +348,21 @@ struct PCBinding final : IPrefixCache {
|
||||
void restore(const Request& r) override {
|
||||
if (restore_fn) restore_fn(r);
|
||||
}
|
||||
/* The entries restore_fn brings back, in chain order: the whole chain if the pool can be made
|
||||
* to hold it, otherwise cut (PrefixCache::restorable_from). Room is made as evict() makes it,
|
||||
* dropping entries with a landed host copy, then landing pending copies and dropping those, but
|
||||
* never erasing one: a restore is worth no lost conversation. The pool's free quarter can go
|
||||
* to it; the reserve's trim after the next publish frees it again. */
|
||||
std::vector<BlockHash> restore_plan(const Request& r, uint64_t salt) {
|
||||
media_keys(r, &mm_, salt);
|
||||
std::vector<BlockHash> want = m->restorable_from(r.prompt, mm_);
|
||||
const int64_t need = (int64_t)want.size() - m->restore_room();
|
||||
if (need <= 0) return want;
|
||||
const int64_t k = m->trim_for(r.prompt, mm_, need);
|
||||
if (k < need && flush_fn && flush_fn()) (void)m->trim_for(r.prompt, mm_, need - k);
|
||||
/* Landing copies may have moved records; take the chain again against the room made. */
|
||||
return m->restorable_from(r.prompt, mm_, m->restore_room());
|
||||
}
|
||||
void begin_step() override { m->begin_step(); }
|
||||
void hold(const Request& r) override {
|
||||
media_keys(r, &mm_, salt_id);
|
||||
@@ -405,6 +422,7 @@ struct PCBinding final : IPrefixCache {
|
||||
return { st.ckpt_retired, st.ckpt_lru, st.ckpt_refused };
|
||||
}
|
||||
int64_t expired() const override { return m->stats().expired; }
|
||||
int64_t restore_cuts() const override { return m->stats().restore_cuts; }
|
||||
int64_t ckpt_expired() const override { return m->stats().ckpt_expired; }
|
||||
int64_t held_tokens() const override { return m->unshared_tokens(); }
|
||||
|
||||
|
||||
@@ -94,11 +94,17 @@ struct SchedMetrics {
|
||||
int64_t prefix_expired = 0, prefix_ckpt_expired = 0; /* --prefix-cache-ttl */
|
||||
/* Admissions whose attention hit was cut to nothing: no snapshot at or below it (recurrent
|
||||
* state or a window snapshot), a windowed trunk group no window snapshot covers, or blocks
|
||||
* that could not be adopted. `hit_cut_tokens` is the checkpoint shortfall: prompt tokens the
|
||||
* attention cache held and the admission computed again, because the hit resumed at a
|
||||
* snapshot below it or was cut to nothing. */
|
||||
* that could not be adopted. `hit_cut_resumed_below` counts those that resumed at a
|
||||
* snapshot more than one checkpoint interval below the hit: the retention ladder had
|
||||
* nothing nearer, or the restore brought back only part of the chain. `hit_cut_tokens` is
|
||||
* the checkpoint shortfall: prompt tokens the attention cache held and the admission
|
||||
* computed again, because the hit resumed at a snapshot below it or was cut to nothing. */
|
||||
int64_t hit_cut_no_snapshot = 0, hit_cut_window = 0, hit_cut_adopt = 0;
|
||||
int64_t hit_cut_resumed_below = 0;
|
||||
int64_t hit_cut_tokens = 0;
|
||||
/* Restores from the host tier the pool could not hold whole, even after giving up the VRAM
|
||||
* copies of other conversations (PrefixCache::Stats::restore_cuts). */
|
||||
int64_t prefix_restore_cuts = 0;
|
||||
/* Tokens of context held only by the cache, i.e. what eviction would free. Excludes blocks
|
||||
* shared with a running sequence. Same token axis as the paged groups, so comparable with
|
||||
* kv_tokens_used. */
|
||||
|
||||
@@ -973,6 +973,11 @@ int Scheduler::admit_one(SchedReq& s, int64_t budget, int64_t reserve) {
|
||||
RAD_DEBUG("admit %llu: prefix hit of %lld tokens reuses nothing -- no snapshot at or "
|
||||
"below it", (unsigned long long)r.id, (long long)h.n_attn_tokens);
|
||||
} else if (reuse < h.n_attn_tokens) {
|
||||
/* Within an interval of the hit is the ordinary case: a turn's tail past its last
|
||||
* checkpoint. Further down, the snapshots in between are gone, or the attention
|
||||
* blocks reach past what the tiers could restore of the chain. */
|
||||
if (geo_.checkpoints() && h.n_attn_tokens - reuse > geo_.checkpoint_interval)
|
||||
s.hit_cut = SchedReq::HitCut::ResumedBelow;
|
||||
RAD_DEBUG("admit %llu: prefix hit of %lld tokens resumes at the snapshot at %lld",
|
||||
(unsigned long long)r.id, (long long)h.n_attn_tokens, (long long)reuse);
|
||||
}
|
||||
@@ -1092,6 +1097,7 @@ int Scheduler::admit_one(SchedReq& s, int64_t budget, int64_t reserve) {
|
||||
case SchedReq::HitCut::NoSnapshot: ++m_.hit_cut_no_snapshot; break;
|
||||
case SchedReq::HitCut::Window: ++m_.hit_cut_window; break;
|
||||
case SchedReq::HitCut::Adopt: ++m_.hit_cut_adopt; break;
|
||||
case SchedReq::HitCut::ResumedBelow: ++m_.hit_cut_resumed_below; break;
|
||||
case SchedReq::HitCut::None: break;
|
||||
}
|
||||
}
|
||||
@@ -2625,6 +2631,7 @@ SchedMetrics Scheduler::metrics_locked() const {
|
||||
m.prefix_ckpt_refused = cc.refused;
|
||||
m.prefix_expired = pc_->expired();
|
||||
m.prefix_ckpt_expired = pc_->ckpt_expired();
|
||||
m.prefix_restore_cuts = pc_->restore_cuts();
|
||||
m.prefix_held_tokens = pc_->held_tokens(); }
|
||||
m.attn_hit_rate = m.prompt_tokens
|
||||
? (float)((double)m.attn_cached_tokens / (double)m.prompt_tokens) : 0.0f;
|
||||
|
||||
@@ -107,8 +107,9 @@ struct SchedReq {
|
||||
* fit would inflate the prompt and hit totals. */
|
||||
int32_t hit_attn = 0;
|
||||
bool hit_owed = false;
|
||||
/* Why that hit was cut to nothing, for the counters (SchedMetrics::hit_cut_*). */
|
||||
enum class HitCut : uint8_t { None, NoSnapshot, Window, Adopt };
|
||||
/* Why that hit was cut, for the counters (SchedMetrics::hit_cut_*): to nothing, or to a
|
||||
* snapshot more than an interval below it. */
|
||||
enum class HitCut : uint8_t { None, NoSnapshot, Window, Adopt, ResumedBelow };
|
||||
HitCut hit_cut = HitCut::None;
|
||||
|
||||
/* The whole sequence is prompt ++ output; n_computed indexes into it. */
|
||||
|
||||
Reference in new issue
Block a user