radiance 1.7.0

- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-16 18:25:18 +02:00
1 parent b068190326
commit 1e968f6e1d
739 files changed
+128447 -84632

No files matched your search

+85 -138
View File
@@ -19,8 +19,8 @@ namespace rad {
namespace {
/* dlsym returns void*, which is not a function pointer in standard C++ and is one everywhere this
* engine will ever run. The cast is isolated here so the rest of the file reads. */
/* dlsym returns void*; converting it to a function pointer is conditionally supported in
* standard C++ and works on every target here. The cast is isolated in one place. */
template <class Fn>
Fn dl_fn(void* h, const char* name) {
dlerror();
@@ -38,8 +38,8 @@ std::string stem_of(const std::string& path) {
const char* or_empty(const char* s) { return s ? s : ""; }
/* Does a plugin's declared coverage include this device's architecture? The field is a list, so a
* binary built for several is one entry per name, separated by spaces or commas. */
/* Whether a plugin's declared build target list (separated by spaces, commas or semicolons)
* names this device's architecture. */
bool target_covers(const std::string& declared, const char* arch) {
for (size_t i = 0; i < declared.size(); ) {
size_t e = declared.find_first_of(" ,;", i);
@@ -50,11 +50,10 @@ bool target_covers(const std::string& declared, const char* arch) {
return false;
}
/* Two schemas for one op name are the SAME schema when every positional slot means the same thing.
* Parameter keys, types and requiredness are load-bearing: they are the geometry the selector
* matches on. Operand roles, count and optionality are load-bearing: arguments are positional.
* Operand NAMES are not -- the ABI says they are for diagnostics -- so two plugins spelling slot 1
* "b" and "w_gate" agree, and refusing that would be refusing a synonym. */
/* Two schemas for one op are the same when every positional slot means the same thing: parameter
* keys, types and requiredness (what the selector matches on) and operand count, roles and
* optionality (arguments are positional). Operand names are for diagnostics only (ABI), so "b"
* and "w_gate" in slot 1 agree. */
bool schema_same(const RadOpSchema& a, const RadOpSchema& b, std::string* diff) {
if (a.n_params != b.n_params) {
*diff = fmt("%d parameters vs %d", a.n_params, b.n_params);
@@ -68,9 +67,8 @@ bool schema_same(const RadOpSchema& a, const RadOpSchema& b, std::string* diff)
return false;
}
if (x.type != y.type) {
*diff = fmt("parameter '%s' is %s vs %s", or_empty(x.key),
x.type == RAD_P_STR ? "a string" : "an integer",
y.type == RAD_P_STR ? "a string" : "an integer");
*diff = fmt("parameter '%s' is %s vs %s", or_empty(x.key), param_kind_name(x.type),
param_kind_name(y.type));
return false;
}
if (x.required != y.required) {
@@ -108,17 +106,16 @@ void Registry::err_(const char* f, ...) {
}
/* ------------------------------------------------------------------ staging */
/* dlopen and read the plugin's identity, without registering anything. Two phases, because the
* hierarchy is ordered by plugin NAME and the name lives inside the .so: the whole directory must
* be open before anything can be registered, and registration order is what fixes an op's schema. */
/* dlopen and read the plugin's identity without registering anything. Loading has two phases
* because the hierarchy is ordered by plugin name, which lives inside the .so: the whole directory
* is opened before anything registers, and registration order fixes an op's schema. */
int Registry::stage_(const std::string& path, Staged* out) {
out->path = path;
out->file = stem_of(path);
/* RTLD_LOCAL is not a preference. Every kernel plugin exports the same four symbol names --
* rad_kernel_count and friends -- so RTLD_GLOBAL would let the first plugin loaded answer for
* every plugin after it, and the failure would look like a plugin whose kernels vanished. We
* dlsym against the handle instead, which is exactly what RTLD_LOCAL is for. */
/* RTLD_LOCAL is required: every kernel plugin exports the same symbol names (rad_kernel_count
* and friends), so with RTLD_GLOBAL the first plugin loaded would answer for all later ones.
* Symbols are looked up per handle. */
out->code_from = rad::dev_code_mark();
out->handle = dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
out->code_to = rad::dev_code_mark();
@@ -135,10 +132,8 @@ int Registry::stage_(const std::string& path, Staged* out) {
}
const uint32_t v = abi();
if (v != RAD_ABI_VERSION) {
/* Named by FILE, not by RadPluginInfo::name: the struct is exactly the thing that may have
* changed shape between ABI versions, so reading it here would be reading a different
* layout than the one this build was compiled against. Both versions are printed because
* "ABI mismatch" alone does not tell an operator which side is stale. */
/* Named by file, not RadPluginInfo::name: that struct's layout may differ across ABI
* versions. Both versions are printed so the operator can tell which side is stale. */
err_("plugin '%s' was built against ABI version %u; this engine is version %u -- refused",
path.c_str(), v, (unsigned)RAD_ABI_VERSION);
unstage_(*out);
@@ -209,26 +204,25 @@ int Registry::commit_(Staged& s, int order) {
unstage_(s);
return RAD_E_INVAL;
}
/* The second half of the key. OPTIONAL: a plugin written before this export existed serves
* an unquantised container, which is what "" means, so its absence is not an error. */
/* The second half of the key. Optional: a plugin without it serves an unquantised
* container, which "" means. */
if (auto q_fn = dl_fn<const char* (*)(void)>(s.handle, "rad_arch_quant"))
p.arch_quant = or_empty(q_fn());
/* ALSO OPTIONAL, and for the same reason: it answers what the core needs to know before
* it can build the RadBuildCtx that declare runs against. Absent means every answer is
* the zero -- see rad_builder.h. */
/* Optional: answers what the core needs before it builds the RadBuildCtx for declare.
* Absent means every answer is zero (rad_builder.h). */
p.arch_probe = dl_fn<int (*)(const RadModelMeta*, RadArchProbe*)>(s.handle,
"rad_arch_probe");
/* AND THE REPLY FORMAT, optional for the same reason: a plugin that says nothing has its
* model's format read off the chat template. */
/* Optional: absent means the reply format is read off the chat template. */
p.arch_chat_format = dl_fn<const RadChatFormat* (*)(const RadModelMeta*)>(
s.handle, "rad_arch_chat_format");
/* Optional: absent means the model serves no speech route. */
p.arch_audio_format = dl_fn<const RadAudioFormat* (*)(const RadModelMeta*)>(
s.handle, "rad_arch_audio_format");
/* One plugin implements one architecture id AT ONE QUANTISATION, and no two may claim the
* same pair: the pair is what selects the plugin, so two claimants is a coin toss over
* which graph a model gets built from (§2.4). Two plugins sharing an id at different
* quantisations is the NORMAL case -- qwen35_bf16 and qwen35_fp8 are the same architecture
* over two weight formats -- and refusing that would make §2.4 unimplementable. */
/* The (architecture id, quantisation) pair selects the plugin, so no two plugins may claim
* the same pair (§2.4). Sharing an id at different quantisations is normal (qwen35_bf16
* and qwen35_fp8). */
for (const Plugin& q : plugins_) {
if (q.arch_id == p.arch_id && q.arch_quant == p.arch_quant) {
err_("architecture id '%s' at quantisation '%s' is claimed by both '%s' and '%s' "
@@ -251,9 +245,8 @@ int Registry::commit_(Staged& s, int order) {
return RAD_E_INVAL;
}
/* Schemas are checked WHOLE before any of them is committed. A plugin that conflicts on
* its fourth op must not leave its first three registered under its name -- a half-loaded
* plugin is a state nobody can reason about afterwards. */
/* All schemas are checked before any is committed, so a plugin refused on one op leaves
* nothing registered. */
n_declared_schemas = sc_n();
for (int i = 0; i < n_declared_schemas; ++i) {
const RadOpSchema* sch = sc_at(i);
@@ -267,11 +260,9 @@ int Registry::commit_(Staged& s, int order) {
auto it = schemas_.find(sch->op);
if (it != schemas_.end()) {
if (!schema_same(*it->second.schema, *sch, &diff)) {
/* Refused at load with both plugins named. Since arguments are positional, two
* disagreeing schemas would make the same call mean different things depending
* on which plugin won selection, and that is not a diagnosable failure -- it
* is silent numerical garbage (§2.3). The whole plugin is refused, not just
* the op: a plugin built against a different vocabulary is stale everywhere. */
/* Disagreeing positional schemas would silently change a call's meaning
* (§2.3). The whole plugin is refused, not just the op: it was built against
* a different vocabulary. */
err_("op '%s' has two different schemas: '%s' fixed it first, '%s' disagrees "
"(%s) -- refusing '%s'",
sch->op, it->second.plugin.c_str(), p.name.c_str(), diff.c_str(),
@@ -300,8 +291,7 @@ int Registry::commit_(Staged& s, int order) {
unstage_(s);
return RAD_E_INVAL;
}
/* A row with no entry point is a row that resolves and then cannot run, which is the
* one failure this layer exists to make impossible. */
/* A row with no entry point would resolve and then fail to run. */
if (!k->launch) {
err_("kernel '%s' in plugin '%s' has no launch function", k->name, p.name.c_str());
unstage_(s);
@@ -313,17 +303,10 @@ int Registry::commit_(Staged& s, int order) {
unstage_(s);
return RAD_E_INVAL;
}
/* EVERY TUNABLE AXIS CARRIES A DEFAULT, AND THE DEFAULT IS ONE OF ITS OWN VALUES.
*
* This is what makes an untuned install fast rather than broken (spec §15): a machine
* with no cache, a shape nobody measured, a cache from a different card -- all of them
* land on the defaults, and there is no other fallback beneath them. A kernel that
* declares an axis without a usable default has no answer at all for those cases, so
* it is refused here rather than resolving and then launching a zero tile.
*
* Checked at LOAD and not at first use, for the same reason the missing launch
* function above is: a library author finds out when the plugin loads, not when some
* shape three hours into a serve happens to miss the cache. */
/* Every tunable axis must carry a default that is one of its own values. Untuned
* shapes (no cache, an unmeasured shape, another card's cache) run the defaults, with
* no other fallback (spec §15). Checked at load rather than first use so a bad axis
* fails at startup, not when some shape first misses the cache. */
for (int v = 0; v < k->n_tunables; ++v) {
const RadTunable& t = k->tunables[v];
if (!t.key || !t.key[0] || !t.values || t.n_values <= 0) {
@@ -336,9 +319,7 @@ int Registry::commit_(Staged& s, int order) {
for (int j = 0; j < t.n_values; ++j) if (t.values[j] == t.deflt) ok = true;
if (!ok) {
err_("kernel '%s' in plugin '%s': tunable '%s' defaults to %lld, which is not "
"one of the values it declares. The default is what runs when this "
"machine has no measurement for a shape, so it has to be a value the "
"kernel can actually launch",
"one of its declared values",
k->name, p.name.c_str(), t.key, (long long)t.deflt);
unstage_(s);
return RAD_E_INVAL;
@@ -354,14 +335,12 @@ int Registry::commit_(Staged& s, int order) {
staged_rows.emplace_back(k, i);
}
/* A KERNEL LIBRARY WITH NO CODE FOR THIS CARD IS LEFT OUT OF THE CARD'S SELECTION. Its
* device rows would otherwise resolve -- a row's constraints say nothing about which card
* it was compiled for -- and the first launch would fail, so an installation carrying
* libraries for several cards would serve none of them but the first in the hierarchy.
* What the library carries is read out of the fat binaries its dlopen registered, which is
* what the launch itself will consult (core/device/aql_code.cpp), not out of
* build_target, which is prose. Its host rows run anywhere and stay. On the host backend
* an engine that serves says no GPU code runs at all (set_no_device_code). */
/* A kernel library with no code for this card has its device rows dropped: constraints
* do not say which card a row was compiled for, so the rows would resolve and then fail
* to launch, and an installation with libraries for several cards would serve only the
* first. Coverage is read from the fat binaries its dlopen registered, which the launch
* consults (core/device/aql_code.cpp), not from build_target. Host rows stay. On the host
* backend no GPU code runs at all (set_no_device_code). */
int n_device = 0;
for (const auto& r : staged_rows) n_device += r.first->domain == RAD_DOMAIN_DEVICE;
std::string why;
@@ -389,8 +368,7 @@ int Registry::commit_(Staged& s, int order) {
unstage_(s);
return RAD_E_INVAL;
}
/* Checked WHOLE before any is registered, for the reason the kernel schemas are: a plugin
* refused on its third quantiser must not leave the first two answering to a recipe. */
/* All checked before any is registered, as with kernel schemas. */
for (int i = 0, n = q_n(); i < n; ++i) {
const RadQuantizerInfo* q = q_at(i);
if (!q || !q->name || !q->name[0] || !q->encoding || !q->quantize) {
@@ -399,8 +377,8 @@ int Registry::commit_(Staged& s, int order) {
unstage_(s);
return RAD_E_INVAL;
}
/* A NAME IS ONE QUANTISER. A recipe that names it would otherwise mean different
* numbers depending on which plugin loaded first. */
/* Quantiser names are unique, so a recipe means the same thing whatever the load
* order. */
auto clash = [&](const char* other) { return std::strcmp(other, q->name) == 0; };
for (const QuantRow& r : quants_)
if (clash(r.info->name)) {
@@ -424,13 +402,12 @@ int Registry::commit_(Staged& s, int order) {
return RAD_E_INVAL;
}
/* Once after the plugin is loaded and before any selection (rad_abi.h). A plugin that cannot
* open -- no device, no config table -- is refused rather than asked to select. */
/* Called once after load, before any selection (rad_abi.h). A plugin that cannot open is
* refused. */
if (auto open = dl_fn<RadPluginOpenFn>(s.handle, "rad_plugin_open")) {
int st = open();
/* RAD_E_UNSUPPORTED is a plugin saying this machine is not one it serves -- a library for
* another card, in an installation that ships several. That is a skip, said once, and
* not a failure: the next library in the hierarchy is the one that serves this card. */
/* RAD_E_UNSUPPORTED: the plugin does not serve this machine (e.g. a library for another
* card). A skip, not a failure. */
if (st == RAD_E_UNSUPPORTED) {
RAD_INFO("plugin '%s' declines this machine and is not loaded", p.name.c_str());
unstage_(s);
@@ -443,15 +420,14 @@ int Registry::commit_(Staged& s, int order) {
}
}
/* What the plugin DECLARES, not what it fixed: a plugin below another one re-declares the same
* ops with the same shapes, and reporting 0 there would read as a plugin that declares
* nothing. Which plugin fixed a given op is schema_owner()'s answer, not a count. */
/* What the plugin declares, including ops an earlier plugin already fixed; schema_owner()
* answers which plugin fixed an op. */
p.n_schemas = n_declared_schemas;
p.n_kernels = (int)staged_rows.size();
for (const RadOpSchema* sch : staged_schemas) schemas_[sch->op] = SchemaEntry{sch, p.name};
for (const RadQuantizerInfo* q : staged_quants) {
quants_.push_back(QuantRow{ q, p.name });
/* Its own schemes are read through it, by everything that decodes a weight. */
/* Register its decoder so every weight reader can decode its schemes. */
if (q->decode) enc_add_decoder(q->decode);
}
const auto concurrent = dl_fn<RadKernelConcurrentFn>(s.handle, "rad_kernel_concurrent");
@@ -470,18 +446,10 @@ int Registry::commit_(Staged& s, int order) {
rows_.push_back(row);
}
/* A KERNEL LIBRARY BUILT FOR ANOTHER CARD FAILS AT EVERY LAUNCH, AND THIS IS THE ONE PLACE IT
* CAN BE NAMED ONCE. An installed .so travelling to a machine it was not compiled for is
* otherwise invisible until the first dispatch, where it surfaces as a driver error carrying a
* kernel name and nothing about why.
*
* A WARNING AND NOT A REFUSAL, deliberately. build_target is text the plugin's author writes;
* it is not derived from what the binary actually contains, so a library covering several
* architectures may still name only one, and refusing on it would be refusing on a claim the
* engine cannot verify. The launch is what is authoritative. This predicts it by name.
*
* "host" and "" are not claims about a device: the first is a library of CPU kernels, which
* run anywhere, and the second is a plugin that declines to claim anything. */
/* A library built for another card fails at every launch with an unhelpful driver error;
* warn once here instead. Only a warning: build_target is author-written text, not derived
* from the binary, so it cannot justify a refusal. "host" (CPU kernels) and "" (no claim) say
* nothing about a device. Applies to libraries whose dlopen registered no fat binaries. */
if (p.kind == RAD_PLUGIN_KERNEL && s.code_to == s.code_from && !p.build_target.empty() &&
p.build_target != "host") {
RadDeviceProps dp{};
@@ -502,9 +470,8 @@ int Registry::commit_(Staged& s, int order) {
return RAD_OK;
}
/* The per-op index select() walks, in (hierarchy order, declaration order). Rebuilt whole on every
* registration: loading is startup and the row count is in the hundreds, so the simple thing is
* also the fast enough thing, and an index that can never be stale is one fewer invariant. */
/* The per-op index select() walks, in (hierarchy order, declaration order). Rebuilt whole on
* every registration; there are only hundreds of rows, at startup. */
void Registry::index_rows_() {
by_op_.clear();
for (const KernelRow& r : rows_) by_op_[r.info->op].push_back(&r);
@@ -534,11 +501,9 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
const std::vector<std::string>& hierarchy) {
int first_error = RAD_OK;
/* Directory by directory in the order given, and within one in filename order, so a set of
* plugins nobody named still loads the same way twice. A file whose name an earlier directory
* already supplied is SHADOWED rather than loaded: the first directory is the one the operator
* put first -- their own plugins ahead of an installation's -- and loading both would be two
* plugins claiming one name, which is refused. */
/* Directories in the given order, files in filename order, so an unconfigured set loads
* reproducibly. A file name an earlier directory already supplied is shadowed: the operator's
* own plugins come ahead of an installation's, and loading both would be a duplicate name. */
std::vector<std::string> files, stems;
std::string where;
for (const std::string& dir : dirs) {
@@ -571,7 +536,6 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
stems.push_back(stem);
}
}
const std::string dir = where;
std::vector<Staged> staged;
for (const std::string& f : files) {
@@ -584,8 +548,8 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
staged.push_back(s);
}
/* An entry names a library by its declared name or by its file, written as the operator sees
* it on disk: `libr4d`, `r4d`, `libr4d.so` and a path to it are one library. */
/* An entry matches a library's declared name or its file: `libr4d`, `r4d`, `libr4d.so` and a
* path to it are one library. */
auto names = [](const std::string& h, const Staged& s) {
return h == s.name || h == s.file || stem_of(h) == s.file;
};
@@ -594,13 +558,10 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
if (s.info && s.info->kind == RAD_PLUGIN_KERNEL)
found += (found.empty() ? "" : ", ") + s.name;
/* A HIERARCHY NAMES THE KERNEL LIBRARIES THAT SERVE, AND ONLY THOSE LOAD. Ordering alone
* cannot keep a library out: selection runs per domain, so a library named first that has no
* device row for an op leaves that op to whichever unnamed library does -- a GPU library on a
* machine whose card it was not built for, say -- and an operator who listed what to use gets
* something else. A kernel library on the search path that the list leaves out is closed again
* before it registers anything, and said once. Architecture and quantiser plugins are not
* kernel libraries and no list ranks them. */
/* A non-empty hierarchy is exclusive. Ordering alone cannot keep a library out: selection
* runs per domain, so an op the named library has no device row for would fall to an unnamed
* one. Unnamed kernel libraries are closed before registering anything. Architecture and
* quantiser plugins are never ranked. */
if (!hierarchy.empty()) {
std::vector<Staged> kept;
std::string left_out;
@@ -623,17 +584,10 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
"does not name, and so not loaded: %s", left_out.c_str());
}
/* The hierarchy is configured, not discovered: a library the operator named takes that
* position. With no list every kernel library on the search path loads, so dropping an .so
* into the directory adds it with no configuration.
*
* A REFERENCE LIBRARY IS PINNED BELOW EVERY OTHER UNNAMED PLUGIN. It declares a kernel for
* every op it knows, so a plugin ranked behind it is unreachable -- an unnamed kernel library
* for this machine's card would load, never be selected for anything, and leave the whole
* model resolving to the naive implementation. Pinning it is what makes an unconfigured
* drop-in work. Naming it in the hierarchy places it where it is named, which is how it is put
* in front of a library to compare against. Which library is one is its own declaration
* (RadPluginReferenceFn), not its name. */
/* A named library takes its position in the list; unnamed ones follow. A reference library
* (RadPluginReferenceFn) is pinned below every other unnamed plugin, because it matches every
* op it declares and would make anything behind it unreachable. Naming it places it where
* named, e.g. ahead of a library to compare against. */
const size_t kUnnamed = (size_t)INT_MAX - 1;
std::vector<size_t> rank(staged.size());
for (size_t i = 0; i < staged.size(); ++i)
@@ -646,20 +600,19 @@ int Registry::load_dirs(const std::vector<std::string>& dirs,
hit = true;
}
}
/* The list is what loads, so an entry that matches nothing is a library that is not
* there to select -- and a list none of whose entries match loads no kernel library. */
/* The list is what loads: an entry that matches nothing loads nothing in its place. */
if (!hit)
RAD_WARN("--kernels (or RADIANCE_KERNELS) names '%s', which is no kernel library in "
"%s, so nothing loads in its place; the kernel libraries there are: %s",
hierarchy[h].c_str(), dir.c_str(), found.empty() ? "none" : found.c_str());
hierarchy[h].c_str(), where.c_str(), found.empty() ? "none" : found.c_str());
}
std::vector<size_t> idx(staged.size());
for (size_t i = 0; i < idx.size(); ++i) idx[i] = i;
std::stable_sort(idx.begin(), idx.end(),
[&](size_t a, size_t b) { return rank[a] < rank[b]; });
/* Orders continue from what is already loaded, so loading kernels/ and then architectures/
* does not produce two plugins at position 0. */
/* Continue from what is already loaded, so loading kernels/ then architectures/ does not put
* two plugins at position 0. */
int order = 0;
for (const Plugin& p : plugins_) order = std::max(order, p.order + 1);
@@ -683,18 +636,14 @@ int Registry::load_tune(const std::string& radiance_home, const std::string& mac
const std::string key = machine.empty() ? rad_machine_key() : machine;
const int s = tune_.load(radiance_home, key);
if (s < 0) return s;
/* A cache measured on another card is not a slower answer, it is a wrong one -- tunecache.h
* makes the machine key line 2 of the file for exactly this. `load` already refuses a
* mismatch, so reaching here with rows means they are this machine's. */
/* `load` refuses a file whose machine key (line 2, tunecache.h) is another machine's, so
* these rows are this machine's. */
return (int)tune_.rows().size();
}
/* Kernel plugins declare the ops they implement AND the parameter schema for each. A row whose op
* has no schema anywhere in the loaded set is a plugin that supplied only half of that contract,
* and the cost is exact: no architecture plugin's parameters for that op can ever be checked, so a
* typo in them becomes a silent miss instead of a named one. Checked once the set is complete,
* because an override plugin may legitimately rely on the schema of the plugin BELOW it, which
* loads later. */
/* A row whose op has no schema in the loaded set cannot have its parameters checked, so a typo
* would become a silent miss. Checked once the set is complete, because an override plugin may
* rely on the schema of a plugin below it, which loads later. */
int Registry::check_complete() {
int st = RAD_OK;
for (const KernelRow& r : rows_) {
@@ -729,9 +678,7 @@ void Registry::close() {
fini_instances();
for (const QuantRow& q : quants_)
if (q.info && q.info->decode) enc_remove_decoder(q.info->decode);
/* Reverse order: a plugin lower in the hierarchy may have been opened against state a higher
* one established, and unwinding in the order things were built is the only order that is
* always safe. */
/* Reverse load order: a later plugin may depend on state an earlier one established. */
for (auto it = plugins_.rbegin(); it != plugins_.rend(); ++it) {
if (it->close) it->close();
if (it->handle) dlclose(it->handle);