radiance 1.5.0

- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their
  own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a
  fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a
  prefix hit on a sliding-window model resumes instead of prefilling again.
  deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards
- ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations,
  as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix
  cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made
  with the PR builds is refused: convert it again with --reuse <old container>
- Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16
  checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe),
  and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and
  the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces
  beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed
  attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9
- a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD
  request by name), the library that made it, and its stack, which addr2line resolves against the
  binary
- the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and
  snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib
  is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and
  startup refuses all three with what replaced them. The compose files no longer mount /data, and
  .env no longer needs RADIANCE_STATE
- --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long
  leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A
  full host tier now drops its least recently used conversations
- --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and
  gives its VRAM to the KV cache, read over the link once an image
- timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival
  to the first and the last token, queueing and tokenisation included
- a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the
  slots it had already freed: after it every recall failed, the cache stayed short until a
  restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and
  always finishes
- a tool result or tool-call arguments that are not JSON are no longer refused as nesting past
  1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the
  bound, since nothing else is parsed into a tree
- the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and
  1.5 GiB), not ttm.pages_limit
- --embedding-placement auto, removed in 1.3.0, is refused with what replaced it
- for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and
  the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For
  architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary
  without declaring it
This commit is contained in:
Deadcode committed 2026-10-13 19:35:16 +02:00
commit b93b531f63
127 files changed
+9609 -4796

No files matched your search

+39 -16
View File
@@ -1115,9 +1115,10 @@ int Mover::drop(int32_t unit, HeatEngine* heat) {
* slot or back across the link (reclaim), and a loan that shrinks under it moves it the same way
* (balance). There is always somewhere for it to go -- each donor's copy went to a unit
* whose budgeted slot it left free, so the free budgeted slots and the free pool slots together
* number at least the donors. The donors are bounded by the turnover slots, and they come out of
* the KV cache's loan only: the arena takes its loan back at every prompt's first chunk, and that
* recall stays a change of address.
* number at least the donors once the quarantine has emptied (a recall drains it first). The
* donors are bounded by the turnover slots, and they come out of the KV cache's loan only: the
* arena takes its loan back at every prompt's first chunk, and that recall stays a change of
* address.
*
* THE HOTTEST UNIT GIVES ITS COPY -- of the victim's layer, when pool_slot_for asks for one --
* because a donor the engine later demotes needs a pool slot of its own where it would have been a
@@ -1458,13 +1459,28 @@ int Mover::reclaim(int lender, int64_t amount, HeatEngine* heat) {
RAD_TRY(flush_moves());
RAD_TRY(rad_stream_sync(mover_));
RAD_TRY(retire(heat));
/* AND NO SLOT IS STILL IN QUARANTINE. The slots the donors below are owed come back through
* it: a donation's victim leaves its budgeted slot that way, and a promotion that refilled the
* slot leaves its pool slot that way (donor_slot). Looked for before the compute stream has
* passed their barriers, the slots of the last few dispatches' swaps are not free yet, and a
* donor finds nowhere to go. Nothing goes on the compute stream from this drain to the end of
* the recall, which issues only the mover's own copies. */
RAD_TRY(rad_stream_sync(compute_));
RAD_TRY(retire(heat));
/* EVERY UNIT PAST THE LOAN GOES BACK TO ITS HOST COPY, which is a change of address -- or,
* for a donor (donor_slot), which has none, it moves: into a free budgeted slot, a copy inside
* the card, or else back across the link into a free pool slot. One of the two is free for
* every donor (donor_slot says why). Nothing is published until the copies have landed. */
* every donor once the quarantine is empty (donor_slot says why). Nothing is published until
* the copies have landed.
*
* A DONOR WITH NOWHERE TO GO STAYS WHERE IT IS, and the recall still finishes: every other
* slot is given back and every moved donor published, so the loan stops short only by that
* unit's slot, and a later recall or balance() moves it. Stopping at it instead would leave
* the slots already taken off their units held by nothing, for the life of the process. */
std::vector<std::pair<size_t, int64_t>> freed;
std::vector<int32_t> moved;
int stuck = 0;
for (int32_t u = 0; u < (int32_t)unit_.size(); ++u) {
UnitState& us = unit_[(size_t)u];
if (us.klass < 0 || us.slab_slot < 0) continue;
@@ -1477,16 +1493,11 @@ int Mover::reclaim(int lender, int64_t amount, HeatEngine* heat) {
cp.slab.add_free(to);
to = -1;
}
const int64_t g = to < 0 ? cp.pool.take() : -1;
if (to >= 0) {
RAD_TRY(rad_memcpy_async(cp.slot_ptr(to), cp.slot_ptr(from), us.bytes, mover_));
us.slab_slot = to;
} else {
const int64_t g = cp.pool.take();
if (g < 0) {
RAD_ERR("mover: unit %d gave its host copy away and neither a budgeted slot nor "
"a pool slot is free to move it to", (int)u);
return RAD_E_STATE;
}
} else if (g >= 0) {
RAD_TRY(rad_memcpy_async((char*)cp.pool_base + g * cp.stride, cp.slot_ptr(from),
us.bytes, mover_));
us.pool_slot = g;
@@ -1499,6 +1510,9 @@ int Mover::reclaim(int lender, int64_t amount, HeatEngine* heat) {
heat->set_tier(u, Tier::HostPinned);
heat->set_busy(u, false);
}
} else {
++stuck;
continue;
}
--cp.n_donated;
++stats_.relocated;
@@ -1525,9 +1539,9 @@ int Mover::reclaim(int lender, int64_t amount, HeatEngine* heat) {
}
/* AND NO KERNEL STILL NAMES ONE. The compute stream is the only reader of the slab -- the
* quarantine barrier rests on the same fact -- so once it has drained, nothing already issued
* can reach a slot past the loan, and everything issued from here reads the host copies. */
RAD_TRY(rad_stream_sync(compute_));
* quarantine barrier rests on the same fact -- and it drained above with nothing issued since,
* so nothing can reach a slot past the loan, and everything issued from here reads the host
* copies. */
for (const auto& f : freed) pools_[f.first].slab.add_free(f.second);
/* EVERY RECORD WAITING ON ONE OF THOSE SLOTS IS DONE WAITING: its barrier is behind the
@@ -1550,6 +1564,14 @@ int Mover::reclaim(int lender, int64_t amount, HeatEngine* heat) {
m.slab_slot = m.pool_slot = m.to_slot = -1;
}
count_flex();
if (stuck > 0) {
stats_.stranded += (uint64_t)stuck;
RAD_ERR("mover: %d unit(s) that gave their host copy away found no free slot to move to; "
"the %s loan stops at %lld instead of %lld until they move", stuck,
lender == kLendKV ? "KV" : "arena", (long long)loan_held(lender),
(long long)loan_[lender]);
return RAD_E_FULL;
}
if (loan_held(lender) > loan_[lender]) {
RAD_ERR("mover: recalled the %s loan to %lld and a slot at %lld is still held",
lender == kLendKV ? "KV" : "arena", (long long)loan_[lender],
@@ -1719,8 +1741,9 @@ std::string Mover::report() const {
(unsigned long long)stats_.starved_pool, (unsigned long long)stats_.quarantined);
if (stats_.donated)
s += fmt(" %llu host copies given by lent units to budgeted victims, %llu such units moved "
"by a recall\n",
(unsigned long long)stats_.donated, (unsigned long long)stats_.relocated);
"by a recall, %llu left past one with no free slot\n",
(unsigned long long)stats_.donated, (unsigned long long)stats_.relocated,
(unsigned long long)stats_.stranded);
if (stats_.ssd_reads)
s += fmt(" file tier: %llu demand reads (%.2f GiB), each a blocking pread in the middle "
"of a dispatch. Raise --host-pool-mib.\n",
+3 -2
View File
@@ -422,8 +422,9 @@ struct MoverStats {
uint64_t dropped = 0;
/* Host copies a unit in a lent slot gave to a budgeted victim that had no pool slot to go to
* (Mover::donor_slot), and such units moved rather than dropped when their loan was recalled
* or shrank. */
uint64_t donated = 0, relocated = 0;
* or shrank. `stranded` counts the recalls that found no free slot for one of them: it stayed
* past the loan until a later recall or balance() moved it. */
uint64_t donated = 0, relocated = 0, stranded = 0;
uint64_t ssd_reads = 0, ssd_bytes = 0;
/* The prefill stager's copies (stage_units): layers staged, units and bytes copied, and
* pooled units a buffer had no room left for -- those were read across the link in place.
+63 -5
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 + c.embedding_host_mib) * 1024 * 1024;
b.host_pool = c.host_pool_total_mib() * 1024 * 1024;
b.ssd = c.weights_disk_tier;
return b;
}
@@ -146,7 +146,8 @@ 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, direct = true; };
bool emb = false, ngram = false, host = true, direct = true;
int access = -1; };
std::map<std::pair<int32_t, int32_t>, size_t> by_group;
std::vector<U> units;
@@ -177,6 +178,9 @@ void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement
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;
/* build_units: the group's strongest access class, which says whether it is a tower's. */
if (mu.access < 0 || access_strength(wi.decl.access) > access_strength(mu.access))
mu.access = wi.decl.access;
/* The placement flags' tables: model-level, so the unit is this one weight. */
if (layer < 0) {
mu.emb = is_embedding_table(prog, w);
@@ -198,6 +202,8 @@ void weight_footprint(const Program& prog, WeightFootprint* out, TablePlacement
if (mu.emb && !mu.mapped) out->embedding += b;
if (mu.ngram) out->ngram += b;
if (mu.ngram && !mu.mapped) out->ngram_device = true;
/* pin_towers moves an encoder tower's unit out of the statics on the same test. */
if (mu.access == RAD_ACCESS_PER_REQUEST && !mu.mapped && mu.expert < 0) out->tower += b;
/* pin_mapped: an n-gram table a device kernel reads stays off the card unless it was
* placed in VRAM. */
if (mu.mapped || (mu.ngram && ngram != TablePlacement::Vram)) out->mapped += b;
@@ -1073,7 +1079,7 @@ void Planner::finish(const Program& prog, Plan* p) {
pl.reason = mu.reason;
pl.bytes = weight_bytes(prog.weights[w]);
p->totals.bytes[(int)mu.tier] += pl.bytes;
if (mu.host_forced) p->embedding_host_used += pl.bytes;
if (mu.host_forced) p->forced_host_used += pl.bytes;
}
}
}
@@ -1142,6 +1148,53 @@ int Planner::pin_embedding(const Program& prog, const Config& cfg, Plan* p) cons
return rc;
}
/* --vision-tower-placement ram: EVERY UNIT OF AN ENCODER TOWER goes to the pinned host pool before
* any strategy runs, as the embedding does, at the DeviceZeroCopy site: the encoder's kernels read
* the weights over the link in place, once an image or a clip, and a text-only request never
* touches them. A tower's unit is one whose every weight the architecture declared read once per
* request (RAD_ACCESS_PER_REQUEST) -- the test weight_footprint counted out of the statics with,
* so the budget the card was split by is the one spent here. The test is the access class and not
* the unit's level: a tower is model-level weights (a stem, a merger) and a layer unit a block. */
int Planner::pin_towers(const Config& cfg, Plan* p) const {
if (cfg.tower_resolved != TablePlacement::Ram) return RAD_OK;
auto tower = [](const MoveUnit& mu) {
return mu.access == RAD_ACCESS_PER_REQUEST && mu.expert < 0 && mu.tier != Tier::Mapped &&
!mu.host_forced;
};
int64_t need = 0, n = 0;
for (const MoveUnit& mu : p->units)
if (tower(mu)) { need += mu.slot_bytes; ++n; }
/* Engine::plan resolves Ram only where weight_footprint found a tower with this same test. */
if (!n) {
RAD_ERR("placement: --vision-tower-placement ram, and this rank's program has no weight it "
"reads once per request");
p->notes.push_back("--vision-tower-placement ram: no encoder tower to place");
return RAD_E_STATE;
}
if (need > p->host_budget) {
RAD_ERR("placement: --vision-tower-placement ram: the encoder towers need %s of the pinned "
"host pool and %s of it is left%s", humanb(need).c_str(),
humanb(p->host_budget).c_str(),
p->file_stage_reserve ? " after the file tier's staging" : "");
p->notes.push_back(fmt("--vision-tower-placement ram: the encoder towers (%s) do not fit "
"the host pool", humanb(need).c_str()));
return RAD_E_NOMEM;
}
for (MoveUnit& mu : p->units) {
if (!tower(mu)) continue;
p->host_budget -= mu.slot_bytes;
p->tower_host_bytes += mu.slot_bytes;
mu.tier = Tier::HostPinned;
mu.site = Site::DeviceZeroCopy;
mu.movable = false;
mu.host_forced = true;
mu.reason = "--vision-tower-placement ram; read over the link in place";
}
RAD_INFO("placement: the encoder towers, %lld units (%s), in the pinned host pool, read in place "
"(--vision-tower-placement ram)", (long long)n, humanb(need).c_str());
return RAD_OK;
}
/* ------------------------------------------------------------------ plan */
int Planner::plan(Plan* out) {
if (!out || !in_.program || !in_.config) return RAD_E_INVAL;
@@ -1216,7 +1269,9 @@ int Planner::plan(Plan* out) {
}
/* NOT a RAD_TRY: a refusal still leaves `out` filled in far enough to print. */
const int hrc = pin_embedding(prog, cfg, out);
int hrc = pin_embedding(prog, cfg, out);
const int trc = pin_towers(cfg, out);
if (hrc >= 0) hrc = trc;
int rc = assign(out);
enforce_op_site_agreement(prog, out);
@@ -1329,7 +1384,7 @@ std::string Plan::report(const Program& prog) const {
humanb(totals.bytes[(int)Tier::VRAM]).c_str());
s += fmt(" host pinned %12s %12s\n",
host_budget > 0 ? humanb(host_budget).c_str() : "none",
humanb(totals.bytes[(int)Tier::HostPinned] - embedding_host_used).c_str());
humanb(totals.bytes[(int)Tier::HostPinned] - forced_host_used).c_str());
if (totals.bytes[(int)Tier::HostPageable])
s += fmt(" host pageable %12s %12s\n", "-",
humanb(totals.bytes[(int)Tier::HostPageable]).c_str());
@@ -1354,6 +1409,9 @@ std::string Plan::report(const Program& prog) const {
if (embedding_host_bytes)
s += fmt(" embedding %12s %12s (--embedding-placement ram, pinned, read in place)\n",
"-", humanb(embedding_host_bytes).c_str());
if (tower_host_bytes)
s += fmt(" encoder tower %12s %12s (--vision-tower-placement ram, pinned, read in place)\n",
"-", humanb(tower_host_bytes).c_str());
if (ngram_copy_bytes)
s += fmt(" n-gram copy %12s %12s (--ngram-placement ram, %s, filled at load)\n",
"-", humanb(ngram_copy_bytes).c_str(),
+15 -8
View File
@@ -95,10 +95,12 @@ struct MoveUnit {
Site site = Site::Device;
int32_t slab_slot = -1;
bool movable = false; /* may the heat engine relocate it after load */
bool host_forced = false; /* --embedding-placement ram put it in the pinned pool */
bool host_forced = false; /* a placement flag put it in the pinned pool: the embedding's
* or the encoder tower's */
/* PLACED BEFORE ANY STRATEGY RAN, so every assignment pass skips it and no VRAM total counts
* it: the mapped tier (no device kernel can read it) and --embedding-placement ram. */
* it: the mapped tier (no device kernel can read it), --embedding-placement ram and
* --vision-tower-placement ram. */
bool preplaced() const { return tier == Tier::Mapped || host_forced; }
const char* reason = "fits in vram"; /* a fixed string, so the report never guesses */
@@ -274,11 +276,13 @@ public:
int64_t vram_budget = 0, host_budget = 0;
int64_t file_stage_reserve = 0;
int64_t file_windows = 0; /* the read windows' part of it */
/* --embedding-placement ram: the pool slots taken out of --host-pool-mib before any strategy
* ran, like the file staging above, and reported beside it rather than among the pooled units.
* `embedding_host_used` is the same tables' weight bytes, the unit the tier totals count in. */
/* --embedding-placement ram and --vision-tower-placement ram: the pool slots each flag's
* units took before any strategy ran, like the file staging above, and reported beside it
* rather than among the pooled units. `forced_host_used` is both flags' weight bytes, the unit
* the tier totals count in, which the pooled weights' figures leave out. */
int64_t embedding_host_bytes = 0;
int64_t embedding_host_used = 0;
int64_t tower_host_bytes = 0;
int64_t forced_host_used = 0;
/* --ngram-placement ram: the n-gram tables the load phase copies into host memory. They stay
* on the mapped tier as far as every pool is concerned; this is what the copy costs in RAM.
* `ngram_copy_card` says which copy: pinned memory a device kernel reads in place over the
@@ -379,6 +383,7 @@ private:
void build_units(const Program& prog, Plan* p);
void pin_mapped(const Program& prog, Plan* p);
int pin_embedding(const Program& prog, const Config& cfg, Plan* p) const;
int pin_towers(const Config& cfg, Plan* p) const;
void build_classes(Plan* p);
void rank_units(Plan* p, std::vector<int32_t>* order) const;
int assign(Plan* p);
@@ -430,11 +435,13 @@ struct WeightFootprint {
bool routed = false; /* a layer has experts: the file tier's read windows */
int64_t mapped = 0; /* no device kernel can read them; they never enter a pool at all */
int64_t hosted = 0; /* --embedding-placement ram: in the pinned host pool, off the card */
/* The tables the two placement flags move, wherever the buckets above count them: `embedding`
/* The tables the placement flags move, wherever the buckets above count them: `embedding`
* is inside statics or hosted, `ngram` inside statics when a device kernel reads it and it is
* placed in VRAM, inside mapped otherwise. */
* placed in VRAM, inside mapped otherwise. `tower` is the encoder towers' units, every weight
* of which the architecture declared read once per request, inside statics. */
int64_t embedding = 0;
int64_t ngram = 0;
int64_t tower = 0;
/* A device kernel reads the n-gram table, so it can be on the card or read over the link from
* pinned host memory; without one only the host gather reads it, from RAM or the container. */
bool ngram_device = false;