server: a control-vector variant, MODEL:NAME, that runs with the vector on

A request turns the control vector on with the `control_vector` body field, or the deployment's
default applies. A client that can only choose a model cannot send the field, and a gateway can
allow or refuse a model by its name but not a field. --control-vector-variant NAME lists
MODEL:NAME as a child of the model, the way an adapter is listed, and a request naming it runs
with the vector on whatever the default; the model's own name keeps the default. Unset, the
default, lists nothing.

The key needs --control-vector off or on. NAME keeps the rule model names keep (no ':' or
whitespace), and may not be a --lora adapter's name or the served model's own. The variant's
name with "control_vector": false is refused, since the request asks for both. With adapters
enabled the variant takes no adapter lookup, and /v1/load_lora_adapter refuses its name.

config_test 68, fleet_config_test 18 and server_test 191 cases pass, and the host suite
(ctest -LE 'gpu|oot') passes. On two R9700s at TP2 (Qwen3.8-Flash-Next IQR-V4 with the shipped
vector), through the front: /v1/models lists MODEL:uncensored and GET /v1/models/MODEL:uncensored
answers; a policy prompt to the variant is answered and to the model's own name refused; the
variant with "control_vector": false is a 400.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-11-16 17:57:46 +01:00
1 parent aadabde0de
commit 157959fd80
10 files changed
+250 -10

No files matched your search

+42
View File
@@ -162,6 +162,10 @@ static const Flag g_flags[] = {
" disabled -- the default, also with no flag at all -- loads\n"
" nothing: no projection op is declared, and a request that\n"
" asks for the vector is refused" },
{ "--control-vector-variant", "NAME", "list MODEL:NAME, a name of this model whose\n"
" requests run with the control vector on; the model's\n"
" own name keeps --control-vector's default. Needs\n"
" --control-vector off or on" },
{ "--deterministic", nullptr, "pin placement to the plan the loader made, so the resident\n"
" set cannot change under the heat engine. The sampler is\n"
" already order-independent and needs no pinning; note that\n"
@@ -548,6 +552,18 @@ static bool parse_template_kwargs(const char* v, std::map<std::string, std::stri
return true;
}
/* A name a request may give as `model`, by the rule a fleet applies to model ids and aliases
* (fleet::valid_name, in a file this one does not include): not empty, and no ':' (reserved for
* base:adapter), whitespace or control character. */
static bool plain_name(const char* s) {
if (!*s) return false;
for (; *s; ++s) {
const unsigned char ch = (unsigned char)*s;
if (ch == ':' || std::isspace(ch) || std::iscntrl(ch)) return false;
}
return true;
}
/* Returns 0 on success, 1 for --help (caller exits 0), negative on a bad argument. An unknown flag
* is an error, not a warning, since a mistyped budget flag changes the plan. */
int config_parse(int argc, char** argv, Config* c) {
@@ -806,6 +822,15 @@ int config_parse(int argc, char** argv, Config* c) {
}
c->control_vector = v;
}
else if (S("--control-vector-variant")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!plain_name(v)) {
RAD_ERR("--control-vector-variant takes a name with no ':' or whitespace -- "
"got '%s'", v);
return RAD_E_INVAL;
}
c->control_vector_variant = v;
}
else if (S("--deterministic")) c->deterministic = true;
else if (S("--checkpoint-interval")) { if (!num(0, INT64_MAX, &c->checkpoint_interval)) return RAD_E_INVAL; }
else if (S("--prefill-span")) { if (!num(1, INT32_MAX, &c->prefill_span)) return RAD_E_INVAL; }
@@ -1263,6 +1288,21 @@ int config_parse(int argc, char** argv, Config* c) {
RAD_ERR("--calib-corpus records into --calib-dir; give one");
return RAD_E_INVAL;
}
if (!c->control_vector_variant.empty()) {
if (c->control_vector == "disabled") {
RAD_ERR("--control-vector-variant needs --control-vector off or on: with no vector "
"loaded, '%s' would have nothing to switch on",
c->control_vector_variant.c_str());
return RAD_E_INVAL;
}
/* An adapter is named the same way, `base:name`, so the two must differ. */
for (const auto& [name, dir] : c->lora.adapters)
if (name == c->control_vector_variant) {
RAD_ERR("--control-vector-variant '%s' is also a --lora adapter's name, so a "
"request naming it could mean either; rename one", name.c_str());
return RAD_E_INVAL;
}
}
if ((!c->calib_dir.empty() || c->calib_layer_hi) && !c->calib() && c->kld_record.empty()) {
RAD_ERR("--calib-dir and --calib-layers belong to a --calib-corpus or --kld-record run");
return RAD_E_INVAL;
@@ -1473,6 +1513,8 @@ const ShowRow kShow[] = {
return o.empty() ? std::string(c.lora.enabled() ? "the adapters' own" : "-") : o; } },
{ "--placement", [](const Config& c) { return c.placement; } },
{ "--control-vector", [](const Config& c) { return c.control_vector; } },
{ "--control-vector-variant", [](const Config& c) {
return or_none(c.control_vector_variant, "none: no variant listed"); } },
{ "--deterministic", [](const Config& c) { return onoff(c.deterministic); } },
{ "--checkpoint-interval", [](const Config& c) { return num(c.checkpoint_interval); } },
{ "--prefill-span", [](const Config& c) { return num(c.prefill_span); } },