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

+5 -212
View File
@@ -1,6 +1,5 @@
#include "runtime/tierexec.h"
#include "mem/sstier.h"
#include "rad_internal.h"
#include <algorithm>
@@ -16,19 +15,18 @@ TierExec::~TierExec() { close(); }
* maintenance path -- a selector call between steps would be affordable and is still the wrong
* shape: the kernel that serves a transfer must not be able to change underneath a half-finished
* batch. */
int TierExec::configure(Registry* reg, KVManager* kv, IdleTiers* tiers, SSDTier* disk,
int TierExec::configure(Registry* reg, KVManager* kv, IdleTiers* tiers,
const std::vector<int32_t>& groups, int max_batch, int64_t max_copy,
int64_t max_chain, bool leader, int device, int64_t slot_off,
const HostArena* ck_store, RadStream shared) {
RadStream shared) {
close();
if (!reg || !kv || !tiers || groups.empty() || max_batch <= 0 || max_copy <= 0 ||
max_chain <= 0)
return RAD_E_INVAL;
reg_ = reg; kv_ = kv; tiers_ = tiers; disk_ = disk; leader_ = leader; device_ = device;
reg_ = reg; kv_ = kv; tiers_ = tiers; leader_ = leader; device_ = device;
max_batch_ = max_batch; max_copy_ = max_copy; max_chain_ = max_chain;
slot_off_ = slot_off;
slot_bytes_ = tiers->entry_bytes();
ck_store_ = ck_store && ck_store->enabled() ? ck_store : nullptr;
shared_ = shared;
RAD_TRY(rad_dev_set(device_));
@@ -139,10 +137,9 @@ void TierExec::close() {
order_.clear();
verify_pending_.clear();
entry_bytes_ = 0;
ck_store_ = nullptr;
enabled_ = false;
leader_ = false;
reg_ = nullptr; kv_ = nullptr; tiers_ = nullptr; disk_ = nullptr;
reg_ = nullptr; kv_ = nullptr; tiers_ = nullptr;
report_.clear();
}
@@ -155,7 +152,7 @@ void TierExec::close() {
* device side built at bringup, on a two-card R9700 Flash-Next server at 200K context:
*
* no tiers 20.54 ms/step collect 14.66
* tiers on, 512 MiB host arena, no disk 33.94 ms/step collect 26.78
* tiers on, 512 MiB host arena 33.94 ms/step collect 26.78
* tiers on, idle threshold a day -- NOTHING EVER MOVED 33.88 ms/step collect 26.66
*
* In the third line not one byte crosses the link, and the step is still 65% longer. The cost is
@@ -536,74 +533,6 @@ int TierExec::issue_restore(std::vector<TierJob>& jobs, RadStream compute,
return st;
}
int TierExec::fence(RadEvent* out, RadStream on) {
*out = nullptr;
if (!enabled_ || (!on && !stream_)) return RAD_OK;
RAD_TRY(rad_dev_set(device_));
RadEvent e = nullptr;
RAD_TRY(rad_event_create(&e));
const int st = rad_event_record(e, on ? on : stream_);
if (st != RAD_OK) { rad_event_destroy(e); return st; }
*out = e;
return RAD_OK;
}
/* ------------------------------------------------------------------ the disk store */
void TierExec::run_disk(std::vector<TierJob>& jobs, std::vector<char>* ok) {
ok->assign(jobs.size(), 1);
for (size_t i = 0; i < jobs.size(); ++i) (*ok)[i] = run_write(jobs[i]) ? 1 : 0;
}
bool TierExec::run_write(TierJob& j) {
if (j.kind != TierJob::Kind::ToDisk) return true; /* the drops move nothing */
bool ok = true;
/* THE WHOLE SLOT, every rank's shard of it, because a disk entry read back must be able to
* serve all of them. A job may carry only the snapshot half, when the blocks are already on
* disk or their write went out earlier. */
if (j.host_slot >= 0) {
const void* src = tiers_->arena().at(j.host_slot);
ok = disk_ && src && disk_->put_block(j.key, nullptr, 0, src, slot_bytes_) == RAD_OK;
}
if (j.ck_slot >= 0) {
const void* cs = ck_store_ ? ck_store_->at(j.ck_slot) : nullptr;
/* A snapshot store that was never opened -- no room for one inside the disk cap -- refuses
* this, which is the right answer and not an error: the slot stays the only copy, as it
* was. */
j.ck_ok = disk_ && cs &&
disk_->put_checkpoint(j.key, j.ck_pos, cs, ck_store_->slot_bytes()) == RAD_OK;
}
return ok;
}
void TierExec::run_fetch(std::vector<TierJob>& jobs, std::vector<char>* ok) {
ok->assign(jobs.size(), 1);
std::vector<BlockHash> keys;
std::vector<void*> dst;
std::vector<size_t> at;
for (size_t i = 0; i < jobs.size(); ++i) {
TierJob& j = jobs[i];
j.started = true;
if (j.host_slot < 0) continue; /* only the snapshot half */
keys.push_back(j.key);
dst.push_back(tiers_->arena().at(j.host_slot));
at.push_back(i);
}
if (!keys.empty()) {
std::vector<char> got(keys.size(), 0);
if (disk_) (void)disk_->get_blocks(keys.data(), (int64_t)keys.size(), dst.data(),
slot_bytes_, got.data());
for (size_t k = 0; k < keys.size(); ++k) (*ok)[at[k]] = got[k];
st_.bytes_in += (int64_t)keys.size() * slot_bytes_;
}
for (TierJob& j : jobs) {
if (!j.ck_want || j.ck_slot < 0) continue;
void* cs = ck_store_ ? ck_store_->at(j.ck_slot) : nullptr;
j.ck_ok = disk_ && cs &&
disk_->get_checkpoint(j.key, j.ck_pos, cs, ck_store_->slot_bytes()) == RAD_OK;
}
}
/* ------------------------------------------------------------------ the report */
void TierExec::report_pass(std::vector<TierJob>& jobs, const std::vector<char>& ok,
@@ -624,11 +553,6 @@ void TierExec::report_pass(std::vector<TierJob>& jobs, const std::vector<char>&
}
tiers_->report(j, good, now_ns);
}
/* STORE SLOTS THE TIERS HAD BEEN KEEPING: a write that read one the cache let go of, or a
* read nothing took. The disk thread is done with them -- these come only from reports. */
std::vector<int32_t> frees;
tiers_->take_checkpoint_frees(&frees);
for (int32_t s : frees) kv_->free_checkpoint(s);
}
bool TierExec::plan_promote(const BlockHash& key, TierJob* out) {
@@ -636,135 +560,4 @@ bool TierExec::plan_promote(const BlockHash& key, TierJob* out) {
return tiers_->plan_promote(key, out);
}
/* ------------------------------------------------------------------ TierIO */
TierIO::~TierIO() { stop(); }
void TierIO::start(TierExec* leader) {
stop();
x_ = leader;
stop_ = false;
th_ = std::thread([this] { loop(); });
}
void TierIO::stop() {
{
std::lock_guard<std::mutex> lk(mu_);
stop_ = true;
}
cv_.notify_all();
if (th_.joinable()) th_.join();
has_work_ = has_done_ = false;
work_.clear();
done_.clear();
ok_.clear();
work_at_ = 0;
fetch_q_.clear();
fetch_done_.clear();
}
bool TierIO::submit(std::vector<TierJob>&& jobs, std::vector<RadEvent>&& fences) {
{
std::lock_guard<std::mutex> lk(mu_);
if (has_work_ || has_done_ || !th_.joinable()) return false;
work_ = std::move(jobs);
work_fences_ = std::move(fences);
ok_.assign(work_.size(), 1);
work_at_ = 0;
has_work_ = true;
}
cv_.notify_all();
return true;
}
bool TierIO::submit_fetch(Fetch&& f) {
{
std::lock_guard<std::mutex> lk(mu_);
if (!th_.joinable()) return false;
fetch_q_.push_back(std::move(f));
}
cv_.notify_all();
return true;
}
bool TierIO::take_fetch(Fetch* out) {
std::lock_guard<std::mutex> lk(mu_);
if (fetch_done_.empty()) return false;
*out = std::move(fetch_done_.front());
fetch_done_.pop_front();
return true;
}
bool TierIO::take(std::vector<TierJob>* jobs, std::vector<char>* ok,
std::vector<RadEvent>* fences) {
std::lock_guard<std::mutex> lk(mu_);
if (!has_done_) return false;
*jobs = std::move(done_);
*ok = std::move(ok_);
if (fences) *fences = std::move(done_fences_);
done_.clear();
done_fences_.clear();
ok_.clear();
has_done_ = false;
return true;
}
bool TierIO::busy() const {
std::lock_guard<std::mutex> lk(mu_);
return has_work_ || has_done_;
}
void TierIO::loop() {
for (;;) {
Fetch f;
bool read = false;
size_t i = 0;
{
std::unique_lock<std::mutex> lk(mu_);
cv_.wait(lk, [this] { return stop_ || !fetch_q_.empty() || (has_work_ && !has_done_); });
if (stop_) return;
if (!fetch_q_.empty()) {
f = std::move(fetch_q_.front());
fetch_q_.pop_front();
read = true;
} else {
i = work_at_;
}
}
if (read) {
/* NOT A BYTE UNTIL EVERY RANK'S RESTORES THAT COULD READ THESE SLOTS HAVE RUN. A fence
* that cannot be waited on leaves the read unstarted, and the records stay on disk. */
bool fenced = true;
for (RadEvent e : f.fences) if (e && rad_event_sync(e) != RAD_OK) fenced = false;
if (fenced) x_->run_fetch(f.jobs, &f.ok);
else f.ok.assign(f.jobs.size(), 0);
std::lock_guard<std::mutex> lk(mu_);
fetch_done_.push_back(std::move(f));
continue;
}
/* NOT A BYTE UNTIL THE COPIES THAT FILLED THE SLOTS HAVE LANDED, once a batch. A fence
* that cannot be waited on fails the batch, and every record keeps what it had. */
bool fenced = true;
if (i == 0)
for (RadEvent e : work_fences_) if (e && rad_event_sync(e) != RAD_OK) fenced = false;
bool ok = false;
if (fenced) ok = i < work_.size() ? x_->run_write(work_[i]) : true;
std::lock_guard<std::mutex> lk(mu_);
if (!fenced) {
ok_.assign(work_.size(), 0);
work_at_ = work_.size();
} else {
if (i < ok_.size()) ok_[i] = ok ? 1 : 0;
work_at_ = i + 1;
}
if (work_at_ >= work_.size()) {
done_ = std::move(work_);
done_fences_ = std::move(work_fences_);
work_.clear();
work_fences_.clear();
has_work_ = false;
has_done_ = true;
}
}
}
} /* namespace rad */
+6 -96
View File
@@ -16,9 +16,6 @@
* - a restore in makes the COMPUTE stream wait for it, so the step that reads the restored
* blocks runs after they land without the host having waited for anything.
*
* The disk store is the one part that is synchronous by nature, and it runs on a thread of its own
* (TierIO below), so the engine thread never waits on a file either.
*
* ============================== THE TRANSFER, AND WHY IT IS SHAPED THIS WAY ====================
*
* A paged pool is LAYER-MAJOR: layer l of group g owns `[base + l*layer_stride, + layer_stride)`
@@ -44,20 +41,13 @@
#include "plugin/registry.h"
#include "rad_core.h"
#include <functional>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
namespace rad {
class SSDTier;
class TierExec {
public:
~TierExec();
@@ -68,10 +58,10 @@ public:
* `max_batch` is the staging buffer in entries, `max_copy` the most entries one copy out may
* carry, and `max_chain` the longest chain one restore brings back -- the index buffers are
* sized from the last two. */
int configure(Registry* reg, KVManager* kv, IdleTiers* tiers, SSDTier* disk,
int configure(Registry* reg, KVManager* kv, IdleTiers* tiers,
const std::vector<int32_t>& groups, int max_batch, int64_t max_copy,
int64_t max_chain, bool leader, int device, int64_t slot_off,
const HostArena* ck_store, RadStream shared);
RadStream shared);
void close();
bool enabled() const { return enabled_; }
std::string report() const { return report_; }
@@ -115,34 +105,14 @@ public:
/* ---------------- restore ----------------
*
* Enqueue a chain of ToDevice jobs, in chain order, and make `compute` wait for them. Every
* job's bytes are in host memory -- a disk entry was read in first (run_fetch) -- so nothing
* here waits on a file. The leader chooses every block first, recalling the loan for the
* Enqueue a chain of ToDevice jobs, in chain order, and make `compute` wait for them. The
* leader chooses every block first, recalling the loan for the
* whole chain at once; a chain the pool cannot hold is cut where the reservation ran out, and
* the jobs past the cut are left unstarted. `ok[i]` is whether job i was fully enqueued on
* this rank. */
int issue_restore(std::vector<TierJob>& jobs, RadStream compute, std::vector<char>* ok);
/* A MARK ON THIS RANK'S TRANSFER STREAM, after everything enqueued on it so far -- or on
* `on`, the rank's compute stream, when it is given. A restore reads host slots
* asynchronously, and a slot it is still reading may be given up and handed to a read off
* disk the moment the restore has reported; the IO thread waits for this mark before it
* writes into any slot it was handed. A snapshot's store slot is read and written by copies
* on the compute stream (KVManager::checkpoint_save), so a disk write or read of one waits
* for that stream's mark. Null when nothing was ever enqueued on the transfer stream. The
* caller owns the event. */
int fence(RadEvent* out, RadStream on = nullptr);
/* ---------------- the disk store (leader only; TierIO's thread) ---------------- */
void run_disk(std::vector<TierJob>& jobs, std::vector<char>* ok);
/* One ToDisk job; true when it was written. */
bool run_write(TierJob& j);
/* ToHost jobs: the blocks read in parallel into the host slots they were given, then the
* snapshots into their store slots. `ok[i]` is the blocks' result, `ck_ok` the snapshot's. */
void run_fetch(std::vector<TierJob>& jobs, std::vector<char>* ok);
/* Leader only. Gives back what a failed job held -- a restore's blocks -- reports every job to
* the policy, and frees the store slots a finished write or an unclaimed read was holding on
* the cache's behalf. `now_ns` is when the pass ran: a promotion is a use. */
/* Leader only. Gives back what a failed job held -- a restore's blocks -- and reports every
* job to the policy. `now_ns` is when the pass ran: a promotion is a use. */
void report_pass(std::vector<TierJob>& jobs, const std::vector<char>& ok, uint64_t now_ns);
/* A lookup hit off-device: the job that would bring it back, or false when the entry is not
@@ -209,14 +179,8 @@ private:
Registry* reg_ = nullptr;
KVManager* kv_ = nullptr;
IdleTiers* tiers_ = nullptr;
SSDTier* disk_ = nullptr;
std::vector<GroupInfo> gi_;
int64_t entry_bytes_ = 0;
/* ---- the linear half ----
* The engine's snapshot store, whose slots the disk thread writes out and reads back whole --
* every rank's shard of a snapshot together. Null on a model with no recurrent state, which
* is the whole of the "off" path here. */
const HostArena* ck_store_ = nullptr;
int max_batch_ = 0;
int64_t max_copy_ = 0;
int64_t max_chain_ = 0;
@@ -275,58 +239,4 @@ private:
Stats st_;
};
/* ------------------------------------------------------------------ the disk thread */
/* THE DISK STORE ON A THREAD OF ITS OWN. A host-to-disk move is a file write of the whole slot,
* and a pass that makes room for a conversation's worth of copies is hundreds of megabytes of it
* -- the engine thread would build no step for as long as the writes took. So a batch is handed
* over and collected later. The thread touches the host arena and the disk store and nothing
* else: every decision about the records is made before the hand-over and after the collection,
* on the engine thread, under the scheduler's lock.
*
* TWO KINDS OF WORK, AND THE READS GO FIRST. A write batch is the background copy to disk: one at
* a time, and the engine does not hand over the next until it has collected the last. A read
* batch is a conversation a request is waiting on (IdleTiers::plan_fetch), so reads queue in the
* order they were asked for and each one is taken ahead of whatever write is out -- between two
* of its jobs, not after the whole batch. */
class TierIO {
public:
~TierIO();
void start(TierExec* leader);
void stop();
/* False when a batch is already out. `fences` are waited on before the first job is written --
* a snapshot's store slot is filled by a copy on the compute stream (TierExec::fence) -- and
* come back with the batch from take(), still the caller's to destroy. */
bool submit(std::vector<TierJob>&& jobs, std::vector<RadEvent>&& fences = {});
/* The finished batch, when there is one. */
bool take(std::vector<TierJob>* jobs, std::vector<char>* ok,
std::vector<RadEvent>* fences = nullptr);
bool busy() const;
/* A read off disk. `tag` is the caller's (the request waiting on it); `fences` are waited on
* before the first byte is written (TierExec::fence) and stay the caller's to destroy. */
struct Fetch {
uint64_t tag = 0;
std::vector<TierJob> jobs;
std::vector<RadEvent> fences;
std::vector<char> ok;
};
/* False when the thread is not running. */
bool submit_fetch(Fetch&& f);
/* A finished read, oldest first. */
bool take_fetch(Fetch* out);
private:
void loop();
TierExec* x_ = nullptr;
std::thread th_;
mutable std::mutex mu_;
std::condition_variable cv_;
std::vector<TierJob> work_, done_;
std::vector<RadEvent> work_fences_, done_fences_;
std::vector<char> ok_;
size_t work_at_ = 0; /* the next write job; the thread's alone while has_work_ */
bool has_work_ = false, has_done_ = false, stop_ = false;
std::deque<Fetch> fetch_q_, fetch_done_;
};
} /* namespace rad */