Archived
kld: --kld-lora NAME scores a runtime LoRA adapter against a reference
This commit is contained in:
1 parent
6490b900e2
commit
e419c1acc3
4 files changed
+21
No files matched your search
@@ -235,6 +235,7 @@ static const Flag g_flags[] = {
|
||||
" agreement, over the positions and tokens DIR was recorded at" },
|
||||
{ "--kld-corpus", "FILE", "JSONL, one {\"prompt\", \"score_from\"?, \"source\"?} a line; --kld-record only" },
|
||||
{ "--kld-out", "FILE", "the --kld-ref report as JSON, and every position's numbers in FILE.rows" },
|
||||
{ "--kld-lora", "NAME", "run --kld-record / --kld-ref through the --lora adapter NAME" },
|
||||
|
||||
{ "--debug-graph", nullptr, "print the entire declared graph and exit-quality detail" },
|
||||
{ "--debug-selection", nullptr, "print the selection table" },
|
||||
@@ -780,6 +781,7 @@ int config_parse(int argc, char** argv, Config* c) {
|
||||
else if (S("--kld-ref")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_ref = v; }
|
||||
else if (S("--kld-corpus")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_corpus = v; }
|
||||
else if (S("--kld-out")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_out = v; }
|
||||
else if (S("--kld-lora")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_lora = v; }
|
||||
else if (S("--debug-graph")) { c->debug_graph = true; c->debug_selection = true; }
|
||||
else if (S("--debug-selection")) c->debug_selection = true;
|
||||
else if (S("--debug-placement")) c->debug_placement = true;
|
||||
@@ -1033,6 +1035,7 @@ const ShowRow kShow[] = {
|
||||
{ "--kld-ref", [](const Config& c) { return or_none(c.kld_ref, "none"); } },
|
||||
{ "--kld-corpus", [](const Config& c) { return or_none(c.kld_corpus, "none"); } },
|
||||
{ "--kld-out", [](const Config& c) { return or_none(c.kld_out, "none"); } },
|
||||
{ "--kld-lora", [](const Config& c) { return or_none(c.kld_lora, "none (the base)"); } },
|
||||
{ "--debug-graph", [](const Config& c) { return onoff(c.debug_graph); } },
|
||||
{ "--debug-selection", [](const Config& c) { return onoff(c.debug_selection); } },
|
||||
{ "--debug-placement", [](const Config& c) { return onoff(c.debug_placement); } },
|
||||
|
||||
@@ -97,6 +97,20 @@ int Engine::run_kld() {
|
||||
if (too_long) return RAD_E_FULL;
|
||||
}
|
||||
|
||||
/* --kld-lora: every document runs through one runtime LoRA adapter, held for the whole run --
|
||||
* how an adapter is scored against a reference recorded from its merged or HF counterpart. */
|
||||
int32_t lora_slot = -1;
|
||||
uint64_t lora_uid = 0;
|
||||
std::shared_ptr<void> lora_hold;
|
||||
if (!cfg_.kld_lora.empty() &&
|
||||
lora_acquire(cfg_.kld_lora, &lora_slot, &lora_uid, &lora_hold) != RAD_OK) {
|
||||
RAD_ERR("kld: --kld-lora '%s' is not a loaded adapter (--lora NAME=PATH)", cfg_.kld_lora.c_str());
|
||||
return RAD_E_NOTFOUND;
|
||||
}
|
||||
if (lora_slot >= 0)
|
||||
RAD_INFO("kld: scoring through the runtime LoRA adapter '%s' (slot %d)", cfg_.kld_lora.c_str(),
|
||||
lora_slot);
|
||||
|
||||
/* Submit every document under one hold of the queue, so batching depends only on the corpus
|
||||
* and the flags and a rerun batches identically. */
|
||||
std::vector<std::unique_ptr<server::Sink>> sinks(n);
|
||||
@@ -110,6 +124,8 @@ int Engine::run_kld() {
|
||||
r->ignore_eos = true;
|
||||
r->sp.temp = 0.0f;
|
||||
r->score = true;
|
||||
r->lora_slot = lora_slot;
|
||||
r->lora_uid = lora_uid;
|
||||
r->sink = sinks[d].get();
|
||||
sinks[d]->id = r->id;
|
||||
reqs[d] = std::move(r);
|
||||
|
||||
@@ -816,6 +816,7 @@ struct Config {
|
||||
* of the two. */
|
||||
std::string kld_record; /* --kld-record DIR */
|
||||
std::string kld_ref; /* --kld-ref DIR */
|
||||
std::string kld_lora; /* --kld-lora NAME: score through this --lora adapter */
|
||||
std::string kld_corpus; /* --kld-corpus FILE, read by --kld-record only */
|
||||
std::string kld_out; /* --kld-out FILE: the report as JSON, rows beside it */
|
||||
bool kld() const { return !kld_record.empty() || !kld_ref.empty(); }
|
||||
|
||||
@@ -412,6 +412,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--kld-out", { "/o.json", "--kld-ref", "/r" } },
|
||||
{ "--lora", { "a=/adapters/a" } }, { "--max-loras", { "2" } },
|
||||
{ "--max-lora-rank", { "32" } }, { "--lora-target-modules", { "q_proj,v_proj" } },
|
||||
{ "--kld-lora", { "a", "--lora", "a=/adapters/a", "--kld-ref", "/r" } },
|
||||
};
|
||||
return v;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user