control vectors: load only when the deployment asks

The graph is declared once, so whether the projection op exists cannot follow a per-request
switch. It follows a startup flag instead:

  --control-vector off       load the vector found for this model, requests default off
  --control-vector on        the same, requests default on
  --control-vector disabled  load nothing (also the default with no flag)

`disabled` declares no op, so an unprojected request costs the stock model's launches rather
than 41 empty ones; a request that asks for the vector is refused by name and the admin route
answers 404. `off`/`on` keep the per-request switch and the dashboard default.

Measured four ways on one box (stock, disabled, off, on -- one boot each, six 4,096-token answers,
speculation off): decode 85.1 / 86.1 / 83.7 / 82.8 tok/s. `disabled` is the stock graph, so there
is nothing to pay; `off` pays the 41 launches, `on` pays the projection. KLD mode serves no
request to carry the switch, so `--control-vector on` is how the projection itself is scored;
config_test covers the three states and the absent default.
This commit is contained in:
C_Tamas authored and StillDeadcode committed 2026-10-21 09:26:17 +02:00
1 parent b15cbb546d
commit f9d80d6cac
6 files changed
+89 -20

No files matched your search

+14
View File
@@ -123,6 +123,11 @@ static const Flag g_flags[] = {
" adapters target. Needed with --max-loras and no --lora"},
{ "--placement", "MODE", "all_vram | layer_offload | expert_tiered | auto" },
{ "--control-vector", "MODE", "off | on | disabled: load the control-vector file found\n"
" for this model and start requests off (off) or on (on).\n"
" 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" },
{ "--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"
@@ -578,6 +583,14 @@ int config_parse(int argc, char** argv, Config* c) {
}
c->placement = v;
}
else if (S("--control-vector")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (std::strcmp(v, "off") && std::strcmp(v, "on") && std::strcmp(v, "disabled")) {
RAD_ERR("--control-vector takes off, on or disabled -- got '%s'", v);
return RAD_E_INVAL;
}
c->control_vector = 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; }
@@ -1036,6 +1049,7 @@ const ShowRow kShow[] = {
for (const std::string& t : c.lora.targets) o += (o.empty() ? "" : ",") + t;
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; } },
{ "--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); } },
+23 -11
View File
@@ -1073,14 +1073,19 @@ int Engine::declare() {
* table from RadBuildCtx, so a table that failed validation must stop the server before a graph
* is built around it.
*
* There is nothing to configure. A vector is a property of the model family, so the engine
* looks for one beside the container (or in the directory, or in $RADIANCE_HOME/vectors) and
* uses it if it is compatible with this container; its operation parameters come from the
* package's own JSON. A file that does not fit is reported and skipped -- a sidecar must never
* stop a server nobody pointed at it -- while the switch itself stays off until a request (or
* the dashboard) asks for it. */
* The feature is loaded only when the deployment asks: `--control-vector off|on`. Without it
* nothing is looked for, the graph declares no projection op, and a request that asks for one
* is refused by name -- so a deployment that does not use the feature pays nothing. With the
* flag, the engine looks beside the container (or in the directory, or in
* $RADIANCE_HOME/vectors) and uses the file if it is compatible; its operation parameters come
* from the package's own JSON. A file that does not fit is reported and skipped -- a sidecar
* must never stop a server nobody pointed at it. The flag's value is the startup switch: `off`
* leaves requests off until one asks (or the dashboard flips the default), `on` starts them on. */
const std::string arch = meta_.arch_id ? meta_.arch_id : "";
if (!arch.empty()) {
if (cfg_.control_vector == "disabled") {
RAD_INFO("control vectors: not loaded (no --control-vector); a request that asks for one is "
"refused");
} else if (!arch.empty()) {
std::string proj_path, tried;
(void) control_vector_discover(cfg_.model, arch, cfg_.radiance_home, &proj_path, &tried);
if (proj_path.empty()) {
@@ -1102,12 +1107,19 @@ int Engine::declare() {
if (cvec_.loaded()) {
cvec_views_.assign(ranks_.size(), RadControlVector{});
cvec_salt_ = control_vector_salt(cvec_);
cvec_default_.store(false);
/* `--control-vector on` starts the request default on, which is also how `--kld-record`/
* `--kld-ref` score the projection itself: those modes serve no request to carry the
* switch. The switch still decides per request. */
const bool default_on = cfg_.control_vector == "on";
cvec_default_.store(default_on);
RAD_INFO("control vectors: %s: %lld directions of %lld, layers %d..%d, scale %.3f -- "
"off until a request asks for it (the dashboard's switch, or a request's `control_vector` "
"field)",
"default %s%s",
cvec_.path.c_str(), (long long) cvec_.n_dirs,
(long long) cvec_.n_embd, cvec_.first, cvec_.last, (double) cvec_.user_scale);
(long long) cvec_.n_embd, cvec_.first, cvec_.last, (double) cvec_.user_scale,
default_on ? "ON" : "off",
default_on ? " (--control-vector on; a request can still say false)"
: " until a request asks for it (the dashboard's switch, or a request's "
"`control_vector` field)");
decide("control vectors", cvec_.path,
"found beside the container, in its directory, or in $RADIANCE_HOME/vectors; "
"requests opt in");
+7
View File
@@ -818,6 +818,13 @@ struct Config {
/* The pinned host pool one rank allocates: --host-pool-mib and the tables placed beside it. */
int64_t host_pool_total_mib() const { return host_pool_mib + embedding_host_mib + tower_host_mib; }
bool deterministic = false;
/* --control-vector off|on. Without the flag (`disabled`) no vector is loaded: the program
* declares no projection op, an off request costs the stock model's launches, and a request
* that asks for one is refused by name. `off` loads the vector found for this container -- the
* op is declared for its layers -- and starts requests off; `on` does the same with the request
* 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";
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