Archived
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:
1 parent
aadabde0de
commit
157959fd80
10 files changed
+250
-10
No files matched your search
@@ -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); } },
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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. */
|
||||
|
||||
+11
-2
@@ -2257,6 +2257,13 @@ The shipped file is Cudecnik's published vector
|
||||
(`POST /admin/control-vector {"enabled": bool}`, behind `server.api-key`; without a key, from a
|
||||
loopback client only). A running request keeps the choice it was admitted with, and nothing is
|
||||
reloaded: the directions are uploaded once and each step carries a row mask.
|
||||
- **By name.** `control-vector-variant: NAME` lists `MODEL:NAME` in `/v1/models` as a child of the
|
||||
model, the way an adapter is (§4.9.1), while the model is loaded. A request naming it runs with
|
||||
the vector on whatever the default and needs no field: for a client that can only choose a model,
|
||||
and for a gateway that allows or refuses a model by its name. The model's own name keeps the
|
||||
default, and the response's `model` is the variant's name, as an adapter's is. The variant's name
|
||||
with `"control_vector": false` is refused, since the request asks for both. Under `defaults:` one
|
||||
name gives every model a variant of its own. Unset, nothing is listed.
|
||||
- **Cost.** A step in which no row takes the vector issues no projection, so `off` runs the same
|
||||
launches as the key unset. Measured on Flash-Next (`w4nl64-i8lm.rad`, TP2, the production settings,
|
||||
speculation off, three 1,536-token greedy answers): median decode of 89.7 tok/s with the key unset,
|
||||
@@ -2278,7 +2285,8 @@ The shipped file is Cudecnik's published vector
|
||||
- `kld-record` / `kld-ref` score every document at the deployment's default.
|
||||
- For the shipped vector, `on` removes a safety behaviour: the model stops refusing policy prompts
|
||||
and reveals its system prompt when asked. A deployment that exposes the API beyond one user should
|
||||
keep the default off and decide who may set the field.
|
||||
keep the default off and decide who may set the field. A variant gives a gateway a name it can
|
||||
allow or refuse; the field stays open to every client that reaches the API.
|
||||
|
||||
**What the switch does where it is aimed** (the PR's measurement: same boot, only `control_vector`
|
||||
changes; the stock column is a separate boot of 1.9.0). First generated token, 20-way distribution:
|
||||
@@ -2318,6 +2326,7 @@ switch is set with `true`. The fleet's own keys (a model's `aliases`, `priority`
|
||||
| `server.download-dir: DIR` | where a repo id is fetched to. Default `$XDG_CACHE_HOME/radiance/hf`, else `~/.cache/radiance/hf` |
|
||||
| `model-revision: REV` | the hub revision a repo id is fetched at: a branch, tag, full commit sha or `refs/pr/N`. Default the repo's moving `main` branch; a deployment that must not restart onto weights nobody reviewed should name a tag or a sha (§3.1) |
|
||||
| `control-vector: off\|on\|disabled` | `disabled` (and the key unset) 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. Refused at startup when the model's plugin does not apply control vectors or no compatible file is found (§4.10) |
|
||||
| `control-vector-variant: NAME` | unset (the default) lists nothing; a NAME lists `MODEL:NAME`, a name of this model whose requests run with the control vector on, while the model's own name keeps the `control-vector` default. Refused without `control-vector: off\|on`, for a NAME that holds `:` or whitespace, and for the name of a `lora` adapter or of the model itself (§4.10) |
|
||||
| `server.radiance-home: DIRS` | where `kernels/`, `architectures/` and `quantizers/` live; homes separated by `:` are searched in order, the first winning (§1.5) |
|
||||
| `server.kernels: LIST` | the kernel libraries to use, separated by `,` or `:`, first wins; a library not named is not loaded. Default: every library found |
|
||||
|
||||
@@ -2961,7 +2970,7 @@ passes but not launches (the UNet runs once per image and branch), so two take t
|
||||
|
||||
| field | notes |
|
||||
|---|---|
|
||||
| `model` | the model, by name or alias, or `base:adapter` for an adapter; without it the model named or aliased `default`, or the only one. An unknown model is 404 |
|
||||
| `model` | the model, by name or alias, `base:adapter` for an adapter, or `base:NAME` for the model's control-vector variant (§4.10); without it the model named or aliased `default`, or the only one. An unknown model is 404 |
|
||||
| `messages` / `prompt` / `input` | chat / completion / embedding |
|
||||
| `images_config` | image models only: the processor mode the request wants, by name (`gundam`, `base`) or as an object restating the served sizes; a geometry the model does not serve is refused (Unlimited-OCR, §5.18) |
|
||||
| `max_tokens`, `max_completion_tokens`, `max_output_tokens`, `max_new_tokens`, `n_predict` | default: what the context leaves after the prompt (`default-max-tokens`); -1 is llama-server's "no limit", the same without the default. Clamped to what the context leaves, and to `max-tokens-cap`, rather than refused (§5.8) |
|
||||
|
||||
+2
-1
@@ -250,7 +250,8 @@ stays until it expires, as a video kept by its server does.
|
||||
### 5.3 Adapters
|
||||
|
||||
LoRA adapters are addressed `base:adapter`. `/v1/load_lora_adapter` takes `base` explicitly. The
|
||||
`:` is reserved in model names and aliases.
|
||||
`:` is reserved in model names and aliases. A model's control-vector variant
|
||||
(`control-vector-variant`, GUIDE §4.10) is addressed and listed the same way, `base:NAME`.
|
||||
|
||||
### 5.4 Fleet-wide routes
|
||||
|
||||
|
||||
@@ -594,6 +594,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--trusted-proxy", { "127.0.0.0/8" } },
|
||||
{ "--served-model-name", { "m" } }, { "--mm-max-patches", { "1024" } },
|
||||
{ "--control-vector", { "off" } },
|
||||
{ "--control-vector-variant", { "uncensored", "--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" } },
|
||||
@@ -801,6 +802,37 @@ TEST(the_control_vector_flag_is_off_on_or_disabled) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The variant is a name a request gives as `model`, so it keeps the rule names keep, and it needs a
|
||||
* loaded vector: with none it would answer as the stock model while the client asked for the
|
||||
* vector. A --lora adapter of the same name would make `base:name` mean two things. */
|
||||
TEST(the_control_vector_variant_needs_a_vector_and_a_plain_name_of_its_own) {
|
||||
{
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--control-vector", "off", "--control-vector-variant", "uncensored" }, &c),
|
||||
RAD_OK);
|
||||
CHECK_EQ(c.control_vector_variant, std::string("uncensored"));
|
||||
}
|
||||
{
|
||||
Config c;
|
||||
CHECK_EQ(parse({}, &c), RAD_OK);
|
||||
CHECK(c.control_vector_variant.empty());
|
||||
}
|
||||
auto refused = [](std::initializer_list<const char*> v) {
|
||||
Config c;
|
||||
int st = RAD_OK;
|
||||
const std::string log = stderr_of([&] { st = parse(v, &c); });
|
||||
CHECK_EQ(st, (int)RAD_E_INVAL);
|
||||
CHECK(has(log, "--control-vector-variant"));
|
||||
};
|
||||
refused({ "--control-vector-variant", "uncensored" });
|
||||
refused({ "--control-vector", "disabled", "--control-vector-variant", "uncensored" });
|
||||
refused({ "--control-vector", "off", "--control-vector-variant", "base:uncensored" });
|
||||
refused({ "--control-vector", "off", "--control-vector-variant", "two words" });
|
||||
refused({ "--control-vector", "off", "--control-vector-variant", "" });
|
||||
refused({ "--control-vector", "off", "--lora", "uncensored=/ad/u",
|
||||
"--control-vector-variant", "uncensored" });
|
||||
}
|
||||
|
||||
TEST(the_wire_mode_is_one_of_two_names) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--tp-wire", "exact" }, &c), RAD_OK);
|
||||
|
||||
@@ -304,6 +304,18 @@ TEST(defaults_sit_under_models) {
|
||||
CHECK_EQ(fc.models[1].priority, 5);
|
||||
}
|
||||
|
||||
/* The variant's name is listed per model, as MODEL:NAME, so one name under defaults: gives every
|
||||
* model a variant of its own without a collision: the switch for a whole fleet at once. */
|
||||
TEST(a_control_vector_variant_under_defaults_reaches_every_model) {
|
||||
fleet::FleetConfig fc;
|
||||
CHECK_EQ(yload("defaults:\n control-vector: off\n control-vector-variant: uncensored\n"
|
||||
"models:\n a:\n model: /m/a.rad\n b:\n model: /m/b.rad\n", &fc), RAD_OK);
|
||||
CHECK_EQ(fc.models[0].cfg.control_vector_variant, "uncensored");
|
||||
CHECK_EQ(fc.models[1].cfg.control_vector_variant, "uncensored");
|
||||
CHECK_EQ(fc.models[1].cfg.given.at("--control-vector-variant"),
|
||||
"defaults.control-vector-variant");
|
||||
}
|
||||
|
||||
TEST(anchors_and_merge_keys) {
|
||||
fleet::FleetConfig fc;
|
||||
/* Top-level keys starting with x- are ignored, so they can hold anchors. */
|
||||
|
||||
@@ -5057,6 +5057,106 @@ int status_with(Fixture& f, const std::string& ep, const std::string& key, const
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* --control-vector-variant: the variant's name runs the vector whatever the default, the model's
|
||||
* own name keeps the default, an explicit false beside the variant's name is refused as the
|
||||
* contradiction it is, and the name is listed as a child of the model the way an adapter is. */
|
||||
TEST(the_control_vector_variant_runs_with_the_vector_and_is_listed) {
|
||||
Fixture f(Fixture::Tweak{ [](ServerOptions& o, Deps& d) {
|
||||
o.control_vector_variant = "uncensored";
|
||||
d.control_vector.available = [] { return true; };
|
||||
d.control_vector.get_default = [] { return false; };
|
||||
} });
|
||||
HttpResponse r = f.post("/v1/chat/completions",
|
||||
R"({"model":"uncensored","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4})");
|
||||
if (r.streaming()) drain(r);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r.status, 200);
|
||||
CHECK(f.sched.last_sp.use_control_vector);
|
||||
|
||||
/* The model's own name runs the default, off here. */
|
||||
HttpResponse r2 = f.post("/v1/chat/completions",
|
||||
R"({"model":"test-model","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4})");
|
||||
if (r2.streaming()) drain(r2);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r2.status, 200);
|
||||
CHECK(!f.sched.last_sp.use_control_vector);
|
||||
|
||||
/* The variant's name with an explicit true is the same request; with false it asks for both. */
|
||||
HttpResponse r3 = f.post("/v1/chat/completions",
|
||||
R"({"model":"uncensored","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4,"control_vector":true})");
|
||||
if (r3.streaming()) drain(r3);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r3.status, 200);
|
||||
CHECK(f.sched.last_sp.use_control_vector);
|
||||
HttpResponse r4 = f.post("/v1/chat/completions",
|
||||
R"({"model":"uncensored","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4,"control_vector":false})");
|
||||
if (r4.streaming()) drain(r4);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r4.status, 400);
|
||||
CHECK(r4.body.find("control_vector") != std::string::npos);
|
||||
CHECK(r4.body.find("uncensored") != std::string::npos);
|
||||
|
||||
/* Listed as a child of the model, and readable on its own. */
|
||||
const json all = json::parse(f.get("/v1/models").body);
|
||||
bool listed = false;
|
||||
for (const json& m : all["data"])
|
||||
if (m.value("id", std::string()) == "uncensored") {
|
||||
listed = true;
|
||||
CHECK_EQ(m.value("parent", std::string()), std::string("test-model"));
|
||||
}
|
||||
CHECK(listed);
|
||||
const HttpResponse one = f.get("/v1/models/uncensored");
|
||||
CHECK_EQ(one.status, 200);
|
||||
CHECK_EQ(json::parse(one.body).value("id", std::string()), std::string("uncensored"));
|
||||
}
|
||||
|
||||
/* With adapters enabled, every name but the model's own must be a loaded adapter. The variant is a
|
||||
* name of the model, so it reaches the base without an adapter lookup, and no adapter may be
|
||||
* loaded under it: `base:name` would then mean two things. */
|
||||
TEST(the_control_vector_variant_is_not_an_adapter) {
|
||||
int lookups = 0;
|
||||
Fixture f(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
o.control_vector_variant = "uncensored";
|
||||
o.lora_acquire = [&](const std::string&, int32_t*, uint64_t*, std::shared_ptr<void>*) {
|
||||
++lookups;
|
||||
return (int)RAD_E_NOTFOUND;
|
||||
};
|
||||
o.lora_names = [] { return std::vector<std::string>{}; };
|
||||
o.lora_load = [](const std::string&, const std::string&, std::string*) {
|
||||
return (int)RAD_OK;
|
||||
};
|
||||
o.lora_unload = [](const std::string&, std::string*, int*) { return (int)RAD_OK; };
|
||||
d.control_vector.available = [] { return true; };
|
||||
d.control_vector.get_default = [] { return false; };
|
||||
} });
|
||||
HttpResponse r = f.post("/v1/chat/completions",
|
||||
R"({"model":"uncensored","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4})");
|
||||
if (r.streaming()) drain(r);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r.status, 200);
|
||||
CHECK_EQ(lookups, 0);
|
||||
CHECK(f.sched.last_sp.use_control_vector);
|
||||
|
||||
/* Any other name still goes to the adapters, which do not know it. */
|
||||
HttpResponse r2 = f.post("/v1/chat/completions",
|
||||
R"({"model":"other","messages":[{"role":"user","content":"hi"}],
|
||||
"max_tokens":4})");
|
||||
if (r2.streaming()) drain(r2);
|
||||
f.sched.join_all();
|
||||
CHECK_EQ(r2.status, 404);
|
||||
CHECK_EQ(lookups, 1);
|
||||
|
||||
const HttpResponse l = f.post("/v1/load_lora_adapter",
|
||||
R"({"lora_name":"uncensored","lora_path":"/adapters/u"})");
|
||||
CHECK_EQ(l.status, 400);
|
||||
CHECK(l.body.find("control-vector variant") != std::string::npos);
|
||||
}
|
||||
|
||||
/* The control vector: absent, the deployment's default applies; an explicit `true` on a
|
||||
* deployment with no vector is refused by name (serving the stock model while the client believes
|
||||
* otherwise would be a silent lie), and on one with a vector it reaches the engine's request. */
|
||||
|
||||
Reference in new issue
Block a user