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/docs/GUIDE.md
T
sfjes c37ce73d72 ops: rmsnorm_p, gelu_mul, logit_softcap, scale in lockstep across libref/libavx/libr4d + OPS.md rows
Elementwise ops with numeric selftest cases against the f64 oracle (both legs
of logit_softcap: bf16 and the f32 band the sampling chain carries). libr4d
gains env-gated verification probes alongside them (R4D_VERIFY_OFF
recompute-on-host checks; default off — instruments, not features).
2026-10-10 00:36:07 -07:00

1879 lines
112 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Radiance — user guide
Radiance is an inference server: it loads a model and answers OpenAI-compatible HTTP requests.
This guide takes you from an empty machine to a running server, and then through operating one.
There is no Python anywhere — not in the engine, not in the tools, not in the build. Everything
below is C++, CMake and shell.
**Where to go from here**
| If you want | Read |
|---|---|
| to get something running | this file, in order |
| every flag of one tool | [TOOLS.md](TOOLS.md) |
| to write a kernel library for your card | [PLUGIN.md](PLUGIN.md) |
| to know why it is built this way | `../spec.md` — the design, and it is binding |
---
## 0. The whole thing in five commands
```sh
./build.sh # build and test
export RADIANCE_HOME=$PWD/build/radiance_home
scripts/hfget.sh Qwen/Qwen3.8-Flash-Next ~/ckpt # get a checkpoint
build/bin/rad-convert ~/ckpt -o ~/m.rad \
--recipe data/recipes/qwen4exp-w4.recipe # quantise it into a container
build/bin/radiance --model ~/m.rad --port 8000 # serve it
```
A checkpoint served at its own precision needs no container at all: `radiance --model ~/ckpt`
reads it as it stands (§3.4).
Then:
```sh
curl -s localhost:8000/v1/chat/completions -H 'Content-Type: application/json' \
-d '{"model":"m","messages":[{"role":"user","content":"hi"}],"max_tokens":50}' \
| jq -r '.choices[0].message.content'
```
and open `http://localhost:8000/` for the dashboard. Everything below is the detail behind those
five lines.
---
## 1. Install
**Or skip this section and run the container image**: `docker/build.sh` builds the engine inside
the ROCm toolchain image, tests it and produces an image that needs only Docker and the `amdgpu`
driver on the host. [`DOCKER.md`](DOCKER.md) covers it, along with ready compose files per model.
### 1.1 What you need
| | |
|---|---|
| **Required** | Linux, a C++20 compiler, CMake 3.21+, Ninja, pthreads |
| **Optional** | ROCm with `hipcc`, for AMD device kernels. Without it you get the host backend. Set `ROCM_PATH` if it is not at `/opt/rocm` |
| **Optional** | OpenMP, used by the host kernel libraries if present |
| **For the shell harnesses** | `curl` and `jq` |
Everything else is vendored in `vendor/` — the HTTP server, the JSON library and the llama.cpp
lifts. There is nothing to `apt install` beyond a toolchain.
**A machine with no GPU is a supported configuration.** The host backend is a real implementation,
not a stub: the core, scheduler, planner, tokeniser, server and `libref` all run through it and
the full test suite passes. It is slow, and it will not serve a production model — but it is a
complete development and inspection environment. A build with ROCm, or the container image, runs
the same host backend on a machine where no card is visible: the GPU library's kernels are left out
there and every op takes its host kernel.
### 1.2 Build
```sh
git clone <repo> radiance && cd radiance
./build.sh
```
That configures, builds and runs the tests. It detects your situation: if `hipcc` is present and a
card can be enumerated, device kernels are compiled for that card's architecture; otherwise you
get the host backend.
Options:
```sh
./build.sh -c # wipe the build directory first
./build.sh --no-hip # force the host backend even where hipcc exists
./build.sh --debug # -DCMAKE_BUILD_TYPE=Debug
./build.sh --asan # AddressSanitizer
./build.sh -b mybuild # build into mybuild/ instead of build/
```
Or drive CMake yourself:
```sh
cmake -S . -B build -G Ninja
cmake --build build -j
ctest --test-dir build --output-on-failure
```
### 1.3 Check that it works
```sh
ctest --test-dir build --output-on-failure # everything (a few minutes)
ctest --test-dir build -LE slow # the fast inner loop (~1 s)
ctest --test-dir build -LE gpu # skip anything needing a card
```
Three of them are worth knowing by name, because they are the ones that actually check kernels:
- **`kbench` / `kbench_moe`** (label `slow`) replay a recorded fixture — every kernel every loaded
library supplies, checked against `libref`'s recorded answers on seeded inputs. **No model file is
needed**, which is what makes this runnable on a build machine. It also regression-tests `libref`
itself, which a live oracle never can.
- **`r4d_selftest`** (labels `slow`, `gpu`) checks libr4d's fusion claims by `memcmp` against the
unfused kernels it says it replaces.
- **`ops_doc`** (fast) checks that `docs/OPS.md` still agrees with what the plugins declare. A
document that is wrong is worse than one that is missing, because it is read instead of the source.
You can also run the kernel check by hand:
```sh
build/bin/rad-kbench --home build/radiance_home --max-cases 1
```
### 1.4 Install to a prefix
```sh
cmake -S . -B build -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build build -j
sudo cmake --install build
```
What lands where:
```
<prefix>/bin/ radiance, rad-convert, rad-info,
rad-kbench, rad-tune, rad-schemas, rad-tokcheck
<prefix>/include/ the ABI headers — all a plugin compiles against
<prefix>/lib/cmake/radiance/ the package config, for find_package(radiance)
<prefix>/share/radiance/ $RADIANCE_HOME: kernels/, architectures/, quantizers/, kernels*.rkb
```
### 1.5 `$RADIANCE_HOME`
This is the directory the engine and every tool scan at startup:
```
$RADIANCE_HOME/
kernels/ kernel libraries libr4d.so, libref.so, libavx.so, yours.so
architectures/ architecture plugins qwen4exp_fp8.so, llama_fp8.so, ...
quantizers/ quantiser plugins libquant.so
kernels.rkb the recorded kernel fixtures rad-kbench replays (and kernels_moe.rkb)
tune/ per-machine tuning caches rad-tune writes
```
It defaults to the install prefix's `share/radiance`. Override it with `--radiance-home DIRS` or the
`RADIANCE_HOME` environment variable — a search path: homes separated by `:`, the first winning,
each holding any of the directories above. A directory of your own plugins goes ahead of an
installation's without copying it, and `rad-info --plugins` prints what the path offers:
```sh
RADIANCE_HOME=$HOME/radiance-plugins:/opt/radiance/share/radiance rad-info --plugins
```
**Running from a build tree**, the home is `build/radiance_home` and the plugins are already in it:
```sh
export RADIANCE_HOME=$PWD/build/radiance_home
build/bin/radiance --model m.rad
```
Adding support for a new card means dropping an `.so` into `kernels/` — not forking the engine.
The engine's own device code is built for every AMD GPU family, so one engine binary starts on any
card; a kernel library whose code objects hold nothing for the card is left out of selection when
it loads, and says so. `docs/PLUGIN.md` §10 is a library for a card the engine has never seen.
### 1.6 Building for a card you do not have
Device kernels are compiled for the architectures the machine reports. To target others:
```sh
cmake -S . -B build -G Ninja -DRAD_GPU_TARGETS='gfx1201;gfx1200'
```
Which of those actually get kernels is decided by the libraries present; each one declares the
architectures it serves and stays out of a build targeting anything else. The engine's own device
code is built for every family's generic target besides, whatever is named here.
---
## 2. Five things to know before you start
**1. A model is a checkpoint served as it stands, or a `.rad` container.** A checkpoint whose
weights are bf16, f16, f32, block-scaled fp8 or Quark's MXFP4 is served at that precision straight
from its directory. Anything that needs quantising is quantised once, by `rad-convert` and a recipe, into a
container. A container holds each weight as the planes of its *encoding* — codes, scales, zero
points, a rotation — in one canonical arrangement, plus the tokeniser, the chat template, the
metadata, the recipe it was quantised with and optionally a draft head. No kernel library is named
in either: the kernels rearrange the planes into their own layouts as the model loads, so a kernel
library can change without a reconvert.
**2. Kernels are plugins, and the order matters.** The engine resolves every op in the model
against an ordered list of kernel libraries: first one that matches an op wins. `--kernels
mylib,libref` names the libraries to use and their order; a library it leaves out is not loaded.
With no list, every library found loads, and the loader puts one that declares itself a reference
implementation last.
Three ship with the tree:
| library | |
|---|---|
| `libr4d` | the device library: AMD RDNA4 (`gfx12xx`). Paged and dense attention, gated delta net, all-reduce over P2P or a host-memory mailbox, skinny and tiled quantised GEMM, rotate-and-quantise fusions. Built when ROCm is present and the build targets a `gfx12` card |
| `libref` | every op naively and generically. The last-resort fallback **and** the correctness oracle `rad-kbench` measures against |
| `libavx` | the host library: the same vocabulary in hand-written x86 SIMD, dispatched by CPU feature at load. Serves every op placed on the host, the n-gram embedding's gather among them. Built on x86-64 |
A library states the architectures it serves and stays out of a build targeting anything else, so a
tree configured for a card it does not cover still builds and still runs.
**3. Architectures are plugins too.** `arch/<id>/` declares a model family's graph. Six ship:
| plugin | serves |
|---|---|
| `llama_fp8`, `llama_dense_fp8` | LLaMA-shaped decoders — MiniCPM5, Llama 3, anything reporting `model_type: llama` |
| `qwen35_bf16` | Qwen3.5 / 3.6 / 3.8 dense (0.8B–27B), bf16 |
| `qwen35_fp8` | the same, block-scaled fp8 |
| `qwen35moe_fp8` | Qwen3.5 / 3.6 MoE (35B-A3B), 256 experts, 8 a token |
| `qwen4exp_fp8` | Qwen4-Exp / Qwen3.8-Flash-Next — hybrid Gated DeltaNet + gated attention, 512 experts |
**4. Falling back to the reference library is a fatal error, not a warning.** `libref` implements
every op naively and generically. It is the oracle and the last resort. If your model resolves any
op to it, the engine **refuses to start** and names the ops, because serving from it would be
orders of magnitude slow with nothing in the output to say so. That list of ops is exactly the
work a new kernel library has to do. `--debug-accept-reference-kernels` overrides it for bring-up.
**5. Every pool is budgeted explicitly.** There is no profiling pass and no utilisation fraction.
The trade between KV blocks and resident weights is real, workload-dependent and **yours to make**.
An engine that quietly re-optimises the split is an engine whose benchmarks do not reproduce.
---
## 3. Get a model in
### 3.1 Download a checkpoint
```sh
scripts/hfget.sh Qwen/Qwen3.8-Flash-Next ~/models/Qwen/Qwen3.8-Flash-Next
```
`curl` and `jq`, nothing else. Re-running resumes: a file whose local size already matches is
skipped and a short one is continued. It also skips duplicate weight formats — if a repo carries
`.safetensors` it will not also pull the `.bin`, the ONNX export and the GGUF.
Set `HF_TOKEN` for a gated or private repo. `HFGET_JOBS` sets concurrency (default 4).
A complete fetch records each file's content key (its LFS sha256, or the size of a small file) in
`.hfget-manifest`, so the next run also fetches a file that changed at the same size. The free-space
check counts only what is still to fetch.
**The server can do this itself.** `--model` takes a repo id where it would take a path:
```sh
radiance --model StillDeadcode/minicpm5-2b-fp8 --port 8000
```
It runs the same script (installed beside the binary, in `libexec/radiance/`) into
`--download-dir/<owner>/<name>` before bring-up, then serves the one `.rad` at the repo's top level,
or the directory as a checkpoint (§3.4) when it holds none. A repo with several containers is
refused by name; pass the file. Every start checks the hub and fetches what changed. A start that
cannot read the listing, or whose update does not fit, serves the copy a complete earlier fetch
left and says so; a transfer that fails part-way stops startup. A path that exists is always a
path, and a name ending in `.rad`, `.safetensors`, `.gguf` or `.json` is never looked up.
### 3.2 Convert it
```sh
rad-convert ~/models/Qwen/Qwen3.8-27B-FP8 -o ~/models/rad/q38-27b-fp8.rad --home $RADIANCE_HOME
```
Input is a `.gguf`, a `.safetensors`, or a directory holding a checkpoint. What happens: the
architecture plugin declares the model's graph and its name map says which checkpoint tensors make
each weight; every op is resolved against the kernel hierarchy and every resolved kernel is asked
whether it reads the encoding each weight will have; then each weight is written once, as its
encoding's planes, and the tokeniser and chat template are baked in.
**A recipe decides what is quantised.** With none, every weight keeps the checkpoint's encoding,
which is right for a bf16 or block-fp8 checkpoint served at its own precision. A model whose served
form needs quantisation work — Flash-Next's four-bit experts, an fp8 head made from a bf16 one —
names it in rules from weight names to quantisers:
```sh
rad-convert ~/models/Qwen/Qwen3.8-Flash-Next -o ~/models/rad/flashnext-w4.rad \
--recipe data/recipes/qwen4exp-w4.recipe --home $RADIANCE_HOME
```
`qwen4exp-w4.recipe` rounds the experts to nearest and needs nothing but the checkpoint. The
production Flash-Next container, `w4nl64-i8lm.rad`, is built by
`data/recipes/qwen4exp-w4nl64-i8-hc8m.recipe`, whose expert rule is GPTQ against recorded Grams:
it expands `$CALIB` from the environment, so it is run as `CALIB=DIR rad-convert ...` with `DIR`
holding a calibration run's files. The recipe's header and [MOE-W4.md](MOE-W4.md) say what that
directory must hold and how it is recorded.
```
# data/recipes/... -- PATTERN QUANTISER OPTIONS; the first match decides
blk.*.ffn_*_exps.*.weight gptq codes=i4 group=128 scale=bf16 transform=fwht128 calib=$CALIB
output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16
blk.*.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16
```
Every weight it quantises is measured against the source and the worst are printed. The recipe
syntax, the quantisers and their options are in [TOOLS.md](TOOLS.md#recipes).
Because it runs the same declare phase the engine does, everything that can refuse has refused by
the time the I/O starts — including a recipe no loaded kernel can serve. On a large checkpoint that
I/O is an hour, so check the plan first:
```sh
rad-convert <checkpoint> -o out.rad --recipe r.recipe --plan-only -v
```
Useful variants:
```sh
# Merge a separate drafter checkpoint (DSpark, DFlash2) into the container
rad-convert $SRC -o out.rad --draft-model ~/models/openbmb/MiniCPM5-2B-DSpark
# Re-quantise some weights and copy the rest from an earlier container
rad-convert $SRC -o new.rad --recipe new.recipe --reuse old.rad
# A bf16 Qwen3.8-27B -- the base release or a finetune of it -- as Qwen's block fp8: the recipe
# writes the linears, and --set states the format, which is what selects the fp8 plugin
rad-convert ~/models/ukisai/Swift-1.5-Qwen3.8-27b -o swift-27b-fp8.rad \
--draft-model ~/models/z-lab/Qwen3.8-27B-DFlash2 --recipe data/recipes/q38-27b-fp8block-df2.recipe \
--set quantization_config.quant_method=fp8 --set quantization_config.fmt=e4m3 \
--set "quantization_config.weight_block_size=128 128" --set quantization_config.activation_scheme=dynamic
```
A checkpoint directory's `model.safetensors.index.json` decides which shard each tensor is read
from. A finetune that changed only some tensors can be assembled from them and the base model: its
changed tensors in shards of their own, links to the base model's shards for the rest, and an index
that points each name at its copy. A name two shards hold that no index entry settles is refused.
The conversions of record live in `scripts/convfn.sh` and `scripts/convdspark.sh`, with their
recipes in `data/recipes/`.
**A release someone else already quantised is read as it ships.** Two forms are imported weight
by weight, so their quantised linears need no recipe rule:
| `quantization_config` | read as | |
|---|---|---|
| `quark`, MXFP4 weights (fp4, per_group 32, e8m0) | `fp4_e2m1*e8m0[1x32]` | byte for byte: the same codes and exponents. A checkpoint of this form is also served as it stands (§3.4) |
| `auto-round` with `packing_format: auto_round:auto_gptq`, and `gptq` (v1) | `i4*bf16[1x128]` or `i8*bf16[1x128]` | the GPTQ-packed codes transposed and made signed, the f16 scales rounded to bf16. Symmetric, group 128 or a multiple of it (per channel included), no act-order. Convert-time only, because the scales are not served as shipped |
The width is read per tensor, so a release mixing int4 experts with int8 projections imports both.
What an import cannot read — an asymmetric zero point, an act-order index, a group under 128 — is
refused by name at the weight. The release's `quantization_config` names the tool, not a served
form, so it is kept in the container as `imported_quantization_config.*`, and the model is served by
its family's quantised plugin (`qwen35_fp8` for Qwen3.8-27B; `qwen4exp_fp8` for Flash-Next).
A weight the architecture declares in another form than the release holds still takes a rule: the
recipe dequantises the import exactly and quantises from that. The two recipes of record:
```sh
# AMD's Quark AWQ-MXFP4 Qwen3.8-27B with the DFlash2 drafter
rad-convert ~/models/amd/Qwen3.8-27B-Quark-AWQ-MXFP4 --draft-model ~/models/z-lab/Qwen3.8-27B-DFlash2 \
--recipe data/recipes/q38-27b-quark-mxfp4-df2.recipe -o q38-27b-quark-mxfp4-df2.rad
# An AutoRound int4 Qwen3.8-Flash-Next: its experts imported, its int4 projections made int8
rad-convert ~/models/ukisai/Swift-1.5-Qwen3.8-Flash-Next-W4A16-AutoRound \
--recipe data/recipes/qwen4exp-autoround-i8-hc8m.recipe -o swift-autoround.rad
```
### 3.3 Look at what you built
```sh
rad-info ~/models/rad/flashnext-w4.rad
```
```
flashnext-w4.rad
format RAD2, 166.4 GiB, little-endian
architecture qwen4exp
model Qwen3.8-Flash-Next
source quant (none)
recipe 14 line(s) -- --recipe prints it
created by rad-convert ...
section offset bytes count
strings 256 1.2 MiB -
metadata 1258752 8.4 KiB 214
...
```
`rad-info` opens the file read-only and loads no plugins. It lists every weight with its encoding
and what made it — the checkpoint as it stood, or the recipe rule's quantiser and options.
```sh
rad-info --meta m.rad # just the metadata table
rad-info --vocab m.rad # vocab summary and normaliser chain
rad-info --recipe m.rad # the recipe it was converted with
rad-info -v m.rad # every tensor
```
### 3.4 Or skip the container
```sh
radiance --model ~/models/Qwen/Qwen3.8-27B-FP8
```
`--model` takes a checkpoint directory, a `.safetensors`, an index or a `.gguf`, and serves it at
its own precision. Its `config.json` (or the GGUF header) is the metadata, the `tokenizer.json` and
chat template beside it are the tokeniser, and `generation_config.json` gives the sampling defaults.
The weights are read once, at load, by every relayout worker at once.
**Nothing is quantised at load.** A weight the architecture plugin reads in another encoding than
the checkpoint holds is named at startup, and the remedy is a container with a recipe that says
what it becomes. MiniCPM5-2B is one: OpenBMB ships it in bf16, and `llama_dense_fp8` reads fp8.
What a container has that a checkpoint does not:
| | |
|---|---|
| the file and mapped tiers | a checkpoint is neither grouped nor aligned for them, so every weight must fit VRAM or the host pool, and a weight only a host kernel reads (the n-gram table) cannot be served |
| a merged drafter | `--draft-model` is `rad-convert`'s; a checkpoint serves the draft head it ships, if any |
| a placement profile | worth about a point of expert hit rate |
A GGUF is read when its architecture plugin maps llama.cpp's tensor names; the shipped plugins map
HuggingFace's, so a model of a shipped architecture is converted from its safetensors release.
---
## 4. Serve it
### 4.1 The simplest run
```sh
radiance --model ~/models/rad/flashnext-w4.rad
```
It claims the card (less `--gpu-headroom-mib`, default 96 MiB), splits it between weights and KV
cache, loads, and serves on `http://0.0.0.0:8000`. The startup log states every budget before
anything is allocated.
```sh
radiance --model m.rad --port 8100 --host 127.0.0.1
```
### 4.2 Look before you leap
```sh
radiance --model m.rad --debug-graph
```
Prints the entire declared graph — every op, the kernel each one resolved to, and why — then exits
without serving. This is the first thing to run against a new container or a new kernel library.
```sh
radiance --model m.rad --debug-selection # just the selection table
radiance --model m.rad --debug-placement # just the placement plan
```
### 4.3 Memory: how the card gets split
The card is split into **resident weights** and the **paged KV pool**, and the engine derives the
split from the card and the model; no flag states either pool. What you move are its inputs:
`--gpu-headroom-mib` leaves card space alone, `--max-model-len` and `--max-num-seqs` bound the
cache, and `--host-pool-mib` decides which experts must stay on the card. The startup receipt
prints every term. On a machine with no visible card (the host backend) half of RAM stands in for
the card and is split the same way; the weights pool is then host memory, holding the weights a
host kernel cannot read where the container stores them.
The non-expert weights come off the top of what is claimed. The rest — the `elastic` line of the startup receipt — is shared by
the expert slab and the KV cache, and no flag divides it:
- **The cache lends** under `--placement auto` or `expert_tiered`, without `--deterministic`, on a
device with virtual memory management. The experts keep on the card exactly what the pinned host
pool (`--host-pool-mib`) cannot hold, plus one expert unit of packing slack; they have nowhere
else to be. The cache takes everything else, up to what it could ever address
(`--max-num-seqs` x `--max-model-len`), and every block no live request holds is lent back to the
expert slab in place. The prefill staging region comes out of the cache's side.
- **Without a lender** — `--deterministic`, a stated `--placement all_vram` or `layer_offload`, or
no virtual memory management — a block the cache does not use would sit empty, so the experts
come first and the cache keeps one `--max-model-len` sequence.
The cache never gets less than one `--max-model-len` sequence, and when both sides fit, both are
whole. With a lending cache, `--host-pool-mib` is what moves the split: a larger pool takes experts
off the card and gives the cache more.
**An uneven world re-splits its cheaper ranks.** The split above is worked out once, for the rank
whose cache costs most, and one block table serves every rank. Where a rank's cache costs less per
token -- an attention-zero rank at `--tp 3` keeps no attention cache -- it gets, under
`expert_tiered`, a KV pool that pages exactly the common token count and the
difference in its weights pool, up to every one of its weights resident; the startup log names the
rank and both sizes (`kv: rank N's cache costs ...`). It holds with or without a lending cache:
under `--deterministic`, or on a device without virtual memory management, the bytes that rank
would never page go to its experts all the same. A rank whose cache costs as much per token as the dearest
rank's is never re-split -- which at `--tp 2` and `--tp 4` is every rank. A rank that costs less and
keeps the common split says why on the same `kv: rank N's cache costs ...` line. Every rank still
allocates its whole `--host-pool-mib`, a re-split rank whose weights all fit on the card included,
and that rank's log says its pinned host pool holds no weights ([`TP3.md`](TP3.md) §1).
**The cache's size decides whether multi-turn works.** The KV side is not only concurrency: prefix
caching holds a finished sequence's blocks so the next turn can reuse them. When the pool cannot
hold the *live sessions*, the cache drops prefixes the next turn wanted and that turn re-prefills
its whole context. At long contexts that is two orders of magnitude of time-to-first-token.
Measured on Qwen3.8-Flash-Next at a 200K context with two ~184K-token sessions and byte-identical
text, the second turn took 173.0 s at a 0.0% prefix hit with a pool that could not hold both
sessions, and 3.0 s at 99.0% with one that could. The fall-off is sharp, and `kv_util` shows a
pool approaching it.
To size it yourself: work out what a token of context costs across **all** paged groups for your
model (the startup log prints this), multiply by the context you actually serve, multiply by the
sessions you want live at once, and compare that with the cache the receipt reports. The cache
already has everything the experts can do without; a larger `--host-pool-mib` (RAM permitting) or
`--kv-cache-dtype fp8` gives it more.
Worked, on Qwen3.8-Flash-Next: two paged groups share one token axis — `kv_attn` at 26.00 KiB and
`kv_qsa_bkey` at 3.25 KiB per 4-token block — so a token of context costs **7.32 KiB**, and a
200K-token sequence is 1.43 GiB. A prefix-cached session occupies roughly 1.8x its context in pool
tokens, so two live 184K sessions want ~662K pool-tokens. That is the number the KV side has to
clear.
What is claimed is not all of the card. The **activation arena** — scratch for the largest step
the engine may run — is taken off the budget *before* it is split, so it is paid for by both
sides. It grows with `--max-num-batched-tokens`, which is why raising the prefill chunk costs
resident experts (§4.5).
**Most of the arena is lent back while the steps are small.** A decode step is a few dozen rows
of the 2048 a prefill chunk carries, so the engine asks the architecture plugin to declare its
activations again at smaller step sizes (the decode rows rounded up to a power of two and at least
256, then four times that, up to the step budget) and packs each into the bottom of the arena. While the recent steps fit a smaller size, the top of the arena holds expert
weights; the first step that needs more takes it back before it runs — a change of address for
the units there, not a copy. Startup prints what each size lends (`activation arena: lends ...`).
A plugin opts in (`RadArchProbe::shape_probe_ok`); one that does not keeps its whole arena.
Related flags:
```sh
--gpu-headroom-mib 96 # VRAM left unclaimed on every card
--kv-cache-dtype fp8 # halve what a token of context costs (a real quantisation)
--host-pool-mib 8192 # pinned host tier for weights
--embedding-placement vram # keep the token embedding on the card (below)
--ngram-placement ram # an n-gram table in RAM instead of read from disk (below)
--weights-disk-tier # stream what fits neither from the container; needs O_DIRECT
```
**Two lookup tables have a placement of their own**, because a step reads only M of their rows and
never the whole table, so a tier below the card serves them at little or no cost:
| | `vram` | `ram` | `disk` |
|---|---|---|---|
| `--embedding-placement` | on the card, with the other weights | pinned host memory of its own, read over the link in place (the default) | refused |
| `--ngram-placement` | on the card, every card holding all of it | a copy in RAM made at load, read by the card over the link | read from the container through a row cache |
The embedding defaults to `ram`; the n-gram table defaults to `auto`, the fastest tier that has
room once every other weight is placed. Startup prints what each resolved to and why. A tier the
flag names that cannot be honoured stops the server with the reason.
**The token embedding** is the largest model-level weight a dense model has -- 248320 x 5120 in bf16
is 1.18 GiB a card at `--tp 2`. By default (`ram`) it is pinned in host memory of its own, every
rank its own shard, on top of `--host-pool-mib` -- the experts' pool keeps all of that -- and the
lookup reads a step's rows over the link in place, so the table costs no VRAM and the KV pool and
the experts get its share. The table is found by what reads it: a model-level weight only
`embed_lookup` reads. A head tied to it is read by a GEMM too and is never moved, since it would
stream whole every step, so such a model keeps it on the card; so does a host that cannot pin it
(available memory and memory cgroups, after the pools, with 4 GiB to spare). Startup says which
and why. Naming `ram` turns either case into a refusal; `vram` keeps the table on the card.
`disk` is refused: the lookup writes activations the card reads, and a host kernel reading the
container cannot write them.
```sh
radiance --model m.rad --tp 2 --embedding-placement vram # the table on the cards
```
**An n-gram table** (Qwen3.8-Flash-Next's is 47.7 GiB) is read a few rows a token, which is why it
can live off the card at all. `disk` reads its rows from the container through a row cache and
direct reads on the host; about half of a step's rows are first-seen, so steps wait on the drive.
`ram` copies the whole table into host memory at load -- 12 to 40 s more startup, depending on the
page cache -- and every gather reads memory: the card's own gather kernel reads a pinned copy over
the link, so a step has no host work in it at all. `vram` puts it on the card, every card holding
all of it, which needs a card that large. `ram` needs the table's size in memory after the pinned
host pools and the prefix cache's host tier, with 4 GiB to spare, and room under every memory cgroup
the process sits in; it refuses the start short of either and names which. `auto` takes the first
of `vram`, `ram` and `disk` that holds the table. Without a device kernel for the gather (a build
with no libr4d), the table is read on the host: `vram` is refused, and `ram` is a copy in locked
huge pages, which also needs a memlock limit that large (`--ulimit memlock=-1` in Docker,
`LimitMEMLOCK=infinity` under systemd).
**A model larger than the card and the host pool together still serves with
`--weights-disk-tier`** -- and every step is then paced by the drive, which is the trade the flag
names. A routed expert that fits neither VRAM nor the pinned pool lives in the container and
nowhere else; before each routed layer's first expert op, on every pass, the engine reads all of
that layer's on-disk experts into one of two VRAM buffers (a router's picks are not known on the
host, and a prefill chunk routes to nearly all of them anyway). The two buffers come out of the
weight budget -- the plan report's `file buffers` line -- and the reads go through four 32 MiB
pinned windows out of `--host-pool-mib` as long runs of the container, skipping resident experts.
What it is for: serving a checkpoint as it ships to calibrate or compare against, not a
production deployment. The bf16 Qwen3.8-Flash-Next (335 GiB) runs at two cards this way at about
28 s a step, and that step costs the same at one token as at 32K, so give it large prefill steps:
```sh
rad-convert ~/models/Qwen/Qwen3.8-Flash-Next -o flashnext-bf16.rad --max-ctx 4096 # no recipe: bf16
radiance --model flashnext-bf16.rad --tp 2 --placement expert_tiered --weights-disk-tier \
--host-pool-mib 12288 --deterministic --gpu-headroom-mib 768 \
--max-num-seqs 32 --max-num-batched-tokens 32768 --num-speculative-tokens 0
```
A production server leaves the flag off, so a budget that does not fit is refused at startup
rather than served from the drive.
**The KV pool is elastic on every run and there is no flag for it.** It holds the blocks it is
actually using plus a buffer it derives — one prefill chunk, or the largest shortfall the
admission path has met in the last few seconds, whichever is larger — and the expert plane grows
into whatever it releases. A pool that held every block it was carved for whether or not a token
was in it would, on a model whose experts do not fit, stream weight over the link for the whole
run to pay for cache nobody is using.
What it leans on is `--gpu-headroom-mib`. That reserve is what the card keeps for allocations
this engine does not make — chief among them a kernel's code object, which HIP loads on the
kernel's *first launch*, not at startup. A card with too little of it left collides with the
first kernel that has never run: a draft head's, a sampler chain's, whatever the early requests
did not reach. It fails its load and faults inside the HIP runtime, which arrives as a segfault in
a kernel that is correct, on a server that had been serving fine.
Startup checks what is left once everything is allocated (`card N settled at ... free`). Memory
taken after the budget read the card — another process on it, such as a desktop, or a driver
allocation — comes out of the headroom, and the line says how much. It warns only when the room
left for first launches is under the 96 MiB the engine allows for its own, and then names the
`--gpu-headroom-mib` value that clears it: what is left rises one for one with the flag, so that
value is a fixed point. A larger headroom that lost part of itself to another process is reported
on the INFO line and not warned.
What the engine itself allocates after the card is read is charged before the split, so it never
comes out of the headroom: the step staging, the KV tiers' copy staging, and its hardware queues.
A queue costs more than its ring — the driver backs each one with VRAM of its own, 33 MiB on an
R9700 — so startup measures one and the receipt's `hardware queues` line shows how many a card
holds at that price.
### 4.4 Long context
```sh
radiance --model m.rad --max-model-len 200000 --kv-cache-dtype fp8 --max-num-seqs 8
```
`--max-model-len` does not reserve anything per request — it sets the worst case the pool is sized
against. `0` takes the model's training context.
`--kv-cache-dtype fp8` is an E4M3 cache with per-(sequence, head) descales. It halves what a token
of context costs, which at a production context is most of the pool. It is a real quantisation and
the model computes a slightly different function with it, so it is stated rather than inferred.
Every architecture serves both widths, and the flag sets every attention cache of the deployment —
a drafter's (DSpark, DFlash2) as well as the trunk's. The delta-net state and the QSA indexer's
key tail are recurrent state rather than an attention cache and keep their own widths.
**Many sequences against a long context.** `--max-num-seqs` runs to 32 on every model here, and
what it costs is not context — a sequence holds only the blocks its tokens occupy — but what exists
per sequence whether it is used or not:
- **Recurrent state.** On a hybrid model every sequence owns its delta-net state, and with
speculation two copies of it. Qwen3.8-Flash-Next keeps 54 MiB a copy on each card, so 32
sequences take 3.4 GiB of the cache share before a single token is cached. The 27B in bf16,
with no experts to give way, then holds about 117K tokens of attention cache, less than one 200K
request, and startup warns that a longer one would be refused. The 27B in FP8 holds 2.8
full-length sessions at 32, the 35B-A3B ten.
- **Block tables.** The step batch's tables are carved for every sequence at the full context.
They are charged to the VRAM budget (`step staging` in the startup receipt), so they come out of
the cache share and not out of `--gpu-headroom-mib`.
The startup line `the pool backs N% of the worst case ... M full-length sessions` counts only the
part of the pool that holds context, so M is the number to compare with the sessions you expect
to keep live. With `--tp-wire wht6`, a decode step above the row count startup names is
all-reduced lossily like a prefill chunk, which a busy step reaches: at 8 sequences and depth 3,
Flash-Next's decode steps are already over it.
### 4.5 Prefill speed: the chunk
A long prompt is prefilled in chunks, and `--max-num-batched-tokens` is how big one is. It is the
single biggest lever on time-to-first-token on a mixture-of-experts model, because a chunk sweeps
the whole expert plane once however many tokens are in it — so four times the chunk is a quarter
of the sweeps.
```sh
radiance --model m.rad --max-num-batched-tokens 2048
```
On a 48-layer MoE at 200K context on two cards, prompts of 8K and 24K tokens:
| chunk asked for | 512 | 1024 | **2048** | 4096 |
|---|---|---|---|---|
| chunk actually run | 512 | 1024 | **2048** | 2048 |
| prefill | 1750 tok/s | 2200 | **2706** | 2620 |
At full context the same change is the difference between waiting and waiting a lot: a
185,253-token prompt prefills in **91 s at a 2048 chunk against 138 s at 512**.
**The 4096 column is the trap, and the engine warns about it.** On a hybrid model the chunk is
clamped to `--checkpoint-interval` (2048 by default) *before* the token budget, so asking for 4096
runs 2048 chunks and pays for 4096 anyway: the activation arena grows with the budget and is
charged to the VRAM budget *before* it is split between weights and KV, so the expert plane loses
residency for a chunk it never got. Startup prints which of the two bound it:
```
chunk geometry: quantum 64 (attn block ..., state chunk ...), checkpoint interval 2048,
max_tok 4096 -> prefill chunks of at most 2048 (the checkpoint interval, not the budget)
```
Read that line, and `RADIANCE_LOG_STEPS=1` prints the token count of every step if you want to see
it per step.
Raising both — `--max-num-batched-tokens 4096 --checkpoint-interval 4096`, which does run 4096
chunks — does not help either: 2610 tok/s against 2748, because the arena takes
another 239 resident experts (9219 to 8980) and the extra amortisation does not pay for them. On
a model whose prefill is bound by the link carrying non-resident experts, the chunk stops winning
as soon as it starts costing residency.
**It does not cost the requests already running.** A longer chunk holds the device longer per
step, so a decode step queued behind one waits longer — but the prefill it is queued behind
finishes sooner, and that is the larger term. Four decoders with a long prompt landing beside
them finished in 29.5 s at a 2048 chunk against 31.9 s at 512.
**Nor does a long prefill lock out the work behind it** (`--busy-prefill-chunk`, default `auto`).
A chunk used to take every token the step had left, so for the whole of a long prompt's prefill —
a minute or more at 256K — a decode row behind it in the batch got no rows and a request that
arrived was not even admitted: a mostly-cached turn that needed a few hundred tokens waited for
somebody else's prompt to finish. Now, when other work is pending in a step, the chunk leaves it
room: one row plus the draft window for every decode row behind it, and a share of the budget
(an eighth, at least one quantum) for each prefill behind it and for the next request waiting to
start. It never drops under the smallest step the prefill stager overlaps (1025 tokens by
default), because under that every routed layer reads its pooled experts synchronously and the
prefill slows far more than the shared step saves; and where holding a chunk back for a waiting
request or another prefill would leave a short remainder before the checkpoint boundary, the
interval is split into two staged halves instead. Decode rows alone only take their few tokens: the
chunk ends a quantum short of the boundary and the next step finishes it, the same pair of steps a
prefill already runs when decode rows are ahead of it. A prompt with nothing beside it is planned exactly as before. `off` restores the old
behaviour; `--busy-prefill-chunk N` holds a shared chunk to N tokens (the startup line warns when
N is under the stager's step). `radiance:engine_prefill_chunks_capped_total` counts the chunks
held back.
**And check it did not cost you the prefix cache.** The arena it grows is charged before the
split (§4.3), so the KV pool shrinks a little — here 516,864 → 499,920 pool tokens, 3.3% — and
§4.3's cliff is sharp enough that 3% is worth confirming rather than assuming. On this shape it
costs nothing: two ~180K sessions, first turns back to back, then the first session's second turn.
| chunk | session A turn 1 | session B turn 1 | A turn 2 | cached | evictions |
|---|---|---|---|---|---|
| 512 | 137.7 s | 130.0 s | 1.42 s | 178,176 of 179,585 | 0 |
| 2048 | **90.6 s** | **93.2 s** | **0.97 s** | 178,176 of 179,585 | 0 |
Identical hit, no evictions, `kv_util` 0.70 → 0.73. Turn one is 34% faster and turn two stays
where it was. Do this on your own shape before you keep the change: `prefix_hit_rate` and
`prefix_evictions` on `/stats` are the two numbers, and the failure looks like turn two taking
as long as turn one.
**What it does cost is decode, and it is small.** The 239 resident experts the arena takes have to
come from somewhere, and steady-state decode is where. Decode step time from `scripts/cstep2.sh`,
which divides by the decode step counter rather than by wall clock, two passes each, generations
long enough that no sequence retires inside the window:
| chunk | one stream | eight streams |
|---|---|---|
| 512 | 22.35 / 22.29 ms/step | 39.52 / 40.52 ms/step |
| 2048 | 22.42 / 22.48 ms/step | 39.52 / 40.73 ms/step |
**+0.6% on a single-stream decode step**; at eight streams the difference is 0.11 ms, below what
the harness resolves. Against a prefill that is 55% faster and a first turn that goes from 138 s
to 91 s, that is the right side of the trade — but it is a real cost and it lands on every turn,
so measure it on your own shape rather than taking the sign on faith.
**Changing it changes the text.** A different chunk is a different batch shape, so the sums inside
a prefill run in a different order, and at a tie that is a different token. A fixed prompt at a
fixed seed gives one answer at 512 and a different one at 2048, and each is byte-identical across
runs and server restarts at its own setting. Reproducibility holds *at a configuration*, which is what it claims; this flag is part of the
configuration in the same way `--tp` and `--num-speculative-tokens` are. Pin it before you record
anything you intend to compare against later.
### 4.6 Speculative decoding
If the container carries a draft head, it is used by default at the depth the plugin states:
```sh
radiance --model m.rad # auto: the drafter's own operating point
radiance --model m.rad --num-speculative-tokens 0 # off
radiance --model m.rad --num-speculative-tokens 3 # a stated depth
```
There is **no `--draft-model`**. This engine loads its drafter from the container — merge one at
conversion time with `rad-convert --draft-model DIR`, or use an MTP head that already ships inside
the target checkpoint, which needs no flag at all. Passing `--draft-model` to the engine is an
error that says so rather than being quietly ignored.
When you measure speculation, **measure step time, not tokens per second.**
A drafter with a sliding window over its own cache (DFlash2) keeps that cache outside the prefix
cache, so a prefix hit leaves it with nothing to attend to for the cached part of the prompt, and
it cannot draft until its window has slid past the hit. On the follow-up turn of a chat that is
most of the reply. Such a hit is therefore ended one drafter window before the end of the prompt,
at a checkpoint: the window is recomputed, which costs that much prefill, and the drafter drafts
from the first token. The reply is the same either way. A hit whose nearest checkpoint below that
point would give back more than two windows is kept whole. `radiance:draft_refills_total` counts
the hits ended early and `radiance:draft_refill_tokens_total` the tokens they recomputed.
**One depth for every request is a compromise; `--draft-window adaptive` lets the text decide.**
Acceptance depends on the text: code and JSON keep accepting deep into the window, prose and
summaries fall off after a position or two. With the adaptive window, `--num-speculative-tokens` is
the ceiling and the engine keeps a smoothed acceptance per draft position for every sequence:
```sh
radiance --model m.rad --num-speculative-tokens 6 --draft-window adaptive
```
A serial draft head runs as many rounds as the deepest window in the step, so the depth is chosen
for the step, not for one sequence: each step's head depth is the one that maximises the tokens all
its sequences are expected to emit over what such a step costs. The cost is measured as the server
runs — the time of every decode step, by its depth and by how many sequences it carried — so there
is nothing to enter; a depth not yet measured is priced from the nearest one that was. Under that
depth each sequence stops at the first draft that would be emitted — it and every draft before it
accepted — less than one time in ten, so a prose reply beside a code reply does not pay verify rows
for drafts nobody takes. The depth moves only after eight steps and for a two-percent gain, because
every new window is a new pass shape and a new recording. A new sequence starts from what the
sequences before it finished on, each counted once.
The adaptive window is the serial draft head's policy. With a block drafter, with prompt lookup
alone, or with speculation off the window stays fixed, and the server says so at startup. Prompt
lookup proposals made when the head declines are counted in the acceptance metrics but do not move
the head's window. At temperature 0 the text is that of a fixed depth wherever fixed depths agree
with each other; above 0 it is distribution-exact. `radiance:draft_depth_adaptive` and
`radiance:draft_verify_depth_total` (§6.3) show where the windows stand. The default is `fixed`.
### 4.7 Two cards
```sh
radiance --model m.rad --tp 2
radiance --model m.rad --tp 2 --tp-wire wht6 --tp-wire-min-kb 128
```
`--tp-wire` chooses the cross-rank all-reduce payload. `exact` (default) is the bf16 all-reduce.
`wht6` accepts a lossy wire: a Walsh-Hadamard-rotated 6-bit payload, 2.4× smaller over PCIe. The
sum a rank receives is then not the sum it would have received and nothing downstream can tell,
which is why it is a named flag and not a heuristic.
`--tp-wire-min-kb` is the floor below which messages are still served exactly — 128 KiB leaves
single-sequence decode exact and compresses prefill, which is where the win is.
At three and four ranks `wht6` selects a different lossy wire with the same floor: tiered int8
over a two-shot all-reduce, both hops quantised (at three the shards are whole 32-element groups,
one group uneven where the message does not divide). Eight ranks have no lossy wire, and
`--tp 8 --tp-wire wht6` stops at startup naming the all-reduce it found no kernel for, and
`--tp-wire exact`. The exact wire at three, four and eight ranks is one-shot up to 1 MiB a message
and two-shot above it, which sends 2·(ranks−1)/ranks of the message per rank instead of
(ranks−1) times it; the two produce the same bits.
On a model with a gated residual (Qwen3.8-Flash-Next) the all-reduce rides inside the residual's
write, with the MoE gather in front of it. At two ranks that holds on either wire: the rotated
forms of `ar_hc_write` and `ar_gather_hc_write` produce the same bytes as the unfused chain on the
same wire. There `wht6` is worth +5.6–6.3% of prefill at a 2048-token chunk (20K prompt 5556 →
5908 tok/s; a 23K extension at 81K depth 4998 → 5278) and −1.3% of the eight-stream decode step;
one-stream decode stays exact. At four ranks only the exact wire has a fused form, and it takes
the decode and verify steps — up to `--max-num-seqs` × (1 + `--num-speculative-tokens`) rows. A
prefill chunk, and a message that goes out on the tiered-int8 wire, runs the unfused chain, where
the all-reduce's own size choice between one-shot and two-shot applies.
**Cards that cannot reach each other's memory still serve.** The all-reduce kernels normally push
into the other card's memory directly (peer to peer, P2P). At launch radiance asks the driver,
for every pair of the cards it will use, whether that works, and logs the answer. Whether it does
is decided by the platform: the IOMMU setting, the PCIe topology, and whether the cards sit behind
a switch that allows peer traffic. When some pair cannot, the same kernels run with their
exchange buffers in pinned host memory instead: every card writes its share to host RAM over its
own link and reads the others' back the same way, and no card touches another card's VRAM. The
startup line names the pairs that failed, and the selection report names the `_host` rows that
took the collectives. The results are the same bytes either way; the cost is a message crossing
two links instead of one. On two R9700s on PCIe 4.0 that cost is within run-to-run noise for
decode, at one stream and at four, and 2–10% on a 23.6K-token prefill, because there the peer
link is no faster than the host link. A machine whose cards reach host memory over a narrower
link than they reach each other pays more.
`--p2p` overrides the driver's answer. `off` takes the host-memory path even where the driver
reports peer access, for a board where peer traffic is broken or slow while the driver still says
it works. `on` takes the peer-to-peer kernels and stops at startup, naming the pairs, if the driver
refuses any of them, so a deployment measured on P2P never quietly serves on host memory. `auto`,
the default, trusts the driver.
### 4.8 Finished conversations: copied to host, VRAM given up on demand
By default a finished conversation's KV blocks stay in VRAM, held by the prefix cache, until the
cache evicts them under pressure — and an evicted prefix is re-prefilled from scratch next turn.
With a host tier, a conversation is **copied** to host memory the moment its request finishes, and
keeps its VRAM copy. From then on it is *clean*: its VRAM can be given up for nothing, and it is,
as soon as something wants it — the expert slab's loan, or a request the pool cannot otherwise
serve. A conversation that comes back before that resumes from VRAM; one that comes back after is
restored from host memory and keeps its host copy, so its next turn copies only what that turn
added. There is no idle threshold on the way out of VRAM.
With a disk tier the same happens one level down: every host copy is written on to disk in the
background and keeps its host slot, and once the write has landed the slot can be given up for
nothing. A full host tier gives up its oldest slots when a new copy or a restore needs one, so a
conversation that no longer fits in host memory is on disk already rather than lost.
```sh
radiance --model m.rad \
--prefix-cache-host-mib 8192 \
--prefix-cache-disk-mib 65536 --prefix-cache-dir /var/cache/radiance
```
- `--prefix-cache-host-mib N` — **this is the switch.** Without a size, nothing is copied. It holds
attention blocks only; a hybrid model's linear-state snapshots are in host memory already, in the
`--checkpoint-slots` store. Size it for the conversations you expect to come back: one that does
not fit comes back from disk instead.
- `--prefix-cache-disk-mib N` — the disk tier's size. Everything that reaches host memory is
written here too, snapshots included, so a full snapshot store detaches its least recently used
snapshot instead of losing it.
- `--prefix-cache-dir DIR` — where the disk tier lives. **Not `--weights-disk-tier`**, which is about
*weights*. The disk tier holds conversation content unencrypted.
- Recovering a 200K-token turn costs a copy over PCIe; recomputing it costs minutes.
On a hybrid model the recurrent state matters as much as the attention blocks — restoring the
blocks alone leaves the session re-running every linear layer over its whole transcript, which
every hit-rate counter reports as a hit. The snapshots never take VRAM: each is copied to host
memory after the step that produced it and back before the step that resumes from it. `/sessions` shows what is stored, where, and whether the
linear half is being served.
### 4.9 What a request that leaves a field out gets
Every default below applies only to a request that does not name the field. A request that names
it wins. Without any of these flags, the server behaves exactly as it always has.
**Temperature, top-k, top-p, min-p.** First one that exists wins:
1. `--temp` / `--top-k` / `--top-p` / `--min-p` on the command line
2. `--generation-config PATH` — a `generation_config.json`
3. `<model>.generation.json` beside the container
4. the container's own `generation.*` metadata
5. the built-in defaults
```sh
radiance --model m.rad --temp 0.7 --top-p 0.8 --top-k 20
```
**The rest of the sampler** has a flag per field, spelled like the request field:
`--presence-penalty`, `--frequency-penalty`, `--repetition-penalty`, `--repeat-last-n`,
`--typical-p`, `--dry-multiplier`, `--dry-base`, `--dry-allowed-length`, `--dry-penalty-last-n`,
`--dry-sequence-breakers` (a JSON array), `--xtc-probability`, `--xtc-threshold`. They are checked
against the same ranges a request is, at startup:
```sh
radiance --model m.rad --presence-penalty 1.5 --repetition-penalty 1.05
```
**How much a request may generate.**
- `--default-max-tokens N` sets `max_tokens` for a request that sends none. The default, `auto`,
is whatever the context leaves after the prompt, as in vLLM. Many clients send no `max_tokens`,
and a reasoning model can think for thousands of tokens before it answers: a small default ends
those answers inside the reasoning, with a `finish_reason: "length"` that chat clients do not
show.
- `--max-tokens-cap N` is the most any request may generate. A larger `max_tokens` is cut to it
rather than refused, and the reply ends with `finish_reason: "length"`, the same as the context
bound (§5.8).
```sh
radiance --model m.rad --default-max-tokens auto --max-tokens-cap 32768
```
**Chat template variables.** `--chat-template-kwargs` hands variables to the chat template on
every chat request, the way a request's own `chat_template_kwargs` does:
```sh
radiance --model m.rad --chat-template-kwargs '{"enable_thinking": false}'
radiance --model m.rad --chat-template-kwargs @template-vars.json
```
- It takes a JSON object, or `@FILE` to read one. Give it more than once and a later key replaces
an earlier one.
- A key the request's own `chat_template_kwargs` names is the request's.
- Thinking is one setting with three spellings. A request that says anything about thinking
(`enable_thinking`, at the top level or in `chat_template_kwargs`, or `reasoning_effort`)
replaces the server's `enable_thinking`. One that names a `reasoning_effort` replaces the
server's effort too.
- `messages`, `tools`, `bos_token`, `eos_token` and `add_generation_prompt` are refused: the
server sets those itself.
- At startup a one-message chat is rendered with the variables. A value the template refuses
stops startup with the template's own message, instead of failing every request.
- `/tokenize` renders `messages` with the same variables, so the count it gives is the prompt
chat serves.
**`--reasoning-effort` is worth knowing about.** It is the default for chat requests that do not
set one, and the value goes to the model's chat template verbatim — so the legal set is the
template's. Qwen3.8 takes `xhigh|medium|low` and **defaults to `xhigh`**, which on a short task can
spend the entire token budget inside `<think>` and return a turn with empty content and
`finish_reason: "length"`. `"none"` turns thinking off. It cannot be combined with a
`reasoning_effort` or `enable_thinking` key in `--chat-template-kwargs`. A value the template
refuses is a warning at startup: requests that send their own effort still work.
```sh
radiance --model m.rad --reasoning-effort medium
```
**The template's set is probed at startup** by rendering each of `low`, `medium`, `high`, `xhigh`
and `max`, and startup names the ones it takes. `/server_info` publishes them as
`capabilities.reasoning_efforts` (with `none` and `minimal`, which are the server's own; `null`
when the template takes any word). A request outside the set gets a 400 with `param:
"reasoning_effort"`, `code: "unsupported_value"` and the set in `error.supported`, rather than the
template's traceback.
**`--reasoning-effort-map FROM=TO,...`** rewrites a request's effort before the template sees it,
for a client that always sends a word of OpenAI's ladder. Qwen3.8 has no `high`, so:
```sh
radiance --model m.rad --reasoning-effort-map high=xhigh
```
It applies to both spellings (`reasoning_effort` and `chat_template_kwargs.reasoning_effort`), and
before `none` and `minimal` are read, so `minimal=low` keeps thinking on. A `TO` the template
refuses stops startup.
**`--thinking-token-budget N`** caps the reasoning instead of its depth. At N tokens inside the
reasoning block the block is closed, by masking the next position to its end token
(`</think>`), and the answer follows. This makes a client's `max_tokens` buy an answer, where
otherwise the reasoning could use all of it. It is the default for chat requests that send no
`thinking_token_budget` of their own (§5.2). It needs a reasoning block that ends in a single
token, as Qwen's and MiniCPM's do. On a model whose block does not, startup stops and says why.
**`--reasoning-format none`** leaves a reasoning block inline in `content` instead of returning it
as `reasoning_content`, for a client that reads it there.
`/server_info` lists every effective default under `request_defaults` (§6.2), and startup prints
one line naming each one the command line moved.
### 4.10 Every flag
`radiance --help` prints this table. Grouped here by what you are doing:
**Model and plugins**
| flag | |
|---|---|
| `--model PATH` | the `.rad` container, a checkpoint served as it stands (§3.4), or a Hugging Face repo id fetched before startup (§3.1) (**required**) |
| `--download-dir DIR` | where a repo id is fetched to. Default `$XDG_CACHE_HOME/radiance/hf`, else `~/.cache/radiance/hf` |
| `--radiance-home DIR` | where `kernels/` and `architectures/` live |
| `--kernels LIST` | the kernel libraries to use, comma-separated, first wins; a library not named is not loaded. Default: every library found |
**Batch shape**
| flag | default | |
|---|---|---|
| `--max-num-batched-tokens N` | 8192 | largest token count one step may carry |
| `--busy-prefill-chunk MODE` | auto | a prefill chunk's share of a step that has other work: `auto` leaves decode rows behind it and waiting requests their room (§4.5), `off` takes the whole step, `N` holds it to N tokens |
| `--max-num-seqs N` | 256 | largest number of sequences one step may carry |
| `--max-model-len N` | 0 | context bound; 0 takes the model's training context |
| `--rope-scaling SPEC` | — | `yarn:FACTOR[:ORIG]`: static YaRN over the container's own rotary keys, no reconvert; `none` takes a checkpoint's YaRN off ([YARN.md](YARN.md)) |
**Memory**
| flag | default | |
|---|---|---|
| `--gpu-headroom-mib N` | 96 | VRAM left unclaimed on every card |
| `--kv-cache-dtype T` | bf16 | `bf16` or `fp8` |
| `--host-pool-mib N` | 0 | pinned host tier (weights) |
| `--embedding-placement WHERE` | ram | `ram` or `vram`: the token embedding pinned in host memory beside `--host-pool-mib` and read in place, or on the card. See §4.3 |
| `--ngram-placement WHERE` | auto | `auto`, `vram`, `ram` or `disk`: an n-gram table on the card, as a copy in RAM made at load and read by the card, or read from the container. See §4.3 |
| `--weights-disk-tier` | off | read weights that fit neither VRAM nor the host pool from the container (O_DIRECT); routed experts a layer at a time |
**Idle session tiers**
| flag | default | |
|---|---|---|
| `--prefix-cache-host-mib N` | 0 (off) | copy finished conversations' KV to host memory |
| `--prefix-cache-disk-mib N` | 0 (off) | and copy them on to disk |
| `--prefix-cache-dir DIR` | — | where the disk tier keeps them |
**Placement and state**
| flag | default | |
|---|---|---|
| `--placement MODE` | auto | `all_vram`, `layer_offload`, `expert_tiered`, `auto` |
| `--deterministic` | off | pin placement to the loader's plan, so the resident set cannot change under the heat engine |
| `--checkpoint-interval N` | 2048 | linear-attention state checkpoint interval, in tokens |
| `--checkpoint-slots N` | 8 | linear-state snapshots the server may hold at once, **in total**, not per sequence. They live in pinned host memory, not VRAM: one slot is a snapshot of every rank's shard (113 MB on Flash-Next at `--tp 2`), allocated at startup. A snapshot is copied off the card after the step that produced it and back before the step that resumes from it. With a disk tier a full store detaches its least recently used snapshot to disk instead of losing it |
| `--checkpoint-policy NAME` | geometric-backoff | also `tip-only`, `keep-all` |
| `--no-prefix-cache` | — | disable prefix caching |
**Parallel**
| flag | default | |
|---|---|---|
| `--tp N` | 1 | tensor-parallel ranks |
| `--tp-wire MODE` | exact | `exact` or `wht6`, the lossy wire (§4.7) |
| `--tp-wire-min-kb N` | 128 | smallest all-reduce the lossy wire is used for |
| `--p2p MODE` | auto | `auto` asks the driver, `on` requires peer access, `off` exchanges through host memory (§4.7) |
**Speculation**
| flag | default | |
|---|---|---|
| `--num-speculative-tokens N` | auto | speculative window; 0 disables. The ceiling under `--draft-window adaptive` |
| `--draft-window MODE` | fixed | `fixed` drafts N every step; `adaptive` follows each sequence's acceptance and the measured step cost, serial draft heads only (§4.6) |
| `--draft-model PATH` | — | **not implemented** — merge at convert time |
**Server**
| flag | default | |
|---|---|---|
| `--host ADDR` | 0.0.0.0 | listen address |
| `--port N` | 8000 | listen port |
| `--api-key KEY` | — | require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but `/health`, `/v1/health`, `/ping` and the dashboard page (§6.6) |
| `--served-model-name NAME` | container's name | the model id `/v1/models` lists, the metrics carry and a response names when its request named none. A request may name any model; the one loaded serves it |
| `--mm-max-patches N` | auto | patches one vision-encoder pass carries, and so the largest image (a patch is 16x16 pixels). `auto` is 16384 when the container carries a vision tower; 0 serves text only and keeps the tower off the card |
| `--override-chat-template PATH` | container's | a Jinja chat template file served in place of the one the container carries. The reply format (reasoning markers, tool calls) is derived from it too, unless the architecture plugin declares one. An unreadable or empty file stops startup |
| `--max-queued-requests N` | 8 × `--max-num-seqs` | requests admitted and unfinished at once; past it, 429 |
| `--http-threads N` | one per core, at least 4 | HTTP workers kept while idle |
| `--read-timeout S` | 30 | seconds a client may go silent while sending a request |
| `--write-timeout S` | 600 | seconds one write to a client may block |
| `--keep-alive-timeout S` | 5 | seconds an idle connection is held open between requests |
| `--max-body-mib N` | 512 | the largest request body; images and video arrive base64 inside it |
| `--retry-after S` | 1 | the `Retry-After` a 429 carries |
| `--no-cors` | CORS on | send no CORS headers (§6.6) |
**Request defaults and bounds** — what a request that leaves a field out gets (§4.9). A request
that names the field wins.
| flag | default | |
|---|---|---|
| `--generation-config PATH` | — | sampler defaults from a `generation_config.json` |
| `--temp F`, `--top-k N`, `--top-p F`, `--min-p F` | from container | sampler defaults |
| `--presence-penalty F`, `--frequency-penalty F` | 0 | [-2, 2] |
| `--repetition-penalty F`, `--repeat-last-n N` | 1, 64 | > 0; ≥ -1 (-1 is all) |
| `--typical-p F` | 1 | (0, 1] |
| `--dry-multiplier F`, `--dry-base F`, `--dry-allowed-length N`, `--dry-penalty-last-n N` | 0, 1.75, 2, -1 | DRY; a multiplier of 0 is off |
| `--dry-sequence-breakers JSON` | `["\n", ":", "\"", "*"]` | a JSON array of at most 16 strings |
| `--xtc-probability F`, `--xtc-threshold F` | 0, 0.1 | [0, 1] |
| `--default-max-tokens N` | `auto` | `max_tokens` for a request that sends none; `auto` is what the context leaves |
| `--max-tokens-cap N` | none | the most any request may generate; a larger `max_tokens` is cut to it, not refused |
| `--max-n N` | the larger of 8 and `--max-num-seqs` | the largest `n` a request may ask for |
| `--max-stop-strings N`, `--max-stop-bytes N` | 64, 4096 | how many stop strings a request may send, and how long each may be |
| `--chat-template-kwargs JSON` | — | variables for the chat template on every chat request; a JSON object or `@FILE`, repeatable |
| `--reasoning-effort S` | template's own | default `reasoning_effort` for chat |
| `--reasoning-effort-map MAP` | — | `FROM=TO,...`: a request's `reasoning_effort` rewritten before the template sees it; `TO` is checked at startup |
| `--thinking-token-budget N` | none | default `thinking_token_budget` for chat: the reasoning block is closed at N tokens |
| `--reasoning-format MODE` | auto | `auto` returns reasoning as `reasoning_content`; `none` leaves it inline in `content` |
**Media** — each replaces what the container's preprocessor configuration states. They do nothing
for a model that takes no images or video.
| flag | default | |
|---|---|---|
| `--image-min-pixels N`, `--image-max-pixels N` | container's | the band an image is resized into; one encoder pass (`--mm-max-patches`) still bounds the top |
| `--video-min-pixels N`, `--video-max-pixels N` | container's | the same for a video's sampled frames together |
| `--video-fps F` | container's, else 2 | frames sampled per second of video |
| `--video-min-frames N`, `--video-max-frames N` | container's, else 4 and 768 | the fewest and most frames sampled from a video |
| `--video-max-frame-tokens N` | container's, else 768 | the most prompt tokens one frame may become; 0 is no cap. A token-budget processor (Gemma 4's) takes 70, 140, 280, 560 or 1120 |
| `--image-tokens N` | container's | a token-budget processor's image budget (Gemma 4's: 70, 140, 280, 560, 1120); a request's `image_tokens` overrides it. The pixel-band flags are refused on such a model |
| `--max-source-pixels N` | 67108864 | the largest image or frame the decoder accepts, before any resize |
**Quality measurement** — instead of serving; see [TOOLS.md](TOOLS.md#the-kl-mode)
| flag | |
|---|---|
| `--kld-record DIR` | run `--kld-corpus` through prefill and write this model's log-probabilities at every scored position to `DIR`: the reference a quantised model is measured against |
| `--kld-ref DIR` | score this model against the reference in `DIR`: mean, median, 99/99.9/99.99th percentile KL divergence and top-1 agreement |
| `--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` |
**Diagnostics**
| flag | |
|---|---|
| `--debug-graph` | print the declared graph and exit |
| `--debug-selection` | print the selection table |
| `--debug-placement` | print the placement plan |
| `--debug-accept-reference-kernels` | serve even when ops resolve to `libref`. **Not a production configuration** |
| `--profile-ops` | per-op device timing |
| `--live` | the live terminal view |
| `-v` / `-vv` | verbose / very verbose |
---
## 5. Talk to it
### 5.1 The endpoints
| | |
|---|---|
| `POST /v1/chat/completions` | chat, with tools, reasoning and streaming |
| `POST /v1/completions` | raw text completion |
| `POST /v1/embeddings` | needs a model with an embedding head, else 501 |
| `POST /v1/messages`, `POST /v1/messages/count_tokens` | Anthropic's Messages API, for Claude Code and the Anthropic SDKs — §5.9 |
| `POST /v1/responses`, `POST /v1/responses/input_tokens` | OpenAI's Responses API, for Codex and the OpenAI SDKs' `responses` client — §5.9 |
| `POST /completion`, `/completions`, `POST /infill` | llama-server's native completion and fill-in-the-middle, for llama.vim, llama.vscode and the clients built on llama-server's own API — §5.9 |
| `GET /v1/models`, `/v1/models/:id` | what is loaded, with `max_model_len` (the context it serves) and `root` (the `--model` path), as vLLM reports them, and `capabilities` (the same object `/server_info` reports); `:id` answers the entry itself, as OpenAI's retrieve does |
| `GET /health`, `/v1/health`, `/ping`, `POST /ping` | liveness |
| `GET /load` | current load |
| `GET /version` | server version |
| `GET /props` | llama-server's props for the clients built against it: `n_ctx`, `total_slots`, `modalities`, `model_path`, the chat template and its capabilities, `bos_token`/`eos_token`, and the request defaults under llama-server's names |
| `POST /apply-template` | the prompt a chat request renders to, as llama-server answers it |
| `POST /v1/chat/completions/input_tokens` | how many tokens that prompt is |
| `GET /server_info` | the whole configuration of the running engine |
| `GET /metrics` | Prometheus |
| `POST /tokenize`, `POST /detokenize` | vLLM's shape (`prompt` or `messages` in, `prompt` out) and llama-server's (`content` in and out, `with_pieces`) |
| `GET /get_tokenizer_info` | |
| `POST /reset_prefix_cache` | drop every cached prefix |
| `GET /` or `/dashboard` | the web dashboard |
| `GET /stats`, `/graph`, `/sessions` | the JSON the dashboard is drawn from |
Method spellings follow vLLM's, including the ones that look odd: `/tokenize` is POST because its
input is a body, and `/ping` answers both GET and POST because different load balancers send
different ones. As llama-server does, `/chat/completions`, `/embeddings` and `/models` answer without the `/v1`
too, for a client configured with the bare host as its base URL -- and `/completions` without it is
llama-server's native completion, as it is there. A path nothing serves is a JSON 404.
A text prompt to `/v1/completions`, `/v1/embeddings` or `/tokenize` reads the model's control
tokens as tokens, as vLLM and llama.cpp do: a client that renders its own chat template can send
`<|im_start|>user\n…` and the model sees the turn markers. The BOS the model declares is prepended
unless the prompt already opens with it.
### 5.2 Chat
```sh
curl -s http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "m",
"messages": [{"role": "user", "content": "Explain merge sort briefly."}],
"max_tokens": 200,
"temperature": 0.7
}' | jq -r '.choices[0].message.content'
```
If the container carries no chat template this endpoint answers **501** and the startup log says
so — use `/v1/completions` instead.
**Turning thinking off.** Three spellings reach the server for one question; all work:
```json
{"chat_template_kwargs": {"enable_thinking": false}}
{"enable_thinking": false}
{"reasoning_effort": "none"}
```
Reasoning text comes back in `choices[].message.reasoning_content`, separate from `content`.
**Reasoning counts against `max_tokens`**, as in OpenAI's API, vLLM and llama.cpp: every
generated token does. A reply that runs out inside its reasoning comes back with empty
`content` and `finish_reason: "length"`. `usage.completion_tokens_details.reasoning_tokens` says
how many of `completion_tokens` were reasoning, the block's end token included, so a client can
tell that case from a model that answered nothing.
**Capping the reasoning.** `thinking_token_budget` (vLLM's name; `thinking_budget`, Qwen's, is
read as the same field) is how many tokens the reasoning may run to. At that count the block is
closed and the model answers from what it has reasoned so far:
```json
{"max_tokens": 4096, "thinking_token_budget": 2048}
```
The count starts after the opening `<think>`. A reasoning block that ends sooner is not
affected. The close is forced by the sampler, so it holds under speculative decoding and at any
temperature. A `grammar` or `response_format` that does not allow the close at some position
keeps that position, and the close comes at the next position that allows it. The budget and
`reasoning_tokens` need the block's end to be one token. A model whose end is not one token
reports no `completion_tokens_details` and refuses a budget with a 400 that says why.
### 5.3 Streaming
```sh
curl -N http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"m","messages":[{"role":"user","content":"Count to ten."}],
"max_tokens":100,"stream":true,
"stream_options":{"include_usage":true}}'
```
Server-sent events, OpenAI's delta format, terminated by `data: [DONE]`.
### 5.4 Tool calls
```sh
curl -s http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "m",
"messages": [{"role":"user","content":"What is in /etc/hosts?"}],
"tools": [{
"type": "function",
"function": {
"name": "read",
"description": "read a file",
"parameters": {"type":"object",
"properties":{"path":{"type":"string"}},
"required":["path"]}
}
}],
"tool_choice": "auto",
"max_tokens": 300
}' | jq '.choices[0].message.tool_calls'
```
Calls come back in `message.tool_calls` with `finish_reason: "tool_calls"`. No `<function>` or
`<param>` markup ever reaches `content`. `scripts/mctools.sh` and `scripts/mcstream.sh` assert
exactly that, including on raw streamed fragments — content cannot be retracted once sent, so a
repair applied at the end is not a fix.
A tool's `parameters` schema shapes the grammar the call is written under. A property whose schema
accepts no value — `false`, or `{"not": {}}`, which is how TypeBox and Arktype export `never` — is
an argument no call writes. Any other `not` is refused with a 400 naming it: the grammar cannot
express a complement, and dropping the constraint silently would serve a call the tool forbids.
Length bounds are held exactly: `maxLength`, `minLength`, `maxItems` and `minItems` up to about
200,000, which costs the first request carrying the tool under a second to compile on a
quarter-million-token vocabulary and nothing per token after that. A bound past 2^31 (as
`Number.MAX_SAFE_INTEGER` is) is no bound, since no context holds that much. One in between is
refused with a 400 naming the property's rule and the count. The same holds for `response_format`
schemas and `{m,n}` in a GBNF grammar.
### 5.5 Constrained output
```sh
# JSON object
-d '{"model":"m","messages":[...],"response_format":{"type":"json_object"}}'
# a JSON schema
-d '{"model":"m","messages":[...],
"response_format":{"type":"json_schema",
"json_schema":{"schema":{"type":"object",
"properties":{"city":{"type":"string"},"pop":{"type":"integer"}},
"required":["city","pop"]}}}}'
# a GBNF grammar directly (cannot be combined with response_format)
-d '{"model":"m","prompt":"...","grammar":"root ::= \"yes\" | \"no\""}'
```
**On chat, a constraint passes through the chat template and may not survive it.** The template
gets to rewrite or drop `grammar` and `response_format` — a tool-calling template produces its own
grammar, for instance — so whether a constraint can be enforced is a property of the model's
template and not only of the server. When the one you asked for is not there at the end, the
request is **refused**:
```
grammar: this model's chat template produced no grammar for it, so the constraint could not
be enforced
```
That is §5.8's rule doing its job -- a field that would change the answer is honoured or
refused, never dropped: an unconstrained 200 would leave you
parsing free prose against a schema you were told was enforced. `/v1/completions` has no template
in the way, so the same grammar works there — which is why the example above uses it.
### 5.6 Completions, embeddings, tokenising
```sh
curl -s http://localhost:8000/v1/completions -H 'Content-Type: application/json' \
-d '{"model":"m","prompt":"def fib(n):","max_tokens":128,"temperature":0}'
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"model":"m","input":"hello"}'
curl -s http://localhost:8000/tokenize -H 'Content-Type: application/json' \
-d '{"prompt":"hello world","return_token_strs":true}'
curl -s http://localhost:8000/tokenize -H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"hi"}]}' # applies the chat template
curl -s http://localhost:8000/detokenize -H 'Content-Type: application/json' \
-d '{"tokens":[15339,1917]}'
curl -s http://localhost:8000/tokenize -H 'Content-Type: application/json' \
-d '{"content":"hello world","with_pieces":true}' # llama-server's shape
```
`/tokenize` takes one of `prompt`, `messages` or llama-server's `content` (a string, or strings and
token ids mixed, with its `add_special` and `parse_special` and their defaults); the `content`
form answers `tokens` as llama-server does, as `{id, piece}` objects with `with_pieces`.
`/detokenize` answers the text as both `prompt` (vLLM) and `content` (llama-server).
**An embedding model** (EmbeddingGemma 2) serves `/v1/embeddings` and nothing else; completions and
chat answer 501. One input is one vector, and an input is never split: it has to fit one step
(`--max-num-batched-tokens`), and a longer one is refused with `context_length_exceeded`.
```sh
# text, a batch of texts, or token ids
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":["first document","second document"]}'
# the model's named prompt in front ("query" -> "task: search result | query: ")
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":"what is the capital of France?","prompt_name":"query"}'
# Matryoshka: the first 256 dimensions, renormalised
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":"hello","dimensions":256}'
# one vector for text and media together: content parts, in order
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":[{"type":"text","text":"a photo of "},
{"type":"image_url","image_url":{"url":"data:image/png;base64,..."}}],
"image_tokens":560}'
# or the chat form, rendered through the model's template
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":[{"type":"input_audio",
"input_audio":{"data":"<base64 wav>","format":"wav"}}]}]}'
```
`input` is a string, an array of token ids, one array of content parts, or a batch of any of
those. A content part is `text`, `image_url`, `video_url`, `input_audio` (wav, mp3, flac, ogg,
opus, m4a, aac, webm or aiff, base64) or `audio_url`; media comes as `data:` URLs, never fetched.
An image becomes up to 280 tokens by default (`--image-tokens`, or a request's `image_tokens`: 70,
140, 280, 560 or 1120), a video one frame a second, at most 32 frames of 140 tokens
(`--video-fps`, `--video-max-frames`, `--video-max-frame-tokens`), and audio 25 tokens a second,
cut at 30 seconds. `prompt_name` takes the names the model's sentence-transformers configuration
states (`query`, `document`, `Retrieval-query`, `STS`, ...) and applies to text and content-part
inputs; a model that states a default prompt applies it when the request names none.
### 5.7 Request fields
| field | notes |
|---|---|
| `model` | accepted and not enforced — one server serves one model |
| `messages` / `prompt` / `input` | chat / completion / embedding |
| `max_tokens`, `max_completion_tokens`, `n_predict` | default: what the context leaves after the prompt (`--default-max-tokens`); -1 is llama-server's "no limit", the same without the default. Clamped to what the context leaves, and to `--max-tokens-cap`, rather than refused — see §5.8 |
| `temperature` | [0, 2] |
| `top_p` | (0, 1] |
| `top_k` | ≥ 0, 0 disables |
| `min_p`, `typical_p` | |
| `presence_penalty`, `frequency_penalty` | [-2, 2] |
| `repetition_penalty` (or `repeat_penalty`), `repeat_last_n` | |
| `xtc_probability`, `xtc_threshold` | |
| `dry_multiplier`, `dry_base`, `dry_allowed_length`, `dry_penalty_last_n`, `dry_sequence_breakers` | |
| `seed` | absent means "pick one" — **not** seed 0 |
| `n` | 1 to `--max-n`, by default the larger of 8 and `--max-num-seqs`. Fan-out over the same prompt; the prefix cache makes it nearly free after the first |
| `priority` | |
| `stop` | a string or an array; at most 64 strings of 4096 bytes (`--max-stop-strings`, `--max-stop-bytes`) |
| `ignore_eos` | generate to `max_tokens` whatever the model emits |
| `stream`, `stream_options.include_usage` | |
| `timings_per_token`, `return_progress` | llama-server's: `timings` on every chunk, and `prompt_progress` chunks while the prompt is read |
| `samplers` | llama-server's sampler order, names or letters. A stage it leaves out is off. The chain here is penalties, DRY, top-k, top-p, min-p, typical, XTC with temperature first (the default) or last (llama-server's default), so a list in either of those orders is honoured and any other is refused by name |
| `session_id` | OpenRouter's conversation id: labels the conversation on `/sessions` and the dashboard |
| `logprobs`, `top_logprobs`, `n_probs` | each generated token's logprob and up to 20 alternatives — see §5.11. Chat: `logprobs: true` with `top_logprobs` alternatives (0 when absent); completions: `logprobs: N`; any endpoint: llama-server's `n_probs: N`, which wins. Not with `echo` (the prompt's logprobs are not computed) |
| `tools`, `tool_choice`, `parallel_tool_calls` | chat only. `tool_choice` is `auto`, `none`, `required` or `{"type":"function","function":{"name":...}}`; the last two hold the whole reply to calls (after the reasoning block), the named form to that one function, and cannot be combined with `response_format` or `grammar` |
| `add_generation_prompt`, `chat_template_kwargs` | chat only |
| `continue_final_message` | chat only. A conversation ending in an assistant message is continued rather than answered, as llama-server and the Anthropic API do -- the reply carries that message's text and what follows it. `true`, `"content"` or `"reasoning_content"` names it explicitly; `add_generation_prompt: true` opens a new turn instead |
| `reasoning_format` | chat only, llama-server's: `none` keeps the reasoning in `content`; `auto` and `deepseek` split it into `reasoning_content`, the default |
| `reasoning_effort`, `enable_thinking` | chat only. The levels are the template's (`capabilities.reasoning_efforts` on `/server_info`); `none` and `minimal` turn thinking off |
| `thinking_token_budget`, `thinking_budget`, `thinking_budget_tokens`, `reasoning_budget_tokens` | chat only. ≥ 0: the reasoning tokens after which the block is closed — see §5.2; -1 is none. Default `--thinking-token-budget`, else none |
| `preserve_thinking` | chat only. The chat template variable of that name, as llama.cpp maps it; Qwen3.6 and later keep earlier turns' reasoning in the prompt with it |
| `response_format`, `json_schema` | chat only. `json_schema` is llama-server's shorthand: the schema itself. Mutually exclusive with `grammar` |
| `functions`, `function_call` | chat only: OpenAI's deprecated spellings of `tools` and `tool_choice`. The reply answers in the old shape too: one call at most, as `message.function_call` with `finish_reason: "function_call"`; the next turn's assistant `function_call` and `function` message are read as the call and its result |
| `grammar` | a GBNF grammar directly. On chat it passes through the chat template and a template that drops it makes the request a refusal — see §5.5 |
| `echo` | `/v1/completions` only |
| `encoding_format` | `/v1/embeddings` only: `float` or `base64` |
| `dimensions`, `prompt_name`, `image_tokens` | `/v1/embeddings` only (an embedding model, §5.6). `dimensions` truncates to the first N and renormalises; it cannot exceed the model's width |
Any field the request omits keeps the deployment default (§4.9). A field the request names wins.
### 5.8 What a field this server does not implement does
Four kinds of field, and the rule they serve is that **a request that returns 200 had every field
that could change its answer honoured**:
- **Accepted** — the table above, in OpenAI's, vLLM's and llama-server's spellings.
- **Inert** — fields that change nothing about the answer, accepted and ignored: OpenAI's and
OpenRouter's bookkeeping (`user`, `metadata`, `store`, `service_tier`, `safety_identifier`,
`prompt_cache_key`, `prediction`), and llama-server's knobs for its own speed and slots
(`cache_prompt`, `id_slot`, `n_cache_reuse`, `backend_sampling`, `reasoning_control`, `n_keep`,
`n_discard`, `speculative.*`, ...). The prefix cache and speculation here are the server's own
and never change the output.
- **Guarded** — known, not implemented, and able to change the answer. llama-server's clients send
every one of them on every request at its off value, so each is accepted there and refused,
naming it, at any other:
```json
{"error": {"message": "mirostat: mirostat is not one of the device samplers (spec 13); it is accepted only at 0, where it does nothing", ...}}
```
| guarded | accepted at | because |
|---|---|---|
| `logit_bias` | empty | the device sampler has no per-token bias stage |
| `mirostat` | 0 | not one of the device samplers |
| `top_n_sigma` | ≤ 0 | not one of the device samplers |
| `dynatemp_range` | 0 | not one of the device samplers |
| `min_keep` | 0 | the cuts keep no minimum count |
| `post_sampling_probs` | false | logprobs are the raw distribution's; the sampler's are not returned |
| `best_of` | 1 | not implemented |
| `suffix` | empty | infilling through `/v1/completions` is not implemented |
| `lora` | empty | explicitly out of scope |
| `modalities`, `audio` | `["text"]`, null | output other than text is not implemented |
| `n_indent`, `t_max_predict_ms`, `return_tokens` | 0, 0, false | not implemented |
| `grammar_lazy`, `grammar_triggers`, `preserved_tokens` | off, empty | the chat format decides them |
- **Anything else is ignored**, as llama-server and vLLM ignore it: a field this server has never
heard of is a client's own extension far more often than a request it misunderstood. The names
are logged at debug.
**The one exception is `max_tokens`.** If `prompt + max_tokens` would exceed the context, the
server clamps `max_tokens` to what is left and serves the request:
```
prompt 72,170 + max_tokens 128,000 > 200,000 context
-> served with max_tokens 127,830
```
It is an exception because the other keys are *settings* — dropping one serves a different model
than the caller asked for — and this one is a *bound*, whose whole purpose is to stop generation
early and which the context was going to stop earlier anyway. Refusing would not produce more
tokens than clamping does; it would produce none. The completion ends with `finish_reason:
"length"` and `usage` reports what it actually got, so the caller can still see what happened, and
`-v` logs the adjustment.
A prompt that does not fit **on its own** is still a 400 — there is no window to generate into, so
no `max_tokens` would have made it servable — and the error names how many tokens have to go:
```
prompt: 220470 prompt tokens does not fit the 200000 token context, which leaves nothing to
generate into; shorten the prompt by at least 20471 tokens
```
At the boundary, where an off-by-one would hide: a 198,729-token prompt asking for `max_tokens`
128,000 against a 200,000 context is served, generates **1,271** tokens — exactly the room left —
and ends `finish_reason: "length"`. `POST /tokenize` is how to size a prompt that
precisely without running the model.
---
### 5.9 Anthropic's, OpenAI's Responses and llama-server's native APIs
`POST /v1/messages` takes Anthropic's request and answers in Anthropic's shapes, streamed
(`message_start`, content blocks, `message_delta`, `message_stop`) or not, so Claude Code and the
Anthropic SDKs work against radiance as they do against llama-server:
```sh
ANTHROPIC_BASE_URL=http://localhost:8000 ANTHROPIC_API_KEY="$KEY" claude
```
It is translated into the chat request it means and served by the chat path, so the template
defaults, refusals and limits are the chat endpoint's. `system` (a string or text blocks), text and
image blocks, `tool_use` and `tool_result`, client tools and `tool_choice`, `stop_sequences`,
`thinking` (`enabled` with a `budget_tokens`, `disabled`, `adaptive`) and `metadata.user_id` (the
conversation's label on `/sessions`) are honoured. A conversation that ends in an assistant message
is continued, and the answer carries what follows it. Thinking blocks come back with an empty
`signature`. Claude Code's per-request billing stamp at the head of the system prompt is held
constant, as llama-server holds it, or no turn could reuse the prefix of the one before.
`document` blocks and Anthropic's server tools (`web_search_…`, `code_execution_…`) run on
Anthropic's side and are refused by name. `POST /v1/messages/count_tokens` answers the prompt's
length. The key may come as `X-Api-Key` (§6.6).
`POST /v1/responses` is OpenAI's Responses API, translated the same way: `instructions` and `input`
(a string, or message, `function_call`, `function_call_output` and `reasoning` items) become the
conversation, `max_output_tokens` and `reasoning.effort` and `text.format` the chat request's
fields, and every field the Responses API does not define passes through to the chat request as it
does in llama-server (`chat_template_kwargs`, `top_k`, ...). The answer is a response object, or
its event stream with every event's `output_index`, `content_index` and `sequence_number`; a reply
cut at `max_output_tokens` is `incomplete`. Function tools are offered to the model; the built-in
tools (web search, file search, computer use) and freeform custom tools have no counterpart here
and are left out, as llama-server leaves them out. Responses are not stored, so
`previous_response_id` is refused: send the conversation as `input`. What a response object
cannot carry is refused rather than computed and dropped: `n` other than 1, and logprobs
(`include` naming `message.output_text.logprobs`, `top_logprobs`, `logprobs`, `n_probs`) --
`/v1/chat/completions` serves those. A failed generation ends the stream in
`response.failed`, as one on `/v1/messages` ends in Anthropic's `error` event.
`POST /completion` (and `/completions` without `/v1`, as llama-server names it) is llama-server's
native completion: a prompt string, token ids, or strings and ids mixed as one prompt; the
request fields of §5.7; and llama-server's answer -- `content`, `stop_type` (`eos`, `limit`,
`word`), `stopping_word`, `tokens_predicted`, `tokens_evaluated`, `generation_settings`,
`timings`, and the generated ids with `return_tokens`. A stream is its chunks with the ids that
made each, then the final result, with no `[DONE]`. `POST /infill` completes between
`input_prefix` and `input_suffix`, with `input_extra` (files, `{filename, text}`) and `prompt`, in
the repository-level fill-in-the-middle layout llama-server builds, byte for byte. It needs a model
with fill-in-the-middle tokens (the Qwen, StarCoder, DeepSeek and CodeLlama spellings are
recognised) and answers 501 without them; the extra files give way first when the prompt does not
fit.
### 5.10 What a response says about its own speed
Every chat and completion response carries a top-level `timings` object for the request. It uses
llama.cpp's field names, so a proxy or dashboard built against llama-server (llama-swap's activity
view, for one) reads it unchanged:
```json
"timings": {
"cache_n": 1024, "prompt_n": 71, "prompt_ms": 284.0,
"prompt_per_token_ms": 4.0, "prompt_per_second": 250.0,
"predicted_n": 64, "predicted_ms": 711.0,
"predicted_per_token_ms": 11.29, "predicted_per_second": 88.6,
"draft_n": 78, "draft_n_accepted": 37
}
```
| field | meaning |
|---|---|
| `prompt_n` | prompt tokens this request computed. Tokens the prefix cache supplied are not in it |
| `cache_n` | prompt tokens the prefix cache supplied. `prompt_n + cache_n` is the prompt |
| `prompt_ms` | from the first step the scheduler gave the request to its first token: the prefill. The time it waited for admission is not in it |
| `prompt_per_second`, `prompt_per_token_ms` | `prompt_n` over `prompt_ms`. A prompt the cache mostly supplied computes few tokens, so this is the speed of the prefill that actually ran, not the prompt length over the time to first token |
| `predicted_n` | tokens generated, the same as `usage.completion_tokens` |
| `predicted_ms` | from the first generated token to the last |
| `predicted_per_second`, `predicted_per_token_ms` | the `predicted_n − 1` tokens after the first, over `predicted_ms`. The first token is the prefill's product. It is the same figure as `/metrics`' time per output token, and with speculative decoding it counts every token a step accepts |
| `draft_n`, `draft_n_accepted` | speculative tokens proposed for this request and how many were accepted. Present when any were proposed, as llama.cpp does |
Milliseconds are wall-clock milliseconds, and the rates are tokens per second. A rate whose count
or time is zero is `null`. A request with several choices (`n`, or a batch of prompts) sums the
counts, and each time runs from the earliest choice's start to the latest choice's end.
When streaming, each choice's final chunk (the one with `finish_reason`) carries its own
`timings`, whether or not the request asked for `stream_options.include_usage`. The usage chunk,
when asked for, carries the request's. `/metrics` stays the aggregate surface (§6.3). It sums
the same quantities over every request, so it cannot say which request they belong to.
### 5.11 Logprobs
The numbers are the **raw distribution's** — the logits as the model wrote them, before any
penalty, temperature, grammar mask or cut — which is what OpenAI and llama-server report. Each
generated token carries its own logprob and its `top_logprobs` most likely alternatives, at most 20.
```bash
curl -s localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"messages": [{"role": "user", "content": "Say hi"}], "temperature": 0,
"logprobs": true, "top_logprobs": 2, "max_tokens": 4 }' | jq -c '.choices[0].logprobs.content[0]'
```
Qwen3.5-0.8B, thinking off:
```json
{"id":9419,"token":"Hello","bytes":[72,101,108,108,111],"logprob":-0.7186,
"top_logprobs":[{"id":9419,"token":"Hello","bytes":[72,101,108,108,111],"logprob":-0.7186},
{"id":12675,"token":"Hi","bytes":[72,105],"logprob":-1.3188}]}
```
- **Chat** answers in OpenAI's shape, with llama-server's `id` beside each token; a stream carries
each token's entry on the chunk that carries its text.
- **`/v1/completions`** answers OpenAI's legacy arrays (`tokens`, `token_logprobs`, `top_logprobs`
as one `{text: logprob}` object a token, `text_offset`) and llama-server's `content` array beside
them.
- **`/completion`** (`n_probs`) answers llama-server's `completion_probabilities`.
- A token that ends inside a UTF-8 character has the readable part as `token` and every byte in
`bytes`, as llama-server does. A stop string's own tokens are not reported, since their text never
went out.
Speculation is unaffected — every verified position is scored, and an accepted draft is the token
the model drew there. The cost is a top-k's worth of work for each row that asks
(`sample_logprobs`, docs/OPS.md): about 0.12 ms a step on an R9700 at a 248K vocabulary, on the
card. The chosen token's logprob is exact when it is among the raw top 20; otherwise it is
recovered from the value it was drawn at by undoing temperature, DRY and the penalties, which
agrees to float rounding.
**Where llama-server differs:** `logprobs: true` without `top_logprobs` returns 20 alternatives
there and none here, which is OpenAI's default. The values themselves agree with llama-server's to
bf16 rounding (within 0.1 on Qwen3.5-0.8B, sampled tokens far down the tail included).
## 6. Operate it
### 6.1 The dashboard
Open `http://<host>:<port>/` in a browser. Three tabs:
**Dashboard** — the live strip across the top (decode step time, decode and prefill throughput,
requests in flight, KV cache in VRAM, draft acceptance), then cards for the batch, memory and
interconnect, and the expert plane.
The **KV cache** meter splits what it is holding into two segments:
```
KV cache 3.3 GiB / 4.5 GiB · 390.1k tok · 75.5%
▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
20.8k tok in flight · 369.3k held for the next turn
```
The full-strength segment is live requests; the ghost segment is **prefix cache** — finished turns
kept so the next turn need not re-prefill. Held is not a second pool: it gives way the moment a
live request needs it. A high held figure with a high hit rate is the cache doing its job, not a
leak. Both segments take their warning colour from the *total* fill, since what causes preemption
is the pool being full.
**Sessions** — one row per stored conversation: how many tokens, which tier it is in, and whether
its linear half is still reachable. Sizes **overlap and cannot be added up**: two sessions sharing
a system prompt share the blocks for it, which is the whole point of a prefix cache.
On a hybrid model, a session with blocks but no reachable snapshot reuses **zero** tokens — the
scheduler clamps reuse to the last linear checkpoint. That verdict is the headline of the tab.
**Model** — the resolved graph: every op, which library serves it, and what did not resolve.
### 6.2 The JSON behind it
```sh
curl -s localhost:8000/stats | jq # counters, memory, throughput
curl -s localhost:8000/sessions | jq # what is stored and where
curl -s localhost:8000/graph | jq # the resolved kernel graph
curl -s localhost:8000/server_info | jq # model, cards, KV, draft depth, wire
```
`/server_info` is the operator's first question asked of a process that is already running: which
model, on how many cards, with how much KV, drafting how deeply, over which wire. All of it is in
the startup log too — but a startup log is on a machine, in a file, from a process that may have
been restarted since.
Its `request_defaults` object says what a request that leaves a field out is served with: every
sampler field, `max_tokens`, `reasoning_effort`, `reasoning_effort_map`, `chat_template_kwargs` and
`reasoning_format`, under the request's own spelling of each. `capabilities.reasoning_efforts`
lists the efforts the chat template takes, or is `null` when it takes any. `server.default_max_tokens` is `null` for `auto`, and
`server.max_tokens_cap` is `null` when there is none.
### 6.3 Metrics
`GET /metrics` is Prometheus text. Two families:
**`vllm:` — the compatibility set**, so existing dashboards work: `num_requests_running`,
`num_requests_waiting`, `num_preemptions_total`, `gpu_cache_usage_perc`, `kv_cache_usage_perc`,
`gpu_prefix_cache_hit_rate`, `prompt_tokens_total`, `generation_tokens_total`,
`time_to_first_token_seconds`, `time_per_output_token_seconds`, `inter_token_latency_seconds`,
`request_prompt_tokens`, `request_generation_tokens`, `request_success_total`, …
**`radiance:` — what this engine actually has**:
| | |
|---|---|
| `engine_steps_total`, `_decode_total`, `_prefill_total`, `_mixed_total` | step counts by kind |
| `engine_step_seconds_total`, `_decode_total` | **the honest step time denominator** |
| `decode_tokens_total`, `prefill_tokens_total` | |
| `decode_tokens_per_second`, `prefill_tokens_per_second` | |
| `draft_tokens_total`, `draft_accepted_total`, `draft_acceptance_ratio` | |
| `draft_position_reached_total`, `draft_position_accepted_total`, `draft_position_acceptance_ratio` | acceptance by position: the two counters over any window, the ratio since start |
| `draft_refills_total`, `draft_refill_tokens_total` | prefix hits ended a drafter window early, and the tokens recomputed (§4.6) |
| `decode_rows_unspeculated_total` | rows that never drafted at all |
| `draft_depth_adaptive`, `draft_verify_depth_total{depth}` | the adaptive window's mean over the running sequences, and verifies by the drafts they carried; only with `--draft-window adaptive` (§4.6) |
| `attn_cached_tokens_total`, `linear_cached_tokens_total` | prefix reuse, both halves |
| `linear_checkpoints_written_total`, `linear_prefix_cache_hit_rate` | |
| `prefix_cache_evictions_total`, `prefix_cache_ckpt_evictions_total` | |
| `num_requests_preempted` | |
| `http_queue_depth`, `http_responses_total`, `http_admission_rejected_total` | |
| `client_disconnect_total`, `stream_overflow_total` | |
Two traps worth naming:
- **`draft_acceptance_ratio` is conditional on having drafted.** It reads healthy while
tokens-per-step collapses. The quantity that separates the two is blocks per step —
`draft_tokens_total / depth` over `engine_steps_decode_total`. `scripts/mcdecl.sh` measures it.
- **Step time is not wall-clock over steps.** Use `engine_step_seconds_decode_total /
engine_steps_decode_total`, which charges only decode. Wall-clock charges idle and prefill to it.
`deploy/grafana/radiance.json` charts both families over time, on Prometheus or VictoriaMetrics.
### 6.4 The live terminal view
```sh
radiance --model m.rad --live
```
Cards, throughput, draft acceptance and the expert plane, redrawn in place. **Redirected it prints
one greppable `key=value` line instead**, so it is usable from a script:
```sh
radiance --model m.rad --live >> serve.log 2>&1
```
The step counter is the field that tells a stalled loop from an idle one: throughput decays toward
zero on its own, but a step count frozen between two draws means the loop itself stopped.
### 6.5 Logging
```sh
RADIANCE_LOG=debug radiance --model m.rad # error|warn|info|debug|trace
radiance --model m.rad -v # same as debug
radiance --model m.rad -vv # same as trace
```
### 6.6 Security
**There is no TLS, and without `--api-key` there is no authentication.** CORS is on, so a page on
any origin can call the API from a browser; `--no-cors` turns it off.
```sh
radiance --model m.rad --api-key "$KEY"
```
With a key, every request must carry `Authorization: Bearer KEY` (or Anthropic's `X-Api-Key: KEY`)
or it is answered 401 — `/tokenize` and `/server_info` included, since they hand out the
vocabulary, the chat template and the configuration. Three paths are exempt: `/health` (and
`/v1/health`) and `/ping`, because a load balancer cannot carry a bearer token and an
authenticated probe is a server that reports itself down, and the dashboard page itself (`/`,
`/dashboard`), which holds no data — on a 401 it shows a key field, keeps the key in the browser's
storage and sends it on every fetch of data it makes.
The key is checked, not encrypted: on any network you do not control, bind to localhost and put a
TLS-terminating reverse proxy in front:
```sh
radiance --model m.rad --host 127.0.0.1 --port 8000 --api-key "$KEY"
```
Also note `--prefix-cache-disk-mib` writes **conversation content unencrypted** under `--prefix-cache-dir`.
### 6.7 Restarting and stopping
Nothing here is a daemon; run it under systemd, a supervisor or `nohup`. `scripts/fnstop.sh` stops
a running server and waits for the process to actually go — which matters, because VRAM is not
released until it does.
---
## 7. When something goes wrong
| What you see | What it means | What to do |
|---|---|---|
| `N declared op(s) resolve to libref` and the engine exits | No kernel library covers those ops on this card. Serving from the reference implementation would be orders of magnitude slow with nothing to say so | Install a library that covers them, or accept the cost with `--debug-accept-reference-kernels`. The named ops are exactly what a new library must implement |
| `did not fit` at load, naming a weight class or a KV group | The split left one side too little. A routed expert cannot be served from the file tier, so it has nowhere else to go | If **weights** did not fit: add or raise `--host-pool-mib`, or lower `--max-model-len` or `--max-num-seqs`. If a **KV group** did not fit: `--kv-cache-dtype fp8`, or a larger `--host-pool-mib` (RAM permitting), which takes experts off the card. The plan report names which, by class, with the shortfall |
| `chat is 501` in the startup line | The container carries no chat template | Re-convert with `--tokenizer`, and check that a `chat_template.jinja` sits beside `tokenizer_config.json` in the checkpoint. Meanwhile use `/v1/completions` |
| `does not read '<weight>' encoded <encoding>` at startup | No loaded kernel takes that weight's encoding for the op that reads it | Convert with a recipe that writes an encoding a loaded kernel reads, or load the library that reads it |
| Prefix hit rate 0% and every turn re-prefills | The KV pool cannot hold the live sessions, so the cache evicts what the next turn wanted | The cache already has everything the experts can do without: a larger `--host-pool-mib` (RAM permitting), `--kv-cache-dtype fp8`, or fewer/shorter sessions. See §4.3 |
| The server dies with no log line, on a request it had been serving fine | A kernel whose code object had never been loaded could not be: the card has no room left. HIP faults inside the launch rather than returning an error, so there is nothing to print | A card left with too little room for a first launch — see §4.3. Set `--gpu-headroom-mib` to the value the startup warning names. `coredumpctl info` names the kernel; `AMD_LOG_LEVEL=1` prints `HSA_STATUS_ERROR_OUT_OF_RESOURCES` just above the fault |
| KV in VRAM stays high with one session and nothing moves | The idle tiers are **off** — they are sized, and with no size nothing is copied | Pass `--prefix-cache-host-mib N` |
| `out of memory` / `the carve reserved N of address space and the card would not back it` | Something else is holding VRAM | Check with `rocm-smi`; stop the other process. The budget is stated before allocation, so the log says what it asked for |
| `pool allocation refused` with `backing allocation of … refused` on the second card, after the first card's pools succeeded | The VRAM budget is measured before any rank allocates. A card that refuses its weights pool lost that memory to another process in between (the line below the refusal says how much is free now). A refused `host_pool` is pinned memory: **every rank pins its own `--host-pool-mib`**, so `--tp 2` pins it twice, and the amdgpu driver caps pinned memory system-wide at `ttm.pages_limit`, half of RAM by default | Stop the other process (`rocm-smi --showpids`). For the host pool, keep `--tp` × `--host-pool-mib` under the cap the refusal names, or raise it with the kernel parameter `ttm.pages_limit` |
| `host_pool: backing allocation of … refused: rad_dev_alloc(…): locking piece K of N`, and `failed to pin userptr` in `journalctl -k` | The IOMMU would not DMA-map one piece of the pinned host pool. Pinned host memory is locked in pieces of at most 1 GiB because an Intel VT-d host in scalable mode was seen to refuse any single pin above about 2.5 GiB; a piece failing means this machine refuses smaller pins still, or a total its IOMMU will not map | Keep IOMMU translation on: `iommu=pt` lets every pin through but on that host also removed peer access between the cards, which moves every all-reduce onto the slower host-memory path. Report the kernel version, the IOMMU mode and the refusal line |
| `a synchronisation has waited 5 s` naming a kernel, then `no queue has advanced`, then `HW Exception … GPU Hang` and a reset in `journalctl -k` (`MES failed to respond to msg=REMOVE_QUEUE`, `MODE1 reset`) | The card stopped running the queue. The kernel named is where it stopped, not necessarily why. The driver resets the whole card, VRAM included, and the engine is aborted. The usual cause is compute wave save/restore being off: the driver evicts a process's queues whenever host memory the card maps is moved under memory pressure, and with `cwsr_enable=0` it cannot preempt a running queue, so the eviction waits for a queue a serve never lets drain. A voltage offset or other clock instability is the other cause seen on R9700s. If the stall line says the queues **advanced**, the wait was long rather than stuck, and nothing is wrong | `cat /sys/module/amdgpu/parameters/cwsr_enable` must print `1` (the engine warns at startup when it is `0`); set `amdgpu.cwsr_enable=1`, rebuild the initramfs and reboot. Remove any `OD_VDDGFX_OFFSET` (`pp_od_clk_voltage`). A reset puts the power cap, fan curve and voltage offset back to firmware defaults, so re-apply them before every start rather than once at boot. Keep the devcoredump under `/sys/class/drm/card*/device/devcoredump/data`; a reboot loses it. `docker inspect` shows exit code 0 for a container Docker has already restarted, which says nothing about how the old process ended |
| `--draft-model is not implemented` | This engine loads its drafter from the container | `rad-convert --draft-model DIR` at conversion time |
| `context_length_exceeded` on a request | The **prompt alone** does not fit the context. `max_tokens` is clamped rather than refused, so this fires only when there is no room left to generate at all | Shorten the prompt by the number of tokens the message names, or raise `--max-model-len` if the model allows it |
| `unknown option '--foo'` and the engine exits | Deliberate. A typo in a budget flag is the difference between the plan you asked for and one the planner invented | Check `radiance --help` |
| Empty `content` and `finish_reason: "length"` on short chat turns | The reasoning spent all of `max_tokens` inside `<think>`; `usage.completion_tokens_details.reasoning_tokens` equals `completion_tokens`. Qwen3.8's default `reasoning_effort` is `xhigh` | `--reasoning-effort medium`, or `"reasoning_effort": "none"` per request; or cap the reasoning with `thinking_token_budget` / `--thinking-token-budget` below `max_tokens` |
| `401` with `invalid api key` | The server was started with `--api-key` | Send `Authorization: Bearer KEY` (§6.6) |
First three things to run when a server will not start:
```sh
rad-info m.rad # is the container what you think it is?
radiance --model m.rad --debug-graph # does every op resolve?
rad-kbench --home $RADIANCE_HOME --max-cases 1 # are the kernels correct at all?
```
---
## 8. Environment
**Operator-facing**
| | |
|---|---|
| `RADIANCE_HOME` | where `kernels/`, `architectures/` and `quantizers/` live; a `:`-separated search path, the first home winning. Same as `--radiance-home` |
| `RADIANCE_KERNELS` | default kernel libraries, comma-separated. Same as `--kernels`, read by the engine *and* every tool, so a plugin validated with `rad-kbench` can be served without editing launchers |
| `RADIANCE_LOG` | `error` \| `warn` \| `info` \| `debug` \| `trace` |
| `ROCM_PATH` | where ROCm lives, if not `/opt/rocm` |
| `HF_TOKEN` | for `scripts/hfget.sh`, and `--model <owner/name>`, on a gated or private repo |
| `XDG_CACHE_HOME` | where `--model <owner/name>` fetches to without `--download-dir` (`$XDG_CACHE_HOME/radiance/hf`, else `~/.cache/radiance/hf`) |
**Tooling**
| | |
|---|---|
| `RADIANCE_TUNE` | pin a kernel's tunable axes instead of reading the tune cache — `op:key=value[,key=value][;op:...]`. For comparing tunings, not for deployment |
| `RADIANCE_CALIB_DIR` | where an engine run writes calibration data for a recipe's `gptq calib=DIR` |
| `RADIANCE_CALIB_TOKENS` | with `RADIANCE_CALIB_DIR`, the tokens the calibration tap accumulates before it writes and switches itself off (default 65536) |
| `RADIANCE_PROFILE_EVERY` | with `--profile-ops`, dump the per-op table every N steps (default 32) |
| `RADIANCE_LOG_STEPS` | log one line per step: its phase, sequences, and each one's token count and context (§4.5) |
There is also a family of instruments for engine development — `RADIANCE_DEBUG_*` (residual probes,
idle scrubs, routing and issue dumps), `RADIANCE_OP_ORACLE*` (named ops checked against `libref` on
the operands the model issued; `scripts/oracle.sh` drives it) and `RADIANCE_OP_REPEAT` (named ops
run a second time on the same inputs, to ask whether a kernel is a function of them). They are
instruments, not features; grep `getenv` if you need one, and read the comment beside it first.
`libr4d` keeps the same culture under `R4D_DIAG` (master switch for selection/store/hidden-state
traces), `R4D_VERIFY_ATTN` and `R4D_VERIFY_OFF` (device kernels recomputed on the host and diffed),
and `RADIANCE_TRACE_RESID` (an arch-side residual ring); all default off.
---
## 9. Further reading
| | |
|---|---|
| `spec.md` | the design, and it is binding. Start here for *why* |
| [TOOLS.md](TOOLS.md) | every flag of every tool, and the shell harnesses |
| [PLUGIN.md](PLUGIN.md) | writing a kernel plugin: exports, constraints, hooks, out-of-tree build |
| [OPS.md](OPS.md) | the conventional op vocabulary. Held to the registries by `ctest -R ops_doc` |
| [ARCHITECTURES.md](ARCHITECTURES.md) | per-architecture geometry, and the traps that stay plausible when they are wrong |
| [IMPLEMENTATION.md](IMPLEMENTATION.md) | layout, build and conventions for working on the engine |
| [KERNELS.md](KERNELS.md) | what `rad-kbench` last measured |
| [QSA.md](QSA.md), [MOE-W4.md](MOE-W4.md) | the sparse-attention indexer; the four-bit expert format |