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

+4 -4
View File
@@ -114,8 +114,8 @@ Mover::~Mover() {
}
/* One place the mover asks for memory. Everything device-side and everything pinned comes out of
* the budgets the operator stated (spec §6); the fallback exists so the placement test can run
* without standing a whole Pools up, and it announces itself. */
* the resolved budgets (spec §6); the fallback exists so the placement test can run without
* standing a whole Pools up, and it announces itself. */
void* Mover::reserve(const char* what, int64_t bytes, int kind) {
if (bytes <= 0) return nullptr;
if (budget_) {
@@ -134,7 +134,7 @@ int Mover::init(const Program& prog, const Plan& plan, const MoverConfig& cfg, P
stats_ = MoverStats{};
if (!budget_)
RAD_WARN("mover: no Pools handed over; allocating its slab and host pool directly. That "
"double-spends --vram-weights-mib against whatever else already reserved it, so "
"double-spends the weights pool against whatever else already reserved it, so "
"it is a test path and not a deployment.");
unit_.assign(plan.units.size(), UnitState{});
@@ -180,7 +180,7 @@ int Mover::init(const Program& prog, const Plan& plan, const MoverConfig& cfg, P
* resident count is untouched by turning the engine on. Under a static plan the plan
* asked for none and the slab is exactly the resident set. */
/* THE PLAN'S NUMBER, not a config cap. The planner reserved these out of
* --vram-weights-mib and the report told the operator how many; allocating a different
* the weights pool and the report told the operator how many; allocating a different
* count here would mean the mover works against one number while the operator was charged
* for another, and the direction that is wrong in is an overrun. */
const int64_t shadow = plan.dynamic ? sc.n_shadow : 0;
+4 -4
View File
@@ -336,7 +336,7 @@ private:
/* ------------------------------------------------------------------ configuration */
struct MoverConfig {
/* Shadow slots and the staging ring are NOT here. They are budgeted by the planner out of
* --vram-weights-mib and reported in the plan (SlabClass::n_shadow, n_stage), and a second
* the weights pool and reported in the plan (SlabClass::n_shadow, n_stage), and a second
* knob for the same quantity is a second number for the mover and the operator to disagree
* about -- with an overrun as the direction that disagreement goes wrong in.
*
@@ -419,7 +419,7 @@ public:
* diagnosis.
*
* `budget` IS THE PRODUCTION PATH AND SHOULD ALWAYS BE PASSED. Pools already allocated
* --vram-weights-mib as one block; a mover that called rad_dev_alloc beside it would spend
* the weights pool as one block; a mover that called rad_dev_alloc beside it would spend
* that budget TWICE and the overrun would surface as an out-of-memory from an unrelated
* launch much later. Reserving from Pools::weights() is also what makes it structurally
* impossible for a promotion to reach a KV block -- there is no path from the weights pool to
@@ -598,7 +598,7 @@ public:
* grouped GEMM is handed every expert's pointer at issue -- so before a routed layer's first
* expert op, every one of its file-tier units is read into a VRAM buffer and published there,
* and after the layer it is published as null again (unstage_units does that half). The
* buffers are the two the plan charged out of --vram-weights-mib (Plan::file_stage_vram).
* buffers are the two the plan charged out of the weights pool (Plan::file_stage_vram).
*
* stage_file_units read every unit of `units` that is on the file tier into `dst`, packed at
* RAD_ALIGN_UNIT in the order given, through the pinned read windows: the
@@ -655,7 +655,7 @@ private:
};
/* One weight class's memory. The slab is two kinds of slot rather than one: the BUDGETED slots
* come out of --vram-weights-mib like every other weight allocation and sit at a fixed stride
* come out of the weights pool like every other weight allocation and sit at a fixed stride
* from one base, and the FLEX slots past them are addresses inside another pool's memory --
* the KV cache's carve, the activation arena's top -- lent while that pool is not using them.
* They cannot be one range because the flex slots are scattered over every layer's stripe of
+24 -15
View File
@@ -80,7 +80,7 @@ int strategy_parse(const char* s, Strategy* out) {
Budgets Budgets::from(const Config& c) {
Budgets b;
b.vram_weights = c.vram_weights_mib * 1024 * 1024;
b.host_pool = c.host_pool_mib * 1024 * 1024;
b.host_pool = (c.host_pool_mib + c.embedding_host_mib) * 1024 * 1024;
b.ssd = c.weights_disk_tier;
return b;
}
@@ -123,7 +123,7 @@ int plan_check_weights_pool(const Plan& p, int64_t pool_bytes) {
}
void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement embedding,
TablePlacement ngram) {
TablePlacement ngram, bool host_backend, bool container) {
if (!out) return;
*out = WeightFootprint{};
@@ -146,7 +146,7 @@ void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement
/* build_units: a model-level weight is its own unit, everything else groups by the declared
* (layer, expert). Ordered, for the same reason build_units is. */
struct U { int32_t layer = -1, expert = -1; int64_t bytes = 0; bool mapped = false;
bool emb = false, ngram = false, host = true; };
bool emb = false, ngram = false, host = true, direct = true; };
std::map<std::pair<int32_t, int32_t>, size_t> by_group;
std::vector<U> units;
@@ -175,6 +175,7 @@ void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement
mu.bytes = align_up(mu.bytes, a) + weight_bytes(wi);
/* pin_mapped: THE WHOLE UNIT GOES, not the one weight. */
if (w < device_ok.size() && !device_ok[w]) mu.mapped = true;
if (!weight_file_direct(wi, prog.ctx.world_size)) mu.direct = false;
if (w < host_ok.size() && !host_ok[w]) mu.host = false;
/* The placement flags' tables: model-level, so the unit is this one weight. */
if (layer < 0) {
@@ -186,6 +187,7 @@ void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement
/* And one align_up a unit, because that is how Mover::init spends the slab: `us.static_off =
* align_up(static_need, RAD_ALIGN_UNIT)` before every unit it places. A budget that summed raw
* bytes would be short by one alignment per unit, which on a 512-expert MoE is real. */
for (U& mu : units) mu.mapped = mapped_unit(mu.mapped, container && mu.direct, host_backend);
std::map<int32_t, int64_t> layer_experts;
std::set<int64_t> expert_strides;
bool ngram_host = true;
@@ -284,8 +286,8 @@ void Planner::resolve_sites(const Program& prog) {
* consulted, because it is not a budget question -- and so is an n-gram table --ngram-placement put
* in RAM or on disk, whatever kernels could read it on a card. The other three off-device tiers are
* what the planner falls back to when VRAM runs out; this one is where the weight has to be
* whatever the budgets say, and charging a pool for bytes that are never copied would make the
* operator size a pool against a number that does not exist.
* whatever the budgets say, and charging a pool for bytes that are never copied would size that
* pool against a number that does not exist.
*
* THE WHOLE UNIT GOES, not the one weight. A unit is the movement granularity and a half-mapped one
* has no meaning -- and it costs nothing here, because `device_ok_` is cleared for EVERY weight
@@ -295,9 +297,15 @@ void Planner::resolve_sites(const Program& prog) {
void Planner::pin_mapped(const Program& prog, Plan* p) {
const TablePlacement ng = in_.config->ngram_resolved;
for (MoveUnit& mu : p->units) {
bool host_only = false;
for (rad_weight w : mu.weights)
bool host_only = false, direct = in_.container;
for (rad_weight w : mu.weights) {
if (w < device_ok_.size() && !device_ok_[w]) host_only = true;
if (w < prog.weights.size() &&
!weight_file_direct(prog.weights[w], prog.ctx.world_size)) direct = false;
}
/* On the host backend a unit stored in another form than its host kernel reads is placed
* like any other weight, in the pool its kernel can read too (mapped_unit). */
host_only = mapped_unit(host_only, direct, in_.host_backend);
/* --ngram-placement keeps an n-gram table OFF THE CARD unless it says vram, whether or not
* a device kernel could read it there: ram and disk are where the operator put it, and the
* strategies below would otherwise spend the card on 48 GB of rows read sixteen a token. */
@@ -619,8 +627,8 @@ int Planner::assign_all_vram(Plan* p) {
used += mu.slot_bytes;
}
if (p->vram_budget > 0 && used > p->vram_budget) {
p->notes.push_back(fmt("all_vram needs %s of weights against a --vram-weights-mib "
"budget of %s: %s short",
p->notes.push_back(fmt("all_vram needs %s of weights against a weights pool "
"of %s: %s short",
humanb(used).c_str(), humanb(p->vram_budget).c_str(),
humanb(used - p->vram_budget).c_str()));
return RAD_E_NOMEM;
@@ -768,9 +776,9 @@ int Planner::assign_expert_tiered(Plan* p) {
rank_units(p, &order);
/* RESERVE THE SPARE SLOTS OUT OF THE BUDGET. The slab has to hold the residents AND the
* shadow slots a promotion writes into, and they all come out of --vram-weights-mib -- so a
* shadow slots a promotion writes into, and they all come out of the weights pool -- so a
* fill that spends the whole budget on residents leaves the mover with nowhere to move into
* and, worse, makes the mover's allocation overrun the pool the operator sized.
* and, worse, makes the mover's allocation overrun the weights pool.
*
* Two passes, and the second is enough: the reserve depends only on the first pass's slot
* counts, and the first pass over-counts (it had more room), so the reserve it produces is an
@@ -900,7 +908,7 @@ int Planner::assign_expert_tiered(Plan* p) {
k = fill(uncapped, --cap);
if (fixed + k.used + k.spare + k.file > p->vram_budget) {
p->notes.push_back(fmt("the file tier's two layer buffers need %s, beside %s of "
"fixed weights, against a --vram-weights-mib budget of %s",
"fixed weights, against a weights pool of %s",
humanb(k.file).c_str(), humanb(fixed).c_str(),
humanb(p->vram_budget).c_str()));
return RAD_E_NOMEM;
@@ -1119,8 +1127,8 @@ int Planner::pin_embedding(const Program& prog, const Config& cfg, Plan* p) cons
mu.host_forced = true;
mu.reason = "--embedding-placement ram; read over the link in place";
RAD_INFO("placement: '%s' (%s) in the pinned host pool, read in place "
"(--embedding-placement %s)", name.c_str(), humanb(mu.bytes).c_str(),
cfg.embedding_placement == TablePlacement::Auto ? "auto" : "ram");
"(--embedding-placement ram%s)", name.c_str(), humanb(mu.bytes).c_str(),
cfg.embedding_placement_given ? "" : ", the default");
}
/* Engine::plan resolves Ram only where weight_footprint found a table with this same test,
* so an empty pass is a plan built from a different program than the budget was: a wiring
@@ -1243,7 +1251,8 @@ int Planner::assign(Plan* p) {
/* Every pool is budgeted explicitly (spec §6). An offload strategy with no number to
* spill against would have to infer one from free VRAM, and an engine that quietly
* re-optimises its own split is an engine whose benchmarks do not reproduce. */
RAD_ERR("placement: %s needs --vram-weights-mib; there is nothing to spill against",
RAD_ERR("placement: %s needs a weights budget and none was resolved; there is nothing to "
"spill against",
strategy_name(s));
return RAD_E_INVAL;
}
+23 -6
View File
@@ -111,7 +111,7 @@ struct MoveUnit {
/* WHAT THE UNIT ACTUALLY COSTS A POOL, which is its class's slot stride and not `bytes`. The
* planner budgets against this and the mover allocates this, so the two cannot drift -- and
* the direction they would drift in is an overrun of the pool the operator sized. `bytes` is
* the direction they would drift in is an overrun of the weights pool. `bytes` is
* still what the report attributes to the weights, because padding is not a weight. */
int64_t slot_bytes = 0;
@@ -179,7 +179,7 @@ struct SlabClass {
/* SHADOW SLOTS: slab slots that are allocated but hold no unit, so a promotion writes into one
* and only then publishes and never DMAs over a slot a kernel might still be reading (mover.h).
*
* THEY COME OUT OF --vram-weights-mib, like everything else in the slab. Taking them from
* THEY COME OUT OF THE WEIGHTS POOL, like everything else in the slab. Taking them from
* whatever VRAM is left over after the slabs is not an option: spec §6 budgets every pool
* explicitly and --gpu-headroom-mib is memory the engine promises NOT to touch. So dynamic
* placement costs a few resident units, and the plan report prints exactly how many.
@@ -260,7 +260,7 @@ public:
* routed layer starts (place/stager.h, FileStager). `file_layer_max` is the most one layer's
* file-tier units take in a buffer, each at its own size rounded to RAD_ALIGN_UNIT, which is
* how the stager packs them; `file_stage_vram` is the two buffers, taken out of
* --vram-weights-mib before any expert is made resident. Both 0 when nothing routed is on the
* the weights pool before any expert is made resident. Both 0 when nothing routed is on the
* file tier. */
int64_t file_layer_max = 0;
int64_t file_stage_vram = 0;
@@ -310,8 +310,23 @@ struct PlannerInput {
* served directly is neither grouped by movement unit nor aligned for O_DIRECT, so with this
* false no unit is file-direct and both tiers are closed (spec §4.3). */
bool container = true;
/* No card is visible and the device backend is the host's own memory (device_is_host()), so a
* host kernel can read the weights pool as well as the container's mapping. See
* mapped_unit(). */
bool host_backend = false;
};
/* DOES A UNIT STAY IN THE CONTAINER'S MAPPING because only a host kernel can read it? On a card,
* always: a host kernel cannot read VRAM, and the mapping is the one host address its bytes
* already have. On the host backend the weights pool is host memory too, and a unit whose stored
* form is not the container's (a widening or a relayout its host kernel asked for at load, or a
* checkpoint served directly) has no place in the mapping that looks the way its kernel reads it,
* so there it takes a converted copy in the weights pool like any other weight. One rule, for the
* planner and the budget alike. */
inline bool mapped_unit(bool host_only, bool direct, bool host_backend) {
return host_only && (direct || !host_backend);
}
class Planner {
public:
explicit Planner(const PlannerInput& in) : in_(in) {}
@@ -399,10 +414,12 @@ struct WeightFootprint {
};
/* `embedding` is what the token embedding's placement resolved to; only Ram moves it out of the
* statics. `ngram` is the n-gram table's; only Vram puts it among them, and only where a device
* kernel reads it. Stated by every caller, so the budget and the planner cannot count it
* differently. */
* kernel reads it. `host_backend` and `container` are PlannerInput's: whether a host kernel can
* read the weights pool, and whether the weights lie in a container at all (a checkpoint served
* directly has no mapping a unit could stay in). Stated by every caller, so the budget and the
* planner cannot count it differently. */
void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement embedding,
TablePlacement ngram);
TablePlacement ngram, bool host_backend, bool container);
/* THE PINNED STAGING THE FILE TIER TAKES OUT OF --host-pool-mib before any unit is placed in it:
* RAD_PLACE_FILE_STAGE_SLOTS of the widest per-layer unit, and the read windows when a routed