radiance 2.0.0

Radiance becomes a multi-model engine: one process serves several models behind one port, loads
each when a request names it, parks it in host memory or restores it from its container, and
shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the
command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP).

Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an
int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block
FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such
weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5,
Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B,
the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0
serves all of them.

Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new
Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill
reworked, and a reworked adaptive draft window.

Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its
configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool
in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server,
each accelerator's memory by model, model states over time.

Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by
AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests
keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410);
eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d
large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi
(#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon
(#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and
multi-model serving as asked for in #367 and #109.

Plugin ABI 39: out-of-tree plugins need to be rebuilt.

Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
This commit is contained in:
Deadcode committed 2026-11-14 22:32:28 +01:00
1 parent b4c04b6042
commit ddcb9c69bb
696 files changed
+120770 -56596

No files matched your search

+4 -1
View File
@@ -133,6 +133,7 @@ public:
int64_t from_hi, int64_t to_lo);
int drafter_short_block(int64_t block);
int drafter_tree(rad_buf parents);
int route_table(rad_buf table);
int declare_encoder(const RadEncoderDecl* d);
int declare_generator(const RadGeneratorDecl* d);
int declare_audio_generator(const RadAudioGenDecl* d);
@@ -267,6 +268,8 @@ std::string dump_graph_str(const Program& p, const std::vector<std::string>* err
/* The same walk as JSON, for the server's Model view, grouped by (op, band table): an op declared
* once per layer with one bucket table is one row with a count. */
std::string dump_graph_json(const Program& p);
/* `reg` is the registry the program was selected through (an engine's share), null for the process
* registry; the dump replays selections against its device facts. */
std::string dump_graph_json(const Program& p, Registry* reg = nullptr);
} /* namespace rad */
+50 -9
View File
@@ -191,11 +191,12 @@ rad_weight Builder::decl_weight(const char* name, const RadWeightDecl* d) {
while (!role.empty() && role.front() == ' ') role.erase(role.begin());
while (!role.empty() && role.back() == ' ') role.pop_back();
const int k = rad_enc_find(&w.enc, role.c_str());
char e[256];
rad_enc_format(&w.enc, e, sizeof e);
if (k < 0)
if (k < 0) {
char e[256];
rad_enc_format(&w.enc, e, sizeof e);
return err(RAD_E_SHAPE, "weight '%s' takes plane '%s' of '%s', which is %s and has "
"no such plane", n.c_str(), role.c_str(), w.source.c_str(), e);
}
if (w.n_sel == RAD_ENC_MAX_PLANES)
return err(RAD_E_INVAL, "weight '%s': more than %d planes", n.c_str(),
RAD_ENC_MAX_PLANES);
@@ -214,14 +215,15 @@ rad_weight Builder::decl_weight(const char* name, const RadWeightDecl* d) {
(p0.dtype == RAD_BF16 || p0.dtype == RAD_F16);
/* A bf16 readout head over an f32 checkpoint tensor: the loader rounds it to bf16. */
const bool narrow = w.n_sel == 1 && d->dtype == RAD_BF16 && p0.dtype == RAD_F32;
char e[256];
rad_enc_format(&w.enc, e, sizeof e);
if (!widen && !narrow)
if (!widen && !narrow) {
char e[256];
rad_enc_format(&w.enc, e, sizeof e);
return err(RAD_E_DTYPE, "weight '%s' is declared %s, and '%s' holds %s as %s: only an "
"exact widening or narrowing is done at load; anything else "
"is a quantisation, which a recipe does before the container "
"is written (spec §4.4)", n.c_str(), rad_dtype_name(d->dtype),
w.source.c_str(), p0.role, e);
}
w.widen = widen;
w.narrow = narrow;
}
@@ -269,7 +271,7 @@ rad_weight Builder::decl_weight(const char* name, const RadWeightDecl* d) {
w.stored_shape[i] = i < d->rank ? d->shape[i] : 0;
w.align = RAD_ALIGN_UNIT;
prog_.weights.push_back(w);
prog_.weights.push_back(std::move(w));
const rad_weight h = (rad_weight)(prog_.weights.size() - 1);
weight_by_name_.emplace(prog_.weights.back().name, h);
return h;
@@ -480,7 +482,8 @@ int64_t Builder::kv_layer_bytes(rad_kvgroup g) {
const int64_t bs = kv_block_size(g);
if (bs <= 0) return 0;
const int64_t nh = gi.decl.n_head_kv > 0 ? gi.decl.n_head_kv : 1;
return rad_dtype_bytes(gi.decl.dtype, 2 * bs * nh * gi.decl.head_dim);
return rad_dtype_bytes(gi.decl.dtype,
bs * nh * rad_kv_row_elems(gi.decl.dtype, gi.decl.head_dim));
}
/* ================================================================== ops */
@@ -2276,6 +2279,38 @@ int Builder::drafter_tree(rad_buf parents) {
return RAD_OK;
}
/* The routing counts' storage (rad_builder.h). The row count is checked in Ctx::bind_routing,
* which knows the reporting layers. */
int Builder::route_table(rad_buf table) {
if (finished_) {
err(RAD_E_STATE, "route_table after declare finished");
return RAD_E_STATE;
}
if (prog_.route_table != RAD_NULL_HANDLE) {
err(RAD_E_STATE, "route_table: buffer '%s' is already the routing table",
prog_.buffers[prog_.route_table].name.c_str());
return RAD_E_STATE;
}
if (table == RAD_NULL_HANDLE || (size_t)table >= prog_.buffers.size()) {
err(RAD_E_INVAL, "route_table: buffer %u is not a declared buffer", (unsigned)table);
return RAD_E_INVAL;
}
const BufferInfo& bi = prog_.buffers[table];
if (bi.decl.dtype != RAD_I32) {
err(RAD_E_DTYPE, "route_table: buffer '%s' is not i32", bi.name.c_str());
return RAD_E_DTYPE;
}
if (bi.decl.domain != RAD_DOMAIN_DEVICE || bi.decl.kind != RAD_BUF_PERSIST) {
err(RAD_E_INVAL, "route_table: buffer '%s' must be a RAD_BUF_PERSIST device buffer: the "
"core reads its rows at the end of every pass and between passes, where a "
"transient's bytes belong to whichever buffer shares them",
bi.name.c_str());
return RAD_E_INVAL;
}
prog_.route_table = table;
return RAD_OK;
}
void Builder::note_v(const char* f, va_list ap) {
char msg[1024];
vsnprintf(msg, sizeof msg, f ? f : "", ap);
@@ -2496,7 +2531,8 @@ void Builder::finish_kv_groups() {
case RAD_KV_RING:
/* One block holds K and V for block_size tokens, the block manager's unit. */
gi.bytes_per_block =
rad_dtype_bytes(d.dtype, 2 * gi.block_size * elem_n_head * d.head_dim) * n_bound;
rad_dtype_bytes(d.dtype, gi.block_size * elem_n_head *
rad_kv_row_elems(d.dtype, d.head_dim)) * n_bound;
gi.bytes_per_state = 0;
break;
case RAD_KV_LINEAR:
@@ -2838,6 +2874,11 @@ int rad_drafter_tree(RadBuilder* b, rad_buf parents) {
return B(b)->drafter_tree(parents);
}
int rad_route_table(RadBuilder* b, rad_buf table) {
if (!b) return RAD_E_INVAL;
return B(b)->route_table(table);
}
int rad_chain_on(void) { return rad_dev_chain_enabled(); }
int rad_drafter_short_block(RadBuilder* b, int64_t block) {
+4 -4
View File
@@ -16,7 +16,7 @@
#include "startup.h"
#include <nlohmann/json.hpp>
#include "util/json.h"
#include <algorithm>
#include <atomic>
@@ -27,7 +27,7 @@
namespace rad {
/* ordered_json keeps keys in insertion order rather than alphabetical. */
using json = nlohmann::ordered_json;
using json = Json;
namespace {
@@ -564,8 +564,8 @@ static json weight_json(const WeightInfo& w) {
return j;
}
std::string dump_graph_json(const Program& p) {
Registry& reg = rad_tools_registry();
std::string dump_graph_json(const Program& p, Registry* r) {
Registry& reg = r ? *r : rad_tools_registry();
json root;
json meta;
meta["arch"] = p.meta.arch_id ? p.meta.arch_id : "";
+105 -41
View File
@@ -13,6 +13,8 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <mutex>
namespace rad {
@@ -28,6 +30,44 @@ Registry& rad_tools_registry() {
return *r;
}
/* ------------------------------------------------------------------ engines in one process */
namespace {
std::mutex g_claim_mu;
bool g_slot_held[RAD_MAX_SLOTS] = {};
std::map<std::string, int> g_arch_engines; /* arch plugin -> engines holding it */
} // namespace
int rad_engine_claim(const std::string& arch_plugin, int n_ranks, int* slot_base) {
std::lock_guard<std::mutex> lk(g_claim_mu);
const Plugin* ap = rad_tools_registry().plugin(arch_plugin);
if (ap && !ap->arch_multi_instance && g_arch_engines[arch_plugin] > 0) {
RAD_ERR("architecture plugin '%s' keeps one model's state per process and already backs "
"a running model; it does not export rad_arch_multi_instance, so a second model on "
"it cannot run beside the first", arch_plugin.c_str());
return RAD_E_STATE;
}
for (int base = 0; base + n_ranks <= RAD_MAX_SLOTS; ++base) {
bool free = true;
for (int i = 0; i < n_ranks && free; ++i) free = !g_slot_held[base + i];
if (!free) continue;
for (int i = 0; i < n_ranks; ++i) g_slot_held[base + i] = true;
++g_arch_engines[arch_plugin];
*slot_base = base;
return RAD_OK;
}
RAD_ERR("no %d free instance slot(s) in a row: the process holds at most %d ranks across its "
"models (RAD_MAX_SLOTS)", n_ranks, RAD_MAX_SLOTS);
return RAD_E_FULL;
}
void rad_engine_release(const std::string& arch_plugin, int slot_base, int n_ranks) {
std::lock_guard<std::mutex> lk(g_claim_mu);
for (int i = 0; i < n_ranks && slot_base + i < RAD_MAX_SLOTS; ++i) g_slot_held[slot_base + i] = false;
auto it = g_arch_engines.find(arch_plugin);
if (it != g_arch_engines.end() && --it->second <= 0) g_arch_engines.erase(it);
}
/* ------------------------------------------------------------------ the reference-kernel gate */
/* An op is "on the reference" when no band in any domain offers a non-reference kernel
@@ -119,46 +159,10 @@ static std::vector<std::string> home_subdirs(const std::string& home, const char
return out;
}
int rad_tools_load_plugins(const std::string& home, const std::vector<std::string>& hierarchy,
const std::string& arch_id, const std::string& quant,
LoadedPlugins* out, bool imported) {
if (!out) return RAD_E_INVAL;
*out = LoadedPlugins{};
Registry& r = rad_tools_registry();
/* Kernels first, in hierarchy order, then architectures (unordered: no two may claim the same
* id). A home need not have every directory, but kernels/ and architectures/ must each exist
* somewhere on the path, or the scan reports the first home's as missing. */
const std::string first = rad_home_dirs(home).front();
std::vector<std::string> kdirs = home_subdirs(home, "kernels");
if (kdirs.empty()) kdirs.push_back(first + "/kernels");
int s = r.load_dirs(kdirs, hierarchy);
if (s < 0) return s;
std::vector<std::string> adirs = home_subdirs(home, "architectures");
if (adirs.empty()) adirs.push_back(first + "/architectures");
s = r.load_dirs(adirs, {});
if (s < 0) return s;
/* Quantisers: rad-convert drives them, and the oracle decodes through them for schemes the
* core does not define. Optional. */
const std::vector<std::string> qdirs = home_subdirs(home, "quantizers");
if (!qdirs.empty()) {
s = r.load_dirs(qdirs, {});
if (s < 0) return s;
}
RAD_TRY(r.check_complete());
/* The tuning cache, once the kernel set is known. A missing file leaves every shape on its
* plugin's first variant. Logged when it has rows; --debug-graph shows the per-shape
* source. */
const std::string tune = rad_home_file(home, TuneCache::rel_path(rad_machine_key()));
const std::string tune_home = tune.substr(0, tune.size() - TuneCache::rel_path(rad_machine_key()).size() - 1);
const int n_tuned = r.load_tune(tune_home);
if (n_tuned > 0) RAD_INFO("tune cache: %d row(s) from %s", n_tuned, tune.c_str());
/* The architecture plugin for (arch_id, quant) among a loaded set, and the kernel libraries it
* selects from, into *out. */
static int pick_arch(Registry& r, const std::string& home, const std::string& arch_id,
const std::string& quant, LoadedPlugins* out, bool imported) {
/* The selection key is the (arch_id, quant) pair (spec §2.4), matched exactly with no
* fallback; a mismatched plugin would only fail later at the name map with a worse message. */
for (const Plugin& p : r.plugins()) {
@@ -240,6 +244,66 @@ int rad_tools_load_plugins(const std::string& home, const std::vector<std::strin
return RAD_OK;
}
int rad_tools_load_plugins(const std::string& home, const std::vector<std::string>& hierarchy,
const std::string& arch_id, const std::string& quant,
LoadedPlugins* out, bool imported) {
if (!out) return RAD_E_INVAL;
*out = LoadedPlugins{};
Registry& r = rad_tools_registry();
/* One plugin set serves every engine in the process (registry.h, Sharing): the first load
* reads the homes, a later one finds the set loaded and only picks its architecture. The home
* and the hierarchy are server-level settings, so every engine asks for the same set; a
* different one is refused rather than served from the wrong libraries. */
static std::string loaded_home;
static std::vector<std::string> loaded_hierarchy;
if (!r.plugins().empty()) {
if (home != loaded_home || hierarchy != loaded_hierarchy) {
RAD_ERR("the plugin set is already loaded from %s; every model in a process uses the "
"same radiance-home and kernels", loaded_home.c_str());
return RAD_E_STATE;
}
return pick_arch(r, home, arch_id, quant, out, imported);
}
loaded_home = home;
loaded_hierarchy = hierarchy;
/* Kernels first, in hierarchy order, then architectures (unordered: no two may claim the same
* id). A home need not have every directory, but kernels/ and architectures/ must each exist
* somewhere on the path, or the scan reports the first home's as missing. */
const std::string first = rad_home_dirs(home).front();
std::vector<std::string> kdirs = home_subdirs(home, "kernels");
if (kdirs.empty()) kdirs.push_back(first + "/kernels");
int s = r.load_dirs(kdirs, hierarchy);
if (s < 0) return s;
std::vector<std::string> adirs = home_subdirs(home, "architectures");
if (adirs.empty()) adirs.push_back(first + "/architectures");
s = r.load_dirs(adirs, {});
if (s < 0) return s;
/* Quantisers: rad-convert drives them, and the oracle decodes through them for schemes the
* core does not define. Optional. */
const std::vector<std::string> qdirs = home_subdirs(home, "quantizers");
if (!qdirs.empty()) {
s = r.load_dirs(qdirs, {});
if (s < 0) return s;
}
RAD_TRY(r.check_complete());
/* The tuning cache, once the kernel set is known. A missing file leaves every shape on its
* plugin's first variant. Logged when it has rows; --debug-graph shows the per-shape
* source. */
const std::string tune = rad_home_file(home, TuneCache::rel_path(rad_machine_key()));
const std::string tune_home = tune.substr(0, tune.size() - TuneCache::rel_path(rad_machine_key()).size() - 1);
const int n_tuned = r.load_tune(tune_home);
if (n_tuned > 0) RAD_INFO("tune cache: %d row(s) from %s", n_tuned, tune.c_str());
return pick_arch(r, home, arch_id, quant, out, imported);
}
/* Optional export. Without it, or on failure, every field is zero and the caller uses its own
* defaults. A failed probe is not an error: the plugin can still refuse in declare, where it has
* the whole configuration and can say why. */
@@ -398,7 +462,7 @@ int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const R
const LoraDeclare* lora) {
if (!out) return RAD_E_INVAL;
Registry& r = rad_tools_registry();
Registry& r = lp.registry ? *lp.registry : rad_tools_registry();
const Plugin* ap = r.plugin(lp.arch_plugin);
if (!ap || !ap->arch_declare) {
RAD_ERR("architecture plugin '%s' is not loaded or exports no rad_arch_declare",
+11
View File
@@ -35,6 +35,9 @@ struct LoadedPlugins {
std::string arch_id;
/* The quantisation half of the selection key, "" for an unquantised container. */
std::string arch_quant;
/* The registry declare selects through: an engine's own share of the process set
* (Registry::share), or null for the process registry itself, as the tools use. */
Registry* registry = nullptr;
/* `name@version`, space separated, in hierarchy order; what a benchmark records as the
* libraries measured. */
@@ -178,4 +181,12 @@ int rad_gate_reference_kernels(const Program& p, bool allow, const char* what);
Registry& rad_tools_registry();
/* Engines in one process (docs/MULTIMODEL.md §3.3). Each holds, while it lives, a contiguous block
* of `n_ranks` instance slots, whose first is its RadBuildCtx::slot_base, and a claim on its
* architecture plugin. A plugin that does not export rad_arch_multi_instance backs one engine at a
* time: a second claim on it is refused by name. RAD_OK with *slot_base set, or a negative status
* after a RAD_ERR line saying why. Release returns the slots and the claim. */
int rad_engine_claim(const std::string& arch_plugin, int n_ranks, int* slot_base);
void rad_engine_release(const std::string& arch_plugin, int slot_base, int n_ranks);
} /* namespace rad */