radiance 1.3.0

- #47: llama-server's request fields, routes and sampler order, and /props (with baKon's model
  entry: max_model_len, root and capabilities on /v1/models, and /v1/models/:id)
- new APIs: Anthropic's Messages API (/v1/messages), OpenAI's Responses API (/v1/responses),
  llama-server's /completion and /infill, logprobs (OpenAI's logprobs and top_logprobs, up to
  20; llama-server's n_probs), OpenAI's legacy `functions`, and X-Api-Key beside the bearer key
- #4: --model takes a Hugging Face repo id (owner/name), fetched before startup into
  ~/.cache/radiance/hf or --download-dir and checked for changes at every start (redxherring)
- #46: --tp 3 --tp-wire wht6 serves -- a three-rank two-shot all-reduce with uneven shards and
  the tiered-int8 wire over it (baKon); scripts/cardclock.py names what holds each card's clock
  under load (baKon)
- CPU-only serving works again; --kernels names the kernel libraries to load; a model the
  loaded libraries cannot fully serve refuses at startup instead of failing its first request;
  --vram-kv-mib and --vram-weights-mib are gone (the split is automatic)
- --embedding-placement ram is the default, and `auto` is gone
- #40: Swift 1.5 recipes; rad-convert reads which shard holds a tensor from the index
- #53: the pinned host pool gets huge pages where shmem THP is off; #57: a crash on video with
  an odd frame width is fixed
This commit is contained in:
Deadcode committed 2026-10-08 18:22:08 +02:00
1 parent 6a2ee986d6
commit 89cee7ce41
107 files changed
+6849 -1091

No files matched your search

+7 -7
View File
@@ -424,8 +424,7 @@ int64_t KVManager::zero_blocks(const KVGroupPlan& p, int64_t tokens) const {
}
int KVManager::carve_into(Pool& kv_pool) {
/* The pool is whatever the operator stated or the resolver derived; nothing here re-decides
* it. What this does decide is how the groups share it, which is arithmetic, not policy. */
/* The pool is what the resolver derived; nothing here re-decides it. What this does decide is how the groups share it, which is arithmetic, not policy. */
const int64_t budget_bytes = kv_pool.avail();
const int64_t fixed = fixed_;
pool_base_ = kv_pool.base();
@@ -434,10 +433,11 @@ int KVManager::carve_into(Pool& kv_pool) {
if (fixed >= budget_bytes) {
RAD_ERR("vram_kv does not fit its fixed costs:\n"
" linear/conv state %10s (%lld sequences)\n"
" --vram-kv-mib %10s\n"
" vram_kv %10s\n"
" SHORT BY %10s\n"
"Lower --max-seqs or raise --vram-kv-mib. The engine will not shrink one of them "
"for you (spec §6).",
"Lower --max-num-seqs, or give the cache more of the card: a smaller "
"--gpu-headroom-mib or a larger --host-pool-mib. The engine will not shrink one of "
"them for you (spec §6).",
humanb(fixed).c_str(), (long long)max_seqs_, humanb(budget_bytes).c_str(),
humanb(fixed - budget_bytes + 1).c_str());
return RAD_E_NOMEM;
@@ -459,8 +459,8 @@ int KVManager::carve_into(Pool& kv_pool) {
}
if (p.n_blocks <= 0) {
RAD_ERR("KV group '%s': a %s KV pool leaves 0 blocks (%s a page) after the fixed "
"linear/conv costs of %s. Raise --vram-kv-mib or --host-pool-mib, or lower "
"--max-seqs.",
"linear/conv costs of %s. Raise --host-pool-mib or lower --gpu-headroom-mib, or "
"lower --max-num-seqs.",
p.name.c_str(), humanb(budget_bytes).c_str(),
humanb(p.bytes_per_block).c_str(), humanb(fixed).c_str());
return RAD_E_NOMEM;
+3 -3
View File
@@ -156,8 +156,8 @@ public:
* exhaust at the same total token count, and any other split strands memory in whichever
* group outlasts the others.
*
* The byte budget comes from the operator and is not derived here: it is whatever `kv_pool`
* still has (which is --vram-kv-mib). The linear-state snapshots take none of it -- they live
* The byte budget is the budget resolver's and is not re-derived here: it is whatever
* `kv_pool` still has (vram_kv). The linear-state snapshots take none of it -- they live
* in pinned host memory (set_checkpoint_store) -- so the pool is the live cache and nothing
* else (spec §6, §7.3). */
int configure(const std::vector<KVGroupInfo>& groups, const Config& cfg, Pool& kv_pool);
@@ -165,7 +165,7 @@ public:
/* configure(), split at the seam the budget resolver needs. plan_groups() sizes every group
* from the declaration and the run configuration -- no pool, no bytes -- and ceiling() then
* says what a FULL cache for `ctx` tokens on max_seqs sequences would cost. Pools are
* allocated before carve() runs, so a derived --vram-kv-mib has to be decided from these two
* allocated before carve() runs, so the KV pool has to be decided from these two
* and nothing else (core/mem/vram_budget.cpp). carve() spends the pool it is given. */
int plan_groups(const std::vector<KVGroupInfo>& groups, const Config& cfg);
int64_t ceiling(int64_t ctx) const;
+12 -2
View File
@@ -988,7 +988,7 @@ static bool chain_extends(const std::vector<BlockHash>& shorter,
}
void IdleTiers::note_session(uint64_t id, const std::vector<BlockHash>& chain, int64_t n_tokens,
uint64_t now_ns) {
uint64_t now_ns, const std::string& label) {
if (chain.empty()) return;
std::lock_guard lk(mu_);
@@ -1008,6 +1008,9 @@ void IdleTiers::note_session(uint64_t id, const std::vector<BlockHash>& chain, i
* to say which of them republished. So the most recent of them is touched and no row is
* added, which is the one answer that is wrong about nothing. */
uint64_t first_seen = 0;
/* A conversation's label outlives the turn that sent it: a later turn without one keeps the
* name an earlier one gave. */
std::string kept_label = label;
bool absorbed = false;
std::vector<uint64_t>& at_root = roots_[chain[0]];
for (size_t i = 0; i < at_root.size();) {
@@ -1016,6 +1019,7 @@ void IdleTiers::note_session(uint64_t id, const std::vector<BlockHash>& chain, i
if (!chain_extends(it->second.chain, chain)) { ++i; continue; }
if (first_seen == 0 || it->second.first_seen_ns < first_seen)
first_seen = it->second.first_seen_ns;
if (kept_label.empty()) kept_label = it->second.label;
sessions_.erase(it);
at_root.erase(at_root.begin() + (long)i);
absorbed = true;
@@ -1028,7 +1032,11 @@ void IdleTiers::note_session(uint64_t id, const std::vector<BlockHash>& chain, i
if (it == sessions_.end() || !chain_extends(chain, it->second.chain)) continue;
if (!newest || it->second.last_used_ns > newest->last_used_ns) newest = &it->second;
}
if (newest) { newest->last_used_ns = now_ns; return; }
if (newest) {
newest->last_used_ns = now_ns;
if (!label.empty()) newest->label = label;
return;
}
}
Session& s = sessions_[id];
@@ -1036,6 +1044,7 @@ void IdleTiers::note_session(uint64_t id, const std::vector<BlockHash>& chain, i
s.n_tokens = n_tokens;
s.first_seen_ns = first_seen ? first_seen : now_ns;
s.chain = chain;
s.label = std::move(kept_label);
at_root.push_back(id);
}
@@ -1079,6 +1088,7 @@ std::vector<IdleTiers::SessionInfo> IdleTiers::sessions(Occupancy* occ) const {
si.model = model_;
si.n_tokens = kv.second.n_tokens;
si.first_seen_ns = kv.second.first_seen_ns;
si.label = kv.second.label;
si.last_used_ns = kv.second.last_used_ns;
si.bytes = (int64_t)kv.second.chain.size() * cfg_.entry_bytes;
out.push_back(std::move(si));
+3 -1
View File
@@ -383,6 +383,7 @@ public:
struct SessionInfo {
uint64_t id = 0;
std::string model;
std::string label; /* the client's own name for the conversation, or "" */
int64_t n_tokens = 0;
int64_t bytes = 0;
uint64_t first_seen_ns = 0;
@@ -426,7 +427,7 @@ public:
* is a row per turn -- a table nobody can read, holding a copy of every prefix of the
* transcript for as long as the newest. */
void note_session(uint64_t id, const std::vector<BlockHash>& chain, int64_t n_tokens,
uint64_t now_ns);
uint64_t now_ns, const std::string& label = std::string());
void set_model(const std::string& m) { model_ = m; }
/* Newest activity first. Recomputes each session's tier histogram from the records, so it is
* a view and never a second copy of the truth. The walk takes the lock in slices and lets
@@ -545,6 +546,7 @@ private:
uint64_t first_seen_ns = 0;
uint64_t last_used_ns = 0;
std::vector<BlockHash> chain;
std::string label;
};
/* Erase one row and its root index entry together. */
+11 -37
View File
@@ -199,22 +199,20 @@ int Pools::configure(const Config& cfg, int64_t vram_capacity,
const int64_t MiB = 1024 * 1024;
const int64_t w = cfg.vram_weights_mib * MiB;
const int64_t kv = cfg.vram_kv_mib * MiB;
const int64_t hp = cfg.host_pool_mib * MiB;
const int64_t hp = (cfg.host_pool_mib + cfg.embedding_host_mib) * MiB;
/* THE BUDGETS ARE RESOLVED BEFORE THIS RUNS AND THIS DOES NOT RE-DECIDE THEM. Either the
* operator stated them or core/mem/vram_budget.cpp derived them from the card, the measured
* driver residency and the computed arena -- and either way they arrive here as two numbers
* with a report behind them. Either way this component refuses rather than shrinking
* anything: an engine that quietly re-optimises a split is an engine whose
* benchmarks do not reproduce (spec §6). A zero here means the resolver was never called,
* which is a wiring bug and gets named as one. */
/* THE BUDGETS ARE RESOLVED BEFORE THIS RUNS AND THIS DOES NOT RE-DECIDE THEM.
* core/mem/vram_budget.cpp derived them from the card, the measured driver residency and the
* computed arena, and they arrive here as two numbers with a report behind them. This
* component refuses rather than shrinking anything: an engine that quietly re-optimises a
* split is an engine whose benchmarks do not reproduce (spec §6). A zero here means the
* resolver was never called, which is a wiring bug and gets named as one. */
std::string missing;
if (cfg.vram_weights_mib <= 0) missing += " vram_weights resolved to 0 MiB\n";
if (cfg.vram_kv_mib <= 0) missing += " vram_kv resolved to 0 MiB\n";
if (!missing.empty()) {
fit_report_ = "VRAM pool budgets are empty -- state --vram-weights-mib / --vram-kv-mib, or "
"let the card be split from --gpu-headroom-mib and --host-pool-mib:\n"
+ missing;
fit_report_ = "VRAM pool budgets are empty: the budget resolver (core/mem/vram_budget.cpp) "
"did not run before the pools were configured:\n" + missing;
RAD_ERR("%s", fit_report_.c_str());
return RAD_E_INVAL;
}
@@ -230,8 +228,8 @@ int Pools::configure(const Config& cfg, int64_t vram_capacity,
" total %10s\n"
" card total %10s\n"
" OVER BY %10s\n"
"Lower --vram-weights-mib / --vram-kv-mib, or state neither and let the card be split "
"from --gpu-headroom-mib and --host-pool-mib (spec §6).\n",
"The resolved split is larger than the card, which the resolver does not produce: a "
"wiring bug (spec §6).\n",
humanb(w).c_str(), humanb(kv).c_str(),
humanb(want).c_str(), humanb(vram_capacity).c_str(),
humanb(want - vram_capacity).c_str());
@@ -239,30 +237,6 @@ int Pools::configure(const Config& cfg, int64_t vram_capacity,
return RAD_E_NOMEM;
}
/* THE SLACK IS NAMED, because nothing else will name it -- and after the resolver ran there
* should be almost none. `vram_capacity` is totalGlobalMem: it is not the free VRAM and it is
* not the sum of the budgets. What is left over here is the driver's residency, the activation
* arena, --gpu-headroom-mib, and whatever MiB rounding could not place; vram_budget.cpp's
* report breaks that down term by term. A budget a couple of GiB under the card is that much
* of the expert plane streaming from host memory instead, which costs real prefill throughput
* on a model whose experts do not fit.
*
* THIS IS FOR A STATED BUDGET AND ONLY FOR ONE. A size threshold cannot tell the two apart: a
* small dense model whose cache is already at the largest context it can address leaves many
* GiB that NOTHING can spend, and warning there would tell the operator to leave unset the
* very flags they already left unset. Where the resolver made the split it has already printed
* every term including the unusable one, and there is nothing to add. */
if (vram_capacity > 0 && !cfg.vram_budget_derived) {
const int64_t slack = vram_capacity - want;
if (slack >= 1024 * MiB)
RAD_WARN("VRAM budgets total %s of the card's %s, so %s is neither budgeted nor "
"accounted. The driver's context, the activation arena and "
"--gpu-headroom-mib come out of it; anything past those is throughput on the "
"floor. Leave --vram-weights-mib / --vram-kv-mib unset to have the card split "
"automatically.",
humanb(want).c_str(), humanb(vram_capacity).c_str(), humanb(slack).c_str());
}
int st = RAD_OK;
int s;
/* Order matters only for the diagnostic: allocate the two big ones first so a failure names
+2 -2
View File
@@ -342,7 +342,7 @@ int PrefixCache::insert(uint64_t session,
const std::vector<int32_t>& tokens,
const std::vector<MMContentKey>& mm,
const std::vector<std::vector<int32_t>>& blocks,
int64_t n_tokens) {
int64_t n_tokens, const std::string& label) {
if (!enabled_) return RAD_OK;
if (blocks.size() != groups_.size()) return RAD_E_INVAL;
if (n_tokens > (int64_t)tokens.size()) return RAD_E_INVAL;
@@ -427,7 +427,7 @@ int PrefixCache::insert(uint64_t session,
if (it == map_.end()) continue;
tiers_->note_used(hs[(size_t)b], it->second.blocks, now);
}
tiers_->note_session(session, hs, n_tokens, now);
tiers_->note_session(session, hs, n_tokens, now, label);
}
/* A CONVERSATION'S SNAPSHOTS BELONG TO ITS LATEST TURN. The index keys a session by REQUEST
+2 -1
View File
@@ -206,7 +206,8 @@ public:
const std::vector<int32_t>& tokens,
const std::vector<MMContentKey>& mm,
const std::vector<std::vector<int32_t>>& blocks,
int64_t n_tokens);
int64_t n_tokens,
const std::string& label = std::string());
/* Drop the least recently used entries, releasing their KV references. Returns how many were
* dropped. Blocks a live sequence still holds stay allocated -- releasing the cache's
+45 -68
View File
@@ -82,11 +82,21 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
const bool shared = host_reserve > b.headroom;
if (shared) b.headroom = host_reserve;
/* A host backend has no VRAM to speak of and reports none; there is nothing here to resolve
* and inventing a capacity would be exactly the inference §6 forbids. */
/* A DEVICE THAT REPORTS NO CAPACITY HAS NOTHING TO SPLIT, and inventing a capacity would be
* exactly the inference §6 forbids. What each pool needs is still known: the weights pool
* holds what the planner would copy out of the container -- the statics and experts
* weight_footprint counts -- and the cache is its ceiling, every sequence at the full context.
* (The host backend reports half the machine's memory and is split like a card.) */
if (b.capacity <= 0) {
b.weights = cfg.vram_weights_mib * kMiB;
b.kv = cfg.vram_kv_mib * kMiB;
b.weights = std::max<int64_t>(b.statics + b.expert_ceiling, kMiB);
b.kv = std::max<int64_t>(b.kv_ceiling, kMiB);
cfg.vram_weights_mib = to_mib_up(b.weights);
cfg.vram_kv_mib = to_mib_up(b.kv);
if (log)
b.report = fmt("the device reports no capacity: weights pool %s (what the planner "
"copies out of the container), cache %s (every sequence at the full "
"context)", humanb(cfg.vram_weights_mib * kMiB).c_str(),
humanb(cfg.vram_kv_mib * kMiB).c_str());
if (out) *out = b;
return RAD_OK;
}
@@ -98,17 +108,10 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
* plugin's init has run and its code object is resident. */
b.already_held = std::max<int64_t>(b.capacity - freeb, 0);
const bool want_w = cfg.vram_weights_mib <= 0;
const bool want_kv = cfg.vram_kv_mib <= 0;
b.derived_weights = want_w;
b.derived_kv = want_kv;
/* What is left after the terms nobody gets to spend. */
b.drift = (want_w || want_kv) ? kDriverDrift : 0;
int64_t fixed = b.already_held + b.drift + b.headroom + b.arena + b.staging + b.queues;
if (!want_w) fixed += cfg.vram_weights_mib * kMiB; /* a stated pool is fixed too */
if (!want_kv) fixed += cfg.vram_kv_mib * kMiB;
b.claimable = b.capacity - fixed;
b.drift = kDriverDrift;
b.claimable = b.capacity - (b.already_held + b.drift + b.headroom + b.arena + b.staging +
b.queues);
if (b.claimable < 0) {
b.report = fmt(
@@ -120,7 +123,6 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
" activation arena %10s (buffer plan + kernel scratch)\n"
" step staging %10s (block tables, media and KV tier staging)\n"
" hardware queues %10s (%d at %s each, measured)\n"
"%s%s"
" ------------------------------\n"
" SHORT BY %10s\n"
"Lower --gpu-headroom-mib, lower --max-num-batched-tokens (the arena scales with it), "
@@ -128,42 +130,31 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
humanb(b.capacity).c_str(), humanb(b.already_held).c_str(), humanb(b.drift).c_str(),
humanb(b.headroom).c_str(), humanb(b.arena).c_str(), humanb(b.staging).c_str(),
humanb(b.queues).c_str(), b.n_queues, humanb(b.queue_bytes).c_str(),
want_w ? "" : fmt(" --vram-weights-mib %10s (stated)\n",
humanb(cfg.vram_weights_mib * kMiB).c_str()).c_str(),
want_kv ? "" : fmt(" --vram-kv-mib %10s (stated)\n",
humanb(cfg.vram_kv_mib * kMiB).c_str()).c_str(),
humanb(-b.claimable).c_str());
if (log) RAD_ERR("%s", b.report.c_str());
if (out) *out = b;
return RAD_E_NOMEM;
}
b.weights = want_w ? 0 : cfg.vram_weights_mib * kMiB;
b.kv = want_kv ? 0 : cfg.vram_kv_mib * kMiB;
/* ---- the static weights come off the top ------------------------------------------------
*
* They are a floor and not a share. Only a DERIVED weight budget pays them here: an operator
* who stated --vram-weights-mib has already decided what the weights get, and second-guessing
* that is the re-optimisation §6 forbids. */
if (want_w) {
b.statics = std::min(b.statics, b.claimable);
if (b.statics >= b.claimable && b.claimable > 0) {
/* Not fatal: the planner will demote what does not fit and the model still serves,
* badly. Name it, because "why is this model 8x slower than it should be" has no other
* answer at startup. */
if (log) RAD_WARN("the static (non-expert) weights alone want %s of the %s this card has to "
"give. Every expert will stream from host memory and the KV cache has "
"nothing left -- this model wants more VRAM, fewer ranks of it, or a smaller "
"--max-num-batched-tokens.",
humanb(b.statics).c_str(), humanb(b.claimable).c_str());
}
* They are a floor and not a share. */
b.statics = std::min(b.statics, b.claimable);
if (b.statics >= b.claimable && b.claimable > 0) {
/* Not fatal: the planner will demote what does not fit and the model still serves,
* badly. Name it, because "why is this model 8x slower than it should be" has no other
* answer at startup. */
if (log) RAD_WARN("the static (non-expert) weights alone want %s of the %s this card has to "
"give. Every expert will stream from host memory and the KV cache has "
"nothing left -- this model wants more VRAM, fewer ranks of it, or a smaller "
"--max-num-batched-tokens.",
humanb(b.statics).c_str(), humanb(b.claimable).c_str());
}
b.elastic = want_w ? b.claimable - b.statics : b.claimable;
b.elastic = b.claimable - b.statics;
if (b.elastic < 0) b.elastic = 0;
/* ---- and only what is left is divided --------------------------------------------------- */
if (want_w && want_kv) {
{
/* An unset cache ceiling (plan_groups failed) bounds nothing; zero experts is a ceiling of
* zero, which weight_footprint always measures. */
const int64_t kv_cap = b.kv_ceiling > 0 ? b.kv_ceiling : b.elastic;
@@ -198,20 +189,12 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
b.kv = kv;
b.weights = b.statics + exp;
b.unusable = std::max<int64_t>(b.elastic - kv - exp, 0);
} else if (want_kv) {
b.kv = b.kv_ceiling > 0 ? std::min(b.claimable, b.kv_ceiling) : b.claimable;
b.unusable = b.claimable - b.kv;
} else if (want_w) {
/* The KV pool was stated, so `claimable` is already net of it; the weights take the rest,
* still capped at what the model has to put there. */
int64_t exp = b.elastic;
if (exp > b.expert_ceiling) {
b.unusable = exp - b.expert_ceiling;
exp = b.expert_ceiling;
}
b.experts = exp;
b.weights = b.statics + exp;
}
/* A POOL NOTHING IS PLACED IN STILL HAS TO EXIST. Where every weight is read where the
* container's mapping has it -- every op on the host, on the host backend -- the statics and
* experts are zero, and the pools refuse a zero budget as a resolver that never ran. A MiB,
* out of the headroom as the rounding's is. */
b.weights = std::max<int64_t>(b.weights, kMiB);
/* ---- THE PREFILL STAGING REGION, out of the expert share ---------------------------------
*
@@ -227,12 +210,12 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
* The share is the budget's -- what the slab alone leaves off -- which is the most a step can
* see: the loans the KV cache and the smaller arena levels make only ever add residency. A
* layer whose pooled part is larger than a buffer stages what fits and streams the rest. */
if (want_w && layer_max > 0 && b.expert_ceiling > b.experts && cfg.placement != "all_vram" &&
if (layer_max > 0 && b.expert_ceiling > b.experts && cfg.placement != "all_vram" &&
cfg.placement != "layer_offload") {
const double f = (double)(b.expert_ceiling - b.experts) / (double)b.expert_ceiling;
const int64_t one = ((int64_t)std::ceil(f * (double)layer_max) + RAD_ALIGN_UNIT - 1) /
RAD_ALIGN_UNIT * RAD_ALIGN_UNIT;
if (b.lends && want_kv) {
if (b.lends) {
/* A LENDING CACHE PAYS FOR IT: the experts are at their floor and a byte less would
* leave one with no tier, while the region is lent to the slab whenever the steps are
* small -- the same memory the cache would have lent. */
@@ -263,7 +246,7 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
* because it is a real limit rather than a ratio, is that ONE max-length sequence fits: a
* context no single request can complete is a configuration error however much slack the pool
* has (core/engine_bringup.cpp, configure_kv). */
if (log && b.derived_kv && b.kv_ceiling > 0 && cfg.max_ctx > 0)
if (log && b.kv_ceiling > 0 && cfg.max_ctx > 0)
RAD_INFO("kv: the pool backs %.0f%% of the worst case (%lld sequences all at %lld tokens), "
"%.1f full-length sessions. That is concurrency at length before the scheduler "
"preempts, not a bound on any one request. WITH PREFIX CACHING a finished "
@@ -276,13 +259,11 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
(long long)cfg.max_seqs, (long long)cfg.max_ctx,
(double)cfg.max_seqs * paged_share(b));
/* Rounding the floor up claims up to a MiB the split did not hand out. Take it back from the
* cache where the cache is ours to size -- a paged pool a MiB smaller addresses a handful
* fewer tokens and nothing else -- so the headroom stays whole. Where the KV budget was
* STATED it is not ours to shave and the MiB comes out of the headroom instead. */
cfg.vram_budget_derived = want_w || want_kv;
* cache -- a paged pool a MiB smaller addresses a handful fewer tokens and nothing else -- so
* the headroom stays whole. */
cfg.vram_weights_mib = to_mib_up(b.weights);
const int64_t w_over = cfg.vram_weights_mib * kMiB - b.weights;
cfg.vram_kv_mib = want_kv ? to_mib(std::max<int64_t>(b.kv - w_over, 0)) : to_mib(b.kv);
cfg.vram_kv_mib = to_mib(std::max<int64_t>(b.kv - w_over, 0));
/* THE RECEIPT. Every term, in the order it was spent, so that a split anybody disagrees with
* can be argued about against numbers instead of re-derived from sysfs by hand. The unclaimed
@@ -320,13 +301,11 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
humanb(b.arena).c_str(), humanb(b.staging).c_str(),
humanb(b.queues).c_str(), b.n_queues, humanb(b.queue_bytes).c_str(),
shared ? "left to the host" : "--gpu-headroom-mib", humanb(b.headroom).c_str(),
shared ? "integrated graphics: this memory is the host's; --vram-kv-mib states a pool "
"outright"
shared ? "integrated graphics: this memory is the host's"
: "left unclaimed on purpose",
humanb(b.claimable).c_str(),
humanb(b.statics).c_str(),
b.derived_weights ? "off the top: every rank's own shard, and not a share of anything"
: "(not charged here -- --vram-weights-mib was stated)",
"off the top: every rank's own shard, and not a share of anything",
humanb(b.elastic).c_str(),
b.lends ? "the experts keep what the host pool cannot hold; the cache takes the rest\n"
" and lends what no live request holds to the "
@@ -375,10 +354,8 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
"slab while steps are small\n", humanb(b.stage).c_str(),
b.lends ? "cache" : "experts").c_str()
: "",
humanb(cfg.vram_weights_mib * kMiB).c_str(),
b.derived_weights ? "static + experts" : "stated by --vram-weights-mib",
humanb(cfg.vram_kv_mib * kMiB).c_str(),
b.derived_kv ? "the cache's share" : "stated by --vram-kv-mib",
humanb(cfg.vram_weights_mib * kMiB).c_str(), "static + experts",
humanb(cfg.vram_kv_mib * kMiB).c_str(), "the cache's share",
humanb(unclaimed).c_str());
if (out) *out = b;
+14 -7
View File
@@ -3,7 +3,7 @@
* ============================== WHY THIS IS NOT THE §6 VIOLATION IT LOOKS LIKE ==============================
*
* Spec §6 says the engine does not derive its budgets, and core/mem/pools.cpp still refuses to
* re-optimise a split the operator stated. The reason given there is exact and worth repeating:
* re-optimise the split it is handed. The reason given there is exact and worth repeating:
* a budget derived from the FREE VRAM at startup is a benchmark that moves when somebody opens a
* window on the machine's desktop.
*
@@ -46,10 +46,17 @@
* (KVManager::ceiling), and an expert plane that fits entirely in VRAM has no use for more; when
* both fit, both are whole.
*
* A stated --vram-weights-mib or --vram-kv-mib still wins outright and turns the whole of this
* off for that pool. The point is that the DEFAULT is a full card rather than a guess: VRAM left
* THERE IS NO FLAG THAT STATES A POOL. The split is a full card rather than a guess: VRAM left
* unbudgeted is VRAM no pool can use, and on a model whose experts do not fit, every unbudgeted
* GiB costs measurable decode time.
* GiB costs measurable decode time. What an operator moves is the inputs -- --gpu-headroom-mib
* takes card space away, --max-model-len and --max-num-seqs bound the cache, --host-pool-mib
* decides which experts must stay on the card -- and the arithmetic follows from them.
*
* A HOST BACKEND HAS NO CARD, and half the machine's memory stands in for one (host_vram_bytes),
* split as a card's is. Its weights pool is host memory and holds what a host kernel cannot read
* where the container stores it (mapped_unit in core/place/planner.h). A device that reports no
* capacity at all is sized at what each pool needs: the weights the planner copies, and the cache
* at its ceiling.
*/
#pragma once
#include "../rad_core.h"
@@ -97,8 +104,9 @@ struct VramFacts {
int64_t host_reserve = 0;
};
/* The resolved split, in bytes, beside every term it came from. Always filled, including when the
* operator stated the budgets -- the placement report and the pool report both want the totals. */
/* The resolved split, in bytes, beside every term it came from. Always filled, including for a
* device that reports no capacity -- the placement report and the pool report both want the
* totals. */
struct VramBudget {
int64_t capacity = 0, already_held = 0, headroom = 0, arena = 0, staging = 0;
int64_t drift = 0; /* kDriverDrift: what already_held moves by after it is read */
@@ -120,7 +128,6 @@ struct VramBudget {
* any. */
int64_t stage = 0;
int64_t weights = 0; /* statics + experts: what vram_weights is set to */
bool derived_weights = false, derived_kv = false;
std::string report; /* the block the engine prints at startup */
};