Archived
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.
194 lines
7.8 KiB
C++
194 lines
7.8 KiB
C++
/* schema.cpp -- the op-schema registry and the check an architecture plugin's declared parameters
|
|
* go through. spec.md §2.3.
|
|
*
|
|
* Without a schema, a typo and an unimplemented op give the same "nothing resolved". With one, a
|
|
* misspelled op fails declare with the near-miss named. The core learns the op vocabulary from
|
|
* the plugins, so new ops need no core change.
|
|
*/
|
|
#include "registry.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
|
|
namespace rad {
|
|
|
|
namespace {
|
|
|
|
/* Levenshtein, O(nm). Runs on short names, once per failed declare. */
|
|
int edit_distance(std::string_view a, std::string_view b) {
|
|
const size_t n = b.size();
|
|
std::vector<int> prev(n + 1), cur(n + 1);
|
|
for (size_t j = 0; j <= n; ++j) prev[j] = (int)j;
|
|
for (size_t i = 1; i <= a.size(); ++i) {
|
|
cur[0] = (int)i;
|
|
for (size_t j = 1; j <= n; ++j) {
|
|
const int sub = prev[j - 1] + (a[i - 1] == b[j - 1] ? 0 : 1);
|
|
cur[j] = std::min({ sub, prev[j] + 1, cur[j - 1] + 1 });
|
|
}
|
|
prev.swap(cur);
|
|
}
|
|
return prev[n];
|
|
}
|
|
|
|
/* How far a name may be from a known one and still be suggested: one edit for a short name, up
|
|
* to three for a long one. A wrong suggestion is worse than none. */
|
|
bool close_enough(std::string_view a, std::string_view b, int d) {
|
|
const size_t len = std::max(a.size(), b.size());
|
|
const int budget = len <= 4 ? 1 : (len <= 10 ? 2 : 3);
|
|
return d <= budget;
|
|
}
|
|
|
|
std::string suggest(std::string_view want, const std::vector<std::string>& known) {
|
|
std::string best;
|
|
int best_d = INT32_MAX;
|
|
for (const std::string& k : known) {
|
|
const int d = edit_distance(want, k);
|
|
if (d < best_d || (d == best_d && k < best)) { best_d = d; best = k; }
|
|
}
|
|
if (best.empty() || !close_enough(want, best, best_d)) return "";
|
|
return best;
|
|
}
|
|
|
|
} /* namespace */
|
|
|
|
const char* param_kind_name(int kind) {
|
|
switch (kind) {
|
|
case RAD_P_INT: return "an integer";
|
|
case RAD_P_STR: return "a string";
|
|
case RAD_P_RANGE: return "a range";
|
|
case RAD_P_F64: return "a float";
|
|
default: return "of an unknown kind";
|
|
}
|
|
}
|
|
|
|
const RadOpSchema* Registry::schema(std::string_view op) const {
|
|
auto it = set_->schemas.find(std::string(op));
|
|
return it == set_->schemas.end() ? nullptr : it->second.schema;
|
|
}
|
|
|
|
const Plugin* Registry::schema_owner(std::string_view op) const {
|
|
auto it = set_->schemas.find(std::string(op));
|
|
return it == set_->schemas.end() ? nullptr : plugin(it->second.plugin);
|
|
}
|
|
|
|
std::vector<std::string> Registry::op_names() const {
|
|
std::vector<std::string> out;
|
|
out.reserve(set_->schemas.size());
|
|
for (const auto& kv : set_->schemas) out.push_back(kv.first);
|
|
/* Include ops that have rows but no schema (check_complete() reports those), so a near-miss
|
|
* search can still name them. */
|
|
for (const KernelRow& r : set_->rows)
|
|
if (set_->schemas.find(r.info->op) == set_->schemas.end()) out.emplace_back(r.info->op);
|
|
std::sort(out.begin(), out.end());
|
|
out.erase(std::unique(out.begin(), out.end()), out.end());
|
|
return out;
|
|
}
|
|
|
|
std::string Registry::near_miss(std::string_view op) const {
|
|
return suggest(op, op_names());
|
|
}
|
|
|
|
int Registry::validate(std::string_view op, const RadParam* p, int n_p, std::string* err) const {
|
|
std::string sink;
|
|
if (!err) err = &sink;
|
|
err->clear();
|
|
|
|
const std::string name(op);
|
|
auto it = set_->schemas.find(name);
|
|
if (it == set_->schemas.end()) {
|
|
const std::string did = near_miss(op);
|
|
*err = fmt("no loaded kernel plugin declares op '%s'%s", name.c_str(),
|
|
did.empty() ? "" : fmt("; did you mean '%s'?", did.c_str()).c_str());
|
|
return RAD_E_NOSCHEMA;
|
|
}
|
|
const RadOpSchema& s = *it->second.schema;
|
|
|
|
std::vector<std::string> keys;
|
|
keys.reserve((size_t)s.n_params);
|
|
for (int i = 0; i < s.n_params; ++i) keys.emplace_back(s.params[i].key ? s.params[i].key : "");
|
|
|
|
int n_ranged = 0;
|
|
std::string ranged_key;
|
|
for (int i = 0; i < n_p; ++i) {
|
|
if (!p[i].key || !p[i].key[0]) {
|
|
*err = fmt("%s: parameter %d has no name", name.c_str(), i);
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
for (int j = 0; j < i; ++j) {
|
|
if (p[j].key && std::strcmp(p[i].key, p[j].key) == 0) {
|
|
*err = fmt("%s: parameter '%s' is given twice", name.c_str(), p[i].key);
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
}
|
|
|
|
const RadParamSpec* spec = nullptr;
|
|
for (int j = 0; j < s.n_params; ++j)
|
|
if (keys[(size_t)j] == p[i].key) { spec = &s.params[j]; break; }
|
|
if (!spec) {
|
|
const std::string did = suggest(p[i].key, keys);
|
|
*err = fmt("%s: no parameter '%s' in this op's schema%s", name.c_str(), p[i].key,
|
|
did.empty() ? "" : fmt("; did you mean '%s'?", did.c_str()).c_str());
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
|
|
/* A range is an integer parameter that has not been collapsed yet, so it satisfies an
|
|
* integer slot and nothing else. */
|
|
const bool int_ok = (p[i].kind == RAD_P_INT || p[i].kind == RAD_P_RANGE);
|
|
if (spec->type == RAD_P_INT && !int_ok) {
|
|
*err = fmt("%s: parameter '%s' is %s, but the schema says it is an integer",
|
|
name.c_str(), p[i].key, param_kind_name(p[i].kind));
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
if (spec->type == RAD_P_STR && p[i].kind != RAD_P_STR) {
|
|
*err = fmt("%s: parameter '%s' is %s, but the schema says it is a string",
|
|
name.c_str(), p[i].key, param_kind_name(p[i].kind));
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
if (spec->type == RAD_P_STR && !p[i].sval) {
|
|
*err = fmt("%s: string parameter '%s' is null", name.c_str(), p[i].key);
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
/* A float slot takes only a float: an integer would land in `ival` while the kernel
|
|
* reads `dval` (a silent zero eps). Constraints never match on a float (rad_types.h), so
|
|
* only this check catches it. */
|
|
if (spec->type == RAD_P_F64 && p[i].kind != RAD_P_F64) {
|
|
*err = fmt("%s: parameter '%s' is %s, but the schema says it is a float -- declare it "
|
|
"with RAD_F64()", name.c_str(), p[i].key, param_kind_name(p[i].kind));
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
|
|
if (p[i].kind == RAD_P_RANGE) {
|
|
if (p[i].ihi < p[i].ival) {
|
|
*err = fmt("%s: parameter '%s' is the empty range [%lld, %lld]", name.c_str(),
|
|
p[i].key, p[i].ival, p[i].ihi);
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
if (++n_ranged == 1) ranged_key = p[i].key;
|
|
else {
|
|
/* At most one ranged parameter per op, so the bucket-table index at issue is a
|
|
* single integer; the run phase depends on this (docs/OPS.md). */
|
|
*err = fmt("%s: '%s' and '%s' are both ranges; an op may have at most one ranged "
|
|
"parameter", name.c_str(), ranged_key.c_str(), p[i].key);
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < s.n_params; ++j) {
|
|
/* Only RAD_REQUIRED. RAD_DERIVED is supplied by the kernel: the caller cannot know, e.g.,
|
|
* the block size before a kernel resolves (rad_abi.h, spec §7.2). A caller may still
|
|
* supply one, which pins it. */
|
|
if (s.params[j].required != RAD_REQUIRED) continue;
|
|
bool given = false;
|
|
for (int i = 0; i < n_p && !given; ++i) given = (keys[(size_t)j] == p[i].key);
|
|
if (!given) {
|
|
*err = fmt("%s: required parameter '%s' was not given (declared by plugin '%s')",
|
|
name.c_str(), keys[(size_t)j].c_str(), it->second.plugin.c_str());
|
|
return RAD_E_SCHEMA;
|
|
}
|
|
}
|
|
return RAD_OK;
|
|
}
|
|
|
|
} /* namespace rad */
|