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

+28
View File
@@ -9,6 +9,7 @@
* which makes fusion a selection rather than a compiler pass (spec §2.3).
*/
#include "rad_build.h"
#include "lora/lora.h"
#include "../device/device.h"
#include <algorithm>
@@ -702,6 +703,33 @@ rad_op Builder::decl_op(const char* opname, const RadParam* p, int n_p,
}
}
/* RUNTIME LoRA: A FUSED GEMM OVER A TARGETED WEIGHT IS DECLINED. Every `gemm_*` op other than
* the four an adapter delta can follow (lora::op_is_site) fuses something into its epilogue --
* the gated fold quantises the SiLU product in place -- so the delta has no y to land in. The
* op is recorded resolved to nothing, exactly as a library without the kernel would leave it,
* and the plugin falls back to the unfused chain it emits for that library. The decision reads
* only the weight's own declaration and name map, so the sizing declare makes the same one. */
bool lora_declined = false;
if (lora_targets_ && n_w > 0 && oi.op.rfind("gemm_", 0) == 0 && oi.op != "gemm_nt" &&
oi.op != "gemm_nt_bias" && oi.op != "gemm_nt_q" && oi.op != "gemm_nt_q_bias") {
for (int i = 0; i < n_w && !lora_declined; ++i)
if (w[i] > 0 && w[i] < prog_.weights.size() &&
lora::weight_targeted(prog_, w[i], *lora_targets_))
lora_declined = true;
}
if (lora_declined) {
Band none;
none.hi = oi.ranged_key.empty() ? INT64_MAX : oi.range_hi;
for (int d = 0; d < RAD_N_DOMAINS; ++d)
none.miss[d] = "declined: its weight is a runtime-LoRA target, and a fused GEMM has no "
"output for the adapter's delta (the plugin runs the unfused chain)";
oi.bands.assign(1, none);
prog_.ops.push_back(std::move(oi));
op_bufs_.emplace_back();
return RAD_NULL_HANDLE;
}
if (ref_) {
const size_t at = prog_.ops.size();
if (at >= ref_->ops.size() || ref_->ops[at].op != oi.op)