core: runtime LoRA declare, startup adapters, model routing and a per-adapter prefix key

--lora NAME=PATH, --max-loras, --max-lora-rank, --lora-target-modules. Off unless
named: no site, no pool, no op, and every prefix hash is what it was.
This commit is contained in:
baKon committed 2026-10-16 20:52:09 -05:00
1 parent 86cbc59063
commit ba406ace1b
18 files changed
+684 -4

No files matched your search

+16 -1
View File
@@ -4,6 +4,7 @@
*/
#include "build/startup.h"
#include "build/rad_build.h"
#include "lora/declare.h"
#include "format/tunecache.h"
#include "plugin/registry.h"
@@ -340,7 +341,8 @@ std::vector<std::string> CheckpointSources::refused() const {
int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const RadBuildCtx& ctx,
Program* out, const std::function<int(RadBuilder*, int64_t)>& also,
const Program* ref, const WeightSourceFn& sources, bool instances) {
const Program* ref, const WeightSourceFn& sources, bool instances,
const LoraDeclare* lora) {
if (!out) return RAD_E_INVAL;
Registry& r = rad_tools_registry();
@@ -355,6 +357,8 @@ int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const R
if (ref) b.set_reference(ref);
if (sources) b.set_sources(sources);
b.set_instances(instances);
const bool with_lora = lora && lora->cfg && lora->cfg->enabled();
if (with_lora) b.set_lora_targets(&lora->targets);
int s = ap->arch_declare(&b, &meta, &ctx);
if (s < 0) {
@@ -363,6 +367,17 @@ int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const R
return s;
}
/* RUNTIME LoRA, after the plugin and before the sampler: the sites read the plugin's finished
* graph, and the appended ops go through the same resolution as everything else. */
if (with_lora) {
b.set_lora_targets(nullptr);
s = lora_declare(b, *lora);
if (s < 0) {
for (const auto& e : b.errors()) RAD_ERR(" %s", e.c_str());
return s;
}
}
/* The sampler declares into the same builder before finish(). An unresolved sampler op is not
* a declare failure (a deployment that never sends `typical_p` needs no typical kernel), so a
* negative return here is structural. Skipped for embedding programs and image generators,