Archived
--draft-coupling verifies each row of the chain on its own. Two lossless sequence-level verifiers accept more drafts from the same chain: Block Verification (arXiv 2403.10444) decides the whole chain at once, Traversal Verification (arXiv 2505.12398) walks a path from its last draft back to its first. --draft-verify token (default) is the engine as it was; block switches the coupling on; traversal needs it and is refused otherwise. Block: the sampler marks the consecutive bound rows of a request with the block's length (RadMtpCoupleState::blk) and mtp_couple_verify decides the block on the workgroup of its round-1 row, every FP64 sum a fixed lane tree so the result is the host reference's bit for bit. The wide-plane serial helper is a kernel of its own, which leaves couple_verify without scratch. Traversal: a new op mtp_trav_verify takes the step's topology (parent row, draft token per row) and decides a request on one workgroup, 0 bytes of scratch: the target's law as integer masses of a fixed-point exponential, the walk in FP64. Its header and kernel also handle nodes with several children (Gumbel-top-k and RheoSampling siblings); the serial head here drafts one, so that part has no producer yet and is covered by the tests only. RadMtpCoupleState grows from 152 to 168 bytes (nkids, scheme, blk), so RAD_ABI_VERSION is 41. Exactness: mtp_block_test enumerates the draft tree of a toy model and runs chi-square over the real verify code; mtp_rrs_test runs chi-square and an exhaustive enumeration of the walk (worst |joint - P| 7e-14) with negative controls that fail; spechub_device_test compares the device rows with the host rows. Measured on Qwen3.8-Flash-Next IQR-V4 (TP2, MTP chain 3, coupling) on our branch: about +1% tok/s with traversal, +4.6% at T 1.0 top_k 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1704 lines
80 KiB
C++
1704 lines
80 KiB
C++
/* config_test.cpp -- the command line.
|
|
*
|
|
* Every pool is budgeted explicitly (spec §6), and downstream a mistyped budget flag looks like a
|
|
* decision: nothing after the parser can tell a requested value from one that failed to parse and
|
|
* fell back to a default. So the parser refuses by name, and these tests keep it refusing.
|
|
*
|
|
* Taken the value reaches the field an operator expects
|
|
* Refused a value outside the legal set stops the server instead of being rounded into it
|
|
* Resolved what is left unsaid comes from the environment or a stated default
|
|
*
|
|
* No device, no model, no container: argc/argv in, a Config out.
|
|
*/
|
|
#include "rad_test.h"
|
|
|
|
#include "rad_core.h"
|
|
#include "diag/diag.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <map>
|
|
#include <regex>
|
|
#include <sstream>
|
|
#include <cstdio>
|
|
#include <string>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
using namespace rad;
|
|
|
|
namespace {
|
|
|
|
/* Parse with a --model prepended, so the required-argument check does not trip every case. */
|
|
int parse(std::initializer_list<const char*> v, Config* c) {
|
|
std::vector<std::string> args{ "--model", "/m/x.rad" };
|
|
args.insert(args.end(), v.begin(), v.end());
|
|
Argv a(std::move(args));
|
|
return config_parse(a.argc(), a.argv.data(), c);
|
|
}
|
|
|
|
/* Parse into a fresh Config, for cases that must not inherit flags from an earlier parse. */
|
|
int parse_fresh(std::initializer_list<const char*> v) {
|
|
Config c;
|
|
return parse(v, &c);
|
|
}
|
|
|
|
/* Restores the log level, which `-v` changes and every test in this binary reads. */
|
|
struct LogGuard {
|
|
Log saved = log_level();
|
|
~LogGuard() { log_set_level(saved); }
|
|
};
|
|
|
|
} /* namespace */
|
|
|
|
/* ================================================================== the shape of the call */
|
|
|
|
TEST(help_is_reported_separately_from_an_error) {
|
|
/* 1, not an error: the caller prints usage and exits 0, so `--help` is not a failed run. */
|
|
Config c;
|
|
Argv a({ "--help" });
|
|
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 1);
|
|
Argv b({ "-h" });
|
|
CHECK_EQ(config_parse(b.argc(), b.argv.data(), &c), 1);
|
|
/* It wins from anywhere on the line, even after an otherwise fatal argument. */
|
|
Argv d({ "--tp", "0", "--help" });
|
|
CHECK_EQ(config_parse(d.argc(), d.argv.data(), &c), 1);
|
|
}
|
|
|
|
/* An unknown flag is an error naming it, not a warning: a typo in a budget flag would otherwise
|
|
* yield a plan the operator did not ask for. */
|
|
TEST(an_unknown_option_is_refused) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--not-a-flag" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-num-seq", "8" }, &c), RAD_E_INVAL); /* near-miss on a real flag */
|
|
CHECK_EQ(parse({ "-x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "positional" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* A retired flag is refused, not accepted and ignored. Each names a decision the engine does not
|
|
* take from the operator: the KV cache is elastic and derives its own buffer, the activation arena
|
|
* comes from the buffer plan, and a finished conversation is copied to host memory as soon as
|
|
* possible rather than after an idle time. Starting anyway would serve something other than what
|
|
* the command line expects; a warning would go unread. */
|
|
TEST(a_retired_flag_is_refused) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--kv-flex-mib", "512" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--vram-headroom-mib", "2000" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kv-idle-to-host", "30" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kv-idle-to-disk", "1800" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kv-host-cache-mib", "4096" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* An empty key is no key: --api-key "" -- or --api-key "$UNSET_VAR" in a unit file whose variable
|
|
* was typo'd -- must not start a server that looks guarded on its command line and answers every
|
|
* route keyless. The shipped compose files fail closed on ${RADIANCE_API_KEY:?}; this is the
|
|
* refusal for every other way the binary meets an empty value. */
|
|
TEST(an_empty_api_key_is_refused) {
|
|
CHECK_EQ(parse_fresh({ "--api-key", "" }), RAD_E_INVAL);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--api-key", "k" }, &c), 0);
|
|
CHECK(c.api_key == "k");
|
|
}
|
|
|
|
/* --api-key-env reads the key where `ps` cannot: the empty-value refusal's sibling is the
|
|
* never-set one -- a compose environment: or unit Environment= line with a typo'd name must
|
|
* refuse at startup, not serve keyless under a guarded-looking command line. */
|
|
TEST(an_api_key_env_that_is_unset_is_refused_and_one_that_is_set_is_the_key) {
|
|
unsetenv("RAD_TEST_KEY_ENV");
|
|
CHECK_EQ(parse_fresh({ "--api-key-env", "RAD_TEST_KEY_ENV" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--api-key-env", "" }), RAD_E_INVAL);
|
|
setenv("RAD_TEST_KEY_ENV", "s3cret", 1);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--api-key-env", "RAD_TEST_KEY_ENV" }, &c), 0);
|
|
CHECK(c.api_key == "s3cret");
|
|
CHECK(c.api_key_env == "RAD_TEST_KEY_ENV");
|
|
unsetenv("RAD_TEST_KEY_ENV");
|
|
}
|
|
|
|
/* --allow-host repeats: the loopback-only routes take the set of names, and an empty one is
|
|
* a hole cut by a typo, so it is refused like the empty key. */
|
|
TEST(allow_host_repeats_and_refuses_the_empty_name) {
|
|
CHECK_EQ(parse_fresh({ "--allow-host", "" }), RAD_E_INVAL);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--allow-host", "box", "--allow-host", "box.example" }, &c), 0);
|
|
CHECK(c.allow_hosts.size() == 2);
|
|
CHECK(c.allow_hosts[0] == "box" && c.allow_hosts[1] == "box.example");
|
|
}
|
|
|
|
/* --trusted-proxy repeats: the sockets inside these networks may name the client behind them
|
|
* for the log. Anything but a numeric network with a prefix is refused at startup, because a
|
|
* typo there silently unvouches a proxy -- the server would keep answering through it and log
|
|
* the proxy on every line, with nothing to show for the flag. */
|
|
TEST(trusted_proxy_repeats_and_refuses_anything_but_a_cidr) {
|
|
CHECK_EQ(parse_fresh({ "--trusted-proxy", "127.0.0.1" }), RAD_E_INVAL); /* no prefix */
|
|
CHECK_EQ(parse_fresh({ "--trusted-proxy", "127.0.0.0/33" }), RAD_E_INVAL); /* out of family */
|
|
CHECK_EQ(parse_fresh({ "--trusted-proxy", "::1/129" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--trusted-proxy", "proxy.internal/32" }), RAD_E_INVAL);/* not numeric */
|
|
CHECK_EQ(parse_fresh({ "--trusted-proxy", "[::1]/128" }), RAD_E_INVAL); /* URL form, not CIDR */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--trusted-proxy", "127.0.0.0/8", "--trusted-proxy", "::1/128" }, &c), 0);
|
|
CHECK(c.trusted_proxies.size() == 2);
|
|
CHECK(c.trusted_proxies[0] == "127.0.0.0/8" && c.trusted_proxies[1] == "::1/128");
|
|
}
|
|
|
|
/* A flag written last with no argument is refused rather than reading past argv. */
|
|
TEST(a_flag_missing_its_argument_is_refused_rather_than_read_past) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--tp" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--port" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kv-cache-dtype" }, &c), RAD_E_INVAL);
|
|
Argv a({ "--model" });
|
|
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* --draft-short-from takes a count, 0 for never, or auto (the default): the engine resolves auto to
|
|
* never for a chain and to two decoding sequences for a tree drafter. */
|
|
TEST(draft_short_from_takes_a_count_never_or_auto) {
|
|
Config c;
|
|
CHECK_EQ(c.draft_short_from, -1ll);
|
|
CHECK_OK(parse({ "--draft-short-from", "4" }, &c));
|
|
CHECK_EQ(c.draft_short_from, 4ll);
|
|
CHECK_OK(parse({ "--draft-short-from", "0" }, &c));
|
|
CHECK_EQ(c.draft_short_from, 0ll);
|
|
CHECK_OK(parse({ "--draft-short-from", "auto" }, &c));
|
|
CHECK_EQ(c.draft_short_from, -1ll);
|
|
CHECK_EQ(parse_fresh({ "--draft-short-from", "-2" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--draft-short-from", "some" }), RAD_E_INVAL);
|
|
}
|
|
|
|
/* KL mode records or scores, never both, and requires that direction's inputs. Guessing between
|
|
* them could make a quantised model the reference. */
|
|
TEST(the_kl_mode_records_or_scores_and_says_which_input_it_lacks) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-corpus", "/c.jsonl" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kld_record, std::string("/r"));
|
|
CHECK_EQ(c.kld_corpus, std::string("/c.jsonl"));
|
|
CHECK(c.kld());
|
|
|
|
Config d;
|
|
CHECK_EQ(parse({ "--kld-ref", "/r", "--kld-out", "/o.json" }, &d), RAD_OK);
|
|
CHECK_EQ(d.kld_ref, std::string("/r"));
|
|
CHECK_EQ(d.kld_out, std::string("/o.json"));
|
|
CHECK(d.kld());
|
|
|
|
Config e;
|
|
CHECK_EQ(parse({}, &e), RAD_OK);
|
|
CHECK(!e.kld());
|
|
|
|
Config f;
|
|
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-ref", "/s" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kld-record", "/r" }, &f), RAD_E_INVAL); /* no corpus */
|
|
CHECK_EQ(parse({ "--kld-ref", "/r", "--kld-corpus", "/c" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kld-out", "/o.json" }, &f), RAD_E_INVAL); /* nothing to report */
|
|
CHECK_EQ(parse({ "--kld-ref" }, &f), RAD_E_INVAL);
|
|
|
|
/* --kld-top is the recording's form; a scoring run reads it from the reference. */
|
|
Config g;
|
|
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-corpus", "/c.jsonl", "--kld-top", "512" }, &g), RAD_OK);
|
|
CHECK_EQ(g.kld_top, 512);
|
|
CHECK_EQ(parse({ "--kld-ref", "/r", "--kld-top", "512" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-corpus", "/c", "--kld-top", "9000" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-corpus", "/c", "--kld-top", "-1" }, &f), RAD_E_INVAL);
|
|
}
|
|
|
|
/* The diagnose mode: one mode a run, and its corpus and baseline belong to its workload. A run
|
|
* that took one of them without a DIR would measure nothing while looking configured. */
|
|
TEST(the_diagnose_mode_takes_its_own_flags_and_nothing_else) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--diagnose-tokens", "64", "--diagnose-runs", "1",
|
|
"--diagnose-concurrency", "1,2", "--diagnose-prefill", "1024,4096",
|
|
"--diagnose-corpus", "/c.jsonl", "--diagnose-baseline", "/b.json" }, &c), RAD_OK);
|
|
CHECK(c.diagnose_mode());
|
|
CHECK_EQ(c.diagnose, std::string("/d"));
|
|
CHECK_EQ(c.diagnose_tokens, 64);
|
|
CHECK_EQ(c.diagnose_runs, 1);
|
|
CHECK_EQ(c.diagnose_concurrency.size(), (size_t)2);
|
|
CHECK_EQ(c.diagnose_prefill.size(), (size_t)2);
|
|
CHECK_EQ(c.diagnose_corpus, std::string("/c.jsonl"));
|
|
CHECK_EQ(c.diagnose_baseline, std::string("/b.json"));
|
|
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(!d.diagnose_mode());
|
|
CHECK_EQ(d.diagnose_tokens, 256); /* the defaults the report states */
|
|
CHECK_EQ(d.diagnose_runs, 3);
|
|
CHECK_EQ(d.diagnose_concurrency.size(), (size_t)4);
|
|
CHECK_EQ(d.diagnose_prefill.size(), (size_t)4);
|
|
|
|
Config f;
|
|
CHECK_EQ(parse({ "--diagnose-corpus", "/c.jsonl" }, &f), RAD_E_INVAL); /* no workload */
|
|
CHECK_EQ(parse({ "--diagnose-baseline", "/b.json" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--kld-ref", "/r" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--debug-graph" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--calib-corpus", "/c.jsonl", "--calib-dir", "/s" }, &f),
|
|
RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--diagnose-concurrency", "1,,2" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--diagnose-prefill", "8" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--diagnose", "/d", "--diagnose-runs", "0" }, &f), RAD_E_INVAL);
|
|
}
|
|
|
|
/* Runtime LoRA: the adapters reach their fields in order, the targets as sorted leaf names, and a
|
|
* combination that would size slots no adapter uses, or name an adapter that is not served, is
|
|
* refused by name. A text model's slot count against its adapters, and its targets, are checked
|
|
* at startup, where the engine knows whether the model generates text. */
|
|
TEST(the_lora_flags_reach_their_fields_and_refuse_what_serves_no_adapter) {
|
|
Config c;
|
|
CHECK_OK(parse({ "--lora", "b=/ad/b", "--lora", "a=/ad/a", "--max-loras", "3",
|
|
"--max-lora-rank", "32", "--lora-target-modules", "v_proj, q_proj,v_proj" },
|
|
&c));
|
|
REQUIRE_EQ(c.lora.adapters.size(), (size_t)2);
|
|
CHECK_EQ(c.lora.adapters[0].first, std::string("b"));
|
|
CHECK_EQ(c.lora.adapters[1].second, std::string("/ad/a"));
|
|
CHECK_EQ(c.lora.slots(), 3);
|
|
CHECK_EQ(c.lora.max_rank, 32);
|
|
CHECK(c.lora.targets == std::vector<std::string>({ "q_proj", "v_proj" }));
|
|
Config d;
|
|
CHECK_OK(parse({}, &d));
|
|
CHECK(!d.lora.enabled());
|
|
CHECK_EQ(d.lora.rank(false), 16);
|
|
CHECK_EQ(d.lora.rank(true), 64);
|
|
Config e;
|
|
const std::string dir = radtest::tmp_path("loradir");
|
|
mkdir(dir.c_str(), 0755);
|
|
CHECK_OK(parse({ "--lora-dir", dir.c_str() }, &e));
|
|
CHECK(e.lora.enabled());
|
|
CHECK_EQ(e.lora.slots(), 2);
|
|
CHECK_EQ(e.lora.rank(true), 64);
|
|
|
|
auto refused = [](std::initializer_list<const char*> v, const char* why) {
|
|
int st = RAD_OK;
|
|
const std::string log = stderr_of([&] { st = parse_fresh(v); });
|
|
if (st != RAD_E_INVAL || log.find(why) == std::string::npos)
|
|
std::fprintf(stderr, " expected a refusal naming '%s', got %d: %s", why, st,
|
|
log.c_str());
|
|
CHECK_EQ(st, (int)RAD_E_INVAL);
|
|
CHECK(log.find(why) != std::string::npos);
|
|
};
|
|
refused({ "--lora", "/ad/a" }, "NAME=PATH");
|
|
refused({ "--lora", "a=" }, "NAME=PATH");
|
|
refused({ "--lora", "a=/x", "--lora", "a=/y" }, "names the adapter 'a' twice");
|
|
refused({ "--max-lora-rank", "32" }, "--max-lora-rank sizes runtime LoRA slots");
|
|
refused({ "--lora-target-modules", "q_proj" }, "--lora-target-modules sizes");
|
|
refused({ "--lora-dir", "/no/such/dir" }, "is not a directory");
|
|
refused({ "--lora", "a=/x", "--lora-target-modules", "self_attn.q_proj" }, "leaf names");
|
|
refused({ "--lora", "a=/x", "--lora-target-modules", ".*proj" }, "leaf names");
|
|
refused({ "--lora", "a=/x", "--lora-target-modules", " , " }, "names no module");
|
|
refused({ "--lora", "a=/x", "--kld-lora", "a" }, "in KL mode");
|
|
refused({ "--lora", "a=/x", "--kld-lora", "b", "--kld-ref", "/r" }, "'b' is not one of");
|
|
refused({ "--lora", "a=/x", "--kld-ref", "/r", "--kld-lora-sources", "d" }, "give --kld-lora");
|
|
}
|
|
|
|
TEST(the_model_is_required_and_nothing_else_is) {
|
|
Config c;
|
|
Argv none({});
|
|
CHECK_EQ(config_parse(none.argc(), none.argv.data(), &c), RAD_E_INVAL);
|
|
|
|
Config ok;
|
|
CHECK_EQ(parse({}, &ok), RAD_OK);
|
|
CHECK_EQ(ok.model, std::string("/m/x.rad"));
|
|
}
|
|
|
|
/* ================================================================== taken */
|
|
|
|
TEST(the_pool_size_flags_are_gone_and_say_what_replaced_them) {
|
|
/* The card's split belongs to the resolver (core/mem/vram_budget.h); a launch line that sizes
|
|
* a pool is refused by name rather than served with a different split. */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--vram-weights-mib", "20480" }, &c), RAD_E_INVAL);
|
|
Config k;
|
|
CHECK_EQ(parse({ "--vram-kv-mib", "6144" }, &k), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_prefix_cache_disk_flags_are_gone_and_the_host_size_was_renamed) {
|
|
/* The prefix cache has no disk tier. A launch line naming the disk tier, or the host tier's
|
|
* old flag name, is refused. */
|
|
for (const char* f : { "--prefix-cache-host-mib", "--prefix-cache-disk-mib", "--prefix-cache-dir" }) {
|
|
Config c;
|
|
CHECK_EQ(parse({ f, "4096" }, &c), RAD_E_INVAL);
|
|
}
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.prefix_cache_mib, 0ll);
|
|
CHECK_EQ(d.prefix_cache_ttl, 3600ll); /* an hour */
|
|
Config z;
|
|
CHECK_EQ(parse({ "--prefix-cache-ttl", "0" }, &z), RAD_OK);
|
|
CHECK_EQ(z.prefix_cache_ttl, 0ll); /* never */
|
|
Config n;
|
|
CHECK_EQ(parse({ "--prefix-cache-ttl", "-1" }, &n), RAD_E_INVAL);
|
|
Config h;
|
|
CHECK_EQ(parse({ "--prefix-cache-ttl", "1h" }, &h), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_sizes_and_counts_reach_the_fields_they_name) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--tp", "2",
|
|
"--max-num-batched-tokens", "512",
|
|
"--max-num-seqs", "8",
|
|
"--max-model-len", "200000",
|
|
"--host-pool-mib", "12288",
|
|
"--prefix-cache-mib", "4096",
|
|
"--prefix-cache-ttl", "600",
|
|
"--checkpoint-interval", "2048",
|
|
"--checkpoint-slots", "8",
|
|
"--tp-wire-min-kb", "64",
|
|
"--port", "8100" }, &c), RAD_OK);
|
|
CHECK_EQ(c.tp, 2);
|
|
CHECK_EQ(c.max_tok, 512ll);
|
|
CHECK_EQ(c.max_seqs, 8ll);
|
|
CHECK_EQ(c.max_ctx, 200000ll);
|
|
CHECK_EQ(c.host_pool_mib, 6144ll); /* a rank's share of the 12288 at --tp 2 */
|
|
CHECK_EQ(c.prefix_cache_mib, 4096ll);
|
|
CHECK_EQ(c.prefix_cache_ttl, 600ll);
|
|
CHECK_EQ(c.checkpoint_interval, 2048ll);
|
|
CHECK_EQ(c.checkpoint_slots, 8ll);
|
|
CHECK_EQ(c.tp_wire_min_kb, 64ll);
|
|
CHECK_EQ(c.port, 8100);
|
|
|
|
/* --max-model-len may exceed INT_MAX and must not wrap. */
|
|
Config big;
|
|
CHECK_EQ(parse({ "--max-model-len", "4294967296" }, &big), RAD_OK);
|
|
CHECK_EQ(big.max_ctx, 4294967296ll);
|
|
}
|
|
|
|
TEST(the_paths_and_names_reach_their_fields) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--radiance-home", "/rh",
|
|
"--weights-disk-tier",
|
|
"--placement", "expert_tiered",
|
|
"--host", "0.0.0.0",
|
|
"--generation-config", "/g.json",
|
|
"--reasoning-effort", "medium",
|
|
"--served-model-name", "qwen-coder",
|
|
"--override-chat-template", "/t.jinja" }, &c), RAD_OK);
|
|
CHECK_EQ(c.radiance_home, std::string("/rh"));
|
|
CHECK(c.weights_disk_tier);
|
|
CHECK_EQ(c.placement, std::string("expert_tiered"));
|
|
CHECK_EQ(c.host, std::string("0.0.0.0"));
|
|
CHECK_EQ(c.generation_config, std::string("/g.json"));
|
|
CHECK_EQ(c.reasoning_effort, std::string("medium"));
|
|
CHECK_EQ(c.served_model_name, std::string("qwen-coder"));
|
|
CHECK_EQ(c.override_chat_template, std::string("/t.jinja"));
|
|
}
|
|
|
|
/* The reasoning budget is a count or unset (-1); a negative value cannot be given. */
|
|
TEST(thinking_token_budget_takes_a_count_and_defaults_to_none) {
|
|
Config c;
|
|
CHECK_EQ(parse({}, &c), RAD_OK);
|
|
CHECK_EQ(c.thinking_token_budget, (int64_t)-1);
|
|
Config d;
|
|
CHECK_EQ(parse({ "--thinking-token-budget", "2048" }, &d), RAD_OK);
|
|
CHECK_EQ(d.thinking_token_budget, (int64_t)2048);
|
|
Config e;
|
|
CHECK_EQ(parse({ "--thinking-token-budget", "0" }, &e), RAD_OK);
|
|
CHECK_EQ(e.thinking_token_budget, (int64_t)0);
|
|
Config f;
|
|
CHECK(parse({ "--thinking-token-budget", "-1" }, &f) < 0);
|
|
Config g;
|
|
CHECK(parse({ "--thinking-token-budget", "lots" }, &g) < 0);
|
|
}
|
|
|
|
TEST(the_boolean_flags_are_off_until_they_are_given) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(!d.deterministic);
|
|
CHECK(d.prefix_cache); /* on by default; the flag turns it off */
|
|
CHECK(!d.debug_graph);
|
|
CHECK(!d.debug_selection);
|
|
CHECK(!d.debug_placement);
|
|
CHECK(!d.accept_reference_kernels);
|
|
CHECK(!d.proceed_incompatible);
|
|
CHECK(!d.profile_ops);
|
|
CHECK(!d.live_view);
|
|
|
|
Config c;
|
|
CHECK_EQ(parse({ "--deterministic", "--no-prefix-cache", "--debug-placement",
|
|
"--debug-accept-reference-kernels", "--profile-ops", "--live",
|
|
"--proceed-with-incompatible-configuration" }, &c), RAD_OK);
|
|
CHECK(c.deterministic);
|
|
CHECK(!c.prefix_cache);
|
|
CHECK(c.debug_placement);
|
|
CHECK(c.accept_reference_kernels);
|
|
CHECK(c.proceed_incompatible);
|
|
CHECK(c.profile_ops);
|
|
CHECK(c.live_view);
|
|
}
|
|
|
|
/* The graph dump implies the selection table: without the kernel chosen for each node, the graph
|
|
* does not show what will run. */
|
|
TEST(debug_graph_turns_the_selection_table_on_too) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--debug-graph" }, &c), RAD_OK);
|
|
CHECK(c.debug_graph);
|
|
CHECK(c.debug_selection);
|
|
|
|
Config s;
|
|
CHECK_EQ(parse({ "--debug-selection" }, &s), RAD_OK);
|
|
CHECK(!s.debug_graph); /* not the reverse */
|
|
CHECK(s.debug_selection);
|
|
}
|
|
|
|
TEST(the_verbosity_flags_move_the_log_level) {
|
|
LogGuard guard;
|
|
Config c;
|
|
log_set_level(Log::Info);
|
|
CHECK_EQ(parse({ "-v" }, &c), RAD_OK);
|
|
CHECK((int)log_level() == (int)Log::Debug);
|
|
CHECK_EQ(parse({ "-vv" }, &c), RAD_OK);
|
|
CHECK((int)log_level() == (int)Log::Trace);
|
|
}
|
|
|
|
/* ================================================================== refused */
|
|
|
|
TEST(tp_below_one_is_refused) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--tp", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp", "notanumber" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp", "1" }, &c), RAD_OK);
|
|
}
|
|
|
|
/* A span is a whole number of intervals, one or more; 1 is the default and plans as before. */
|
|
TEST(a_prefill_span_below_one_interval_is_refused) {
|
|
Config c;
|
|
CHECK_EQ(c.prefill_span, 1);
|
|
CHECK_EQ(parse({ "--prefill-span", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-span", "-2" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-span", "2x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-span", "4" }, &c), RAD_OK);
|
|
CHECK_EQ(c.prefill_span, 4);
|
|
}
|
|
|
|
/* A budget flag takes a whole number; a typo is refused rather than read as 0 or its prefix. */
|
|
TEST(a_numeric_flag_refuses_what_is_not_a_number) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--max-num-seqs", "8x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-num-batched-tokens", "4k" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--host-pool-mib", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--checkpoint-interval", "" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--port", "70000" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "three" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "auto" }, &c), RAD_OK);
|
|
CHECK_EQ(c.n_spec, -1);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "3" }, &c), RAD_OK);
|
|
CHECK_EQ(c.n_spec, 3);
|
|
}
|
|
|
|
/* --prefill-interleave is a step count, off by default and at most 64. */
|
|
TEST(prefill_interleave_takes_a_step_count_up_to_64) {
|
|
Config d;
|
|
REQUIRE_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.prefill_interleave, 0);
|
|
CHECK(!d.prefill_interleave_set); /* not given: bring-up serves auto:1 */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--prefill-interleave", "4" }, &c), RAD_OK);
|
|
CHECK_EQ(c.prefill_interleave, 4);
|
|
CHECK(c.prefill_interleave_set);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "65" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "-1" }, &c), RAD_E_INVAL);
|
|
/* auto sizes the hold from measured step costs (Scheduler::interleave_steps) */
|
|
Config a;
|
|
CHECK_EQ(parse({ "--prefill-interleave", "auto" }, &a), RAD_OK);
|
|
CHECK_EQ(a.prefill_interleave, -1);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "automatic" }, &c), RAD_E_INVAL);
|
|
/* auto:SHARE gives decode-only steps SHARE of a chunk step's time, in (0, 4] */
|
|
Config h;
|
|
CHECK_EQ(parse({ "--prefill-interleave", "auto:1" }, &h), RAD_OK);
|
|
CHECK_EQ(h.prefill_interleave, -1);
|
|
CHECK(h.prefill_interleave_share == 1.0);
|
|
CHECK(a.prefill_interleave_share == 0.25);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "auto:0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "auto:5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--prefill-interleave", "auto:x" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(mixed_step_target_is_an_opt_in_soft_millisecond_target) {
|
|
Config d;
|
|
REQUIRE_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.mixed_step_target_ms, 0);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--mixed-step-target-ms", "150" }, &c), RAD_OK);
|
|
CHECK_EQ(c.mixed_step_target_ms, 150);
|
|
CHECK_EQ(parse({ "--mixed-step-target-ms", "60001" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--mixed-step-target-ms", "-1" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* ================================================================== the table, the parser and the help agree
|
|
*
|
|
* One table (g_flags) drives the help text and the startup report, and a separate chain of ifs
|
|
* parses. A flag in the table the parser does not take, a number read without the strict parser,
|
|
* or a default the help states by hand that the code does not have, each passes every sampled
|
|
* test. These walk the whole table. */
|
|
namespace {
|
|
|
|
/* Each option and its argument's metavariable as the help prints them ("" for a switch). */
|
|
std::vector<std::pair<std::string, std::string>> usage_options() {
|
|
const std::string text = stderr_of([] { config_usage("radiance"); });
|
|
std::vector<std::pair<std::string, std::string>> out;
|
|
size_t at = 0;
|
|
while (at < text.size()) {
|
|
size_t nl = text.find('\n', at);
|
|
if (nl == std::string::npos) nl = text.size();
|
|
const std::string line = text.substr(at, nl - at);
|
|
at = nl + 1;
|
|
if (line.rfind(" -", 0) != 0) continue;
|
|
std::istringstream in(line);
|
|
std::string name, arg;
|
|
in >> name >> arg;
|
|
/* The help starts after the padded column; a metavariable is upper case. */
|
|
const bool is_arg = !arg.empty() && line.find(name + " " + arg) == 2 &&
|
|
std::all_of(arg.begin(), arg.end(), [](char ch) {
|
|
return (ch >= 'A' && ch <= 'Z') || ch == '_';
|
|
});
|
|
out.emplace_back(name, is_arg ? arg : "");
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/* A legal value for every option that takes one, with any option it cannot be given without. */
|
|
const std::map<std::string, std::vector<std::string>>& legal_values() {
|
|
static const std::map<std::string, std::vector<std::string>> v = {
|
|
{ "--model", { "/m/y.rad" } }, { "--download-dir", { "/d" } },
|
|
{ "--model-revision", { "v1.2" } },
|
|
{ "--radiance-home", { "/h1:/h2" } }, { "--kernels", { "libref" } },
|
|
{ "--tp", { "2" } }, { "--tp-wire", { "wht6" } }, { "--tp-wire-min-kb", { "64" } },
|
|
{ "--tp-attn-split", { "rows" } }, { "--weight-prefetch", { "off" } },
|
|
{ "--p2p", { "off" } }, { "--max-num-batched-tokens", { "512" } },
|
|
{ "--busy-prefill-chunk", { "256" } }, { "--prefill-interleave", { "2" } },
|
|
{ "--mixed-step-target-ms", { "150" } },
|
|
{ "--preempt-wait-ms", { "5000" } },
|
|
{ "--max-num-seqs", { "4" } },
|
|
{ "--max-model-len", { "4096" } }, { "--rope-scaling", { "yarn:4" } },
|
|
{ "--gpu-memory-mib", { "16384" } }, { "--gpu-headroom-mib", { "128" } },
|
|
{ "--kv-cache-dtype", { "i8" } },
|
|
{ "--state-cache-dtype", { "f16" } },
|
|
{ "--kv-resident", { "65536" } },
|
|
{ "--host-pool-mib", { "1024" } }, { "--host-headroom-mib", { "2048" } },
|
|
{ "--embedding-placement", { "vram" } },
|
|
{ "--vision-tower-placement", { "ram" } }, { "--ngram-placement", { "disk" } },
|
|
{ "--debug-draft-oracle", { "/o.txt", "--spec-ngram", "4" } },
|
|
{ "--prefix-cache-mib", { "256" } }, { "--prefix-cache-ttl", { "60" } },
|
|
{ "--placement", { "all_vram" } }, { "--checkpoint-interval", { "256" } },
|
|
{ "--prefill-span", { "2" } },
|
|
{ "--checkpoint-slots", { "4" } }, { "--checkpoint-policy", { "tip-only" } },
|
|
{ "--prefix-resume", { "nearest" } },
|
|
{ "--num-speculative-tokens", { "2" } }, { "--spec-ngram", { "4" } },
|
|
{ "--spec-ngram-min", { "1" } }, { "--spec-ngram-max", { "6" } },
|
|
{ "--draft-window", { "fixed" } }, { "--draft-short-from", { "4" } },
|
|
{ "--draft-coupling", { "on" } }, { "--draft-verify", { "block" } },
|
|
{ "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } },
|
|
{ "--api-key-env", { "RAD_KEY_ENV_INVENTORY" } },
|
|
{ "--allow-host", { "box" } },
|
|
{ "--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" } },
|
|
{ "--reasoning-effort-map", { "high=xhigh" } }, { "--thinking-token-budget", { "128" } },
|
|
{ "--typical-p", { "0.9" } }, { "--presence-penalty", { "0.5" } },
|
|
{ "--frequency-penalty", { "0.5" } }, { "--repetition-penalty", { "1.1" } },
|
|
{ "--repeat-last-n", { "64" } }, { "--dry-multiplier", { "0.8" } },
|
|
{ "--dry-base", { "1.75" } }, { "--dry-allowed-length", { "2" } },
|
|
{ "--dry-penalty-last-n", { "-1" } }, { "--dry-sequence-breakers", { "[\"\\n\"]" } },
|
|
{ "--xtc-probability", { "0.5" } }, { "--xtc-threshold", { "0.1" } },
|
|
{ "--default-max-tokens", { "256" } }, { "--max-tokens-cap", { "1024" } },
|
|
{ "--max-n", { "4" } }, { "--max-queued-requests", { "4096" } },
|
|
{ "--max-stop-strings", { "8" } }, { "--max-stop-bytes", { "256" } },
|
|
{ "--chat-template-kwargs", { "{\"enable_thinking\": false}" } },
|
|
{ "--reasoning-format", { "none" } }, { "--http-threads", { "4" } },
|
|
{ "--read-timeout", { "10" } }, { "--write-timeout", { "10" } },
|
|
{ "--keep-alive-timeout", { "2" } }, { "--max-body-mib", { "64" } },
|
|
{ "--retry-after", { "2" } }, { "--image-min-pixels", { "1024" } },
|
|
{ "--image-max-pixels", { "4096" } }, { "--video-min-pixels", { "1024" } },
|
|
{ "--video-max-pixels", { "4096" } }, { "--video-fps", { "2" } },
|
|
{ "--video-min-frames", { "2" } }, { "--video-max-frames", { "8" } },
|
|
{ "--video-max-frame-tokens", { "70" } }, { "--image-tokens", { "280" } },
|
|
{ "--max-source-pixels", { "1000000" } },
|
|
{ "--expert-stats", { "/s/experts.json" } },
|
|
{ "--expert-profile", { "/p.json" } }, { "--expert-pin-top", { "0.2" } },
|
|
{ "--draft-expert-placement", { "host" } },
|
|
{ "--kld-record", { "/r", "--kld-corpus", "/c.jsonl" } }, { "--kld-ref", { "/r" } },
|
|
{ "--kld-corpus", { "/c.jsonl", "--kld-record", "/r" } },
|
|
{ "--kld-out", { "/o.json", "--kld-ref", "/r" } },
|
|
{ "--kld-top", { "512", "--kld-record", "/r", "--kld-corpus", "/c.jsonl" } },
|
|
{ "--calib-corpus", { "/c.jsonl", "--calib-dir", "/d" } },
|
|
{ "--calib-dir", { "/d", "--calib-corpus", "/c.jsonl" } },
|
|
{ "--calib-layers", { "0:32", "--calib-corpus", "/c.jsonl", "--calib-dir", "/d" } },
|
|
{ "--image-gen-max-pixels", { "1048576" } },
|
|
{ "--image-gen-max-refs", { "2" } },
|
|
{ "--lora", { "a=/adapters/a" } },
|
|
{ "--lora-dir", { "/" } },
|
|
{ "--max-loras", { "2", "--lora-target-modules", "q_proj" } },
|
|
{ "--max-lora-rank", { "32", "--lora", "a=/adapters/a" } },
|
|
{ "--lora-target-modules", { "q_proj,v_proj", "--max-loras", "1" } },
|
|
{ "--kld-lora", { "a", "--lora", "a=/adapters/a", "--kld-ref", "/r" } },
|
|
{ "--kld-lora-sources", { "doc/", "--kld-lora", "a", "--lora", "a=/adapters/a",
|
|
"--kld-ref", "/r" } },
|
|
{ "--diagnose", { "/d" } },
|
|
{ "--diagnose-tokens", { "64", "--diagnose", "/d" } },
|
|
{ "--diagnose-runs", { "1", "--diagnose", "/d" } },
|
|
{ "--diagnose-concurrency", { "1,2", "--diagnose", "/d" } },
|
|
{ "--diagnose-prefill", { "1024,4096", "--diagnose", "/d" } },
|
|
{ "--diagnose-corpus", { "/c.jsonl", "--diagnose", "/d" } },
|
|
{ "--diagnose-baseline", { "/b.json", "--diagnose", "/d" } },
|
|
};
|
|
return v;
|
|
}
|
|
|
|
} /* namespace */
|
|
|
|
/* Every option the table lists parses with a legal value (a switch with none) and is reported as
|
|
* given on the command line. --draft-model is listed to be refused by name, and --help is not a
|
|
* setting. */
|
|
TEST(every_listed_option_parses_and_is_reported_as_given) {
|
|
LogGuard lg;
|
|
/* --api-key-env resolves at parse time and fails closed on an unset name, so the inventory
|
|
* needs the variable it names to exist. */
|
|
setenv("RAD_KEY_ENV_INVENTORY", "inventory-key", 1);
|
|
const auto opts = usage_options();
|
|
CHECK(opts.size() > 90);
|
|
const std::vector<std::string> names = diag::config_option_names();
|
|
int checked = 0;
|
|
for (const auto& [name, arg] : opts) {
|
|
if (name == "--help" || name == "--draft-model") continue;
|
|
CHECK(std::find(names.begin(), names.end(), name) != names.end());
|
|
std::vector<std::string> args{ "--model", "/m/x.rad", name };
|
|
if (!arg.empty()) {
|
|
auto it = legal_values().find(name);
|
|
if (it == legal_values().end()) {
|
|
std::fprintf(stderr, " no legal value listed for %s %s\n", name.c_str(), arg.c_str());
|
|
CHECK(false);
|
|
continue;
|
|
}
|
|
args.insert(args.end(), it->second.begin(), it->second.end());
|
|
}
|
|
Config c;
|
|
Argv a(args);
|
|
int st = RAD_OK;
|
|
const std::string log = stderr_of([&] { st = config_parse(a.argc(), a.argv.data(), &c); });
|
|
if (st != RAD_OK) std::fprintf(stderr, " %s refused: %s", name.c_str(), log.c_str());
|
|
CHECK_EQ(st, (int)RAD_OK);
|
|
auto g = c.given.find(name);
|
|
CHECK(g != c.given.end() && g->second == "command line");
|
|
++checked;
|
|
}
|
|
CHECK(checked > 90);
|
|
}
|
|
|
|
/* A whole-number option refuses what is not one, and a number option a word: "8x" read as 8, ""
|
|
* as 0 or "12k" as 12 would each be served as a decision. Seconds are whole numbers too. */
|
|
TEST(every_numeric_option_refuses_what_is_not_its_kind) {
|
|
const std::vector<std::string> seconds = { "--prefix-cache-ttl", "--read-timeout",
|
|
"--write-timeout", "--keep-alive-timeout",
|
|
"--retry-after" };
|
|
int n_int = 0, n_num = 0;
|
|
for (const auto& [name, arg] : usage_options()) {
|
|
const bool whole = arg == "N" ||
|
|
std::find(seconds.begin(), seconds.end(), name) != seconds.end();
|
|
if (!whole && arg != "F") continue;
|
|
(whole ? n_int : n_num)++;
|
|
for (const char* bad : whole ? std::vector<const char*>{ "8x", "", "12k", "1.5", "high" }
|
|
: std::vector<const char*>{ "high", "", "0.5x" }) {
|
|
Config c;
|
|
int st = RAD_OK;
|
|
const std::string log = stderr_of([&] { st = parse({ name.c_str(), bad }, &c); });
|
|
if (st != RAD_E_INVAL)
|
|
std::fprintf(stderr, " %s %s was not refused\n", name.c_str(), bad);
|
|
CHECK_EQ(st, (int)RAD_E_INVAL);
|
|
CHECK(has(log, name));
|
|
}
|
|
}
|
|
std::fprintf(stderr, " %d whole-number and %d number option(s)\n", n_int, n_num);
|
|
CHECK(n_int >= 35);
|
|
CHECK(n_num >= 12);
|
|
}
|
|
|
|
/* A default the help states as a number is the default a parse with no flags reports. */
|
|
TEST(every_default_the_help_states_is_the_one_reported) {
|
|
const std::string text = stderr_of([] { config_usage("radiance"); });
|
|
Config c;
|
|
REQUIRE_EQ(parse({}, &c), RAD_OK);
|
|
const std::vector<diag::ConfigRow> rows = diag::config_rows(c);
|
|
/* The help of one option: its line and the indented lines after it. */
|
|
std::string block, flag;
|
|
int compared = 0;
|
|
auto settle = [&] {
|
|
std::smatch m;
|
|
static const std::regex def(R"(\(default (-?[0-9][0-9.]*)\))");
|
|
if (flag.empty() || !std::regex_search(block, m, def)) return;
|
|
const std::string want = m[1];
|
|
const diag::ConfigRow* row = nullptr;
|
|
for (const diag::ConfigRow& r : rows) if (r.flag == flag) row = &r;
|
|
REQUIRE(row != nullptr);
|
|
const bool ok = row->value == want || row->value.rfind(want + " ", 0) == 0;
|
|
if (!ok) std::fprintf(stderr, " %s: help says %s, the report %s\n", flag.c_str(),
|
|
want.c_str(), row->value.c_str());
|
|
CHECK(ok);
|
|
++compared;
|
|
};
|
|
size_t at = 0;
|
|
while (at < text.size()) {
|
|
size_t nl = text.find('\n', at);
|
|
if (nl == std::string::npos) nl = text.size();
|
|
const std::string line = text.substr(at, nl - at);
|
|
at = nl + 1;
|
|
if (line.rfind(" -", 0) == 0) {
|
|
settle();
|
|
std::istringstream in(line);
|
|
in >> flag;
|
|
block = line;
|
|
} else if (line.rfind(" ", 0) == 0) {
|
|
block += " " + line;
|
|
} else {
|
|
settle();
|
|
flag.clear();
|
|
block.clear();
|
|
}
|
|
}
|
|
settle();
|
|
CHECK(compared >= 8);
|
|
}
|
|
|
|
/* --placement names one of the planner's four strategies, refused at the command line rather than
|
|
* at startup once the model is open. */
|
|
TEST(the_placement_is_one_of_the_planners_four) {
|
|
for (const char* ok : { "all_vram", "layer_offload", "expert_tiered", "auto" }) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--placement", ok }, &c), RAD_OK);
|
|
CHECK_EQ(c.placement, std::string(ok));
|
|
}
|
|
for (const char* bad : { "all-vram", "AUTO", "", "tiered" }) {
|
|
Config c;
|
|
int st = RAD_OK;
|
|
const std::string log = stderr_of([&] { st = parse({ "--placement", bad }, &c); });
|
|
CHECK_EQ(st, (int)RAD_E_INVAL);
|
|
CHECK(has(log, "--placement"));
|
|
}
|
|
}
|
|
|
|
/* 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"));
|
|
}
|
|
}
|
|
|
|
/* 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);
|
|
CHECK_EQ(c.tp_wire_exact, 1);
|
|
CHECK_EQ(parse({ "--tp-wire", "wht6" }, &c), RAD_OK);
|
|
CHECK_EQ(c.tp_wire_exact, 0);
|
|
/* A lossy wire is undetectable downstream (a rank just receives a different sum), so an
|
|
* unknown name stops the server instead of falling through to the default mode. */
|
|
CHECK_EQ(parse({ "--tp-wire", "wht8" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp-wire", "" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp-wire", "EXACT" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* The row split of a prefill's attention is not bit-identical to the head split, so heads is
|
|
* the default and anything but the two names stops the server. */
|
|
TEST(the_attention_split_is_one_of_two_names) {
|
|
Config c;
|
|
CHECK_EQ(c.tp_attn_rows, 0);
|
|
CHECK_EQ(parse({ "--tp-attn-split", "rows" }, &c), RAD_OK);
|
|
CHECK_EQ(c.tp_attn_rows, 1);
|
|
CHECK_EQ(parse({ "--tp-attn-split", "heads" }, &c), RAD_OK);
|
|
CHECK_EQ(c.tp_attn_rows, 0);
|
|
CHECK_EQ(parse({ "--tp-attn-split", "1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp-attn-split", "" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--tp-attn-split", "ROWS" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* The weight reads beside the collectives are on unless a deployment turns them off; anything but
|
|
* the two names stops the server. */
|
|
TEST(weight_prefetch_is_on_or_off) {
|
|
Config c;
|
|
CHECK(c.weight_prefetch);
|
|
CHECK_EQ(parse({ "--weight-prefetch", "off" }, &c), RAD_OK);
|
|
CHECK(!c.weight_prefetch);
|
|
CHECK_EQ(parse({ "--weight-prefetch", "on" }, &c), RAD_OK);
|
|
CHECK(c.weight_prefetch);
|
|
CHECK_EQ(parse({ "--weight-prefetch", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--weight-prefetch", "" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_p2p_mode_is_one_of_three_names) {
|
|
Config c;
|
|
CHECK_EQ(c.p2p, RAD_P2P_AUTO);
|
|
CHECK_EQ(parse({ "--p2p", "on" }, &c), RAD_OK);
|
|
CHECK_EQ(c.p2p, RAD_P2P_ON);
|
|
CHECK_EQ(parse({ "--p2p", "off" }, &c), RAD_OK);
|
|
CHECK_EQ(c.p2p, RAD_P2P_OFF);
|
|
CHECK_EQ(parse({ "--p2p", "auto" }, &c), RAD_OK);
|
|
CHECK_EQ(c.p2p, RAD_P2P_AUTO);
|
|
/* An unknown name stops the server: `on` guarantees a deployment measured on P2P never
|
|
* silently serves through host memory, which a typo falling through to auto could do. */
|
|
CHECK_EQ(parse({ "--p2p", "yes" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--p2p", "" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--p2p", "OFF" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_state_cache_dtype_is_f32_or_f16) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.state_cache_dtype, std::string("f32"));
|
|
Config c;
|
|
CHECK_EQ(parse({ "--state-cache-dtype", "f16" }, &c), RAD_OK);
|
|
CHECK_EQ(c.state_cache_dtype, std::string("f16"));
|
|
CHECK_EQ(parse({ "--state-cache-dtype", "f32" }, &c), RAD_OK);
|
|
CHECK_EQ(c.state_cache_dtype, std::string("f32"));
|
|
CHECK_EQ(parse({ "--state-cache-dtype", "bf16" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--state-cache-dtype", "1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--state-cache-dtype" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_kv_cache_dtype_is_one_of_three_names) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "bf16" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_cache_dtype, std::string("bf16"));
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "fp8" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_cache_dtype, std::string("fp8"));
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "i8" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_cache_dtype, std::string("i8"));
|
|
/* Three values only: an "auto" resolving to bf16 would be a second name for the default, and
|
|
* each value should be unambiguous in a log. The packed caches are refused by name, with the
|
|
* cache that serves in their place. */
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "auto" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "fp16" }, &c), RAD_E_INVAL);
|
|
for (const char* gone : { "fp8_v4", "k6_v4" }) {
|
|
int rc = RAD_OK;
|
|
const std::string err = stderr_of([&] { rc = parse({ "--kv-cache-dtype", gone }, &c); });
|
|
CHECK_EQ(rc, RAD_E_INVAL);
|
|
CHECK(err.find("i8 is the 8-bit cache") != std::string::npos);
|
|
}
|
|
CHECK_EQ(c.kv_cache_dtype, std::string("i8"));
|
|
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.kv_cache_dtype, std::string("bf16"));
|
|
}
|
|
|
|
/* --kv-resident is the whole switch: absent or 0 and nothing streams, and it is whole tokens
|
|
* rounded up to the group's page at startup. The mode flag is gone, and a launch line that still
|
|
* passes it is refused by name rather than silently served without streaming. */
|
|
TEST(kv_resident_is_the_whole_switch_and_its_ring_is_whole_tokens) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.kv_resident, 0ll); /* nothing streams */
|
|
CHECK(!d.kv_streams); /* derived: no group streams either */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--kv-resident", "262144" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_resident, 262144ll);
|
|
CHECK_EQ(parse({ "--kv-resident", "0" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_resident, 0ll);
|
|
CHECK_EQ(parse({ "--kv-resident", "-1" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* The embedding takes ram (default) or vram; the n-gram table takes auto (default), vram, ram or
|
|
* disk. The parser records whether the embedding placement was named and leaves resolution to
|
|
* Engine::plan, which can refuse a placement with the model in hand. */
|
|
TEST(the_embedding_is_ram_or_vram_and_the_ngram_table_takes_four) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.embedding_placement == TablePlacement::Ram);
|
|
CHECK(!d.embedding_placement_given);
|
|
CHECK(d.ngram_placement == TablePlacement::Auto);
|
|
CHECK_EQ(d.embedding_host_mib, 0ll); /* set by the resolver */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--embedding-placement", "ram", "--ngram-placement", "disk" }, &c), RAD_OK);
|
|
CHECK(c.embedding_placement == TablePlacement::Ram);
|
|
CHECK(c.embedding_placement_given);
|
|
CHECK(c.ngram_placement == TablePlacement::Disk);
|
|
Config v;
|
|
CHECK_EQ(parse({ "--embedding-placement", "vram", "--ngram-placement", "auto" }, &v), RAD_OK);
|
|
CHECK(v.embedding_placement == TablePlacement::Vram);
|
|
CHECK(v.embedding_placement_given);
|
|
CHECK(v.ngram_placement == TablePlacement::Auto);
|
|
CHECK(v.embedding_resolved == TablePlacement::Vram); /* untouched until plan */
|
|
CHECK_EQ(parse({ "--ngram-placement", "ram" }, &v), RAD_OK);
|
|
CHECK(v.ngram_placement == TablePlacement::Ram);
|
|
for (const char* bad : { "auto", "disk" })
|
|
CHECK_EQ(parse({ "--embedding-placement", bad }, &c), RAD_E_INVAL);
|
|
for (const char* bad : { "RAM", "memory", "host", "" }) {
|
|
CHECK_EQ(parse({ "--embedding-placement", bad }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--ngram-placement", bad }, &c), RAD_E_INVAL);
|
|
}
|
|
CHECK_EQ(parse({ "--ngram-placement" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* ram=DIR is ram whose pinned copy is a shared file in DIR; a later plain placement drops the
|
|
* directory, and no other tier takes one. */
|
|
TEST(the_ngram_table_takes_a_directory_for_a_shared_ram_copy) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.ngram_share_dir.empty());
|
|
Config s;
|
|
CHECK_EQ(parse({ "--ngram-placement", "ram=/tmp/x" }, &s), RAD_OK);
|
|
CHECK(s.ngram_placement == TablePlacement::Ram);
|
|
CHECK_EQ(s.ngram_share_dir, std::string("/tmp/x"));
|
|
CHECK_EQ(parse({ "--ngram-placement", "ram=/tmp/x", "--ngram-placement", "ram" }, &s), RAD_OK);
|
|
CHECK(s.ngram_placement == TablePlacement::Ram);
|
|
CHECK(s.ngram_share_dir.empty());
|
|
Config c;
|
|
for (const char* bad : { "ram=", "disk=", "vram=/tmp/x", "auto=/tmp/x" })
|
|
CHECK_EQ(parse({ "--ngram-placement", bad }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--embedding-placement", "ram=/tmp/x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--embedding-placement", "disk=/tmp/x" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* disk=DIR is disk read from the table's own file in DIR (#130); it and ram=DIR replace each
|
|
* other, and a plain placement drops both directories. */
|
|
TEST(the_ngram_table_takes_a_directory_for_its_own_file_on_disk) {
|
|
Config s;
|
|
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane" }, &s), RAD_OK);
|
|
CHECK(s.ngram_placement == TablePlacement::Disk);
|
|
CHECK_EQ(s.ngram_disk_dir, std::string("/mnt/optane"));
|
|
CHECK(s.ngram_share_dir.empty());
|
|
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane", "--ngram-placement", "ram=/dev/shm" },
|
|
&s), RAD_OK);
|
|
CHECK(s.ngram_placement == TablePlacement::Ram);
|
|
CHECK(s.ngram_disk_dir.empty());
|
|
CHECK_EQ(s.ngram_share_dir, std::string("/dev/shm"));
|
|
CHECK_EQ(parse({ "--ngram-placement", "disk=/mnt/optane", "--ngram-placement", "disk" }, &s),
|
|
RAD_OK);
|
|
CHECK(s.ngram_disk_dir.empty());
|
|
}
|
|
|
|
/* --draft-window takes exactly two names; the default is kDraftWindowDefault, which the help text
|
|
* also states. Whether the window can adapt (a serial drafter, depth above zero) is decided by the
|
|
* scheduler with the program in hand, not the parser. */
|
|
TEST(the_draft_window_is_fixed_or_adaptive) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.draft_window == kDraftWindowDefault);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--draft-window", "adaptive" }, &c), RAD_OK);
|
|
CHECK(c.draft_window == DraftWindow::Adaptive);
|
|
CHECK_EQ(parse({ "--draft-window", "fixed" }, &c), RAD_OK);
|
|
CHECK(c.draft_window == DraftWindow::Fixed);
|
|
CHECK_EQ(parse({ "--draft-window", "adaptive", "--num-speculative-tokens", "6" }, &c), RAD_OK);
|
|
CHECK(c.draft_window == DraftWindow::Adaptive);
|
|
CHECK_EQ(c.n_spec, 6);
|
|
for (const char* bad : { "Adaptive", "auto", "dynamic", "1", "" })
|
|
CHECK_EQ(parse({ "--draft-window", bad }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--draft-window" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(std::string(draft_window_name(DraftWindow::Adaptive)), std::string("adaptive"));
|
|
CHECK_EQ(std::string(draft_window_name(DraftWindow::Fixed)), std::string("fixed"));
|
|
}
|
|
|
|
/* --draft-verify is token (alias rowwise) unless asked for; block and traversal parse. block
|
|
* implies the coupled drafting and refuses coupling off; traversal needs the coupling and says so. */
|
|
TEST(the_draft_verify_is_token_block_or_traversal) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(!d.draft_verify_block);
|
|
CHECK(!d.draft_verify_traversal);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--draft-verify", "block" }, &c), RAD_OK);
|
|
CHECK(c.draft_verify_block);
|
|
CHECK(!c.draft_verify_traversal);
|
|
CHECK(c.draft_coupling);
|
|
Config t;
|
|
CHECK_EQ(parse({ "--draft-coupling", "on", "--draft-verify", "traversal" }, &t), RAD_OK);
|
|
CHECK(t.draft_verify_traversal);
|
|
CHECK(!t.draft_verify_block);
|
|
CHECK_EQ(parse({ "--draft-verify", "rowwise" }, &t), RAD_OK);
|
|
CHECK(!t.draft_verify_traversal);
|
|
CHECK_EQ(parse({ "--draft-verify", "token" }, &t), RAD_OK);
|
|
CHECK(!t.draft_verify_block);
|
|
Config b;
|
|
for (const char* bad : { "Block", "Traversal", "on", "" })
|
|
CHECK_EQ(parse({ "--draft-verify", bad }, &b), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--draft-verify" }, &b), RAD_E_INVAL);
|
|
Config off;
|
|
CHECK_EQ(parse({ "--draft-verify", "block", "--draft-coupling", "off" }, &off), RAD_E_INVAL);
|
|
Config nocouple;
|
|
CHECK_EQ(parse({ "--draft-verify", "traversal" }, &nocouple), RAD_E_INVAL);
|
|
}
|
|
|
|
/* --draft-coupling is off unless asked for, and only off and on parse: a misspelt value must not
|
|
* start a server on the other path. */
|
|
TEST(the_draft_coupling_is_off_or_on) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(!d.draft_coupling);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--draft-coupling", "on" }, &c), RAD_OK);
|
|
CHECK(c.draft_coupling);
|
|
CHECK_EQ(parse({ "--draft-coupling", "off" }, &c), RAD_OK);
|
|
CHECK(!c.draft_coupling);
|
|
for (const char* bad : { "On", "1", "yes", "true", "" })
|
|
CHECK_EQ(parse({ "--draft-coupling", bad }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--draft-coupling" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* An unknown policy name is refused; falling through to the default would make a comparison
|
|
* silently measure the default against itself. */
|
|
TEST(the_checkpoint_policy_is_one_of_the_three_that_exist) {
|
|
Config c;
|
|
for (const char* p : { "geometric-backoff", "tip-only", "keep-all" }) {
|
|
CHECK_EQ(parse({ "--checkpoint-policy", p }, &c), RAD_OK);
|
|
CHECK_EQ(c.checkpoint_policy, std::string(p));
|
|
}
|
|
CHECK_EQ(parse({ "--checkpoint-policy", "lru" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--checkpoint-policy", "geometric_backoff" }, &c), RAD_E_INVAL);
|
|
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.checkpoint_policy, std::string("geometric-backoff"));
|
|
}
|
|
|
|
/* --expert-stats is off until it names a file, and needs one. */
|
|
TEST(expert_stats_is_off_until_it_names_a_file) {
|
|
LogGuard lg;
|
|
auto row = [](const Config& c) {
|
|
for (const diag::ConfigRow& r : diag::config_rows(c))
|
|
if (r.flag == "--expert-stats") return r;
|
|
return diag::ConfigRow{};
|
|
};
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.expert_stats.empty());
|
|
CHECK_EQ(row(d).value, std::string("off"));
|
|
Config c;
|
|
CHECK_EQ(parse({ "--expert-stats", "/s/experts.json" }, &c), RAD_OK);
|
|
CHECK_EQ(c.expert_stats, std::string("/s/experts.json"));
|
|
CHECK_EQ(row(c).value, std::string("/s/experts.json"));
|
|
CHECK_EQ(row(c).source, std::string("command line"));
|
|
CHECK(parse_fresh({ "--expert-stats" }) < 0);
|
|
}
|
|
|
|
/* A prefix hit resumes on the cold run's chunk grid unless the operator trades that for a shorter
|
|
* re-prefill; any other word is refused. */
|
|
TEST(prefix_resume_is_exact_unless_nearest_is_asked_for) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.prefix_exact);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--prefix-resume", "nearest" }, &c), RAD_OK);
|
|
CHECK(!c.prefix_exact);
|
|
CHECK_EQ(parse({ "--prefix-resume", "exact" }, &c), RAD_OK);
|
|
CHECK(c.prefix_exact);
|
|
CHECK_EQ(parse({ "--prefix-resume", "deepest" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* --checkpoint-slots is auto by default, resolved by the engine once a snapshot's size is known;
|
|
* a count is taken as given, 0 included, and the report shows which. */
|
|
TEST(the_checkpoint_slots_are_auto_or_a_count) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.checkpoint_slots, -1ll);
|
|
auto row = [](const Config& c) {
|
|
for (const diag::ConfigRow& r : diag::config_rows(c))
|
|
if (r.flag == "--checkpoint-slots") return r;
|
|
return diag::ConfigRow{};
|
|
};
|
|
CHECK_EQ(row(d).value, std::string("auto"));
|
|
CHECK_EQ(row(d).source, std::string("default"));
|
|
|
|
Config a;
|
|
CHECK_EQ(parse({ "--checkpoint-slots", "auto" }, &a), RAD_OK);
|
|
CHECK_EQ(a.checkpoint_slots, -1ll);
|
|
CHECK_EQ(row(a).value, std::string("auto"));
|
|
CHECK_EQ(row(a).source, std::string("command line"));
|
|
for (const auto& [arg, want] : std::vector<std::pair<const char*, long long>>{
|
|
{ "0", 0 }, { "8", 8 }, { "96", 96 }, { "9223372036854775807", INT64_MAX } }) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--checkpoint-slots", arg }, &c), RAD_OK);
|
|
CHECK_EQ(c.checkpoint_slots, want);
|
|
CHECK_EQ(row(c).value, std::string(arg));
|
|
}
|
|
for (const char* bad : { "-1", "Auto", "auto8", "8 ", "", "0x10", "1e3",
|
|
"9223372036854775808" }) {
|
|
Config c;
|
|
int st = RAD_OK;
|
|
const std::string log = stderr_of([&] { st = parse({ "--checkpoint-slots", bad }, &c); });
|
|
if (st != RAD_E_INVAL) std::fprintf(stderr, " '%s' was not refused\n", bad);
|
|
CHECK_EQ(st, (int)RAD_E_INVAL);
|
|
CHECK(has(log, "--checkpoint-slots"));
|
|
}
|
|
}
|
|
|
|
/* The request parser's ranges, enforced at startup: a default outside them would 400 every
|
|
* request omitting the field, from a server that reports healthy. */
|
|
TEST(the_sampler_defaults_are_range_checked_at_startup) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--temp", "0.7", "--top-k", "20", "--top-p", "0.95",
|
|
"--min-p", "0.05" }, &c), RAD_OK);
|
|
CHECK_NEAR(c.sample_temp, 0.7f, 1e-6);
|
|
CHECK_EQ(c.sample_top_k, 20);
|
|
CHECK_NEAR(c.sample_top_p, 0.95f, 1e-6);
|
|
CHECK_NEAR(c.sample_min_p, 0.05f, 1e-6);
|
|
|
|
/* The legal endpoints. Temperature 0 is greedy and top_k 0 is off. */
|
|
CHECK_EQ(parse({ "--temp", "0" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--temp", "2" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--top-k", "0" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--top-p", "1" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--min-p", "0" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--min-p", "1" }, &c), RAD_OK);
|
|
|
|
CHECK_EQ(parse({ "--temp", "2.1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--top-p", "0" }, &c), RAD_E_INVAL); /* empty nucleus */
|
|
CHECK_EQ(parse({ "--top-p", "1.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--min-p", "1.5" }, &c), RAD_E_INVAL);
|
|
|
|
/* A negative value is refused: below the parser a negative field means unset, and the
|
|
* container's default would be served instead. */
|
|
CHECK_EQ(parse({ "--temp", "-0.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--top-k", "-5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--top-p", "-0.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--min-p", "-0.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--temp", "nan" }, &c), RAD_E_INVAL);
|
|
|
|
/* Unset is negative, not zero, so the container's generation config can be resolved
|
|
* underneath: zero is a real temperature and top_k, indistinguishable from asking for greedy. */
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.sample_temp < 0.0f);
|
|
CHECK(d.sample_top_k < 0);
|
|
CHECK(d.sample_top_p < 0.0f);
|
|
CHECK(d.sample_min_p < 0.0f);
|
|
}
|
|
|
|
/* A number must be the whole argument; atof would read "high" as 0, which for --temp is greedy. */
|
|
TEST(a_sampler_default_that_is_not_a_number_is_refused) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--temp", "high" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--temp", "0.7x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--temp", "" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--top-k", "20.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--top-p", "inf" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--presence-penalty", "nan" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* ================================================================== request defaults and bounds
|
|
*
|
|
* None of these changes anything until given: each unset value is the server's built-in behaviour
|
|
* or a marker the engine reads as "leave it". */
|
|
TEST(the_request_defaults_and_bounds_are_unset_until_given) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(!d.sample_typical_p && !d.sample_rep_penalty && !d.sample_pres_penalty &&
|
|
!d.sample_freq_penalty && !d.sample_dry_multiplier && !d.sample_dry_base &&
|
|
!d.sample_xtc_probability && !d.sample_xtc_threshold);
|
|
CHECK(!d.sample_penalty_last_n && !d.sample_dry_allowed_length &&
|
|
!d.sample_dry_penalty_last_n && !d.sample_dry_seq_breakers);
|
|
CHECK_EQ(d.default_max_tokens, -1ll);
|
|
CHECK_EQ(d.max_tokens_cap, 0ll);
|
|
CHECK_EQ(d.max_n, 0ll);
|
|
CHECK_EQ(d.max_queued_requests, 0ll);
|
|
CHECK_EQ(d.max_stop_strings, 64ll);
|
|
CHECK_EQ(d.max_stop_bytes, 4096ll);
|
|
CHECK(d.chat_template_kwargs.empty());
|
|
CHECK_EQ(d.reasoning_format, std::string("auto"));
|
|
/* The transport's own values (server/http.h TransportOptions). */
|
|
CHECK_EQ(d.http_threads, 0);
|
|
CHECK_EQ(d.http_read_timeout_s, 30);
|
|
CHECK_EQ(d.http_write_timeout_s, 600);
|
|
CHECK_EQ(d.http_keep_alive_timeout_s, 5);
|
|
CHECK_EQ(d.http_max_body_mib, 512ll);
|
|
CHECK_EQ(d.retry_after_s, 1);
|
|
CHECK(d.cors);
|
|
CHECK(!d.media_flags_set());
|
|
}
|
|
|
|
TEST(the_request_defaults_reach_their_fields) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--typical-p", "0.9", "--presence-penalty", "1.5",
|
|
"--frequency-penalty", "-0.5", "--repetition-penalty", "1.05",
|
|
"--repeat-last-n", "-1", "--dry-multiplier", "0.8", "--dry-base", "1.75",
|
|
"--dry-allowed-length", "3", "--dry-penalty-last-n", "256",
|
|
"--dry-sequence-breakers", R"(["\n", ":"])",
|
|
"--xtc-probability", "0.5", "--xtc-threshold", "0.1",
|
|
"--default-max-tokens", "4096", "--max-tokens-cap", "8192",
|
|
"--max-n", "4", "--max-queued-requests", "64",
|
|
"--max-stop-strings", "8", "--max-stop-bytes", "256",
|
|
"--reasoning-format", "none" }, &c), RAD_OK);
|
|
CHECK_NEAR(*c.sample_typical_p, 0.9f, 1e-6);
|
|
CHECK_NEAR(*c.sample_pres_penalty, 1.5f, 1e-6);
|
|
CHECK_NEAR(*c.sample_freq_penalty, -0.5f, 1e-6);
|
|
CHECK_NEAR(*c.sample_rep_penalty, 1.05f, 1e-6);
|
|
CHECK_EQ(*c.sample_penalty_last_n, -1);
|
|
CHECK_NEAR(*c.sample_dry_multiplier, 0.8f, 1e-6);
|
|
CHECK_NEAR(*c.sample_dry_base, 1.75f, 1e-6);
|
|
CHECK_EQ(*c.sample_dry_allowed_length, 3);
|
|
CHECK_EQ(*c.sample_dry_penalty_last_n, 256);
|
|
CHECK(*c.sample_dry_seq_breakers == std::vector<std::string>({ "\n", ":" }));
|
|
CHECK_NEAR(*c.sample_xtc_probability, 0.5f, 1e-6);
|
|
CHECK_NEAR(*c.sample_xtc_threshold, 0.1f, 1e-6);
|
|
CHECK_EQ(c.default_max_tokens, 4096ll);
|
|
CHECK_EQ(c.max_tokens_cap, 8192ll);
|
|
CHECK_EQ(c.max_n, 4ll);
|
|
CHECK_EQ(c.max_queued_requests, 64ll);
|
|
CHECK_EQ(c.max_stop_strings, 8ll);
|
|
CHECK_EQ(c.max_stop_bytes, 256ll);
|
|
CHECK_EQ(c.reasoning_format, std::string("none"));
|
|
|
|
/* `auto` is 0, resolved per request to what the context leaves. */
|
|
Config a;
|
|
CHECK_EQ(parse({ "--default-max-tokens", "auto" }, &a), RAD_OK);
|
|
CHECK_EQ(a.default_max_tokens, 0ll);
|
|
|
|
/* An empty breaker list is a stated value (DRY with no breakers), not unset. */
|
|
Config e;
|
|
CHECK_EQ(parse({ "--dry-sequence-breakers", "[]" }, &e), RAD_OK);
|
|
CHECK(e.sample_dry_seq_breakers && e.sample_dry_seq_breakers->empty());
|
|
|
|
/* A request may send a negative penalty, so the flag accepts one. */
|
|
Config n;
|
|
CHECK_EQ(parse({ "--presence-penalty", "-2" }, &n), RAD_OK);
|
|
CHECK_NEAR(*n.sample_pres_penalty, -2.0f, 1e-6);
|
|
}
|
|
|
|
/* Request ranges, enforced at startup: a default outside them would 400 every request that
|
|
* omits the field. */
|
|
TEST(the_request_defaults_are_range_checked_like_a_request) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--typical-p", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--typical-p", "1.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--presence-penalty", "2.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--frequency-penalty", "-3" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--repetition-penalty", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--repeat-last-n", "-2" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-base", "0.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-penalty-last-n", "-2" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--xtc-probability", "1.5" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--xtc-threshold", "-0.1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-allowed-length", "3.5" }, &c), RAD_E_INVAL);
|
|
/* With DRY on, a request whose allowed length is below 1 is refused at admission, so a
|
|
* default below 1 is refused here rather than refusing every such request. */
|
|
CHECK_EQ(parse({ "--dry-allowed-length", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-allowed-length", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-allowed-length", "1" }, &c), RAD_OK);
|
|
CHECK_EQ(parse({ "--dry-sequence-breakers", R"("\n")" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--dry-sequence-breakers", "[1]" }, &c), RAD_E_INVAL);
|
|
/* The sampler takes at most 16 (sample/host_ref.h); more would refuse every DRY request. */
|
|
CHECK_EQ(parse({ "--dry-sequence-breakers",
|
|
R"(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"])" },
|
|
&c), RAD_E_INVAL);
|
|
|
|
CHECK_EQ(parse({ "--default-max-tokens", "0" }, &c), RAD_E_INVAL); /* spell it `auto` */
|
|
CHECK_EQ(parse({ "--default-max-tokens", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--default-max-tokens", "AUTO" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--default-max-tokens", "4294967296" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-tokens-cap", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-n", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-queued-requests", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-stop-strings", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-stop-bytes", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--reasoning-format", "deepseek" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--reasoning-format", "" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* Contradictory bounds are refused: a default above the cap is never served, and an `n` above the
|
|
* queue size gets 429 however long its caller waits. */
|
|
TEST(request_bounds_that_contradict_each_other_are_refused) {
|
|
CHECK_EQ(parse_fresh({ "--default-max-tokens", "4096", "--max-tokens-cap", "1024" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--default-max-tokens", "1024", "--max-tokens-cap", "1024" }), RAD_OK);
|
|
CHECK_EQ(parse_fresh({ "--default-max-tokens", "auto", "--max-tokens-cap", "1024" }), RAD_OK);
|
|
|
|
CHECK_EQ(parse_fresh({ "--max-n", "65", "--max-queued-requests", "64" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--max-n", "64", "--max-queued-requests", "64" }), RAD_OK);
|
|
/* The queue's default is 8 x --max-num-seqs, and the check uses it. */
|
|
CHECK_EQ(parse_fresh({ "--max-num-seqs", "2", "--max-n", "17" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--max-num-seqs", "2", "--max-n", "16" }), RAD_OK);
|
|
/* A stated queue smaller than the default n (8, or --max-num-seqs). */
|
|
CHECK_EQ(parse_fresh({ "--max-queued-requests", "4" }), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_template_variables_merge_key_by_key_and_later_wins) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--chat-template-kwargs", R"({"enable_thinking": false, "custom": "a"})",
|
|
"--chat-template-kwargs", R"({"custom": "b", "n": 3})" }, &c), RAD_OK);
|
|
CHECK_EQ(c.chat_template_kwargs.size(), 3u);
|
|
CHECK_EQ(c.chat_template_kwargs["enable_thinking"], std::string("false"));
|
|
CHECK_EQ(c.chat_template_kwargs["custom"], std::string("\"b\"")); /* JSON text, quoted */
|
|
CHECK_EQ(c.chat_template_kwargs["n"], std::string("3"));
|
|
|
|
/* @FILE reads the object from a file. */
|
|
const std::string path = radtest::tmp_path("kwargs.json");
|
|
FILE* fp = std::fopen(path.c_str(), "w");
|
|
REQUIRE(fp != nullptr);
|
|
const std::string body = R"({"date_string": "01 Jan 2026"})";
|
|
CHECK_EQ(std::fwrite(body.data(), 1, body.size(), fp), body.size());
|
|
std::fclose(fp);
|
|
Config f;
|
|
const std::string at = "@" + path;
|
|
CHECK_EQ(parse({ "--chat-template-kwargs", at.c_str() }, &f), RAD_OK);
|
|
CHECK_EQ(f.chat_template_kwargs["date_string"], std::string("\"01 Jan 2026\""));
|
|
unlink(path.c_str());
|
|
CHECK_EQ(parse({ "--chat-template-kwargs", at.c_str() }, &f), RAD_E_INVAL); /* gone */
|
|
}
|
|
|
|
TEST(a_template_variable_the_server_owns_or_cannot_read_is_refused) {
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", "[1]" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", "{nope" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"("enable_thinking")" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"({"enable_thinking": "no"})" }), RAD_E_INVAL);
|
|
/* The renderer sets these; one here would replace every conversation. */
|
|
for (const char* k : { "messages", "tools", "bos_token", "eos_token", "add_generation_prompt" }) {
|
|
const std::string j = std::string("{\"") + k + "\": 1}";
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", j.c_str() }), RAD_E_INVAL);
|
|
}
|
|
/* Two flags setting the thinking default, with no precedence between them. */
|
|
CHECK_EQ(parse_fresh({ "--reasoning-effort", "low",
|
|
"--chat-template-kwargs", R"({"reasoning_effort": "high"})" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"({"enable_thinking": true})",
|
|
"--reasoning-effort", "none" }), RAD_E_INVAL);
|
|
CHECK_EQ(parse_fresh({ "--reasoning-effort", "low",
|
|
"--chat-template-kwargs", R"({"custom": 1})" }), RAD_OK);
|
|
}
|
|
|
|
TEST(the_transport_flags_reach_their_fields_and_hold_their_floors) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--http-threads", "16", "--read-timeout", "10", "--write-timeout", "120",
|
|
"--keep-alive-timeout", "30", "--max-body-mib", "64", "--retry-after", "5",
|
|
"--no-cors" }, &c), RAD_OK);
|
|
CHECK_EQ(c.http_threads, 16);
|
|
CHECK_EQ(c.http_read_timeout_s, 10);
|
|
CHECK_EQ(c.http_write_timeout_s, 120);
|
|
CHECK_EQ(c.http_keep_alive_timeout_s, 30);
|
|
CHECK_EQ(c.http_max_body_mib, 64ll);
|
|
CHECK_EQ(c.retry_after_s, 5);
|
|
CHECK(!c.cors);
|
|
|
|
/* The transport keeps at least four workers, so fewer is refused, not ignored. */
|
|
CHECK_EQ(parse({ "--http-threads", "2" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--read-timeout", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--write-timeout", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--keep-alive-timeout", "x" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-body-mib", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--retry-after", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--retry-after", "0" }, &c), RAD_OK);
|
|
}
|
|
|
|
TEST(the_media_flags_reach_their_fields_and_refuse_an_empty_band) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--image-min-pixels", "3136", "--image-max-pixels", "1003520",
|
|
"--video-min-pixels", "4096", "--video-max-pixels", "8388608",
|
|
"--video-fps", "1.5", "--video-min-frames", "2", "--video-max-frames", "64",
|
|
"--video-max-frame-tokens", "0", "--max-source-pixels", "16777216" }, &c),
|
|
RAD_OK);
|
|
CHECK(c.media_flags_set());
|
|
CHECK_EQ(*c.image_min_pixels, 3136ll);
|
|
CHECK_EQ(*c.image_max_pixels, 1003520ll);
|
|
CHECK_EQ(*c.video_min_pixels, 4096ll);
|
|
CHECK_EQ(*c.video_max_pixels, 8388608ll);
|
|
CHECK_NEAR(*c.video_fps, 1.5, 1e-9);
|
|
CHECK_EQ(*c.video_min_frames, 2);
|
|
CHECK_EQ(*c.video_max_frames, 64);
|
|
CHECK_EQ(*c.video_max_frame_tokens, 0); /* 0 is "no per-frame cap" */
|
|
CHECK_EQ(*c.max_source_pixels, 16777216ll);
|
|
|
|
CHECK_EQ(parse({ "--image-min-pixels", "2000", "--image-max-pixels", "1000" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-min-pixels", "2000", "--video-max-pixels", "1000" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-min-frames", "8", "--video-max-frames", "4" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--image-max-pixels", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-fps", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-fps", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-min-frames", "0" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--video-max-frame-tokens", "-1" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--max-source-pixels", "0" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* --draft-model (familiar from vLLM) is refused by name; accepting it and serving the container's
|
|
* own drafter, or none, would silently differ from what was asked. */
|
|
TEST(draft_model_is_refused_by_name_rather_than_ignored) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--draft-model", "/d.rad" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--draft-model" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
/* ================================================================== resolved */
|
|
|
|
TEST(auto_speculation_is_negative_one_and_not_zero) {
|
|
/* The depth is the drafter's, stated by the architecture plugin once the container is open,
|
|
* so "auto" survives as a distinct value here. Zero is off. */
|
|
Config c;
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "auto" }, &c), RAD_OK);
|
|
CHECK_EQ(c.n_spec, -1);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "0" }, &c), RAD_OK);
|
|
CHECK_EQ(c.n_spec, 0);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "3" }, &c), RAD_OK);
|
|
CHECK_EQ(c.n_spec, 3);
|
|
/* Only the word means auto; a negative depth would be read as auto downstream. */
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "-3" }, &c), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--num-speculative-tokens", "-1" }, &c), RAD_E_INVAL);
|
|
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.n_spec, -1); /* auto is also the default */
|
|
}
|
|
|
|
/* --spec-ngram K is prompt lookup alone at window K: it sets the window, agrees with a matching
|
|
* --num-speculative-tokens and refuses another; the pattern range must be a range. Off by
|
|
* default, at the lengths 2..4. */
|
|
TEST(spec_ngram_sets_the_window_and_refuses_another) {
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.spec_ngram, 0);
|
|
CHECK_EQ(d.spec_ngram_min, 2);
|
|
CHECK_EQ(d.spec_ngram_max, 4);
|
|
Config c;
|
|
CHECK_EQ(parse({ "--spec-ngram", "5" }, &c), RAD_OK);
|
|
CHECK_EQ(c.spec_ngram, 5);
|
|
CHECK_EQ(c.n_spec, 5);
|
|
Config e;
|
|
CHECK_EQ(parse({ "--spec-ngram", "5", "--num-speculative-tokens", "5" }, &e), RAD_OK);
|
|
CHECK_EQ(e.n_spec, 5);
|
|
Config f;
|
|
{
|
|
LogGuard lg;
|
|
CHECK_EQ(parse({ "--spec-ngram", "5", "--num-speculative-tokens", "3" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--spec-ngram", "5", "--num-speculative-tokens", "auto" }, &f),
|
|
RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--spec-ngram-min", "5", "--spec-ngram-max", "3" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--spec-ngram-max", "16" }, &f), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--spec-ngram", "65" }, &f), RAD_E_INVAL);
|
|
}
|
|
Config g;
|
|
CHECK_EQ(parse({ "--spec-ngram-min", "1", "--spec-ngram-max", "8" }, &g), RAD_OK);
|
|
CHECK_EQ(g.spec_ngram_min, 1);
|
|
CHECK_EQ(g.spec_ngram_max, 8);
|
|
CHECK_EQ(g.n_spec, -1); /* the range alone changes no window */
|
|
}
|
|
|
|
/* --gpu-headroom is an alias for --gpu-headroom-mib; both set the same field. */
|
|
TEST(gpu_headroom_parses_under_both_spellings) {
|
|
Config a, b, d;
|
|
CHECK_EQ(parse({ "--gpu-headroom-mib", "256" }, &a), RAD_OK);
|
|
CHECK_EQ(parse({ "--gpu-headroom", "256" }, &b), RAD_OK);
|
|
CHECK_EQ(a.gpu_headroom_mib, 256ll);
|
|
CHECK_EQ(b.gpu_headroom_mib, 256ll);
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK_EQ(d.gpu_headroom_mib, 96ll);
|
|
}
|
|
|
|
/* --gpu-memory-mib is the inverse of --gpu-headroom-mib; they cannot be combined. The default
|
|
* headroom is not "given", so memory alone is legal and leaves the default until the resolver. */
|
|
TEST(gpu_memory_mib_parses_and_excludes_headroom) {
|
|
Config a;
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "28000" }, &a), RAD_OK);
|
|
CHECK_EQ(a.gpu_memory_mib, 28000ll);
|
|
CHECK_EQ(a.gpu_headroom_mib, 96ll);
|
|
CHECK(a.given.count("--gpu-memory-mib"));
|
|
CHECK(!a.given.count("--gpu-headroom-mib"));
|
|
|
|
Config z;
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "0" }, &z), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "-1" }, &z), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "8x" }, &z), RAD_E_INVAL);
|
|
|
|
Config b, c;
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "28000", "--gpu-headroom-mib", "96" }, &b), RAD_E_INVAL);
|
|
CHECK_EQ(parse({ "--gpu-memory-mib", "28000", "--gpu-headroom", "96" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(the_kernel_hierarchy_is_separated_by_commas_or_colons_and_ordered) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--kernels", "libr4d.so,libref.so" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kernel_hierarchy.size(), 2u);
|
|
CHECK_EQ(c.kernel_hierarchy[0], std::string("libr4d.so")); /* first wins, so order matters */
|
|
CHECK_EQ(c.kernel_hierarchy[1], std::string("libref.so"));
|
|
|
|
/* Empty segments are dropped: a trailing comma is a typo, and a plugin path of "" matches
|
|
* nothing and would warn on every start. */
|
|
Config t;
|
|
CHECK_EQ(parse({ "--kernels", ",a,,b," }, &t), RAD_OK);
|
|
CHECK_EQ(t.kernel_hierarchy.size(), 2u);
|
|
CHECK_EQ(t.kernel_hierarchy[0], std::string("a"));
|
|
CHECK_EQ(t.kernel_hierarchy[1], std::string("b"));
|
|
|
|
Config one;
|
|
CHECK_EQ(parse({ "--kernels", "solo" }, &one), RAD_OK);
|
|
CHECK_EQ(one.kernel_hierarchy.size(), 1u);
|
|
|
|
/* A colon separates as a comma does: rad-kbench, rad-tune and rad-convert document
|
|
* `--kernels A:B`, and the engine must load the same list from the same spelling. */
|
|
Config col;
|
|
CHECK_EQ(parse({ "--kernels", "mykernels:libr4d,libref" }, &col), RAD_OK);
|
|
REQUIRE_EQ(col.kernel_hierarchy.size(), 3u);
|
|
CHECK_EQ(col.kernel_hierarchy[0], std::string("mykernels"));
|
|
CHECK_EQ(col.kernel_hierarchy[1], std::string("libr4d"));
|
|
CHECK_EQ(col.kernel_hierarchy[2], std::string("libref"));
|
|
}
|
|
|
|
/* There is deliberately no built-in default hierarchy: naming one card's kernel library in the
|
|
* core would rank the installed library behind the reference elsewhere. The loader orders an empty
|
|
* hierarchy. */
|
|
TEST(an_unnamed_hierarchy_stays_empty_for_the_loader_to_order) {
|
|
Config c;
|
|
CHECK_EQ(parse({}, &c), RAD_OK);
|
|
CHECK_EQ(c.kernel_hierarchy.size(), 0u);
|
|
}
|
|
|
|
/* The engine honours the same environment variables as the tools, so a plugin validated with
|
|
* rad-kbench or rad-tune serves without editing every launcher's command line. */
|
|
TEST(the_environment_supplies_what_the_line_left_unsaid) {
|
|
const char* old_home = getenv("RADIANCE_HOME");
|
|
const char* old_kern = getenv("RADIANCE_KERNELS");
|
|
const std::string save_home = old_home ? old_home : "";
|
|
const std::string save_kern = old_kern ? old_kern : "";
|
|
|
|
setenv("RADIANCE_HOME", "/env/home", 1);
|
|
setenv("RADIANCE_KERNELS", "env_a,env_b", 1);
|
|
|
|
Config c;
|
|
CHECK_EQ(parse({}, &c), RAD_OK);
|
|
CHECK_EQ(c.radiance_home, std::string("/env/home"));
|
|
CHECK_EQ(c.kernel_hierarchy.size(), 2u);
|
|
CHECK_EQ(c.kernel_hierarchy[0], std::string("env_a"));
|
|
|
|
/* The command line wins over the environment. */
|
|
Config f;
|
|
CHECK_EQ(parse({ "--radiance-home", "/flag/home", "--kernels", "flag_only" }, &f), RAD_OK);
|
|
CHECK_EQ(f.radiance_home, std::string("/flag/home"));
|
|
CHECK_EQ(f.kernel_hierarchy.size(), 1u);
|
|
CHECK_EQ(f.kernel_hierarchy[0], std::string("flag_only"));
|
|
|
|
/* An empty variable is treated as unset, not as an empty hierarchy. */
|
|
setenv("RADIANCE_KERNELS", "", 1);
|
|
Config e;
|
|
CHECK_EQ(parse({}, &e), RAD_OK);
|
|
CHECK_EQ(e.kernel_hierarchy.size(), 0u);
|
|
|
|
/* $RADIANCE_KERNELS splits by the same rule as --kernels. */
|
|
setenv("RADIANCE_KERNELS", "env_a:env_b", 1);
|
|
Config k;
|
|
CHECK_EQ(parse({}, &k), RAD_OK);
|
|
CHECK(k.kernel_hierarchy == (std::vector<std::string>{ "env_a", "env_b" }));
|
|
|
|
unsetenv("RADIANCE_HOME");
|
|
Config h;
|
|
CHECK_EQ(parse({}, &h), RAD_OK);
|
|
CHECK(!h.radiance_home.empty()); /* the compiled-in default */
|
|
|
|
/* A home set but empty is unset too: as the tools read it, and an empty home would load no
|
|
* plugin. The source names the default, not the environment. */
|
|
setenv("RADIANCE_HOME", "", 1);
|
|
Config eh;
|
|
CHECK_EQ(parse({}, &eh), RAD_OK);
|
|
CHECK_EQ(eh.radiance_home, h.radiance_home);
|
|
CHECK(!eh.given.count("--radiance-home"));
|
|
|
|
if (old_home) setenv("RADIANCE_HOME", save_home.c_str(), 1); else unsetenv("RADIANCE_HOME");
|
|
if (old_kern) setenv("RADIANCE_KERNELS", save_kern.c_str(), 1); else unsetenv("RADIANCE_KERNELS");
|
|
}
|
|
|
|
TEST(the_download_dir_is_taken_and_left_empty_until_given) {
|
|
/* Empty means the XDG cache, which hf_model.cpp resolves only when --model is a repo id, so a
|
|
* server started on a local file never reads HOME for it. */
|
|
Config c;
|
|
CHECK_EQ(parse({}, &c), 0);
|
|
CHECK(c.download_dir.empty());
|
|
Config d;
|
|
CHECK_EQ(parse({ "--download-dir", "/big/models" }, &d), 0);
|
|
CHECK_EQ(d.download_dir, std::string("/big/models"));
|
|
}
|
|
|
|
/* The last occurrence wins for every flag with a value: scripts append overrides. */
|
|
TEST(a_repeated_flag_takes_the_last_one) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--port", "1", "--port", "8100" }, &c), RAD_OK);
|
|
CHECK_EQ(c.port, 8100);
|
|
CHECK_EQ(parse({ "--kv-cache-dtype", "bf16", "--kv-cache-dtype", "i8" }, &c), RAD_OK);
|
|
CHECK_EQ(c.kv_cache_dtype, std::string("i8"));
|
|
/* A bad value is refused even after a good one. */
|
|
CHECK_EQ(parse({ "--tp-wire", "exact", "--tp-wire", "nope" }, &c), RAD_E_INVAL);
|
|
}
|
|
|
|
TEST(usage_names_every_flag_it_documents) {
|
|
/* config_usage writes to stderr; it must mention the flags an operator most likely looks
|
|
* for, so a flag added without a help line is caught. */
|
|
const std::string text = stderr_of([] { config_usage("radiance"); });
|
|
for (const char* f : { "--model", "--host-pool-mib", "--kv-cache-dtype",
|
|
"--num-speculative-tokens", "--draft-window", "--draft-coupling", "--draft-verify",
|
|
"--checkpoint-policy",
|
|
"--prefix-cache-mib", "--prefix-cache-ttl", "--tp-wire",
|
|
"--embedding-placement", "--ngram-placement",
|
|
"--kld-record", "--kld-ref", "--default-max-tokens", "--max-tokens-cap",
|
|
"--presence-penalty", "--dry-sequence-breakers",
|
|
"--chat-template-kwargs", "--reasoning-format", "--max-n",
|
|
"--max-queued-requests", "--max-stop-strings", "--http-threads",
|
|
"--max-body-mib", "--no-cors", "--image-max-pixels", "--video-fps",
|
|
"--max-source-pixels", "--download-dir" })
|
|
CHECK(has(text, f));
|
|
CHECK(has(text, std::string("Default ") + draft_window_name(kDraftWindowDefault)));
|
|
/* top_k 0 is the sampler's candidate width, not the whole vocabulary or "off". */
|
|
CHECK(has(text, "0 is the 1024 most"));
|
|
CHECK(!has(text, "top_k (0 = off)"));
|
|
CHECK(text.size() > 1000);
|
|
}
|
|
|
|
/* --rope-scaling is validated at the command line: a typo is refused rather than serving the
|
|
* trained rotary at a length it cannot reach. */
|
|
TEST(rope_scaling_takes_yarn_with_a_factor_above_one_or_none) {
|
|
for (const char* ok : { "yarn:4", "yarn:2.5", "yarn:4:262144", "none" }) {
|
|
Config c;
|
|
CHECK_EQ(parse({ "--rope-scaling", ok }, &c), RAD_OK);
|
|
CHECK_EQ(c.rope_scaling, std::string(ok));
|
|
}
|
|
for (const char* bad : { "yarn:1", "yarn:0.5", "yarn:4x", "yarn:", "yarn:4:", "yarn:4:0",
|
|
"yarn:4:12k", "linear:2", "yarn" }) {
|
|
Config c;
|
|
CHECK(parse({ "--rope-scaling", bad }, &c) < 0);
|
|
}
|
|
Config d;
|
|
CHECK_EQ(parse({}, &d), RAD_OK);
|
|
CHECK(d.rope_scaling.empty());
|
|
}
|
|
|
|
RAD_TEST_MAIN()
|