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); } },
+7
View File
@@ -3447,6 +3447,13 @@ int Engine::run_server() {
o.plugin_words = ranks_.empty() ? 0 : ranks_[0]->program.plugin_words;
o.model_id = !cfg_.served_model_name.empty() ? cfg_.served_model_name
: meta_.name && *meta_.name ? meta_.name : "radiance";
o.control_vector_variant = cfg_.control_vector_variant;
if (!o.control_vector_variant.empty() && o.control_vector_variant == o.model_id) {
RAD_ERR("--control-vector-variant '%s' is the served model's own name, so a request "
"naming it would run the default; rename it or give --served-model-name",
o.model_id.c_str());
return RAD_E_INVAL;
}
o.host = cfg_.host;
o.port = cfg_.port;
o.api_key = cfg_.api_key;
+6
View File
@@ -943,6 +943,12 @@ struct Config {
* default on. The graph is declared once, so this flag is the deployment's only decision about
* whether the op exists at all; the value names the startup switch. */
std::string control_vector = "disabled";
/* --control-vector-variant NAME: a second name for this model, listed as MODEL:NAME the way an
* adapter is, whose requests run with the vector on whatever the default; the model's own name
* keeps the default. Empty -- the default -- lists nothing, so a deployment that does not pick
* the vector by name sees no extra entry. A client that can only choose a model sends nothing
* else, and a gateway can allow or refuse the name. Needs --control-vector off or on. */
std::string control_vector_variant;
int64_t checkpoint_interval = 2048; /* linear-state checkpoints (spec §7.3) */
/* Checkpoint intervals one step may carry of a prefill alone in its step, from an interval
* boundary past the first (--prefill-span; 1 splits at every interval). The step's rows stay
+34 -7
View File
@@ -490,13 +490,18 @@ int Server::submit_all(const OaiRequest& r, std::vector<Generation>* gens, ApiEr
}
}
/* The control-vector variant is a name of the served model, not an adapter: it takes no
* slot. */
const bool variant =
!opt_.control_vector_variant.empty() && r.model == opt_.control_vector_variant;
/* Runtime LoRA: `model` picks the adapter. The served model's own name, or no name, is the
* base; with adapters enabled anything else must be a loaded adapter, since a typo served by
* the base would answer as the wrong model without a word. */
int32_t lora_slot = -1;
uint64_t lora_uid = 0;
std::shared_ptr<void> lora_hold;
if (opt_.lora_acquire && !r.model.empty() && r.model != opt_.model_id) {
if (opt_.lora_acquire && !r.model.empty() && r.model != opt_.model_id && !variant) {
if (opt_.lora_acquire(r.model, &lora_slot, &lora_uid, &lora_hold) != RAD_OK) {
std::string names = opt_.model_id;
if (opt_.lora_names)
@@ -511,14 +516,22 @@ int Server::submit_all(const OaiRequest& r, std::vector<Generation>* gens, ApiEr
}
}
/* The control vector: the request's own choice, else the deployment's runtime default. A
* deployment with no vector refuses the on state by name rather than serve the stock model. */
/* The control vector: the variant's name turns it on, else the request's own choice, else the
* deployment's runtime default. The variant's name with an explicit `false` is refused rather
* than served either way, since the request asks for both. A deployment with no vector refuses
* the on state by name rather than serve the stock model. */
bool projection_on = false;
{
const bool named = r.control_vector >= 0;
projection_on = named
? (r.control_vector == 1)
: (deps_.control_vector.get_default && deps_.control_vector.get_default());
if (variant && named && r.control_vector == 0) {
*err = err_bad("control_vector",
"is false, but model '" + r.model + "' is the control-vector variant, "
"which runs with the vector on; send one or the other");
return RAD_E_INVAL;
}
const bool by_default =
deps_.control_vector.get_default && deps_.control_vector.get_default();
projection_on = variant || (named ? r.control_vector == 1 : by_default);
if (projection_on &&
!(deps_.control_vector.available && deps_.control_vector.available())) {
*err = err_bad("control_vector",
@@ -2302,7 +2315,8 @@ HttpResponse Server::handle_models(const HttpRequest& req) {
std::vector<std::string> adapters;
if (opt_.lora_names) adapters = opt_.lora_names();
const bool is_adapter = !id.empty() && std::find(adapters.begin(), adapters.end(), id) != adapters.end();
if (!id.empty() && id != opt_.model_id && !is_adapter) {
const bool is_variant = !id.empty() && id == opt_.control_vector_variant;
if (!id.empty() && id != opt_.model_id && !is_adapter && !is_variant) {
ApiError e;
e.status = 404;
e.type = "not_found_error";
@@ -2325,6 +2339,15 @@ HttpResponse Server::handle_models(const HttpRequest& req) {
c.capabilities = capabilities().dump();
metrics_.observe_http(200);
std::vector<ModelCard> cards{ c };
/* The control-vector variant is listed as a child of the model, as an adapter is, so the front
* names it `base:name` and a client that only picks a model can find it. */
if (!opt_.control_vector_variant.empty()) {
ModelCard vc = c;
vc.id = opt_.control_vector_variant;
vc.parent = opt_.model_id;
cards.push_back(vc);
if (is_variant) return HttpResponse::json_body(200, model_body(vc));
}
for (const std::string& a : adapters) {
ModelCard ac = c;
ac.id = a;
@@ -2383,6 +2406,10 @@ HttpResponse Server::handle_lora_admin(const HttpRequest& req, bool load) {
const std::string name = j["lora_name"].get<std::string>();
if (name.empty() || name == opt_.model_id)
return fail(400, "invalid_request_error", "lora_name must be non-empty and not the served model's name");
if (load && !opt_.control_vector_variant.empty() && name == opt_.control_vector_variant)
return fail(400, "invalid_request_error",
"lora_name '" + name + "' is this model's control-vector variant "
"(--control-vector-variant), so a request naming it could mean either");
std::string err;
int s;
int in_flight = 0;
+4
View File
@@ -192,6 +192,10 @@ struct ServerOptions {
* of an adapter requests still use drains it: RAD_OK with *in_flight > 0 (Engine::lora_unload). */
std::function<int(const std::string&, const std::string&, std::string*)> lora_load;
std::function<int(const std::string&, std::string*, int*)> lora_unload;
/* --control-vector-variant: the name whose requests run with the control vector on, as the
* server sees it (the front strips `base:` from it as from an adapter's). Empty: no such
* name. */
std::string control_vector_variant;
/* A generator's adapters (Engine::gen_lora_acquire): the images and videos endpoints' `loras`
* and <lora:...> tags get a slot holding that combination, a hold on it and a note on what was
* left out; `gen_lora_names` is GET /v1/loras. Unset without adapters. */