This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/config.cpp
T
Deadcode 7c7f755931 Merge Gemma 4 31B: PRs #74, #75, #81 and #86 (sfjes, keptn42), with fixes
The gemma4_bf16 architecture (sliding and global attention, the proportional RoPE ladder, the
assistant head as a drafter that reads the trunk's cache, the vision tower), its w4a8 decode
junctions, the h512/gqa8 and h256/gqa2 attention kernels, compressed-tensors int4 import, multi-EOS
from generation_config, the call/reasoning reply format, a window group that keeps the keys a
prefill chunk still reads, and window snapshots in checkpoint slots so a prefix hit on a
sliding-window trunk resumes.

Fixes on top: the investigation switches and diagnostic blocks out of the served paths; int4 import
through the checkpoint import framework; attention_k_eq_v from the config; the fused junctions only
where every reader takes their pair; a shared-KV head binds no group of its own; the compose file
without HSA_ENABLE_IPC_MODE_LEGACY (TP2 fails with it on ROCm 10.1); a checkpoint carries a window
only where a hit resumes from it; the README says the linked container is keptn42's calibrated GPTQ
build and what the in-tree recipe gives.
2026-10-12 20:46:37 +02:00

1051 lines
67 KiB
C++

/* config.cpp -- the command line. Every pool is budgeted explicitly: no profiling pass, no
* utilisation fraction, no inference about what the workload will be. The trade between KV blocks
* and resident weights is real and workload-dependent -- a long-context low-concurrency server and
* a short-context high-concurrency one want opposite splits -- but it is the operator's to make.
* An engine that quietly re-optimises the split is an engine whose benchmarks do not reproduce
* (spec §6).
*/
#include "rad_core.h"
#include "format/rope_override.h"
#include "sample/host_ref.h"
#include "server/oai.h"
#include "diag/diag.h"
#include <nlohmann/json.hpp>
#include <algorithm>
#include <cerrno>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
namespace rad {
struct Flag {
const char* name;
const char* arg; /* null for a boolean */
const char* help;
};
/* Built from kDraftWindowDefault, so the default is stated in one place. Defined before the table
* that points at it: the two are initialised in this order. */
static const std::string g_draft_window_help =
std::string("fixed | adaptive: how many drafts each sequence carries. fixed drafts\n"
" --num-speculative-tokens every step; adaptive makes that\n"
" the ceiling and follows each sequence's acceptance and the\n"
" measured step cost (a serial draft head only). Default ") +
draft_window_name(kDraftWindowDefault);
static const Flag g_flags[] = {
{ "--model", "PATH", "the .rad container, a checkpoint served as it stands, or a\n"
"Hugging Face repo id (owner/name), fetched before startup" },
{ "--download-dir", "DIR", "where a repo id is fetched to; default\n"
"$XDG_CACHE_HOME/radiance/hf, else ~/.cache/radiance/hf" },
{ "--radiance-home", "DIRS", "where kernels/, architectures/ and quantizers/ live; several\n"
"homes separated by ':' are searched in order, the first winning" },
{ "--kernels", "LIST", "the kernel libraries to use, comma-separated, first wins; unnamed ones are not loaded. Default: every library found" },
{ "--tp", "N", "tensor-parallel ranks" },
{ "--tp-wire", "MODE", "cross-rank all-reduce payload: exact (default) or wht6, a\n"
"lossy wire: rotated 6-bit at 2 ranks, tiered int8 at 3\n"
"and 4, none at 8" },
{ "--tp-wire-min-kb", "N", "smallest all-reduce, in KiB, the lossy wire is used for" },
{ "--p2p", "MODE", "how the collectives reach the other cards: auto (default)\n"
"asks the driver, on requires peer access and stops without\n"
"it, off exchanges through pinned host memory" },
{ "--max-num-batched-tokens", "N", "the largest token count one step may carry" },
{ "--busy-prefill-chunk", "MODE", "a prefill chunk's share of a step that has other work: auto\n"
"(default) leaves decode rows and new requests their room,\n"
"off takes the whole step, N holds the chunk to N tokens" },
{ "--max-num-seqs", "N", "the largest number of sequences one step may carry" },
{ "--max-model-len", "N", "context bound; 0 takes the model's training context" },
{ "--rope-scaling", "SPEC", "yarn:FACTOR[:ORIG]: static YaRN over the container's own rotary\n"
"keys, no reconvert (docs/YARN.md); none: off" },
{ "--gpu-headroom-mib", "N", "VRAM left unclaimed on every card (default 96)" },
{ "--kv-cache-dtype", "T", "bf16 | fp8 -- fp8 halves what a token of context costs" },
{ "--host-pool-mib", "N", "pinned host tier" },
{ "--embedding-placement", "WHERE", "ram (default) | vram: where the token embedding lives. ram\n"
" pins it in host memory beside --host-pool-mib, read over the\n"
" link in place; by default a model whose output head reads the\n"
" table, or a host without the memory, keeps it on the card" },
{ "--ngram-placement", "WHERE", "auto (default) | vram | ram | disk: where an n-gram\n"
" embedding table lives (Qwen3.8-Flash-Next: 47.7 GiB).\n"
" vram puts all of it on every card; ram copies it into\n"
" host memory at load, pinned for the cards to read\n"
" (locked, where only a host kernel reads it); disk reads\n"
" its rows from the container on the host. auto takes the\n"
" first of the three that holds it" },
{ "--weights-disk-tier", nullptr, "read weights that fit neither VRAM nor the host pool from the\n"
" container on disk (O_DIRECT); a routed expert is read a layer\n"
" at a time, so a step is paced by the drive" },
{ "--prefix-cache-host-mib", "N", "copy finished conversations' KV to host memory, up to N MiB,\n"
" so their VRAM can go to experts and a return restores\n"
" instead of re-prefilling. 0 is off. Part of it holds\n"
" snapshots on a hybrid or sliding-window model;\n"
" startup says how many" },
{ "--prefix-cache-dir", "DIR", "where the disk tier keeps them. Not --weights-disk-tier, which is\n"
" about WEIGHTS" },
{ "--prefix-cache-disk-mib", "N", "and copy them on to disk under --prefix-cache-dir, up to N MiB,\n"
" so a full host tier gives slots up for nothing. Holds\n"
" conversation content unencrypted. 0 is off" },
{ "--placement", "MODE", "all_vram | layer_offload | expert_tiered | auto" },
{ "--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"
" this does NOT make the engine bit-reproducible across\n"
" batch positions -- see spec §19" },
{ "--checkpoint-interval","N", "linear-attention state checkpoint interval, in tokens" },
/* TOTAL, NOT PER SEQUENCE. The snapshot store is one pool of N slots for the whole server
* (KVManager::set_checkpoint_store), so an operator reading "per sequence" and setting 2 gets
* 2 for the whole server rather than 2 x --max-num-seqs. At the default 8 slots and
* 8 sequences that is one snapshot a sequence, which is what an append-only chat wants --
* the next turn's hit lands at the end of the last one. */
{ "--checkpoint-slots", "N", "linear-state or sliding-window snapshots "
"retained IN TOTAL (not "
"per sequence), in pinned host memory; compare "
"against --max-num-seqs" },
{ "--no-prefix-cache", nullptr, "disable prefix caching" },
{ "--checkpoint-policy", "NAME", "which snapshots a session retains: geometric-backoff "
"(default), tip-only, keep-all" },
{ "--num-speculative-tokens", "N", "speculative window; 0 disables. Default `auto`: the drafter's\n"
" own operating point, which the plugin states. A container\n"
" with no draft head is unaffected -- auto resolves to 0." },
{ "--draft-window", "MODE", g_draft_window_help.c_str() },
{ "--draft-model", "PATH", "NOT IMPLEMENTED -- merge the drafter at convert time" },
{ "--host", "ADDR", "listen address" },
{ "--port", "N", "listen port" },
{ "--api-key", "KEY", "require `Authorization: Bearer KEY` on every request but /health, /ping and the dashboard page" },
{ "--served-model-name", "NAME", "the model id /v1/models lists and responses carry; default the container's name" },
{ "--mm-max-patches", "N", "patches one encoder pass carries, and so the largest image (a patch is 16x16\n"
"pixels). Default `auto`: 16384 when the container carries a vision tower. 0\n"
"serves text only and keeps the tower off the card" },
{ "--generation-config", "PATH", "a generation_config.json whose sampler settings become the default\n"
" for requests that send none. Without it the container's own\n"
" `generation.*` metadata is used, then a <model>.generation.json\n"
" beside the container, then the built-in defaults" },
{ "--override-chat-template", "PATH", "a Jinja chat template file, used in place of the one the container carries" },
{ "--temp", "F", "default temperature for requests that do not set one" },
{ "--top-k", "N", "default top_k (0 = off) for requests that do not set one" },
{ "--top-p", "F", "default top_p for requests that do not set one" },
{ "--min-p", "F", "default min_p (0 = off) for requests that do not set one.\n"
" These four override whatever the container or its generation\n"
" config asked for; unset, they are resolved from it" },
{ "--reasoning-effort", "S", "default `reasoning_effort` for chat requests that do not set one.\n"
" The value goes to the model's chat template verbatim, so the legal\n"
" set is the template's: Qwen3.8 takes xhigh|medium|low and defaults\n"
" to xhigh, which on a short task can spend the whole token budget\n"
" inside <think> and answer nothing. \"none\" turns thinking off" },
{ "--reasoning-effort-map", "MAP", "FROM=TO[,FROM=TO...]: a `reasoning_effort` a request sends, replaced before\n"
" the chat template sees it -- high=xhigh lets a client that always sends\n"
" OpenAI's top level reach Qwen3.8's. TO is checked against the template at\n"
" startup; none and minimal turn thinking off. Repeatable" },
{ "--thinking-token-budget", "N", "default `thinking_token_budget` for chat requests that do not set one: at\n"
" N reasoning tokens the reasoning block is closed and the answer follows,\n"
" so a client's max_tokens is not spent on reasoning alone. Unset is no\n"
" limit. Needs a reasoning block that ends in one token, as </think> is" },
{ "--typical-p", "F", "default typical_p, (0, 1]. This flag and the eleven below set the default\n"
" for requests that do not name the field; a request that names it wins" },
{ "--presence-penalty", "F", "default presence_penalty, [-2, 2]" },
{ "--frequency-penalty", "F", "default frequency_penalty, [-2, 2]" },
{ "--repetition-penalty", "F", "default repetition_penalty, > 0" },
{ "--repeat-last-n", "N", "default repeat_last_n, the tokens those penalties look back over; -1 is all" },
{ "--dry-multiplier", "F", "default dry_multiplier; 0 is DRY off" },
{ "--dry-base", "F", "default dry_base, >= 1" },
{ "--dry-allowed-length", "N", "default dry_allowed_length" },
{ "--dry-penalty-last-n", "N", "default dry_penalty_last_n; -1 is the whole context" },
{ "--dry-sequence-breakers", "JSON", "default dry_sequence_breakers, a JSON array of at most 16 strings" },
{ "--xtc-probability", "F", "default xtc_probability, [0, 1]" },
{ "--xtc-threshold", "F", "default xtc_threshold, [0, 1]" },
{ "--default-max-tokens", "N", "max_tokens for requests that do not set one: N, or `auto` (default),\n"
" whatever the context leaves after the prompt" },
{ "--max-tokens-cap", "N", "the most any request may generate. A larger max_tokens is cut to it rather\n"
" than refused, and the reply ends with finish_reason \"length\". 0 is none\n"
" (default)" },
{ "--max-n", "N", "the largest `n` a request may ask for (default: the larger of 8 and\n"
" --max-num-seqs)" },
{ "--max-queued-requests", "N", "requests admitted and unfinished at once, past which the answer is 429\n"
" (default 8 x --max-num-seqs)" },
{ "--max-stop-strings", "N", "stop strings one request may send (default 64)" },
{ "--max-stop-bytes", "N", "bytes in one stop string (default 4096)" },
{ "--chat-template-kwargs", "JSON", "variables handed to the chat template on every chat request: a JSON object,\n"
" or @FILE to read one. Repeatable, a later key replacing an earlier one.\n"
" A key the request's own chat_template_kwargs names is the request's, and a\n"
" request that says anything about thinking replaces enable_thinking and\n"
" reasoning_effort here" },
{ "--reasoning-format", "MODE", "auto (default): a reasoning block comes back as reasoning_content.\n"
" none: it stays inline in content" },
{ "--http-threads", "N", "HTTP workers kept while idle (default: one per core, at least 4)" },
{ "--read-timeout", "S", "seconds a client may go silent while sending a request (default 30)" },
{ "--write-timeout", "S", "seconds one write to a client may block (default 600)" },
{ "--keep-alive-timeout", "S", "seconds an idle connection is held open between requests (default 5)" },
{ "--max-body-mib", "N", "the largest request body; images and video arrive base64 inside it\n"
" (default 512)" },
{ "--retry-after", "S", "the Retry-After a 429 carries, in seconds (default 1)" },
{ "--no-cors", nullptr, "send no CORS headers, so a page on another origin cannot read the API" },
{ "--image-min-pixels", "N", "an image is resized to at least N pixels (default: the container's)" },
{ "--image-max-pixels", "N", "and to at most N; one encoder pass (--mm-max-patches) still bounds it" },
{ "--video-min-pixels", "N", "a video's sampled frames together resize to at least N pixels" },
{ "--video-max-pixels", "N", "and to at most N" },
{ "--video-fps", "F", "frames sampled per second of video" },
{ "--video-min-frames", "N", "the fewest frames sampled from a video" },
{ "--video-max-frames", "N", "the most frames sampled from a video" },
{ "--video-max-frame-tokens", "N", "the most prompt tokens one video frame may become; 0 is no cap (a token\n"
" budget processor -- Gemma 4's -- takes 70, 140, 280, 560 or 1120)" },
{ "--image-tokens", "N", "a token-budget processor's image budget (Gemma 4: 70, 140, 280, 560, 1120;\n"
" default the container's); a request's `image_tokens` overrides it" },
{ "--max-source-pixels", "N", "the largest image or video frame the decoder accepts, before any resize\n"
" (default 67108864). The media flags above default to what the container\n"
" states, and do nothing for a model that takes no media" },
{ "--kld-record", "DIR", "instead of serving, run --kld-corpus through prefill and write this\n"
" model's log-probabilities at every scored position to DIR: the\n"
" reference a quantised model is measured against" },
{ "--kld-ref", "DIR", "instead of serving, score this model against the reference in DIR:\n"
" mean, median, 99/99.9/99.99th percentile KL divergence and top-1\n"
" agreement, over the positions and tokens DIR was recorded at" },
{ "--kld-corpus", "FILE", "JSONL, one {\"prompt\", \"score_from\"?, \"source\"?} a line; --kld-record only" },
{ "--kld-out", "FILE", "the --kld-ref report as JSON, and every position's numbers in FILE.rows" },
{ "--debug-graph", nullptr, "print the entire declared graph and exit-quality detail" },
{ "--debug-selection", nullptr, "print the selection table" },
{ "--debug-placement", nullptr, "print the placement plan" },
{ "--debug-accept-reference-kernels", nullptr,
"serve even when ops resolve only to a reference library. NOT a production configuration: the reference\n"
" implementation is an oracle and a last resort, and falling back\n"
" to it is orders of magnitude of speed with nothing to say so." },
{ "--profile-ops", nullptr, "per-op device timing (see the caveat it prints)" },
{ "--live", nullptr, "the live view: cards, throughput, draft acceptance, the expert plane.\n"
" Redirected it prints one greppable key=value line instead" },
{ "-v", nullptr, "verbose" },
{ "-vv", nullptr, "very verbose" },
{ "--help", nullptr, "this" },
};
void config_usage(const char* argv0) {
fprintf(stderr, "usage: %s --model FILE [options]\n\n", argv0);
/* A help text's continuation lines start under its first line, whatever indentation the
* string itself carries. */
for (const Flag& f : g_flags) {
char left[64];
snprintf(left, sizeof left, "%s%s%s", f.name, f.arg ? " " : "", f.arg ? f.arg : "");
std::string help;
for (const char* p = f.help; *p; ++p) {
help += *p;
if (*p != '\n') continue;
help.append(35, ' ');
while (p[1] == ' ') ++p;
}
fprintf(stderr, " %-32s %s\n", left, help.c_str());
}
fprintf(stderr,
"\nEvery pool is budgeted explicitly. The trade between KV blocks and resident weights\n"
"is the operator's to make: an engine that re-optimises it quietly is an engine whose\n"
"benchmarks do not reproduce.\n");
}
/* The four names exactly, lower case: what a table's placement costs is the operator's to state,
* so a spelling this build does not know stops the server rather than picking a tier. */
static bool parse_table_placement(const char* v, TablePlacement* out) {
if (!std::strcmp(v, "auto")) *out = TablePlacement::Auto;
else if (!std::strcmp(v, "vram")) *out = TablePlacement::Vram;
else if (!std::strcmp(v, "ram")) *out = TablePlacement::Ram;
else if (!std::strcmp(v, "disk")) *out = TablePlacement::Disk;
else return false;
return true;
}
static std::vector<std::string> split_commas(const std::string& s) {
std::vector<std::string> out;
size_t i = 0;
while (i <= s.size()) {
size_t j = s.find(',', i);
if (j == std::string::npos) j = s.size();
if (j > i) out.push_back(s.substr(i, j - i));
i = j + 1;
}
return out;
}
/* A NUMBER IS THE WHOLE ARGUMENT OR IT IS REFUSED. atof reads "high" as 0, and for --temp that is
* greedy decoding: a typo that changes every reply and says nothing. */
static bool parse_num(const char* flag, const char* v, double* out) {
char* end = nullptr;
errno = 0;
const double d = std::strtod(v, &end);
if (!*v || !end || *end || errno == ERANGE || !std::isfinite(d)) {
RAD_ERR("%s takes a number, not '%s'", flag, v);
return false;
}
*out = d;
return true;
}
static bool parse_int(const char* flag, const char* v, int64_t lo, int64_t hi, int64_t* out) {
char* end = nullptr;
errno = 0;
const long long n = std::strtoll(v, &end, 10);
if (!*v || !end || *end || errno == ERANGE) {
RAD_ERR("%s takes a whole number, not '%s'", flag, v);
return false;
}
if (n < lo || n > hi) {
if (lo > INT32_MIN && (hi == INT32_MAX || hi == INT64_MAX))
RAD_ERR("%s must be >= %lld, not %lld", flag, (long long)lo, n);
else
RAD_ERR("%s must be in [%lld, %lld], not %lld", flag, (long long)lo, (long long)hi, n);
return false;
}
*out = n;
return true;
}
/* A SAMPLER DEFAULT IS CHECKED AGAINST THE RANGE A REQUEST'S OWN VALUE IS (server::sampler_value_ok),
* here rather than at the first request. A default outside it would be a 400 on every request
* that omits the field -- a server that starts, reports healthy, and answers nothing. */
static bool sampler_num(const char* flag, const char* field, const char* v, double* out) {
if (!parse_num(flag, v, out)) return false;
std::string why;
if (!server::sampler_value_ok(field, *out, &why)) {
RAD_ERR("%s %s: %s %s", flag, v, field, why.c_str());
return false;
}
return true;
}
static bool sampler_int(const char* flag, const char* field, const char* v, int* out) {
int64_t n = 0;
double d = 0;
if (!parse_int(flag, v, INT32_MIN, INT32_MAX, &n) || !sampler_num(flag, field, v, &d))
return false;
*out = (int)n;
return true;
}
/* THE NAMES THE RENDERER SETS ITSELF. The template context is built from these and the variables
* are written over them (common_chat_template_direct_apply_impl), so a variable by one of these
* names would replace the conversation, the tools or the special tokens of every request. */
static const char* const kTemplateOwnNames[] = {
"messages", "tools", "bos_token", "eos_token", "add_generation_prompt",
};
/* --chat-template-kwargs: a JSON object, or @FILE holding one, merged key by key into `out`. */
static bool parse_template_kwargs(const char* v, std::map<std::string, std::string>* out) {
std::string text = v;
std::string src = "--chat-template-kwargs";
if (!text.empty() && text[0] == '@') {
std::ifstream f(text.substr(1), std::ios::binary);
if (!f) {
RAD_ERR("--chat-template-kwargs %s: cannot read %s", v, text.c_str() + 1);
return false;
}
std::ostringstream ss;
ss << f.rdbuf();
src += " " + text.substr(1);
text = ss.str();
}
const nlohmann::json j = nlohmann::json::parse(text, nullptr, false);
if (j.is_discarded() || !j.is_object()) {
RAD_ERR("%s takes a JSON object, such as '{\"enable_thinking\": false}'", src.c_str());
return false;
}
for (auto it = j.begin(); it != j.end(); ++it) {
for (const char* own : kTemplateOwnNames)
if (it.key() == own) {
RAD_ERR("%s: '%s' is set by the server for every request and cannot be a template "
"variable", src.c_str(), own);
return false;
}
if (it.key() == "enable_thinking" && !it.value().is_boolean()) {
RAD_ERR("%s: enable_thinking takes true or false", src.c_str());
return false;
}
/* dump(): the template context takes JSON, so a string arrives still quoted. */
(*out)[it.key()] = it.value().dump();
}
return true;
}
/* Returns 0 on success, 1 for --help (caller exits 0), negative on a bad argument. An unknown
* flag is an error naming it, not a warning: a typo in a budget flag is the difference between
* the plan you asked for and one the planner invented. */
int config_parse(int argc, char** argv, Config* c) {
auto need = [&](int& i) -> const char* {
if (i + 1 >= argc) { RAD_ERR("%s needs an argument", argv[i]); return nullptr; }
return argv[++i];
};
for (int i = 1; i < argc; ++i) {
std::string a = argv[i];
const char* v = nullptr;
auto S = [&](const char* n) { return a == n; };
if (S("--help") || S("-h")) return 1;
else if (S("-v")) log_set_level(Log::Debug);
else if (S("-vv")) log_set_level(Log::Trace);
else if (S("--model")) { if (!(v = need(i))) return RAD_E_INVAL; c->model = v; }
else if (S("--download-dir")) { if (!(v = need(i))) return RAD_E_INVAL; c->download_dir = v; }
else if (S("--radiance-home")) { if (!(v = need(i))) return RAD_E_INVAL; c->radiance_home = v; }
else if (S("--kernels")) { if (!(v = need(i))) return RAD_E_INVAL; c->kernel_hierarchy = split_commas(v); }
else if (S("--tp")) { if (!(v = need(i))) return RAD_E_INVAL; c->tp = atoi(v); }
else if (S("--tp-wire")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "exact")) c->tp_wire_exact = 1;
else if (!std::strcmp(v, "wht6")) c->tp_wire_exact = 0;
else { RAD_ERR("--tp-wire takes exact or wht6, not '%s'", v); return RAD_E_INVAL; }
}
else if (S("--p2p")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "auto")) c->p2p = RAD_P2P_AUTO;
else if (!std::strcmp(v, "on")) c->p2p = RAD_P2P_ON;
else if (!std::strcmp(v, "off")) c->p2p = RAD_P2P_OFF;
else { RAD_ERR("--p2p takes auto, on or off, not '%s'", v); return RAD_E_INVAL; }
}
else if (S("--tp-wire-min-kb")) { if (!(v = need(i))) return RAD_E_INVAL; c->tp_wire_min_kb = atoll(v); }
else if (S("--max-num-batched-tokens")){ if (!(v = need(i))) return RAD_E_INVAL; c->max_tok = atoll(v); }
else if (S("--busy-prefill-chunk")) {
if (!(v = need(i))) return RAD_E_INVAL;
char* end = nullptr;
const long long n = std::strtoll(v, &end, 10);
if (!std::strcmp(v, "auto")) c->busy_prefill_chunk = -1;
else if (!std::strcmp(v, "off")) c->busy_prefill_chunk = 0;
else if (end && end != v && *end == '\0' && n > 0) c->busy_prefill_chunk = n;
else {
RAD_ERR("--busy-prefill-chunk takes auto, off or a positive token count, not '%s'", v);
return RAD_E_INVAL;
}
}
else if (S("--max-num-seqs")) { if (!(v = need(i))) return RAD_E_INVAL; c->max_seqs = atoll(v); }
else if (S("--max-model-len")) { if (!(v = need(i))) return RAD_E_INVAL; c->max_ctx = atoll(v); }
else if (S("--rope-scaling")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* Checked here, so a typo is a refusal at the command line and not a model served
* with its trained rotary at a length it cannot reach. */
RopeSpec rs;
if (!rope_spec_parse(v, &rs) || rs.kind == RopeSpec::Keep) {
RAD_ERR("--rope-scaling takes yarn:FACTOR (above 1) with an optional :ORIG trained "
"length, or none -- got '%s'", v);
return RAD_E_INVAL;
}
c->rope_scaling = v;
}
/* THE TWO POOLS ARE THE BUDGET RESOLVER'S, always (core/mem/vram_budget.h). A launch
* line that tries to size them is told which flags move the split, rather than "unknown
* option". */
else if (S("--vram-weights-mib") || S("--vram-kv-mib")) {
RAD_ERR("%s was removed: the card is split between the weights and the cache from what "
"the model needs. --gpu-headroom-mib takes card space away, --max-model-len and "
"--max-num-seqs bound the cache, and --host-pool-mib decides which experts stay "
"on the card", a.c_str());
return RAD_E_INVAL;
}
/* --gpu-headroom takes the short name too: it is the flag an operator reaches for and
* "-mib" is the unit, which every other size flag in this list also spells out. Both
* parse to the same field. */
else if (S("--gpu-headroom-mib") || S("--gpu-headroom"))
{ if (!(v = need(i))) return RAD_E_INVAL; c->gpu_headroom_mib = atoll(v); }
else if (S("--kv-cache-dtype")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (std::strcmp(v, "bf16") && std::strcmp(v, "fp8")) {
RAD_ERR("--kv-cache-dtype takes bf16 or fp8, not '%s'", v);
return RAD_E_INVAL;
}
c->kv_cache_dtype = v;
}
else if (S("--host-pool-mib")) { if (!(v = need(i))) return RAD_E_INVAL; c->host_pool_mib = atoll(v); }
else if (S("--embedding-placement") || S("--ngram-placement")) {
const bool emb = S("--embedding-placement");
if (!(v = need(i))) return RAD_E_INVAL;
TablePlacement p;
/* The embedding has two tiers: its lookup writes activations the card reads, which a
* host kernel reading the container cannot reach, so there is no disk -- and with
* ram the default wherever it can be honoured, nothing left for auto to choose. */
if (emb && (!parse_table_placement(v, &p) ||
(p != TablePlacement::Ram && p != TablePlacement::Vram))) {
RAD_ERR("--embedding-placement takes ram or vram, not '%s'", v);
return RAD_E_INVAL;
}
if (!emb && !parse_table_placement(v, &p)) {
RAD_ERR("%s takes auto, vram, ram or disk, not '%s'", a.c_str(), v);
return RAD_E_INVAL;
}
(emb ? c->embedding_placement : c->ngram_placement) = p;
if (emb) c->embedding_placement_given = true;
}
else if (S("--weights-disk-tier")) { c->weights_disk_tier = true; }
else if (S("--prefix-cache-host-mib")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_host_mib = atoll(v); }
else if (S("--prefix-cache-dir")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_dir = v; }
else if (S("--prefix-cache-disk-mib")) { if (!(v = need(i))) return RAD_E_INVAL; c->prefix_cache_disk_mib = atoll(v); }
else if (S("--placement")) { if (!(v = need(i))) return RAD_E_INVAL; c->placement = v; }
else if (S("--deterministic")) c->deterministic = true;
else if (S("--checkpoint-interval")) { if (!(v = need(i))) return RAD_E_INVAL; c->checkpoint_interval = atoll(v); }
else if (S("--checkpoint-slots")) { if (!(v = need(i))) return RAD_E_INVAL; c->checkpoint_slots = atoll(v); }
else if (S("--no-prefix-cache")) c->prefix_cache = false;
else if (S("--checkpoint-policy")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* Named here rather than accepted blind: a policy name this build does not know would
* otherwise fall through to the default and the measurement would compare the default
* against itself. */
if (std::strcmp(v, "geometric-backoff") && std::strcmp(v, "tip-only") &&
std::strcmp(v, "keep-all")) {
RAD_ERR("--checkpoint-policy '%s' is not one of geometric-backoff, tip-only, "
"keep-all", v);
return RAD_E_INVAL;
}
c->checkpoint_policy = v;
}
else if (S("--num-speculative-tokens")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* "auto" is -1 and the engine resolves it once the container is open: the depth is a
* property of the DRAFTER and the ARCHITECTURE PLUGIN is the one that knows it
* (rad_arch_probe): a serial head names a measured throughput trade-off, a block
* drafter names the block length its checkpoint was trained at. */
if (!std::strcmp(v, "auto")) c->n_spec = -1;
else c->n_spec = atoi(v);
/* Every negative depth reads as auto downstream, so only the word may say it. */
if (std::strcmp(v, "auto") && c->n_spec < 0) {
RAD_ERR("--num-speculative-tokens takes auto or a depth >= 0 (0 turns speculation "
"off), not '%s'", v);
return RAD_E_INVAL;
}
}
else if (S("--draft-window")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "fixed")) c->draft_window = DraftWindow::Fixed;
else if (!std::strcmp(v, "adaptive")) c->draft_window = DraftWindow::Adaptive;
else {
RAD_ERR("--draft-window takes fixed or adaptive, not '%s'", v);
return RAD_E_INVAL;
}
}
else if (S("--draft-model")) {
/* REFUSED, NOT QUIETLY IGNORED. Accepting this flag and then serving the container's
* own drafter -- or none -- would hand the caller a server that is not the one they
* asked for, with nothing in the output to say so.
*
* It refuses rather than disappearing because a caller coming from vLLM will reach
* for it, and a message that says where the drafter actually comes from is the whole
* value the flag can still deliver. This engine loads its drafter from the model
* container: rad-convert's OWN --draft-model merges one in, and an MTP head
* that ships inside the target checkpoint needs no flag at all. spec.md §10's
* "separate draft models load as a second plugin" is a design, not a feature. */
if (!(v = need(i))) return RAD_E_INVAL;
RAD_ERR("--draft-model is not implemented. This engine loads its drafter from the "
"model container, not from a second one: merge it at conversion time with "
"`rad-convert --draft-model DIR` and pass the container to --model. "
"An MTP head that ships inside the target checkpoint needs neither flag.");
return RAD_E_INVAL;
}
else if (S("--host")) { if (!(v = need(i))) return RAD_E_INVAL; c->host = v; }
else if (S("--port")) { if (!(v = need(i))) return RAD_E_INVAL; c->port = atoi(v); }
else if (S("--api-key")) { if (!(v = need(i))) return RAD_E_INVAL; c->api_key = v; }
else if (S("--served-model-name")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!*v) { RAD_ERR("--served-model-name takes a non-empty name"); return RAD_E_INVAL; }
c->served_model_name = v;
}
else if (S("--mm-max-patches")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "auto")) c->mm_max_patches = -1;
else {
char* end = nullptr;
const long long n = std::strtoll(v, &end, 10);
if (!end || *end || n < 0) {
RAD_ERR("--mm-max-patches takes auto or a patch count >= 0, not '%s'", v);
return RAD_E_INVAL;
}
c->mm_max_patches = n;
}
}
else if (S("--reasoning-effort")) { if (!(v = need(i))) return RAD_E_INVAL;
c->reasoning_effort = v; }
else if (S("--reasoning-effort-map")) {
if (!(v = need(i))) return RAD_E_INVAL;
const std::string all = v;
size_t at = 0;
while (at <= all.size()) {
const size_t end = std::min(all.find(',', at), all.size());
const std::string pair = all.substr(at, end - at);
const size_t eq = pair.find('=');
if (eq == std::string::npos || eq == 0 || eq + 1 == pair.size() ||
pair.find('=', eq + 1) != std::string::npos) {
RAD_ERR("--reasoning-effort-map takes FROM=TO pairs separated by commas, "
"not '%s'", pair.c_str());
return RAD_E_INVAL;
}
c->reasoning_effort_map[pair.substr(0, eq)] = pair.substr(eq + 1);
at = end + 1;
}
}
else if (S("--thinking-token-budget")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 0, INT32_MAX,
&c->thinking_token_budget))
return RAD_E_INVAL; }
else if (S("--generation-config")) { if (!(v = need(i))) return RAD_E_INVAL;
c->generation_config = v; }
else if (S("--override-chat-template")) { if (!(v = need(i))) return RAD_E_INVAL;
c->override_chat_template = v; }
/* A NEGATIVE VALUE IS REFUSED BY THE RANGE: these four fields use a negative number to
* mean "not set", so `--temp -0.5` taken as given would be read as no flag at all and
* the container's default served in its place. */
else if (S("--temp") || S("--top-p") || S("--min-p")) {
if (!(v = need(i))) return RAD_E_INVAL;
const char* field = S("--temp") ? "temperature" : S("--top-p") ? "top_p" : "min_p";
double d = 0;
if (!sampler_num(a.c_str(), field, v, &d)) return RAD_E_INVAL;
(S("--temp") ? c->sample_temp : S("--top-p") ? c->sample_top_p : c->sample_min_p) = (float)d;
}
else if (S("--top-k")) { if (!(v = need(i))) return RAD_E_INVAL;
if (!sampler_int("--top-k", "top_k", v, &c->sample_top_k))
return RAD_E_INVAL; }
else if (S("--typical-p") || S("--presence-penalty") || S("--frequency-penalty") ||
S("--repetition-penalty") || S("--dry-multiplier") || S("--dry-base") ||
S("--xtc-probability") || S("--xtc-threshold")) {
if (!(v = need(i))) return RAD_E_INVAL;
struct F { const char* flag; const char* field; std::optional<float> Config::* m; };
static const F kF[] = {
{ "--typical-p", "typical_p", &Config::sample_typical_p },
{ "--presence-penalty", "presence_penalty", &Config::sample_pres_penalty },
{ "--frequency-penalty", "frequency_penalty", &Config::sample_freq_penalty },
{ "--repetition-penalty", "repetition_penalty", &Config::sample_rep_penalty },
{ "--dry-multiplier", "dry_multiplier", &Config::sample_dry_multiplier },
{ "--dry-base", "dry_base", &Config::sample_dry_base },
{ "--xtc-probability", "xtc_probability", &Config::sample_xtc_probability },
{ "--xtc-threshold", "xtc_threshold", &Config::sample_xtc_threshold },
};
for (const F& f : kF) {
if (!S(f.flag)) continue;
double d = 0;
if (!sampler_num(f.flag, f.field, v, &d)) return RAD_E_INVAL;
c->*f.m = (float)d;
}
}
else if (S("--repeat-last-n") || S("--dry-allowed-length") || S("--dry-penalty-last-n")) {
if (!(v = need(i))) return RAD_E_INVAL;
const char* field = S("--repeat-last-n") ? "repeat_last_n"
: S("--dry-allowed-length") ? "dry_allowed_length"
: "dry_penalty_last_n";
int n = 0;
if (!sampler_int(a.c_str(), field, v, &n)) return RAD_E_INVAL;
(S("--repeat-last-n") ? c->sample_penalty_last_n
: S("--dry-allowed-length") ? c->sample_dry_allowed_length
: c->sample_dry_penalty_last_n) = n;
}
else if (S("--dry-sequence-breakers")) {
if (!(v = need(i))) return RAD_E_INVAL;
const nlohmann::json j = nlohmann::json::parse(v, nullptr, false);
bool strings = j.is_array();
if (strings) for (const auto& e : j) strings = strings && e.is_string();
if (!strings) {
RAD_ERR("--dry-sequence-breakers takes a JSON array of strings, such as "
"'[\"\\n\", \":\"]', not '%s'", v);
return RAD_E_INVAL;
}
/* The sampler refuses a DRY request with more (sample/host_ref.h), and every request
* leaving the field to this default would be that request. */
if (j.size() > kDryMaxBreakers) {
RAD_ERR("--dry-sequence-breakers holds %zu strings; the sampler takes at most %zu",
j.size(), kDryMaxBreakers);
return RAD_E_INVAL;
}
c->sample_dry_seq_breakers = j.get<std::vector<std::string>>();
}
else if (S("--default-max-tokens")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "auto")) c->default_max_tokens = 0;
else if (!parse_int(a.c_str(), v, 1, INT32_MAX, &c->default_max_tokens)) {
RAD_ERR("--default-max-tokens takes a token count >= 1, or auto");
return RAD_E_INVAL;
}
}
else if (S("--max-tokens-cap")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 0, INT32_MAX, &c->max_tokens_cap))
return RAD_E_INVAL; }
else if (S("--max-n")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 1, INT32_MAX, &c->max_n))
return RAD_E_INVAL; }
else if (S("--max-queued-requests")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 1, INT32_MAX, &c->max_queued_requests))
return RAD_E_INVAL; }
else if (S("--max-stop-strings")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 1, INT32_MAX, &c->max_stop_strings))
return RAD_E_INVAL; }
else if (S("--max-stop-bytes")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 1, INT32_MAX, &c->max_stop_bytes))
return RAD_E_INVAL; }
else if (S("--chat-template-kwargs")) { if (!(v = need(i)) ||
!parse_template_kwargs(v, &c->chat_template_kwargs))
return RAD_E_INVAL; }
else if (S("--reasoning-format")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* Two values, because the reply reader makes one distinction: whether a reasoning
* block is lifted out of the content or left in it. */
if (std::strcmp(v, "auto") && std::strcmp(v, "none")) {
RAD_ERR("--reasoning-format takes auto or none, not '%s'", v);
return RAD_E_INVAL;
}
c->reasoning_format = v;
}
else if (S("--http-threads") || S("--read-timeout") || S("--write-timeout") ||
S("--keep-alive-timeout") || S("--retry-after")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* The transport keeps at least four workers whatever it is told (server/http.cpp);
* fewer would be a number this flag accepted and the server did not serve. */
const int64_t lo = S("--http-threads") ? 4 : S("--retry-after") ? 0 : 1;
int64_t n = 0;
if (!parse_int(a.c_str(), v, lo, INT32_MAX, &n)) return RAD_E_INVAL;
(S("--http-threads") ? c->http_threads
: S("--read-timeout") ? c->http_read_timeout_s
: S("--write-timeout") ? c->http_write_timeout_s
: S("--retry-after") ? c->retry_after_s
: c->http_keep_alive_timeout_s) = (int)n;
}
else if (S("--max-body-mib")) { if (!(v = need(i)) ||
!parse_int(a.c_str(), v, 1, (int64_t)1 << 20, &c->http_max_body_mib))
return RAD_E_INVAL; }
else if (S("--no-cors")) c->cors = false;
else if (S("--image-min-pixels") || S("--image-max-pixels") || S("--video-min-pixels") ||
S("--video-max-pixels") || S("--max-source-pixels")) {
if (!(v = need(i))) return RAD_E_INVAL;
int64_t n = 0;
if (!parse_int(a.c_str(), v, 1, INT64_MAX, &n)) return RAD_E_INVAL;
(S("--image-min-pixels") ? c->image_min_pixels
: S("--image-max-pixels") ? c->image_max_pixels
: S("--video-min-pixels") ? c->video_min_pixels
: S("--video-max-pixels") ? c->video_max_pixels
: c->max_source_pixels) = n;
}
else if (S("--video-fps")) {
if (!(v = need(i))) return RAD_E_INVAL;
double d = 0;
if (!parse_num(a.c_str(), v, &d)) return RAD_E_INVAL;
if (!(d > 0.0)) { RAD_ERR("--video-fps must be > 0, not '%s'", v); return RAD_E_INVAL; }
c->video_fps = d;
}
else if (S("--image-tokens")) {
if (!(v = need(i))) return RAD_E_INVAL;
int64_t n = 0;
if (!parse_int(a.c_str(), v, 1, INT32_MAX, &n)) return RAD_E_INVAL;
c->image_tokens = (int32_t)n;
}
else if (S("--video-min-frames") || S("--video-max-frames") || S("--video-max-frame-tokens")) {
if (!(v = need(i))) return RAD_E_INVAL;
int64_t n = 0;
if (!parse_int(a.c_str(), v, S("--video-max-frame-tokens") ? 0 : 1, INT32_MAX, &n))
return RAD_E_INVAL;
(S("--video-min-frames") ? c->video_min_frames
: S("--video-max-frames") ? c->video_max_frames
: c->video_max_frame_tokens) = (int32_t)n;
}
else if (S("--kld-record")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_record = v; }
else if (S("--kld-ref")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_ref = v; }
else if (S("--kld-corpus")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_corpus = v; }
else if (S("--kld-out")) { if (!(v = need(i))) return RAD_E_INVAL; c->kld_out = v; }
else if (S("--debug-graph")) { c->debug_graph = true; c->debug_selection = true; }
else if (S("--debug-selection")) c->debug_selection = true;
else if (S("--debug-placement")) c->debug_placement = true;
else if (S("--debug-accept-reference-kernels")) c->accept_reference_kernels = true;
else if (S("--profile-ops")) c->profile_ops = true;
else if (S("--live")) c->live_view = true;
else {
RAD_ERR("unknown option '%s'", a.c_str());
return RAD_E_INVAL;
}
/* WHERE EACH OPTION CAME FROM, for the startup report (core/diag/diag.h): every branch
* above that returned refused the option, so reaching here is the option taken. Under the
* table's spelling, so an alias reports as the option it is. */
c->given[S("--gpu-headroom") ? "--gpu-headroom-mib" : a] = "command line";
}
if (c->radiance_home.empty()) {
const char* h = getenv("RADIANCE_HOME");
c->radiance_home = h ? h : RAD_DEFAULT_HOME;
if (h) c->given["--radiance-home"] = "environment (RADIANCE_HOME)";
}
if (c->kernel_hierarchy.empty()) {
/* RADIANCE_KERNELS, ahead of the built-in default.
*
* The tools read the same variable through rad_hierarchy_from_env() in tools/iface.cpp,
* and the engine has to honour it too: otherwise an operator who validated a third-party
* plugin with rad-kbench or rad-tune has no way to serve with it short of editing every
* launcher's command line. Same spelling, same separator. */
const char* e = getenv("RADIANCE_KERNELS");
if (e && *e) {
c->kernel_hierarchy = split_commas(e);
c->given["--kernels"] = "environment (RADIANCE_KERNELS)";
}
}
/* AND THERE IS NO BUILT-IN DEFAULT, deliberately. Naming a library here -- the RDNA4 one, say
* -- would make the core carry the name of one card's kernels, and on any other machine that
* name matches nothing: the engine would warn about a library that is not installed and then
* rank the one that IS installed behind the reference implementation, which matches every op
* and would answer for all of them.
*
* An empty hierarchy is not "no order". The loader loads everything it finds and orders it,
* the reference library last by construction because it matches anything
* (core/plugin/loader.cpp). So dropping a kernel library into $RADIANCE_HOME/kernels is
* enough to be used, on any card, with no configuration. A list names the libraries to use:
* only those load, in its order, so naming one ahead of another settles a tie between two that
* both serve an op and leaving one out keeps it out. */
if (c->model.empty()) {
RAD_ERR("--model is required");
return RAD_E_INVAL;
}
if (c->tp < 1) { RAD_ERR("--tp must be >= 1"); return RAD_E_INVAL; }
/* THE KL MODE: one direction, and each direction with what it reads. A run given both would
* have to pick which one the operator meant, and picking wrong records a quantised model as
* the yardstick. */
if (!c->kld_record.empty() && !c->kld_ref.empty()) {
RAD_ERR("--kld-record writes a reference and --kld-ref scores against one; give one");
return RAD_E_INVAL;
}
if (!c->kld_record.empty() && c->kld_corpus.empty()) {
RAD_ERR("--kld-record needs --kld-corpus: the reference is recorded over a corpus");
return RAD_E_INVAL;
}
if (!c->kld_ref.empty() && !c->kld_corpus.empty()) {
RAD_ERR("--kld-ref reads its tokens from the reference, which recorded them; drop "
"--kld-corpus");
return RAD_E_INVAL;
}
if (!c->kld_out.empty() && c->kld_ref.empty()) {
RAD_ERR("--kld-out is the --kld-ref report");
return RAD_E_INVAL;
}
/* TWO FLAGS THAT WOULD SAY THE SAME THING. --reasoning-effort is a template variable with one
* extra meaning ("none" is enable_thinking false), so naming either key in
* --chat-template-kwargs as well leaves two defaults for one setting and no order to read. */
if (!c->reasoning_effort.empty() &&
(c->chat_template_kwargs.count("reasoning_effort") ||
c->chat_template_kwargs.count("enable_thinking"))) {
RAD_ERR("--reasoning-effort and a reasoning_effort or enable_thinking key in "
"--chat-template-kwargs both set the default for thinking; give one");
return RAD_E_INVAL;
}
if (c->default_max_tokens > 0 && c->max_tokens_cap > 0 &&
c->default_max_tokens > c->max_tokens_cap) {
RAD_ERR("--default-max-tokens %lld is above --max-tokens-cap %lld, so no request could be "
"served at the default", (long long)c->default_max_tokens,
(long long)c->max_tokens_cap);
return RAD_E_INVAL;
}
/* A request is admitted only if all its choices fit the queue, so an `n` past it would be a
* 429 however long the caller waited. Checked only when one of the two was stated: the
* defaults (8, or --max-num-seqs; and 8 x --max-num-seqs) always fit. */
if (c->max_n > 0 || c->max_queued_requests > 0) {
const int64_t n = c->max_n > 0 ? c->max_n : std::max<int64_t>(8, c->max_seqs);
const int64_t q = c->max_queued_requests > 0 ? c->max_queued_requests : c->max_seqs * 8;
if (n > q) {
RAD_ERR("--max-n %lld is above the %lld requests the queue admits "
"(--max-queued-requests), so a request asking for it could never be admitted",
(long long)n, (long long)q);
return RAD_E_INVAL;
}
}
if (c->image_min_pixels && c->image_max_pixels && *c->image_min_pixels > *c->image_max_pixels) {
RAD_ERR("--image-min-pixels is above --image-max-pixels"); return RAD_E_INVAL; }
if (c->video_min_pixels && c->video_max_pixels && *c->video_min_pixels > *c->video_max_pixels) {
RAD_ERR("--video-min-pixels is above --video-max-pixels"); return RAD_E_INVAL; }
if (c->video_min_frames && c->video_max_frames && *c->video_min_frames > *c->video_max_frames) {
RAD_ERR("--video-min-frames is above --video-max-frames"); return RAD_E_INVAL; }
return RAD_OK;
}
/* ------------------------------------------------------------------ the startup report's rows */
namespace {
std::string onoff(bool b) { return b ? "on" : "off"; }
std::string num(int64_t v) { return std::to_string(v); }
std::string or_none(const std::string& s, const char* none) { return s.empty() ? std::string(none) : s; }
std::string fnum(double v) {
char b[48];
snprintf(b, sizeof b, "%g", v);
return b;
}
template <class T>
std::string opt(const std::optional<T>& v, const char* unset) {
if (!v) return unset;
if constexpr (std::is_floating_point_v<T>) return fnum((double)*v);
else return std::to_string(*v);
}
std::string joined(const std::map<std::string, std::string>& m, const char* sep) {
std::string s;
for (const auto& [k, v] : m) s += (s.empty() ? "" : ",") + k + sep + v;
return s.empty() ? "none" : s;
}
using Show = std::string (*)(const Config&);
struct ShowRow { const char* flag; Show show; };
/* HOW EACH OPTION'S VALUE IS SHOWN, one entry an option of the table above, under the same
* spelling. config_rows walks the TABLE, so an option missing here still appears in the report --
* as "(not shown)" -- and diag_test fails naming it. A sentinel a field uses for "resolved at
* startup" (-1, 0, empty) is shown as what it means; the engine's decisions replace it with the
* value it resolved to. */
const ShowRow kShow[] = {
{ "--model", [](const Config& c) { return c.model; } },
{ "--download-dir", [](const Config& c) { return or_none(c.download_dir, "the XDG cache (~/.cache/radiance/hf)"); } },
{ "--radiance-home", [](const Config& c) { return c.radiance_home; } },
{ "--kernels", [](const Config& c) {
std::string s;
for (const std::string& k : c.kernel_hierarchy) s += (s.empty() ? "" : ",") + k;
return or_none(s, "every library found"); } },
{ "--tp", [](const Config& c) { return num(c.tp); } },
{ "--tp-wire", [](const Config& c) { return std::string(c.tp_wire_exact ? "exact" : "wht6"); } },
{ "--tp-wire-min-kb", [](const Config& c) { return num(c.tp_wire_min_kb); } },
{ "--p2p", [](const Config& c) {
return std::string(c.p2p == RAD_P2P_ON ? "on" : c.p2p == RAD_P2P_OFF ? "off" : "auto"); } },
{ "--max-num-batched-tokens", [](const Config& c) { return num(c.max_tok); } },
{ "--busy-prefill-chunk", [](const Config& c) {
return c.busy_prefill_chunk < 0 ? std::string("auto")
: c.busy_prefill_chunk == 0 ? std::string("off") : num(c.busy_prefill_chunk); } },
{ "--max-num-seqs", [](const Config& c) { return num(c.max_seqs); } },
{ "--max-model-len", [](const Config& c) {
return c.max_ctx ? num(c.max_ctx) : std::string("0 (the model's training context)"); } },
{ "--rope-scaling", [](const Config& c) { return or_none(c.rope_scaling, "the checkpoint's own"); } },
{ "--gpu-headroom-mib", [](const Config& c) { return num(c.gpu_headroom_mib); } },
{ "--kv-cache-dtype", [](const Config& c) { return c.kv_cache_dtype; } },
{ "--host-pool-mib", [](const Config& c) { return num(c.host_pool_mib); } },
{ "--embedding-placement", [](const Config& c) { return std::string(table_placement_name(c.embedding_placement)); } },
{ "--ngram-placement", [](const Config& c) { return std::string(table_placement_name(c.ngram_placement)); } },
{ "--weights-disk-tier", [](const Config& c) { return onoff(c.weights_disk_tier); } },
{ "--prefix-cache-host-mib", [](const Config& c) {
return c.prefix_cache_host_mib ? num(c.prefix_cache_host_mib) : std::string("0 (off)"); } },
{ "--prefix-cache-dir", [](const Config& c) { return or_none(c.prefix_cache_dir, "none"); } },
{ "--prefix-cache-disk-mib", [](const Config& c) {
return c.prefix_cache_disk_mib ? num(c.prefix_cache_disk_mib) : std::string("0 (off)"); } },
{ "--placement", [](const Config& c) { return c.placement; } },
{ "--deterministic", [](const Config& c) { return onoff(c.deterministic); } },
{ "--checkpoint-interval", [](const Config& c) { return num(c.checkpoint_interval); } },
{ "--checkpoint-slots", [](const Config& c) { return num(c.checkpoint_slots); } },
{ "--no-prefix-cache", [](const Config& c) {
return std::string(c.prefix_cache ? "not given: prefix caching on" : "prefix caching off"); } },
{ "--checkpoint-policy", [](const Config& c) { return c.checkpoint_policy; } },
{ "--num-speculative-tokens", [](const Config& c) { return c.n_spec < 0 ? std::string("auto") : num(c.n_spec); } },
{ "--draft-window", [](const Config& c) { return std::string(draft_window_name(c.draft_window)); } },
{ "--draft-model", [](const Config&) { return std::string("not implemented (the container's own drafter)"); } },
{ "--host", [](const Config& c) { return c.host; } },
{ "--port", [](const Config& c) { return num(c.port); } },
/* A SECRET IS NOT A VALUE. Whether one is set is what a reader of the log needs. */
{ "--api-key", [](const Config& c) { return std::string(c.api_key.empty() ? "not set" : "set"); } },
{ "--served-model-name", [](const Config& c) { return or_none(c.served_model_name, "the container's name"); } },
{ "--mm-max-patches", [](const Config& c) { return c.mm_max_patches < 0 ? std::string("auto") : num(c.mm_max_patches); } },
{ "--generation-config", [](const Config& c) { return or_none(c.generation_config, "none"); } },
{ "--override-chat-template", [](const Config& c) { return or_none(c.override_chat_template, "none (the container's)"); } },
{ "--temp", [](const Config& c) { return c.sample_temp < 0 ? std::string("unset") : fnum(c.sample_temp); } },
{ "--top-k", [](const Config& c) { return c.sample_top_k < 0 ? std::string("unset") : num(c.sample_top_k); } },
{ "--top-p", [](const Config& c) { return c.sample_top_p < 0 ? std::string("unset") : fnum(c.sample_top_p); } },
{ "--min-p", [](const Config& c) { return c.sample_min_p < 0 ? std::string("unset") : fnum(c.sample_min_p); } },
{ "--reasoning-effort", [](const Config& c) { return or_none(c.reasoning_effort, "the template's default"); } },
{ "--reasoning-effort-map", [](const Config& c) { return joined(c.reasoning_effort_map, "="); } },
{ "--thinking-token-budget", [](const Config& c) {
return c.thinking_token_budget < 0 ? std::string("none") : num(c.thinking_token_budget); } },
{ "--typical-p", [](const Config& c) { return opt(c.sample_typical_p, "the request default"); } },
{ "--presence-penalty", [](const Config& c) { return opt(c.sample_pres_penalty, "the request default"); } },
{ "--frequency-penalty", [](const Config& c) { return opt(c.sample_freq_penalty, "the request default"); } },
{ "--repetition-penalty", [](const Config& c) { return opt(c.sample_rep_penalty, "the request default"); } },
{ "--repeat-last-n", [](const Config& c) { return opt(c.sample_penalty_last_n, "the request default"); } },
{ "--dry-multiplier", [](const Config& c) { return opt(c.sample_dry_multiplier, "the request default"); } },
{ "--dry-base", [](const Config& c) { return opt(c.sample_dry_base, "the request default"); } },
{ "--dry-allowed-length", [](const Config& c) { return opt(c.sample_dry_allowed_length, "the request default"); } },
{ "--dry-penalty-last-n", [](const Config& c) { return opt(c.sample_dry_penalty_last_n, "the request default"); } },
{ "--dry-sequence-breakers", [](const Config& c) {
/* Replaced, not thrown on, like every dump in the report: the strings reach Config from
* outside the engine, and a serialiser that throws would end a startup that is otherwise
* sound over one line of its log. */
return c.sample_dry_seq_breakers
? nlohmann::json(*c.sample_dry_seq_breakers)
.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace)
: std::string("the request default"); } },
{ "--xtc-probability", [](const Config& c) { return opt(c.sample_xtc_probability, "the request default"); } },
{ "--xtc-threshold", [](const Config& c) { return opt(c.sample_xtc_threshold, "the request default"); } },
{ "--default-max-tokens", [](const Config& c) {
return c.default_max_tokens > 0 ? num(c.default_max_tokens)
: std::string("auto (what the context leaves after the prompt)"); } },
{ "--max-tokens-cap", [](const Config& c) { return c.max_tokens_cap > 0 ? num(c.max_tokens_cap) : std::string("none"); } },
{ "--max-n", [](const Config& c) {
return c.max_n > 0 ? num(c.max_n)
: std::string("auto (the larger of 8 and --max-num-seqs)"); } },
{ "--max-queued-requests", [](const Config& c) {
return c.max_queued_requests > 0 ? num(c.max_queued_requests)
: std::string("auto (8 x --max-num-seqs)"); } },
{ "--max-stop-strings", [](const Config& c) { return num(c.max_stop_strings); } },
{ "--max-stop-bytes", [](const Config& c) { return num(c.max_stop_bytes); } },
{ "--chat-template-kwargs", [](const Config& c) { return joined(c.chat_template_kwargs, "="); } },
{ "--reasoning-format", [](const Config& c) { return c.reasoning_format; } },
{ "--http-threads", [](const Config& c) {
return c.http_threads > 0 ? num(c.http_threads)
: std::string("auto (one a hardware thread, at least 4)"); } },
{ "--read-timeout", [](const Config& c) { return num(c.http_read_timeout_s) + " s"; } },
{ "--write-timeout", [](const Config& c) { return num(c.http_write_timeout_s) + " s"; } },
{ "--keep-alive-timeout", [](const Config& c) { return num(c.http_keep_alive_timeout_s) + " s"; } },
{ "--max-body-mib", [](const Config& c) { return num(c.http_max_body_mib); } },
{ "--retry-after", [](const Config& c) { return num(c.retry_after_s) + " s"; } },
{ "--no-cors", [](const Config& c) {
return std::string(c.cors ? "not given: CORS headers sent" : "no CORS headers"); } },
{ "--image-min-pixels", [](const Config& c) { return opt(c.image_min_pixels, "the container's"); } },
{ "--image-max-pixels", [](const Config& c) { return opt(c.image_max_pixels, "the container's"); } },
{ "--video-min-pixels", [](const Config& c) { return opt(c.video_min_pixels, "the container's"); } },
{ "--video-max-pixels", [](const Config& c) { return opt(c.video_max_pixels, "the container's"); } },
{ "--video-fps", [](const Config& c) { return opt(c.video_fps, "the container's"); } },
{ "--video-min-frames", [](const Config& c) { return opt(c.video_min_frames, "the container's"); } },
{ "--video-max-frames", [](const Config& c) { return opt(c.video_max_frames, "the container's"); } },
{ "--video-max-frame-tokens", [](const Config& c) { return opt(c.video_max_frame_tokens, "the container's"); } },
{ "--image-tokens", [](const Config& c) { return opt(c.image_tokens, "the container's"); } },
{ "--max-source-pixels", [](const Config& c) { return opt(c.max_source_pixels, "67108864"); } },
{ "--kld-record", [](const Config& c) { return or_none(c.kld_record, "none"); } },
{ "--kld-ref", [](const Config& c) { return or_none(c.kld_ref, "none"); } },
{ "--kld-corpus", [](const Config& c) { return or_none(c.kld_corpus, "none"); } },
{ "--kld-out", [](const Config& c) { return or_none(c.kld_out, "none"); } },
{ "--debug-graph", [](const Config& c) { return onoff(c.debug_graph); } },
{ "--debug-selection", [](const Config& c) { return onoff(c.debug_selection); } },
{ "--debug-placement", [](const Config& c) { return onoff(c.debug_placement); } },
{ "--debug-accept-reference-kernels", [](const Config& c) { return onoff(c.accept_reference_kernels); } },
{ "--profile-ops", [](const Config& c) { return onoff(c.profile_ops); } },
{ "--live", [](const Config& c) { return onoff(c.live_view); } },
{ "-v", [](const Config& c) { return onoff(c.given.count("-v") > 0); } },
{ "-vv", [](const Config& c) { return onoff(c.given.count("-vv") > 0); } },
};
} /* namespace */
namespace diag {
std::vector<ConfigRow> config_rows(const Config& c) {
std::vector<ConfigRow> out;
for (const Flag& f : g_flags) {
/* --help asks for this text and serves nothing; it is not a setting. */
if (!std::strcmp(f.name, "--help")) continue;
ConfigRow r;
r.flag = f.name;
r.value = "(not shown)";
for (const ShowRow& s : kShow)
if (!std::strcmp(s.flag, f.name)) { r.value = s.show(c); break; }
auto g = c.given.find(f.name);
r.source = g != c.given.end() ? g->second : "default";
out.push_back(std::move(r));
}
return out;
}
std::vector<std::string> config_option_names() {
std::vector<std::string> out;
for (const Flag& f : g_flags)
if (std::strcmp(f.name, "--help")) out.push_back(f.name);
return out;
}
} /* namespace diag */
} /* namespace rad */