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

+159 -52
View File
@@ -26,7 +26,7 @@
#include "rad_quant.h"
#include <dlfcn.h>
#include <nlohmann/json.hpp>
#include "util/json.h"
#include <sys/stat.h>
@@ -84,7 +84,7 @@ int clef_metadata(const std::string& in, const std::string& config_dir, const Ch
"checkpoint (or under --config)", path.c_str());
return -1;
}
nlohmann::json c;
Json c;
try { f >> c; } catch (const std::exception& e) {
RAD_ERR("%s: %s", path.c_str(), e.what());
return -1;
@@ -163,7 +163,7 @@ int laya_metadata(const std::string& in, const std::string& config_dir, MetaOwn&
dir = slash == std::string::npos ? "." : in.substr(0, slash);
}
}
auto read_json = [](const std::string& path, nlohmann::json* j) {
auto read_json = [](const std::string& path, Json* j) {
std::ifstream f(path);
if (!f) { RAD_ERR("%s: a Laya checkpoint carries it; cannot read it", path.c_str()); return -1; }
try { f >> *j; } catch (const std::exception& e) {
@@ -181,7 +181,7 @@ int laya_metadata(const std::string& in, const std::string& config_dir, MetaOwn&
if (enc.keys[i] != "model_type" && enc.keys[i] != "architectures") meta.set(enc.keys[i], enc.vals[i]);
meta.m = enc.m;
nlohmann::json rl;
Json rl;
if (read_json(dir + "/rl_agent_config.json", &rl) < 0) return -1;
const std::pair<const char*, long long> counts[] = { { "max_len", 1 }, { "head_max_len", 1 },
{ "head_layers", 0 } };
@@ -200,7 +200,7 @@ int laya_metadata(const std::string& in, const std::string& config_dir, MetaOwn&
auto num = [](double v) { char s[32]; std::snprintf(s, sizeof s, "%.9g", v); return std::string(s); };
std::string temps = "1 1 1";
if (rl.contains("temperature")) {
const nlohmann::json& t = rl["temperature"];
const Json& t = rl["temperature"];
if (!t.is_array() || t.size() != 3 || !t[0].is_number() || !t[1].is_number() || !t[2].is_number()) {
RAD_ERR("%s/rl_agent_config.json: `temperature` is not three numbers (choice, score, "
"noul)", dir.c_str());
@@ -217,10 +217,10 @@ int laya_metadata(const std::string& in, const std::string& config_dir, MetaOwn&
/* The special tokens by name (tokenizer_config.json), their ids from tokenizer.json. */
const std::string tdir = dir + "/tokenizer";
if (tokjson->empty()) *tokjson = tdir + "/tokenizer.json";
nlohmann::json tc, tj;
Json tc, tj;
if (read_json(tdir + "/tokenizer_config.json", &tc) < 0 || read_json(*tokjson, &tj) < 0) return -1;
for (const char* which : { "cls_token", "sep_token", "mask_token" }) {
const nlohmann::json* v = tc.contains(which) ? &tc[which] : nullptr;
const Json* v = tc.contains(which) ? &tc[which] : nullptr;
if (v && v->is_object() && v->contains("content")) v = &(*v)["content"];
if (!v || !v->is_string()) {
RAD_ERR("%s/tokenizer_config.json: no `%s`", tdir.c_str(), which);
@@ -346,8 +346,8 @@ void usage() {
" the engine. Default: the checkpoint's training context\n"
" --draft-model DIR a drafter that ships as its own repository (DFlash2), merged\n"
" under `draft.`\n"
" --kv-cache-dtype T bf16 | fp8, the cache width declare is run at. Default: the\n"
" first of bf16, fp8 at which every op resolves -- the container\n"
" --kv-cache-dtype T bf16 | i8, the cache width declare is run at. Default: the\n"
" first of bf16, i8 at which every op resolves -- the container\n"
" is the same at either, so this only picks the kernels it checks\n"
" --max-spec N the max_spec declare is run at (default 4, or the block a\n"
" drafter states; a number given here is used as given); 0\n"
@@ -373,11 +373,24 @@ void usage() {
" every target; several targets mean the module is their concate-\n"
" nation (a fused qkv), and the adapter's rows split along them\n"
" in the order listed\n"
" --in-place with --reuse: EXTEND that container instead of writing a new one.\n"
" --in-place with --reuse: EXTEND that container (the first --reuse; further\n"
" ones only supply planes) instead of writing a new one.\n"
" Its weights stay where they are; new ones are written past its\n"
" end and the header last. Refused when a weight it holds would\n"
" change or a new weight is an expert. <file>.pre-append keeps the\n"
" old header and length\n"
" change or a new weight is an expert of a layer it holds experts\n"
" of. <file>.pre-append keeps the old header and length\n"
" --replace GLOB with --in-place: a weight the glob matches that the container\n"
" holds under another encoding or rule is written again past its\n"
" end, and the old planes stay behind as unreachable bytes until\n"
" the container is converted to a new file (repeatable). A\n"
" layer's other experts move with one that is written again,\n"
" their planes copied\n"
" --defer GLOB leave every weight the glob matches out of this container, for\n"
" a later --in-place run to add (repeatable). With --in-place a\n"
" weight the container already holds stays. The container loads\n"
" once no weight is left out, so a checkpoint larger than the disk\n"
" converts a layer at a time: the first run defers the layers\n"
" whose tensors are not there yet, each later run adds some\n"
" --gpus LIST the cards (HIP device numbers, comma separated) the quantisers\n"
" may run on, and large weights then run two at a time. A\n"
" quantiser writes the same bytes on a card as on the host; with\n"
@@ -426,6 +439,8 @@ int main(int argc, char** argv) {
bool verbose = false, plan_only = false, list_quant = false;
std::string reuse_path, changed_path;
std::vector<std::string> reuse_more; /* --reuse given again: more containers to copy from */
std::vector<std::string> defer; /* --defer: globs of the weights this run leaves out */
std::vector<std::string> replace; /* --replace: globs of the weights --in-place may rewrite */
std::vector<std::string> lora_paths;
double lora_strength = 1.0;
std::string lora_map;
@@ -493,16 +508,18 @@ int main(int argc, char** argv) {
}
else if (a == "--lora-map") lora_map = next("--lora-map");
else if (a == "--in-place") in_place = true;
else if (a == "--defer") defer.push_back(next("--defer"));
else if (a == "--replace") replace.push_back(next("--replace"));
else if (a == "--gpus") {
for (const std::string& d : rad_split_list(next("--gpus")))
gpus.push_back((int)rad_flag_int("rad-convert", "--gpus", d.c_str(), 0, 1023));
}
else if (a == "--kv-cache-dtype") {
const std::string v = next("--kv-cache-dtype");
if (v == "fp8") kv_dtype = RAD_F8E4M3;
if (v == "i8") kv_dtype = RAD_I8;
else if (v == "bf16") kv_dtype = RAD_BF16;
else { std::fprintf(stderr, "rad-convert: --kv-cache-dtype takes bf16 "
"or fp8, not '%s'\n", v.c_str());
"or i8, not '%s'\n", v.c_str());
return 2; }
}
else if (a == "-v" || a == "--verbose") { verbose = true; log_set_level(Log::Debug); }
@@ -571,6 +588,11 @@ int main(int argc, char** argv) {
}
if (out.empty()) out = reuse_path;
}
if (!replace.empty() && !in_place) {
std::fprintf(stderr, "rad-convert: --replace names weights --in-place writes again; a "
"conversion to a new file writes every changed weight anyway\n");
return 2;
}
if (in.empty() || out.empty()) { usage(); return 2; }
/* The output is opened with O_TRUNC, so it must not be the --reuse container unless
* --in-place is given. */
@@ -663,12 +685,10 @@ int main(int argc, char** argv) {
RadFile reuse;
if (!reuse_path.empty() && reuse.open(reuse_path.c_str()) != RAD_OK) return 1;
/* Further --reuse containers supply only weights the first lacks or holds converted otherwise:
* a container assembled from several converts (a mixed-precision recipe). */
* a container assembled from several converts (a mixed-precision recipe). With --in-place the
* first is the container extended and the others supply the planes of weights written past
* its end. */
std::deque<RadFile> reuse_extra;
if (!reuse_more.empty() && in_place) {
std::fprintf(stderr, "rad-convert: --in-place extends one container; give --reuse once\n");
return 2;
}
for (const std::string& r : reuse_more) {
reuse_extra.emplace_back();
if (reuse_extra.back().open(r.c_str()) != RAD_OK) return 1;
@@ -926,12 +946,12 @@ int main(int argc, char** argv) {
return n;
};
/* The KV cache width is a serve-time choice the container does not record; only the kernels
* differ (an fp8-cache attention may have no bf16 form). Without --kv-cache-dtype, check
* differ (an int8-cache attention may have no bf16 form). Without --kv-cache-dtype, check
* against the first width at which every op resolves, else report the one with fewest holes. */
const std::vector<int> widths = kv_dtype != RAD_DT_INVALID
? std::vector<int>{ kv_dtype }
: std::vector<int>{ RAD_BF16, RAD_F8E4M3 };
auto width_name = [](int dt) { return dt == RAD_F8E4M3 ? "fp8" : "bf16"; };
: std::vector<int>{ RAD_BF16, RAD_I8 };
auto width_name = [](int dt) { return dt == RAD_I8 ? "i8" : "bf16"; };
Program prog;
size_t dead = 0;
for (size_t k = 0; k < widths.size(); ++k) {
@@ -1161,10 +1181,13 @@ int main(int argc, char** argv) {
};
std::vector<Job> jobs;
jobs.reserve(plan.size());
int64_t reused_inplace = 0, n_inplace = 0, n_changed = 0;
int64_t reused_inplace = 0, n_inplace = 0, n_changed = 0, n_deferred = 0;
std::vector<int64_t> defer_hits(defer.size(), 0);
std::vector<int64_t> replace_hits(replace.size(), 0);
int64_t n_replaced = 0, replaced_dead = 0;
for (Logical* Lp : plan) {
Logical& L = *Lp;
/* What the writer is told of a logical weight. */
auto weight_of = [](const Logical& L) {
RadWriter::Weight ww;
ww.name = L.src.name;
const RecipeRule* rr = L.rule ? L.rule->rule : L.import_rule;
@@ -1176,10 +1199,56 @@ int main(int argc, char** argv) {
ww.layer = L.layer;
ww.expert = L.expert;
ww.slot = L.slot;
return ww;
};
/* Whether container R holds `ww` as entry `e` with the planes this run would write: the same
* encoding, quantiser, options and shape, and for an expert the same place in its layer. */
auto held_same = [](const RadFile& R, const RadFileEntry& e, const RadWriter::Weight& ww) {
const bool expert = ww.expert >= 0 || e.expert >= 0;
bool same = rad_enc_equal(&R.encoding(e), &ww.enc) && ww.quantizer == R.str(e.quantizer) &&
ww.options == R.str(e.options) && e.rank == ww.rank &&
(!expert || (e.layer == ww.layer && e.expert == ww.expert &&
e.slot == ww.slot));
for (uint32_t i = 0; same && i < RAD_MAX_RANK; ++i)
if (e.shape[i] != ww.shape[i]) same = false;
return same;
};
auto replace_names = [&](const std::string& name) {
for (const std::string& g : replace)
if (recipe_glob(g.c_str(), name.c_str())) return true;
return false;
};
/* The layers whose experts --replace writes again: a layer's experts sit at one stride, so the
* ones whose rule did not change move with the ones whose did, their planes copied. */
std::unordered_set<int32_t> moved_layers;
if (in_place && !replace.empty())
for (const Logical* Lp : plan) {
if (Lp->expert < 0) continue;
const RadWriter::Weight ww = weight_of(*Lp);
const RadFileEntry* re = reuse.find(ww.name);
if (re && !held_same(reuse, *re, ww) && replace_names(ww.name))
moved_layers.insert(ww.layer);
}
int64_t n_moved = 0, moved_bytes = 0;
/* Written past the end of an --in-place container from another --reuse container's planes. */
int64_t n_from_other = 0, other_bytes = 0;
for (Logical* Lp : plan) {
Logical& L = *Lp;
RadWriter::Weight ww = weight_of(L);
int64_t plane_total = 0;
for (int k = 0; k < L.enc.n_planes; ++k)
plane_total += rad_enc_plane_bytes(&L.enc.plane[k], L.src.rows, L.src.cols);
/* --- Deferred: left for a later --in-place run, unless the container being extended holds
* it already. Its checkpoint tensors are not read. */
{
bool hit = false;
for (size_t d = 0; d < defer.size(); ++d)
if (recipe_glob(defer[d].c_str(), ww.name.c_str())) { ++defer_hits[d]; hit = true; }
if (hit && !(in_place && reuse.find(ww.name))) { ++n_deferred; continue; }
}
/* --- Reused: the same encoding, quantiser, options and shape in the --reuse container give
* the same planes, assuming the same checkpoint (the operator's responsibility; neither
* container records e.g. a Hessian's contents). */
@@ -1194,50 +1263,73 @@ int main(int argc, char** argv) {
/* The movement group is the declaration's either way (add_weight and add_existing
* record ww's), so a plugin that regroups a weight still reuses its planes; only an
* expert's layer, index and slot say where its planes sit in a stride table. */
const bool expert = ww.expert >= 0 || re->expert >= 0;
bool same = rad_enc_equal(&reuse.encoding(*re), &ww.enc) &&
ww.quantizer == reuse.str(re->quantizer) &&
ww.options == reuse.str(re->options) && re->rank == ww.rank &&
(!expert || (re->layer == ww.layer && re->expert == ww.expert &&
re->slot == ww.slot));
for (uint32_t i = 0; same && i < RAD_MAX_RANK; ++i)
if (re->shape[i] != ww.shape[i]) same = false;
const bool same = held_same(reuse, *re, ww);
if (in_place) {
if (!same) {
/* --replace: the weight is written again past the end and the old planes are
* left behind. Every glob that matches counts, as --defer's do. */
bool rep = false;
for (size_t d = 0; d < replace.size(); ++d)
if (recipe_glob(replace[d].c_str(), ww.name.c_str())) {
++replace_hits[d];
rep = true;
}
if (!same && !rep) {
RAD_ERR("--in-place: '%s' is in %s as %s by '%s %s', and this run would write "
"it as %s by '%s %s'. A weight cannot be replaced in place; convert "
"to a new file.", ww.name.c_str(), reuse_path.c_str(),
"it as %s by '%s %s'. Name it with --replace to write it again past "
"the end, or convert to a new file.", ww.name.c_str(),
reuse_path.c_str(),
enc_name(reuse.encoding(*re)).c_str(), reuse.str(re->quantizer),
reuse.str(re->options), enc_name(ww.enc).c_str(),
ww.quantizer.c_str(), ww.options.c_str());
w.abort();
return 1;
}
if (w.add_existing(ww, reuse, *re) < 0) { w.abort(); return 1; }
reused_inplace += (int64_t)re->bytes;
++n_inplace;
continue;
/* An unchanged expert of a layer that is written again goes with it: the same
* planes, copied past the end (the job below reads them from the container). */
const bool moved = same && ww.expert >= 0 && moved_layers.count(ww.layer) != 0;
if (same && !moved) {
if (w.add_existing(ww, reuse, *re) < 0) { w.abort(); return 1; }
reused_inplace += (int64_t)re->bytes;
++n_inplace;
continue;
}
if (moved) { ++n_moved; moved_bytes += (int64_t)re->bytes; }
else ++n_replaced;
replaced_dead += (int64_t)re->bytes;
}
if (!same) re = nullptr;
re = same ? re : nullptr;
}
RadFile* rf = re ? &reuse : nullptr;
for (size_t x = 0; !re && !reads_changed && x < reuse_extra.size(); ++x) {
RadFile& R = reuse_extra[x];
const RadFileEntry* e = R.find(ww.name);
if (!e) continue;
const bool expert = ww.expert >= 0 || e->expert >= 0;
bool same = rad_enc_equal(&R.encoding(*e), &ww.enc) && ww.quantizer == R.str(e->quantizer) &&
ww.options == R.str(e->options) && e->rank == ww.rank &&
(!expert || (e->layer == ww.layer && e->expert == ww.expert &&
e->slot == ww.slot));
for (uint32_t i = 0; same && i < RAD_MAX_RANK; ++i)
if (e->shape[i] != ww.shape[i]) same = false;
if (same) { re = e; rf = &R; }
if (held_same(R, *e, ww)) {
re = e;
rf = &R;
if (in_place) { ++n_from_other; other_bytes += (int64_t)e->bytes; }
}
}
const int64_t idx = w.add_weight(ww);
if (idx < 0) { w.abort(); return 1; }
jobs.push_back(Job{ Lp, idx, re, rf, plane_total });
}
/* A --replace glob no weight of the container matches is a typo too. */
for (size_t d = 0; d < replace.size(); ++d)
if (!replace_hits[d]) {
RAD_ERR("--replace %s matches no weight %s holds", replace[d].c_str(),
reuse_path.c_str());
w.abort();
return 1;
}
/* A --defer glob no weight matches is a typo; refuse it. */
for (size_t d = 0; d < defer.size(); ++d)
if (!defer_hits[d]) {
RAD_ERR("--defer %s matches no weight of this conversion", defer[d].c_str());
w.abort();
return 1;
}
/* A --changed name no weight reads is a typo or an unconverted tensor; refuse it. */
if (!changed.empty()) {
std::vector<std::string> unread;
@@ -1565,15 +1657,30 @@ int main(int argc, char** argv) {
RAD_INFO("wrote %s: %lld weight(s), %s of weights, %u vocab token(s)", out.c_str(),
(long long)w.weight_count(), humanb(written.load()).c_str(),
(unsigned)vb.tokens.size());
if (in_place)
if (in_place) {
RAD_INFO("--in-place: %lld weight(s), %s, kept where they were in %s; %lld added past "
"its end", (long long)n_reused.load(), humanb(reused.load()).c_str(),
reuse_path.c_str(), (long long)(w.weight_count() - n_reused.load()));
"its end", (long long)(n_reused.load() - n_moved - n_from_other),
humanb(reused.load() - moved_bytes - other_bytes).c_str(), reuse_path.c_str(),
(long long)(w.weight_count() - n_reused.load() + n_moved + n_from_other));
if (n_from_other)
RAD_INFO("--in-place: %lld of the added weight(s), %s, are another --reuse "
"container's planes", (long long)n_from_other, humanb(other_bytes).c_str());
if (n_replaced)
RAD_INFO("--replace: %lld of the added weight(s) replace one the container held and "
"%lld unchanged expert(s) of their layers moved with them, planes copied; "
"%s of old planes are unreachable until it is converted to a new file "
"(rad-info --unreferenced lists them)",
(long long)n_replaced, (long long)n_moved, humanb(replaced_dead).c_str());
}
else if (reuse.is_open())
RAD_INFO("--reuse: %lld weight(s), %s, copied from %s; the other %lld were written",
(long long)n_reused.load(), humanb(reused.load()).c_str(), reuse_path.c_str(),
(long long)(w.weight_count() - n_reused.load()));
if (n_deferred)
RAD_WARN("--defer: %lld weight(s) left out. The container does not load until --in-place "
"runs have added them", (long long)n_deferred);
std::vector<const Logical*> measured;
for (const Logical* L : plan) if (L->err >= 0) measured.push_back(L);
if (!measured.empty()) {