diff --git a/core/config.cpp b/core/config.cpp index 47c147b4..812ac10b 100644 --- a/core/config.cpp +++ b/core/config.cpp @@ -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); } }, diff --git a/core/engine_bringup.cpp b/core/engine_bringup.cpp index 77517438..c42871ca 100644 --- a/core/engine_bringup.cpp +++ b/core/engine_bringup.cpp @@ -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"); diff --git a/core/rad_core.h b/core/rad_core.h index c23c9f55..c6447c01 100644 --- a/core/rad_core.h +++ b/core/rad_core.h @@ -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 diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 332d37a4..d81c506a 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -1442,8 +1442,11 @@ runs, it moves every token's residual stream off that direction. radiance implem `--cvec-mode project` operation for it (`hc_project`, `docs/OPS.md`), which is what the published package for Qwen3.8-Flash-Next was tuned for: -**The switch is present whenever a compatible vector is there — there is nothing to pass on the -command line.** The engine looks, in order, at: +**One flag loads it: `--control-vector off` or `--control-vector on`** (explicit +`--control-vector disabled` is the same as no flag). Without it nothing is loaded: the graph declares no projection op (so an off request costs the stock model's launches), a +request that asks for the vector is refused by name, and `/admin/control-vector` answers 404. 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. With the flag the engine looks, in order, at: 1. `.control-vector.gguf` beside the model, and 2. `control-vector.gguf` in the container's directory (one file serves a directory of quants of @@ -1451,12 +1454,13 @@ command line.** The engine looks, in order, at: 3. `/vectors/-control-vector.gguf` for each `--radiance-home`, i.e. `…/vectors/qwen4exp-control-vector.gguf`. -So a deployment that drops the file beside its Flash-Next container offers the Model-view switch and -the `control_vector` request field with nothing else to configure; every quantisation of the family -shares it, because the file names the architecture and the width, not the quant. The operation's -parameters come from the package's own JSON (`layer_range`, `scale`, `mode`), so there is no flag for -them either: a file that does not fit this container is reported and skipped, never served. The -default for *requests* is off at startup. +So a deployment that starts with `--control-vector off` (or `on`) and drops the file beside its +Flash-Next container offers the Model-view switch and the `control_vector` request field; every +quantisation of the family shares it, because the file names the architecture and the width, not the +quant. The operation's parameters come from the package's own JSON (`layer_range`, `scale`, `mode`), +so there is no flag for them: a file that does not fit this container is reported and skipped, never +served. Only the startup switch is a flag, because it is the one decision that changes the declared +graph. - **Only a compatible container accepts it.** The file must be a GGUF `controlvector` whose `controlvector.model_hint` (when present) is this model's architecture (`qwen4exp`), whose @@ -1467,6 +1471,10 @@ default for *requests* is off at startup. requests that name no choice, and a request's own `control_vector` field always wins. **No switch reloads the model**: the directions are uploaded once at startup and each step carries a per-request row mask. +- **What the states cost** (this box, 4,096-token answers, speculation off, one boot per state, + median of six): stock 85.1 tok/s decode, `disabled` 86.1 (the same graph, nothing to pay), `off` + 83.7 (41 launches a token, each returning at the zero-row guard — values untouched), `on` 82.8 + (the projection itself). Prefill is the same in all four, 3,661–3,710 tok/s. - **The op is a no-op when off** — it skips a disabled row without reading or writing it, so an unprojected request's stream is the one the stock model computes. Measured in the engine's own KLD mode (`--kld-record` on stock 1.9.0, `--kld-ref` on this branch, both `--deterministic`, 227 @@ -1477,7 +1485,7 @@ default for *requests* is off at startup. its own corpus. The boot-to-boot spread is bimodal (≈0.02 or ≈0.08 mean KL, top-1 ≈96.5% or ≈92.5%) and wider than the effect, so reproducibility — not the feature — is what limits a quality claim on this box; within one boot it is exact (a repeated request is bit-identical, and - `control_vector: false` matches sending no field). With no vector file present the two builds + `control_vector: false` matches sending no field). Without `--control-vector` the two builds declare the same graph (same ops, buffers, arena and kernel selections, 17,090,734 bytes of `--debug-graph` either way; its listing varies in row order, so content, not bytes), and the table's own bytes are taken back out of the VRAM budget so the plan cannot see them @@ -1544,6 +1552,7 @@ The published vector, its JSON and the llama.cpp patches it was built against ar |---|---| | `--model PATH` | required: the `.rad` container, a checkpoint served as it stands (§3.4), or a Hugging Face repo id fetched before startup (§3.1) | | `--download-dir DIR` | where a repo id is fetched to. Default `$XDG_CACHE_HOME/radiance/hf`, else `~/.cache/radiance/hf` | +| `--control-vector off\|on\|disabled` | `disabled` (and no flag at all) loads nothing, declares no projection op and refuses a request that asks; `off` loads the vector found for this model and starts requests off; `on` starts them on (§4.10) | | `--radiance-home DIRS` | where `kernels/`, `architectures/` and `quantizers/` live; homes separated by `:` are searched in order, the first winning (§1.5) | | `--kernels LIST` | the kernel libraries to use, separated by `,` or `:`, first wins; a library not named is not loaded. Default: every library found | diff --git a/docs/TOOLS.md b/docs/TOOLS.md index 443d2266..b349a0a7 100644 --- a/docs/TOOLS.md +++ b/docs/TOOLS.md @@ -794,6 +794,10 @@ The mode changes these settings itself: Everything else comes from the command line: run every candidate with the same flags, and the reference with the exact wire and a bf16 KV cache. +The control vector's switch is per request, and KLD mode serves none, so a deployment that has one +loaded is scored with it **off**. `--control-vector on` starts the deployment default on, which is how +the projection itself is scored (the switch still decides per request, and a request's false wins). + `--kld-out FILE` writes the report as JSON, and every position's KL, both NLLs and the argmax agreement to `FILE.rows` (`[positions, 4]` f32, reference row order), so two candidates can be compared position by position. diff --git a/tests/config_test.cpp b/tests/config_test.cpp index 49883424..af3afa53 100644 --- a/tests/config_test.cpp +++ b/tests/config_test.cpp @@ -437,6 +437,7 @@ const std::map>& legal_values() { { "--num-speculative-tokens", { "2" } }, { "--draft-window", { "fixed" } }, { "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } }, { "--served-model-name", { "m" } }, { "--mm-max-patches", { "1024" } }, + { "--control-vector", { "off" } }, { "--generation-config", { "/g.json" } }, { "--override-chat-template", { "/t.jinja" } }, { "--temp", { "0.7" } }, { "--top-k", { "40" } }, { "--top-p", { "0.9" } }, { "--min-p", { "0.05" } }, { "--reasoning-effort", { "low" } }, @@ -603,6 +604,28 @@ TEST(the_placement_is_one_of_the_planners_four) { } } +/* Three states, and the absent one is the zero-cost default: off and on load the module, disabled -- + * or no flag -- does not, so no projection op is declared. */ +TEST(the_control_vector_flag_is_off_on_or_disabled) { + for (const char* ok : { "off", "on", "disabled" }) { + Config c; + CHECK_EQ(parse({ "--control-vector", ok }, &c), RAD_OK); + CHECK_EQ(c.control_vector, std::string(ok)); + } + { + Config c; + CHECK_EQ(parse({}, &c), RAD_OK); + CHECK_EQ(c.control_vector, std::string("disabled")); + } + for (const char* bad : { "auto", "OFF", "", "1", "true" }) { + Config c; + int st = RAD_OK; + const std::string log = stderr_of([&] { st = parse({ "--control-vector", bad }, &c); }); + CHECK_EQ(st, (int)RAD_E_INVAL); + CHECK(has(log, "--control-vector")); + } +} + TEST(the_wire_mode_is_one_of_two_names) { Config c; CHECK_EQ(parse({ "--tp-wire", "exact" }, &c), RAD_OK);