Archived
radiance 1.11.0
New models: - GLM-5.3-Flash reads pictures: its vision tower and processor (--image-tokens sets the budget), with decode kernels for a few rows and the DSA indexer split over the ranks - Sage-A1.5 (fp8 and MXFP4) with its vision tower and a DFlash2 drafter - Unlimited-OCR (bf16) - Gemma 4 31B with z-lab's DFlash and RedHatAI's DFlash2 drafters; at four cards its all-reduces are fused with the junctions, overlapped with the compute and sent compressed - Ornith-1.5-35B-A3B w4a8 compose files Speed: - Block drafters (DFlash, DFlash2) accept their drafts on the card, and the next step is issued ahead - The four-rank all-reduce is faster for every --tp 4 model - qwen35_w8a8: the norms and SiLU write the int8 linears' operands directly - --attn-prefill-fp8 off|qk|pv|both: fp8 QK and PV legs for the h256 prefill attention (about +20% prefill on a 221K-token prompt for the 27B MXFP4 at TP2); lossy, off by default Features: - Control vectors: --control-vector off|on|disabled (disabled by default), a per-request switch, and the published Qwen3.8-Flash-Next refusal-direction vector (its license is in NOTICE) - Krea 2: the `rebalance` request field, as ComfyUI's ConditioningKrea2Rebalance - Cards with a small PCI BAR run, with kernel arguments kept in host memory - Dashboard: live acceptance figures; statsdump rotates its file at a size cap - KV caches every rank holds whole (GLM-5.3's latent and index caches) take one host-tier slot Fixes: - Long conversations taking turns no longer fall back to an early snapshot: a host-tier restore makes room as memory pressure does and waits a step for the previous turn's release (two conversations of 142K and 147K tokens sent back to back: 31.3 s per turn before, 2.8 s now) - Kernels before Linux 6.16 (amdgpu below 3.64) no longer hang at startup: virtual memory management is turned off there, with a warning - Gemma 4 dense scales its token embeddings as Hugging Face does (bf16), which changes its output - The four-rank all-reduce fences prefill-sized messages, for a rare divergence after a fresh start - GLM-5.3: every refusal names the setting and the reason; its template keeps string content - Several pictures in one request no longer refuse processors that take one image at a time Changes: Plugin ABI 26: out-of-tree plugins must be rebuilt. The environment switches the PRs added are fixed rules or flags now (R4D_ATTN_FP8 is --attn-prefill-fp8).
This commit is contained in:
commit
9eaf10da6e
210 files changed
+14363
-2138
No files matched your search
+261
-16
@@ -2,6 +2,7 @@
|
||||
#include "mem/kv.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
namespace rad {
|
||||
@@ -76,6 +77,7 @@ static const char* kv_kind_name(int k) {
|
||||
case RAD_KV_WINDOW: return "window";
|
||||
case RAD_KV_LINEAR: return "linear";
|
||||
case RAD_KV_CONV: return "conv";
|
||||
case RAD_KV_RING: return "ring";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
@@ -126,7 +128,10 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
KVGroupPlan p;
|
||||
p.index = (int32_t)i;
|
||||
p.name = g.name.empty() ? fmt("kv%zu", i) : g.name;
|
||||
p.kind = g.decl.kind;
|
||||
/* R-SWA: RAD_KV_RING is a window group whose floor is per sequence (declare_runtime_window
|
||||
* / SeqWindow), so it plans as a RAD_KV_WINDOW group with `runtime_win` set below. No
|
||||
* other plan-path code has to know the kind. */
|
||||
p.kind = g.decl.kind == RAD_KV_RING ? RAD_KV_WINDOW : g.decl.kind;
|
||||
p.n_layers = (int64_t)g.layers.size();
|
||||
|
||||
if (p.n_layers <= 0) {
|
||||
@@ -161,7 +166,9 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
}
|
||||
if (p.kind == RAD_KV_WINDOW) {
|
||||
if (g.decl.window <= 0) {
|
||||
RAD_ERR("KV group '%s': RAD_KV_WINDOW with window 0", p.name.c_str());
|
||||
RAD_ERR("KV group '%s': %s with window 0", p.name.c_str(),
|
||||
g.decl.kind == RAD_KV_RING ? "RAD_KV_RING (the ring's W)"
|
||||
: "RAD_KV_WINDOW");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
/* +1 because a window that is not block-aligned straddles one extra block. */
|
||||
@@ -233,6 +240,28 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
}
|
||||
bundling_ = compare_bundling(bundles);
|
||||
|
||||
/* R-SWA: a declared runtime window turns the group's plan over to per-sequence windows (see
|
||||
* declare_runtime_window). Applied after every declaration above, so a fixed-window group's
|
||||
* plan is exactly what it was. */
|
||||
for (auto& p : plans_) apply_runtime_window(p);
|
||||
/* A RAD_KV_RING group carries a runtime window by its kind, whether or not the caller had a
|
||||
* manager to declare it on first (the engine's sizing probes declare it, but plan_groups must
|
||||
* not depend on that). `window` is the ring's W. */
|
||||
for (size_t i = 1; i < plans_.size(); ++i) {
|
||||
KVGroupPlan& p = plans_[i];
|
||||
if (groups[i].decl.kind != RAD_KV_RING || p.runtime_win) continue;
|
||||
p.runtime_win = true;
|
||||
p.runtime_tokens = groups[i].decl.window;
|
||||
p.win_snap = false;
|
||||
}
|
||||
for (const auto& [g, w] : runtime_decl_) {
|
||||
if (g < 0 || g >= (int32_t)plans_.size() || !plans_[(size_t)g].runtime_win) {
|
||||
RAD_ERR("declare_runtime_window(%d): the group is not a RAD_KV_WINDOW or RAD_KV_RING "
|
||||
"group in this program (a runtime window needs a windowed group)", (int)g);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- fixed costs first: they are not per-token ---- */
|
||||
checkpoint_bytes_ = 0;
|
||||
window_ck_bytes_ = 0;
|
||||
@@ -243,7 +272,7 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
for (size_t i = 1; i < plans_.size(); ++i) {
|
||||
KVGroupPlan& p = plans_[i];
|
||||
p.win_snap = !has_state && p.kind == RAD_KV_WINDOW && p.window_blocks > 0 &&
|
||||
!groups[i].drafter;
|
||||
!p.runtime_win && !groups[i].drafter;
|
||||
if (p.win_snap && !p.zero && p.n_layers > 0)
|
||||
window_ck_bytes_ += p.window_blocks * p.bytes_per_block;
|
||||
}
|
||||
@@ -257,26 +286,107 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
if (p.stateful()) fixed += align_up(p.bytes_per_state * p.n_states, RAD_ALIGN_UNIT);
|
||||
/* And one unit per paged group, whose size need not be a multiple of the alignment. */
|
||||
for (const auto& p : plans_) if (p.paged()) fixed += RAD_ALIGN_UNIT;
|
||||
/* A runtime window's ring is per sequence and on top of the context the split sizes: one
|
||||
* ring a sequence, carved as a fixed cost. Its reference is the context itself, which the
|
||||
* split already covers (the group is not capped at window_blocks). */
|
||||
for (const auto& p : plans_)
|
||||
if (p.runtime_win && !p.zero)
|
||||
fixed += align_up(max_seqs_ * p.ring_blocks_max() * p.bytes_per_block, RAD_ALIGN_UNIT);
|
||||
|
||||
fixed_ = fixed;
|
||||
ckpts_ = budget_ckpts;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* Windowed groups are capped at window_pool_cap, as in carve(). */
|
||||
/* Windowed groups are capped at window_pool_cap, as in carve(). A runtime-window group is not:
|
||||
* its blocks are the reference (one context a sequence, as a FULL group) plus the ring its fixed
|
||||
* costs already carry. */
|
||||
int64_t KVManager::ceiling(int64_t ctx) const {
|
||||
if (ctx <= 0) return 0;
|
||||
int64_t need = fixed_;
|
||||
for (const auto& p : plans_) {
|
||||
if (!p.paged() || p.block_size <= 0) continue;
|
||||
int64_t blocks = max_seqs_ * ((ctx + p.block_size - 1) / p.block_size);
|
||||
if (p.kind == RAD_KV_WINDOW && p.window_blocks > 0)
|
||||
if (p.kind == RAD_KV_WINDOW && !p.runtime_win && p.window_blocks > 0)
|
||||
blocks = std::min(blocks, window_pool_cap(p));
|
||||
need += blocks * p.bytes_per_block;
|
||||
}
|
||||
return need;
|
||||
}
|
||||
|
||||
/* Moves a WINDOW group's plan to per-sequence runtime windows (declare_runtime_window). Returns
|
||||
* false for any other group, so plan_groups() can apply it to every plan unconditionally. */
|
||||
bool KVManager::apply_runtime_window(KVGroupPlan& p) const {
|
||||
auto it = runtime_decl_.find(p.index);
|
||||
if (it == runtime_decl_.end() || p.kind != RAD_KV_WINDOW || p.runtime_win) return false;
|
||||
p.runtime_win = true;
|
||||
p.runtime_tokens = it->second;
|
||||
/* The window a sequence may inherit (a fixed-window cap) is no longer the bound, and the
|
||||
* declare-time window is not the sequence's own, so nothing here is snapshot-able. */
|
||||
p.win_snap = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int KVManager::declare_runtime_window(int32_t g, int64_t window_tokens) {
|
||||
if (g <= 0 || window_tokens <= 0) {
|
||||
RAD_ERR("declare_runtime_window: group %d with a window of %lld (a runtime window needs a "
|
||||
"real group and a positive W)", (int)g, (long long)window_tokens);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
const KVGroupPlan* p = plan(g);
|
||||
if (p && p->kind != RAD_KV_WINDOW) {
|
||||
RAD_ERR("group '%s' is not RAD_KV_WINDOW or RAD_KV_RING, so it cannot carry a runtime "
|
||||
"window", p->name.c_str());
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (p && p->runtime_win && p->runtime_tokens != window_tokens) {
|
||||
/* A RAD_KV_RING group's W is its declaration's `window`, and one already planned for
|
||||
* another W has its ring in the fixed costs. */
|
||||
RAD_ERR("declare_runtime_window(%d): group '%s' already carries a runtime window of %lld "
|
||||
"tokens, and its ring is sized for that", (int)g, p->name.c_str(),
|
||||
(long long)p->runtime_tokens);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (configured_) {
|
||||
RAD_ERR("declare_runtime_window(%d) after the carve: the group's blocks and fixed costs "
|
||||
"are already sized for a different window", (int)g);
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
runtime_decl_[g] = window_tokens;
|
||||
/* A plan built before the declaration (the engine's probes, or plan_groups() then declare)
|
||||
* is updated in place; the next plan_groups() picks the declaration up on its own.
|
||||
*
|
||||
* A plan set shorter than `g` returns RAD_E_INVAL below with this store kept: deliberate.
|
||||
* The declaration is the caller's standing intent (it survives forget(), whose vectors are
|
||||
* emptied together and are not this map), and the short plan set is the probe ordering the
|
||||
* declaration exists for -- the next plan_groups() applies it to a plan that has the group. */
|
||||
if (!plans_.empty()) {
|
||||
if (g >= (int32_t)plans_.size()) return RAD_E_INVAL;
|
||||
KVGroupPlan& q = plans_[(size_t)g];
|
||||
/* Whether the plan counted this group's window snapshot section (plan_groups' rule). */
|
||||
const bool counted = q.win_snap && !q.zero && q.n_layers > 0;
|
||||
if (!apply_runtime_window(q)) return RAD_OK; /* already applied */
|
||||
/* The cost this declaration adds, against the plan as published: the ring is one a
|
||||
* sequence, and the group gives up its window snapshot section. */
|
||||
fixed_ += align_up(max_seqs_ * q.ring_blocks_max() * q.bytes_per_block, RAD_ALIGN_UNIT);
|
||||
if (counted) {
|
||||
const int64_t was = q.window_blocks * q.bytes_per_block;
|
||||
/* The plan counted this group's snapshot section, so both totals carry `was`.
|
||||
* Saturating hides an accounting bug; surface it in debug builds. */
|
||||
assert(window_ck_bytes_ >= was && checkpoint_bytes_ >= was &&
|
||||
"runtime window: snapshot byte totals below the section being removed");
|
||||
window_ck_bytes_ = window_ck_bytes_ > was ? window_ck_bytes_ - was : 0;
|
||||
checkpoint_bytes_ = checkpoint_bytes_ > was ? checkpoint_bytes_ - was : 0;
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int64_t KVManager::runtime_window_tokens(int32_t g) const {
|
||||
const KVGroupPlan* p = plan(g);
|
||||
return p && p->runtime_win ? p->runtime_tokens : 0;
|
||||
}
|
||||
|
||||
/* The vectors parallel to plans_ are filled at different points of the carve, so a partial carve
|
||||
* would leave plans_ passing bounds checks (reserve_block checks plans_, then reads free_usable_)
|
||||
* over empty block state. On failure forget() empties both, so every entry point refuses
|
||||
@@ -329,11 +439,11 @@ int64_t KVManager::paged_split(int64_t budget_bytes, std::vector<int64_t>* block
|
||||
if (tokens_cap_ > 0 && tokens > tokens_cap_) tokens = tokens_cap_;
|
||||
|
||||
/* A windowed group cannot address past its pool cap; cap it and give the bytes back to
|
||||
* the others. */
|
||||
* the others. A runtime-window group's cap is the context plus its ring (a fixed cost). */
|
||||
int32_t capped = -1;
|
||||
for (int32_t i : open) {
|
||||
const auto& p = plans_[i];
|
||||
if (p.kind != RAD_KV_WINDOW) continue;
|
||||
if (p.kind != RAD_KV_WINDOW || p.runtime_win) continue;
|
||||
if (tokens / p.block_size > window_pool_cap(p)) { capped = i; break; }
|
||||
}
|
||||
if (capped < 0) break;
|
||||
@@ -370,7 +480,8 @@ int64_t KVManager::pool_mib_for_tokens(int64_t tokens, int64_t max_mib) const {
|
||||
int64_t KVManager::zero_blocks(const KVGroupPlan& p, int64_t tokens) const {
|
||||
if (tokens == kUnboundedTokens) return 0;
|
||||
const int64_t b = tokens / p.block_size;
|
||||
if (p.kind == RAD_KV_WINDOW && b > window_pool_cap(p)) return window_pool_cap(p);
|
||||
if (p.kind == RAD_KV_WINDOW && !p.runtime_win && b > window_pool_cap(p))
|
||||
return window_pool_cap(p);
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -509,20 +620,31 @@ int KVManager::carve_into(Pool& kv_pool) {
|
||||
|
||||
configured_ = true;
|
||||
report_ = bundling_.report();
|
||||
/* A runtime-window group reads as "ring": its window is the sequence's own, not the plan's. */
|
||||
auto kind_of = [](const KVGroupPlan& p) {
|
||||
return p.runtime_win ? "ring" : kv_kind_name(p.kind);
|
||||
};
|
||||
for (const auto& p : plans_) {
|
||||
if (p.paged())
|
||||
report_ += fmt(" %-14s %-6s %3lld layers block %4lld tok page %8s "
|
||||
"%7lld blocks = %9s (%lld tokens)\n",
|
||||
p.name.c_str(), kv_kind_name(p.kind), (long long)p.n_layers,
|
||||
p.name.c_str(), kind_of(p), (long long)p.n_layers,
|
||||
(long long)p.block_size, humanb(p.bytes_per_block).c_str(),
|
||||
(long long)p.n_blocks, humanb(p.pool_bytes).c_str(),
|
||||
(long long)(p.n_blocks * p.block_size));
|
||||
else
|
||||
report_ += fmt(" %-14s %-6s %3lld layers state %8s %7lld slots = %9s\n",
|
||||
p.name.c_str(), kv_kind_name(p.kind), (long long)p.n_layers,
|
||||
p.name.c_str(), kind_of(p), (long long)p.n_layers,
|
||||
humanb(p.bytes_per_state).c_str(),
|
||||
(long long)p.n_states, humanb(p.pool_bytes).c_str());
|
||||
}
|
||||
for (const auto& p : plans_) {
|
||||
if (!p.runtime_win) continue;
|
||||
report_ += fmt(" %-14s runtime window W=%lld: a sequence keeps its reference and a ring "
|
||||
"of at most %lld block(s), rewritten in place\n",
|
||||
p.name.c_str(), (long long)p.runtime_tokens,
|
||||
(long long)p.ring_blocks_max());
|
||||
}
|
||||
/* The pool's address range, so a GPU fault address can be placed in the carve. */
|
||||
report_ += fmt(" pool at %p, %s; groups at +%lld..+%lld\n",
|
||||
pool_base_, humanb(pool_ ? pool_->bytes() : 0).c_str(),
|
||||
@@ -805,7 +927,17 @@ int64_t KVManager::blocks_for(int32_t g, int64_t n_tokens) const {
|
||||
const KVGroupPlan* p = plan(g);
|
||||
if (!p || !p->paged() || n_tokens <= 0) return 0;
|
||||
int64_t n = ceil_div(n_tokens, p->block_size);
|
||||
if (p->kind == RAD_KV_WINDOW) n = std::min(n, window_seq_cap(*p));
|
||||
if (p->kind == RAD_KV_WINDOW) {
|
||||
if (p->runtime_win) {
|
||||
/* The reference's blocks up to n, plus one ring. Without a sequence the floor is
|
||||
* unknown, so the whole context is the bound on the reference. */
|
||||
const int64_t ring = p->ring_blocks_max();
|
||||
const int64_t ctx = max_ctx_ > 0 ? max_ctx_ : n_tokens;
|
||||
n = std::min(n, ceil_div(ctx, p->block_size)) + ring;
|
||||
} else {
|
||||
n = std::min(n, window_seq_cap(*p));
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -836,6 +968,7 @@ int KVManager::add_sequence(uint64_t id) {
|
||||
s.id = id;
|
||||
s.blocks.resize(plans_.size());
|
||||
s.first_block_pos.assign(plans_.size(), 0);
|
||||
s.win.resize(plans_.size());
|
||||
s.state.assign(plans_.size(), -1);
|
||||
s.dirty_from.assign(plans_.size(), 0);
|
||||
seqs_.emplace(id, std::move(s));
|
||||
@@ -853,6 +986,9 @@ int KVManager::preempt(uint64_t id) {
|
||||
for (int32_t b : s->blocks[g]) drop_block((int32_t)g, b);
|
||||
s->blocks[g].clear();
|
||||
s->first_block_pos[g] = 0;
|
||||
/* The runtime window goes with the blocks: re-admission re-arms it at the prompt end
|
||||
* (the scheduler's admission path calls set_window again before the KV grows). */
|
||||
s->win[g] = SeqWindow{};
|
||||
s->dirty_from[g] = 0;
|
||||
/* The recurrent state goes too (see preempt in kv.h, spec §7.1). */
|
||||
if (s->state[g] >= 0) { drop_state((int32_t)g, s->state[g]); s->state[g] = -1; }
|
||||
@@ -870,6 +1006,12 @@ int KVManager::rollback(uint64_t id, int64_t n_tokens) {
|
||||
if (n_tokens < 0) return RAD_E_INVAL;
|
||||
/* Nothing to free; RAD_OK so "every draft accepted" needs no special path in the caller. */
|
||||
if (n_tokens >= s->n_tokens) return RAD_OK;
|
||||
/* A runtime-windowed sequence unwinds nothing: the ring's slots are reused once it is full,
|
||||
* so the slots a rejected verify wrote may already hold newer keys. The scheduler gates
|
||||
* drafting on has_runtime_window, so this refuses rather than corrupts, and only a caller
|
||||
* that drafts beside a runtime window can reach it. */
|
||||
for (const SeqWindow& w : s->win)
|
||||
if (w.set) return RAD_E_UNSUPPORTED;
|
||||
|
||||
for (size_t g = 0; g < plans_.size(); ++g) {
|
||||
const auto& p = plans_[g];
|
||||
@@ -899,6 +1041,80 @@ int64_t KVManager::first_block_pos(uint64_t id, int32_t g) const {
|
||||
return s->first_block_pos[(size_t)g];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ the runtime window */
|
||||
|
||||
int KVManager::set_window(uint64_t id, int64_t visible_lo, int64_t window_tokens) {
|
||||
if (!configured_) return RAD_E_STATE;
|
||||
Seq* s = find(id);
|
||||
if (!s) return RAD_E_NOTFOUND;
|
||||
if (visible_lo < 0 || window_tokens <= 0) return RAD_E_INVAL;
|
||||
/* The reference is written linearly, so the floor cannot be behind KV the sequence already
|
||||
* holds: rebasing would have to move blocks the ring has not been shaped for. */
|
||||
if (visible_lo < s->n_tokens) {
|
||||
RAD_ERR("sequence %llu: runtime window floor %lld is behind its %lld held tokens",
|
||||
(unsigned long long)id, (long long)visible_lo, (long long)s->n_tokens);
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
bool any = false;
|
||||
/* With a declared runtime window in the program, arm exactly the declared groups: a plain
|
||||
* fixed-window group beside them is carved for its fixed window, and arming it silently
|
||||
* converts it. With none declared this is the caller-sizes-the-pool path kv.h states, and
|
||||
* every windowed group arms as before. */
|
||||
bool declared = false;
|
||||
for (const KVGroupPlan& p : plans_)
|
||||
if (p.kind == RAD_KV_WINDOW && p.runtime_win) declared = true;
|
||||
for (size_t g = 0; g < plans_.size(); ++g) {
|
||||
const KVGroupPlan& p = plans_[g];
|
||||
if (p.kind != RAD_KV_WINDOW) continue;
|
||||
if (declared && !p.runtime_win) {
|
||||
RAD_ERR("sequence %llu: set_window meets fixed-window group '%s' beside a declared "
|
||||
"runtime window; its pool is carved for its fixed window and the mix is not "
|
||||
"supported", (unsigned long long)id, p.name.c_str());
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
SeqWindow w;
|
||||
w.set = true;
|
||||
w.window = window_tokens;
|
||||
w.visible_lo = visible_lo;
|
||||
/* Whole blocks: the ring starts at the first boundary at or after the floor, and the
|
||||
* tokens in [visible_lo, ring_pos) stay in the reference's last block (SeqWindow). The
|
||||
* ring itself must span all of W: the frozen tokens are the oldest of the tail, so a
|
||||
* smaller ring would lose the last W - span positions. */
|
||||
w.ring_pos = ceil_div(visible_lo, p.block_size) * p.block_size;
|
||||
w.ring_blocks = ceil_div(window_tokens, p.block_size);
|
||||
if (w.ring_blocks < 1) w.ring_blocks = 1; /* the ring always has somewhere to write */
|
||||
/* What the sequence can hold: the reference's blocks, then the whole ring. */
|
||||
const int64_t need = w.ring_pos / p.block_size + w.ring_blocks;
|
||||
if (p.n_blocks > 0 && need > p.n_blocks) return RAD_E_FULL;
|
||||
s->win[g] = w;
|
||||
any = true;
|
||||
}
|
||||
if (!any) return RAD_E_UNSUPPORTED;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
bool KVManager::runtime_window(uint64_t id, int32_t g, SeqWindow* out) const {
|
||||
const Seq* s = find(id);
|
||||
if (!s || g < 0 || g >= (int32_t)s->win.size() || !s->win[(size_t)g].set) return false;
|
||||
if (out) *out = s->win[(size_t)g];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KVManager::has_runtime_window(uint64_t id) const {
|
||||
const Seq* s = find(id);
|
||||
if (!s) return false;
|
||||
for (const SeqWindow& w : s->win) if (w.set) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* What ensure() must have in the table for `n_tokens`: the reference grows linearly until the
|
||||
* floor, then the ring fills up to its whole span and never grows again. */
|
||||
int64_t KVManager::window_table_len(const KVGroupPlan& p, const SeqWindow& w, int64_t n_tokens) {
|
||||
const int64_t ref = w.ring_pos / p.block_size;
|
||||
if (n_tokens <= w.ring_pos) return ceil_div(n_tokens, p.block_size);
|
||||
return ref + std::min(w.ring_blocks, ceil_div(n_tokens - w.ring_pos, p.block_size));
|
||||
}
|
||||
|
||||
int64_t KVManager::seq_tokens(uint64_t id) const { const Seq* s = find(id); return s ? s->n_tokens : 0; }
|
||||
|
||||
int64_t KVManager::take_table_changes(uint64_t id, int32_t g) const {
|
||||
@@ -1023,11 +1239,15 @@ int64_t KVManager::step_blocks(const KVGroupPlan& p) const {
|
||||
/* Slides from the step's first query, not its last. The query at keep_from reads keys down to
|
||||
* keep_from - window + 1, which lies in block keep_from / block - (window_blocks - 1) or later
|
||||
* (window_blocks - 1 >= window / block). A target from the step's end is the same for a decode
|
||||
* step but drops keys the earlier rows of a prefill chunk still need. */
|
||||
* step but drops keys the earlier rows of a prefill chunk still need.
|
||||
*
|
||||
* A sequence with a runtime window is left alone. Its visible set is anchored at 0, so nothing in
|
||||
* the table is below a sliding floor to recycle; the ring's blocks are rewritten in place and
|
||||
* the table never moves (SeqWindow). */
|
||||
void KVManager::recycle_window(Seq* s, int64_t keep_from) {
|
||||
for (size_t g = 0; g < plans_.size(); ++g) {
|
||||
const auto& p = plans_[g];
|
||||
if (p.kind != RAD_KV_WINDOW) continue;
|
||||
if (p.kind != RAD_KV_WINDOW || s->win[g].set) continue;
|
||||
int64_t first = s->first_block_pos[g] / p.block_size;
|
||||
int64_t target = std::max<int64_t>(first,
|
||||
keep_from / p.block_size - (p.window_blocks - 1));
|
||||
@@ -1066,7 +1286,9 @@ int KVManager::ensure(uint64_t id, int64_t n_tokens, int64_t keep_from) {
|
||||
const auto& p = plans_[g];
|
||||
if (p.paged()) {
|
||||
int64_t first = s->first_block_pos[g] / p.block_size;
|
||||
int64_t want = ceil_div(n_tokens, p.block_size) - first;
|
||||
int64_t want = s->win[g].set
|
||||
? window_table_len(p, s->win[g], n_tokens) - first
|
||||
: ceil_div(n_tokens, p.block_size) - first;
|
||||
need[g] = want - (int64_t)s->blocks[g].size();
|
||||
if (need[g] < 0) need[g] = 0;
|
||||
/* Copy-on-write: the partial block is the only one a write reaches; if it is shared,
|
||||
@@ -1102,7 +1324,9 @@ int KVManager::ensure(uint64_t id, int64_t n_tokens, int64_t keep_from) {
|
||||
}
|
||||
}
|
||||
}
|
||||
int64_t want = ceil_div(n_tokens, p.block_size) - first;
|
||||
int64_t want = s->win[g].set
|
||||
? window_table_len(p, s->win[g], n_tokens) - first
|
||||
: ceil_div(n_tokens, p.block_size) - first;
|
||||
if ((int64_t)s->blocks[g].size() < want)
|
||||
s->dirty_from[g] = std::min<int64_t>(s->dirty_from[g],
|
||||
(int64_t)s->blocks[g].size());
|
||||
@@ -1126,6 +1350,10 @@ int KVManager::adopt(uint64_t id, int32_t g, const std::vector<int32_t>& blocks,
|
||||
if (!s) return RAD_E_NOTFOUND;
|
||||
const KVGroupPlan* p = plan(g);
|
||||
if (!p || !p->paged()) return RAD_E_INVAL;
|
||||
/* A runtime window's table is its own reference plus ring, laid out against a floor no cache
|
||||
* entry knows (set_window), so blocks adopted from a prefix hit would sit at the wrong
|
||||
* positions. Prefix publish is skipped for such a sequence; this is the backstop. */
|
||||
if (s->win[(size_t)g].set) return RAD_E_STATE;
|
||||
/* Whole blocks only (see adopt in kv.h). */
|
||||
if (n_tokens % p->block_size != 0) return RAD_E_INVAL;
|
||||
if ((int64_t)blocks.size() != n_tokens / p->block_size) return RAD_E_INVAL;
|
||||
@@ -1146,6 +1374,14 @@ int KVManager::fork(uint64_t parent, uint64_t child) {
|
||||
Seq* pa = find(parent);
|
||||
if (!pa) return RAD_E_NOTFOUND;
|
||||
if (seqs_.count(child)) return RAD_E_DUPLICATE;
|
||||
/* The window is runtime data: a child that shared the table without it would read the ring
|
||||
* as if it were a reference. A forking model (speculative decoding) does not carry one. */
|
||||
for (const SeqWindow& w : pa->win)
|
||||
if (w.set) {
|
||||
RAD_ERR("sequence %llu: fork refused, it carries a runtime window",
|
||||
(unsigned long long)parent);
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* Pass 1: the child needs its own state slot in every stateful group before anything is
|
||||
* shared (see fork in kv.h, spec §7.3). */
|
||||
@@ -1160,6 +1396,7 @@ int KVManager::fork(uint64_t parent, uint64_t child) {
|
||||
if (plans_[g].paged()) {
|
||||
ch->blocks[g] = pa->blocks[g];
|
||||
ch->first_block_pos[g] = pa->first_block_pos[g];
|
||||
ch->win[g] = pa->win[g];
|
||||
for (int32_t b : ch->blocks[g]) add_ref(g, b);
|
||||
} else {
|
||||
grab_state((int32_t)g, &ch->state[g]);
|
||||
@@ -1189,7 +1426,10 @@ int KVManager::make_room(uint64_t id, int64_t n_tokens,
|
||||
if (p.paged()) {
|
||||
int64_t first = s->first_block_pos[g] / p.block_size;
|
||||
int64_t want = ceil_div(n_tokens, p.block_size) - first;
|
||||
if (p.kind == RAD_KV_WINDOW) want = std::min(want, window_seq_cap(p));
|
||||
if (p.kind == RAD_KV_WINDOW) {
|
||||
if (s->win[g].set) want = window_table_len(p, s->win[g], n_tokens) - first;
|
||||
else want = std::min(want, window_seq_cap(p));
|
||||
}
|
||||
int64_t extra = want - (int64_t)s->blocks[g].size() + 1; /* +1 for a COW copy */
|
||||
if (extra > available_blocks((int32_t)g)) return false;
|
||||
} else if (p.stateful() && s->state[g] < 0 && free_states_[g].empty()) return false;
|
||||
@@ -1369,6 +1609,9 @@ bool KVManager::window_rows(uint64_t id, int64_t pos, std::vector<int32_t>* out)
|
||||
out->clear();
|
||||
const Seq* s = find(id);
|
||||
if (!s || pos <= 0) return false;
|
||||
/* A runtime window is excluded from window snapshots (set_window): the window length is
|
||||
* runtime data and the table is a reference plus a ring, not [lo, pos). */
|
||||
for (const SeqWindow& w : s->win) if (w.set) return false;
|
||||
for (size_t g = 0; g < plans_.size(); ++g) {
|
||||
const KVGroupPlan& p = plans_[g];
|
||||
if (!p.win_snap) continue;
|
||||
@@ -1390,6 +1633,8 @@ bool KVManager::window_rows(uint64_t id, int64_t pos, std::vector<int32_t>* out)
|
||||
int KVManager::seed_window(uint64_t id, int64_t pos) {
|
||||
Seq* s = find(id);
|
||||
if (!s) return RAD_E_NOTFOUND;
|
||||
/* A sequence with a runtime window is never resumed from a window snapshot (set_window). */
|
||||
for (const SeqWindow& w : s->win) if (w.set) return RAD_E_STATE;
|
||||
/* Check every group before taking anything, as ensure() does. */
|
||||
for (size_t g = 0; g < plans_.size(); ++g) {
|
||||
const KVGroupPlan& p = plans_[g];
|
||||
|
||||
+113
-3
@@ -11,6 +11,10 @@
|
||||
* RAD_KV_LINEAR per-sequence, fixed size: the GDN recurrent state
|
||||
* RAD_KV_CONV per-sequence, fixed size: a rolling window of conv_width-1 + n_spec entries
|
||||
*
|
||||
* A RAD_KV_RING group is a RAD_KV_WINDOW whose floor is per sequence and set at runtime (R-SWA,
|
||||
* see SeqWindow); it is planned as a WINDOW group with `runtime_win` set, so no kind of its own
|
||||
* reaches the plan.
|
||||
*
|
||||
* The two stateful kinds are also allocated, mapped and freed here, so one allocator decides what
|
||||
* a sequence owns. With two, a freed sequence's state slot could still be handed to the next
|
||||
* request by the other.
|
||||
@@ -50,6 +54,45 @@ struct BundleComparison {
|
||||
};
|
||||
BundleComparison compare_bundling(const std::vector<int64_t>& bundles);
|
||||
|
||||
/* ------------------------------------------------------------------ the runtime window */
|
||||
/* A sequence's per-sequence window on a RAD_KV_WINDOW group, set at runtime (R-SWA, the
|
||||
* "reference + ring" attention of Unlimited-OCR: a full causal prefill over the prompt and image
|
||||
* tokens, then a ring of W decode slots right after it, rewritten in place forever).
|
||||
*
|
||||
* A fixed sliding window (`KVGroupPlan::window_blocks`, gemma4's) keeps the last W tokens: the
|
||||
* table starts where the window begins and blocks leave from its front. A runtime window instead
|
||||
* retains the whole prefill as the reference and appends into a ring after it:
|
||||
*
|
||||
* visible = [0, visible_lo) U [visible_lo, visible_lo + W)
|
||||
*
|
||||
* `visible_lo` is the sequence's own prefill length (image tokens included), so the visible set is
|
||||
* per sequence. The reference is never recycled and first_block_pos stays 0 (the table still
|
||||
* starts at position 0); only the ring's slot mapping recycles, so RoPE positions keep increasing
|
||||
* with the token's own position and a decode query sees the whole reference plus the ring.
|
||||
*
|
||||
* Blocks are whole, so the ring can start only on a block boundary: it starts at
|
||||
* `ring_pos = ceil(visible_lo / block) * block` with `ceil(W / block)` blocks, and the tokens in
|
||||
* [visible_lo, ring_pos) stay in the reference's last block (they are the oldest of the tail and
|
||||
* are never rewritten). The visible tail is therefore W .. W + block - 1 tokens when W is a block
|
||||
* multiple -- with block_size 128 = W the 128-256 token granularity of the plan, exact even when
|
||||
* the floor is not aligned -- and up to one block more otherwise, always a superset of the
|
||||
* reference implementation's last W. The ring's blocks hold the newest positions in place (no
|
||||
* block is allocated past them, so the sequence's bytes are flat once the floor is set):
|
||||
*
|
||||
* block index = ring_pos / block + ((pos - ring_pos) / block) % ring_blocks
|
||||
*
|
||||
* A sequence with a runtime window is excluded from prefix-cache reuse, window snapshots, forking
|
||||
* and speculative rollback: all three assume the declare-time window, and the runtime length is
|
||||
* not in any cache key (see KVManager::set_window). */
|
||||
struct SeqWindow {
|
||||
bool set = false;
|
||||
int64_t window = 0; /* W as set */
|
||||
int64_t visible_lo = 0; /* the retained reference ends here */
|
||||
int64_t ring_pos = 0; /* block-aligned first ring token position */
|
||||
int64_t ring_blocks = 0; /* whole blocks the ring holds */
|
||||
int64_t ring_span(int64_t block) const { return ring_blocks * block; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ per-group plan */
|
||||
struct KVGroupPlan {
|
||||
int32_t index = -1; /* position in Program::kv_groups */
|
||||
@@ -62,6 +105,18 @@ struct KVGroupPlan {
|
||||
int64_t bytes_per_state = 0; /* LINEAR/CONV: per sequence, every layer */
|
||||
int64_t conv_slots = 0; /* CONV: conv_width - 1 + n_spec */
|
||||
int64_t window_blocks = 0; /* WINDOW: the per-sequence block cap */
|
||||
/* WINDOW: sequences may be given a runtime window (declare_runtime_window). Such a group is
|
||||
* sized for the whole context plus one ring per sequence instead of being capped at
|
||||
* window_blocks, its window is not snapshotted, and a sequence armed with one is bounded by
|
||||
* its own reference + ring rather than by window_blocks. */
|
||||
bool runtime_win = false;
|
||||
int64_t runtime_tokens = 0; /* the W set_window arms a sequence with */
|
||||
/* The most ring blocks one sequence needs: ceil(W / block), the reference's fraction d of
|
||||
* the ring's first block being frozen in it (see SeqWindow). */
|
||||
int64_t ring_blocks_max() const {
|
||||
return runtime_tokens > 0 && block_size > 0
|
||||
? (runtime_tokens + block_size - 1) / block_size : 0;
|
||||
}
|
||||
/* WINDOW: a checkpoint slot carries this group's window (has_window_snapshot). Set only for a
|
||||
* trunk group of a model with no linear state. A drafter's window is recomputed by draft
|
||||
* refill, and a model with linear state re-prefills a hit on a windowed trunk, so neither
|
||||
@@ -206,9 +261,49 @@ public:
|
||||
/* Recycles a committed chunk's window blocks. ensure() keeps a chunk's blocks beside the
|
||||
* window and only the next ensure() recycles them, so a prefill waiting for its next chunk
|
||||
* would hold a whole chunk of blocks; several such prefills can exhaust the pool. The
|
||||
* scheduler calls this when it advances n_computed, passing the new n_computed. */
|
||||
* scheduler calls this when it advances n_computed, passing the new n_computed.
|
||||
*
|
||||
* A sequence with a runtime window retains its reference and rewrites its ring in place, so
|
||||
* nothing below the floor may be recycled and this is a no-op for it. */
|
||||
void trim_window(uint64_t seq, int64_t keep_from);
|
||||
|
||||
/* ---------------- the runtime window (R-SWA; see SeqWindow) ---------------- */
|
||||
/* Mark a WINDOW group as carrying per-sequence runtime windows of `window_tokens`. Call before
|
||||
* plan_groups()/configure(): it changes the plan (the group is sized for the whole context
|
||||
* plus one ring a sequence, its window is not snapshotted, and the ring joins the fixed
|
||||
* costs), so a group declared after the plan is refused. A fixed-window group is untouched.
|
||||
*
|
||||
* A group that is not marked still accepts set_window() -- the caller then sizes the pool
|
||||
* itself, e.g. by declaring the group's window as the whole context -- and each sequence's
|
||||
* capacity is checked at set_window()/ensure() against the blocks actually carved. Once any
|
||||
* group is marked, set_window() arms only marked groups: a plain fixed-window group beside a
|
||||
* declared runtime window is refused, not silently converted (its pool is carved for the
|
||||
* fixed window). */
|
||||
int declare_runtime_window(int32_t group, int64_t window_tokens);
|
||||
|
||||
/* Give a sequence a runtime window with `visible_lo` (its prefill length, image tokens
|
||||
* included) as the retained reference's end and a ring of `window_tokens` after it. Every
|
||||
* paged WINDOW group of the sequence gets the same floor. Call it before the sequence's KV
|
||||
* grows past `visible_lo` -- at admission, where the scheduler knows the prompt length -- so
|
||||
* the reference is written linearly and no checkpoint can be reserved for it (a snapshot
|
||||
* would describe a window the sequence no longer has).
|
||||
*
|
||||
* RAD_E_UNSUPPORTED no windowed group, or the fixed/runtime-window mix above;
|
||||
* RAD_E_INVAL a negative floor or a window of 0;
|
||||
* RAD_E_STATE the sequence already holds tokens past the floor;
|
||||
* RAD_E_FULL the reference plus the ring exceeds what this group carved. */
|
||||
int set_window(uint64_t seq, int64_t visible_lo, int64_t window_tokens);
|
||||
|
||||
/* The sequence's window in `group`, or false when it has none (a fixed-window group keeps
|
||||
* KVGroupPlan::window_blocks and first_block_pos). The step batch maps a ring position with
|
||||
* SeqWindow's rule; every other position maps as (pos - first_block_pos) / block_size. */
|
||||
bool runtime_window(uint64_t seq, int32_t group, SeqWindow* out) const;
|
||||
/* Whether any group has a runtime window set for the sequence. Prefix publish, checkpoint
|
||||
* reservation and snapshots are skipped for it (see set_window). */
|
||||
bool has_runtime_window(uint64_t seq) const;
|
||||
/* The W declare_runtime_window gave the group, 0 if it carries no runtime windows. */
|
||||
int64_t runtime_window_tokens(int32_t group) const;
|
||||
|
||||
/* 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
|
||||
* corrupt the cache entry. Bumps each block's refcount. */
|
||||
@@ -363,7 +458,11 @@ public:
|
||||
/* The absolute token position block_table(seq, group)[0] covers: zero for a FULL group, the
|
||||
* recycled prefix for a WINDOW group. The slot mapping is (pos - first_block_pos) /
|
||||
* block_size; without the offset a sliding-window sequence writes to the wrong slot once it
|
||||
* passes its window. */
|
||||
* passes its window.
|
||||
*
|
||||
* A sequence with a runtime window (set_window) keeps 0 for the group's whole life: its table
|
||||
* is [reference][ring] from position 0 and only the ring's slot index recycles (SeqWindow),
|
||||
* so the mapping above holds for the reference and SeqWindow's rule for the ring. */
|
||||
int64_t first_block_pos(uint64_t seq, int32_t group) const;
|
||||
|
||||
/* The first table entry changed since the last call; entries below it are unchanged, and
|
||||
@@ -461,6 +560,9 @@ private:
|
||||
* for a windowed group. 0 for kUnboundedTokens, which is not a count. */
|
||||
int64_t zero_blocks(const KVGroupPlan& p, int64_t tokens) const;
|
||||
void forget();
|
||||
/* Turns a WINDOW group into a runtime-window one (declare_runtime_window). Returns false for a
|
||||
* group that is not windowed. */
|
||||
bool apply_runtime_window(KVGroupPlan& p) const;
|
||||
|
||||
/* One traversal serving both checkpoint directions; see checkpoint_save. */
|
||||
int checkpoint_copy(const int32_t* state_slots, int n_slots, int32_t ck_slot, bool save,
|
||||
@@ -471,6 +573,7 @@ private:
|
||||
int64_t n_tokens = 0;
|
||||
std::vector<std::vector<int32_t>> blocks; /* per group */
|
||||
std::vector<int64_t> first_block_pos; /* WINDOW: token pos of blocks[0] */
|
||||
std::vector<SeqWindow> win; /* per group: the runtime window, if any */
|
||||
std::vector<int32_t> state; /* per group, -1 when not stateful */
|
||||
/* Per group, the lowest table entry written since the batch builder last staged this
|
||||
* sequence. An append or truncation lowers it to where it touched; a shift lowers it to
|
||||
@@ -486,8 +589,12 @@ private:
|
||||
void drop_state(int32_t g, int32_t s);
|
||||
Seq* find(uint64_t seq);
|
||||
const Seq* find(uint64_t seq) const;
|
||||
/* Recycle a WINDOW group's blocks no query at or past `keep_from` can read. */
|
||||
/* Recycle a WINDOW group's blocks no query at or past `keep_from` can read. A runtime window
|
||||
* (SeqWindow) is not trimmed: its reference must stay and its ring rewrites slots in place. */
|
||||
void recycle_window(Seq* s, int64_t keep_from);
|
||||
/* The table length a runtime-windowed sequence needs to hold `n_tokens`: the reference's
|
||||
* blocks, then the ring's up to its whole span. */
|
||||
static int64_t window_table_len(const KVGroupPlan& p, const SeqWindow& w, int64_t n_tokens);
|
||||
|
||||
std::vector<KVGroupPlan> plans_;
|
||||
std::vector<std::vector<int32_t>> free_blocks_; /* per group */
|
||||
@@ -515,6 +622,9 @@ private:
|
||||
int64_t fixed_ = 0; /* the non-negotiable floor: states, conv slots, padding */
|
||||
int64_t ckpts_ = 0; /* --checkpoint-slots, kept for the warning on a model with none */
|
||||
int64_t tokens_cap_ = 0; /* cap_paged_tokens(): the least any rank can carve; 0 is none */
|
||||
/* declare_runtime_window(): group -> W. Survives forget(), which plan_groups() calls at its
|
||||
* start: it is a declaration about the program, not about a plan. */
|
||||
std::unordered_map<int32_t, int64_t> runtime_decl_;
|
||||
|
||||
/* ---- the loan (see the public block) ----
|
||||
*
|
||||
|
||||
+8
-3
@@ -462,8 +462,9 @@ void PrefixCache::take_over(uint64_t session, const std::vector<BlockHash>& hs,
|
||||
|
||||
std::vector<BlockHash> PrefixCache::restorable_from(const std::vector<int32_t>& tokens,
|
||||
const std::vector<MMContentKey>& mm,
|
||||
int64_t fit) const {
|
||||
int64_t fit, bool* cut) const {
|
||||
std::vector<BlockHash> out;
|
||||
if (cut) *cut = false;
|
||||
if (!enabled_ || !tiers_ || tokens.empty()) return out;
|
||||
|
||||
/* Only blocks a hit can use: one token must remain, so a prompt ending on a block boundary
|
||||
@@ -488,13 +489,16 @@ std::vector<BlockHash> PrefixCache::restorable_from(const std::vector<int32_t>&
|
||||
if (out.empty() || (int64_t)out.size() <= fit) return out;
|
||||
|
||||
/* Restored up to `fit`, the hit ends at the first entry left behind. */
|
||||
++stats_.restore_cuts;
|
||||
if (cut) *cut = true;
|
||||
int64_t keep = std::max<int64_t>(0, fit);
|
||||
if (has_linear_) {
|
||||
const auto best = deepest_ckpt(hs, at[(size_t)keep] * block_size_);
|
||||
const int64_t upto = best == ck_by_prefix_.end() ? 0 : best->second.pos / block_size_;
|
||||
keep = std::lower_bound(at.begin(), at.begin() + keep, upto) - at.begin();
|
||||
}
|
||||
RAD_DEBUG("prefix cache: restore of %zu entries cut to %lld: the pool holds %lld of them, and "
|
||||
"the hit ends at token %lld", out.size(), (long long)keep,
|
||||
(long long)std::max<int64_t>(0, fit), (long long)(at[(size_t)keep] * block_size_));
|
||||
out.resize((size_t)keep);
|
||||
return out;
|
||||
}
|
||||
@@ -508,7 +512,8 @@ int64_t PrefixCache::restore_room() const {
|
||||
|
||||
int64_t PrefixCache::trim_for(const std::vector<int32_t>& tokens,
|
||||
const std::vector<MMContentKey>& mm, int64_t n_blocks) {
|
||||
if (!enabled_ || n_blocks <= 0) return 0;
|
||||
/* Without a host tier a trim erases, and making room for a restore must lose nothing. */
|
||||
if (!enabled_ || n_blocks <= 0 || !tiers_ || !tiers_->host_on()) return 0;
|
||||
const std::vector<BlockHash> hs = chain_all(tokens, mm, (int64_t)tokens.size() / block_size_);
|
||||
std::unordered_set<BlockHash, BlockHashHash> spare(hs.begin(), hs.end());
|
||||
for (const auto& h : held_) spare.insert(h.first);
|
||||
|
||||
+6
-9
@@ -256,20 +256,19 @@ public:
|
||||
* on a miss or token mismatch. Separate from lookup because lookup is const and has no
|
||||
* device; a promotion allocates blocks and runs a scatter between steps.
|
||||
*
|
||||
* `fit` is how many entries the pool can take. A longer chain is cut, and counted
|
||||
* (Stats::restore_cuts): with recurrent state at the deepest snapshot the shorter prefix
|
||||
* reaches, since the hit resumes there and blocks past it would come back for nothing;
|
||||
* without, at `fit`. */
|
||||
* `fit` is how many entries the pool can take. A longer chain is cut, and `*cut` set: with
|
||||
* recurrent state at the deepest snapshot the shorter prefix reaches, since the hit resumes
|
||||
* there and blocks past it would come back for nothing; without, at `fit`. */
|
||||
std::vector<BlockHash> restorable_from(const std::vector<int32_t>& tokens,
|
||||
const std::vector<MMContentKey>& mm,
|
||||
int64_t fit = INT64_MAX) const;
|
||||
int64_t fit = INT64_MAX, bool* cut = nullptr) const;
|
||||
/* Entries a restore can place now: free blocks against the carve, the least over the cached
|
||||
* groups. Lent blocks count, since KVManager::reserve_blocks recalls the loan for them. */
|
||||
int64_t restore_room() const;
|
||||
/* Room for a restore of this prompt's chain: trim(), sparing the chain itself (its blocks
|
||||
* would only have to come back too) and every chain a waiting request holds (hold()), whose
|
||||
* next attempt would restore it again. Nothing is lost; the reserve's trim after the next
|
||||
* publish puts the pool's free quarter back. */
|
||||
* next attempt would restore it again. Only entries whose host copy has landed leave VRAM,
|
||||
* so nothing is lost; with no host tier it takes nothing. */
|
||||
int64_t trim_for(const std::vector<int32_t>& tokens, const std::vector<MMContentKey>& mm,
|
||||
int64_t n_blocks);
|
||||
|
||||
@@ -357,8 +356,6 @@ public:
|
||||
int64_t drops = 0;
|
||||
/* Entries and snapshots removed by --prefix-cache-ttl, from any tier. */
|
||||
int64_t expired = 0, ckpt_expired = 0;
|
||||
/* Restores from the host tier cut short because the pool could not hold the chain. */
|
||||
int64_t restore_cuts = 0;
|
||||
};
|
||||
const Stats& stats() const { return stats_; }
|
||||
|
||||
|
||||
@@ -82,9 +82,8 @@ struct VramFacts {
|
||||
bool lends = false;
|
||||
/* A loaded control vector's direction table: device bytes the engine already holds, which are
|
||||
* not part of the program or the pools and must not shrink what the plan may claim. It comes
|
||||
* out of the headroom, as every deployment keeps that unclaimed. Without this, a deployment
|
||||
* that merely *offers* a vector would plan its expert cache against a smaller card than one
|
||||
* that does not, which is exactly the difference "off == stock" cannot allow. */
|
||||
* out of the headroom, as every deployment keeps that unclaimed, so a deployment that only
|
||||
* offers a vector plans its expert cache against the same card as one that does not. */
|
||||
int64_t held_out = 0;
|
||||
/* Integrated graphics: host memory the card must leave to the host, since device memory is
|
||||
* host memory there. 0 on a discrete card. */
|
||||
|
||||
Reference in new issue
Block a user