radiance 1.14.0

New models and formats:
- libr3d: a kernel library for RDNA3 (gfx11) cards
- nomic-embed-text-v2-moe (the nomicbert plugin)
- Gemma 4 E2B with its per-layer MLP width, and Google's unmodified E2B/E4B directories in bf16
- DeepSeek-V4.1-Flash converted straight from its release: the Engram tables, the fused imatrix and
  rad-convert --chat-template for a release that ships no template
- GGUF Q8_0, Q4_K and Q6_K tensors import as their planes; rad-convert writes them without a recipe
- Qwen3.8-Flash-Next-FP8 converts and serves through qwen4exp_fp8

Speed:
- hc_read's decode kernels as one grid (34.7 -> 25.2 us at 4 rows) and its tiled up-mix pipelined
- gemm_fp8a8: the narrow form's scales staged through LDS (Flash-Next int8 at 32 rows 83.6 -> 68.3
  us), the gated three-tile form at 8 waves (gate_up at 48 rows 272.9 -> 180.6 us)
- Qwen3.8-27B: the delta net's out-projection read beside its decode recurrent update (x1 19.40 ->
  19.10 ms a step), and the verify's split-KV attention sized by context depth (x3 at 180K 42.4 ->
  40.3 ms a step)
- Hy-Memory (HYV3) decode: fused QK norm, RoPE and KV store, residual adds folded into the norms,
  coalesced one-token expert GEMMs
- spechub: the coupled verify walks the live candidates only (151 -> 31 us a launch)

Speculation:
- DFlash2: lossless coupled acceptance at T > 0 (--draft-coupling on)
- A block drafter's proposals verified as a tree, on by default for the Gemma 4 31B's DFlash2, with
  a block-16 tree that runs its short block under load

Features:
- Decode-hot residency: --draft-expert-placement host, --expert-profile, --expert-pin-top, and
  --expert-stats FILE for the routed experts each layer selects
- --ngram-placement ram=DIR: one n-gram table shared by engines on separate cards
- Prefix cache: --prefix-resume exact (default) resumes a hit on the cold run's own chunk grid, so it
  answers bit-identically; snapshots at a head other prompts share, from 528-token prompts, and for
  tip-only one drafter window below the tip; hits on models whose KV groups have different block
  sizes; the snapshot store keeps a floor of 8 ahead of --host-headroom-mib
- Typed tool-call argument tags; rad-chatparse --request renders and reads back one request as the
  server does
- MiniMax-H3: keyframes ride a latent upscale
- Gemma 3's fused all-reduce junction on the lossy wire

Fixes:
- A speculative step shorter than its band (an MTP step of 4 rows at gqa 8) no longer stops the
  engine with a scratch refusal at issue (#293)
- --p2p off: prefill back to 1.12.0's rate; 1.13.0's push check read a host-memory slot over the link
  twice (#323)
- A chat template that cannot render a conversation is refused at load, not mid-request
- imatrix entries found under llama.cpp's spelling; the W4A8 prefill's tail scale read; the GDN conv
  kernels on an f32 weight; dense integer rows at the group they compute (a Q8_0 weight at group 32)
- --expert-profile refuses a profile recorded on another model
- hc_read's one-grid wait traps past its deadline instead of reading a stale value

Changes: Plugin ABI 31, unchanged. RADIANCE_DRAFT_TREE, DFLASH2_TREE_NODES, DFLASH2_TREE_TEMP and
DFLASH_Q_TEMP are gone (trees run where the probe says they pay; temperatures 1.25 / 0.6).
This commit is contained in:
Deadcode committed 2026-10-29 12:04:24 +01:00
1 parent 481fcd5df0
commit 4a61d7296b
160 files changed
+8790 -6819

No files matched your search

+27 -18
View File
@@ -16,7 +16,7 @@ plugin claims.
| `arch/hyv3_gguf` | `hyv3` | `gguf_ftype_15` | llama.cpp Hy-Memory Q4_K_M GGUF, dequantized and recipe-converted to native Radiance weights; TP1/2 |
| `arch/qwen35_w8a8` | `qwen35` | `w8a8_fwht128` | `qwen35_fp8` with an int8 trunk: i8 weights with a bf16 scale per 128 of K, rotated by a 128-wide Hadamard, against int8 activations under the same rotation (`data/recipes/q38-27b-w8a8-df2.recipe`) |
| `arch/qwen35moe_fp8` | `qwen35moe` | `fp8_e4m3` | `qwen35_fp8` with the feed-forward routed |
| `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert |
| `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert, or Qwen's FP8 release as it ships |
| `arch/glm5next` | `glm5next` | *(empty)* | GLM-5.3-Flash from AMD's Quark MXFP4 export: four mHC residual streams over 34 KDA and 11 sparse latent-attention (MLA) layers with a DSA indexer, 288 MXFP4 experts at top-8 under sigmoid routing, block-FP8 attention and dense layers at f32 scales, each weight served as stored; its MTP layer is a serial drafter. Pictures through its vision tower (`arch/common/rad_block_glm_vision.h`); bf16 KV |
| `arch/lfm2_bf16` | `lfm2` | *(empty)* | LiquidAI's LFM2 and LFM2-VL, bf16, one rank |
| `arch/embgemma2` | `embeddinggemma2` | *(empty)* | EmbeddingGemma 2: a bidirectional encoder with Gemma 4's vision tower and audio conformer, pooled to one vector |
@@ -345,8 +345,11 @@ Architecture tests cover geometry, GGUF tensor maps, dense-to-MoE scheduling, TP
and FP32 combine order; checkpoint tests cover Q4_K/Q6_K block decoding. Numerical parity against Tencent/llama.cpp
remains untested.
See [HYV3 W4 decode optimizations](benchmarks/hyv3-w4-decode.md) for affected paths,
historical measurements, validation limits and the remaining benchmark/quality gates.
Decode on the full-GPTQ W4 model, TP1 on one R9700 (10,030-token prompt, 2,000 generated tokens,
greedy, no drafter): 76.6 tok/s before the per-128 I4 expert packing, the one-row W4/W5 epilogue,
the in-GEMM BF16 narrowing, the fused Q/K norm + RoPE + KV store and the residual and shared-expert
folds; 109.6 tok/s with them, prefill unchanged (7,876 to 7,927 tok/s). The answer is byte-identical,
and on an eight-document teacher-forced corpus the two builds agree at every top-1 (mean KL 7.6e-8).
## `qwen35_w8a8`
@@ -415,6 +418,13 @@ plugin reads each weight's encoding from the container and declares the op that
- bf16: every norm gain, `A_log`, `dt_bias`, `conv1d`, `in_proj_a` and `in_proj_b` (48 rows is not
a whole scale block), the router, `shared_expert_gate` and `embed_tokens`.
Qwen's own `Qwen3.8-Flash-Next-FP8` converts without a recipe too. Its `quantization_config`
(`quant_method: fp8`, no `fmt`) is block-scaled E4M3, descriptor `fp8_e4m3`; no `qwen4exp` plugin
claims it, so each weight is read as it ships and this plugin serves it: the routed experts (MTP
head's included) at block FP8 with their bf16 `weight_scale_inv`, the n-gram table's 128 FP8
shards under its one `ngram_embedding.weight_scale`, and every other weight bf16. A recipe applies
to it as to the bf16 checkpoint, with each FP8 weight read through its scales.
**The attention cache takes `--kv-cache-dtype fp8_v4` or `k6_v4`.** The QSA layers' cache (and the
MTP head's layer, which shares it) is then declared at head_dim 200 or 176, a token's quantised row
over two, and read by the gqa12 rows (gqa6 with 4-token pages at four ranks) of those layouts
@@ -872,9 +882,9 @@ text 12 layers, hidden 768, ffn 3072, vocab 250048, 12 heads of 64, type vo
mean over every real token, cast to the f32 pooled buffer; the server L2-normalises
```
The block order is the one the verified variant uses: attention on the raw stream, then LN1, the
feed-forward on LN1's output, then LN2 over that output plus the feed-forward's. The checkpoint's
shared `experts.bias` is not applied, and the plugin does not map it. A container that sets
Block order: attention on the raw stream, then LN1, the feed-forward on LN1's output, then LN2
over that output plus the feed-forward's. The checkpoint's shared `experts.bias` is not applied,
and the plugin does not map it. A container that sets
`prenorm`, `causal`, interleaved, partial or scaled rotary, a gelu variant, renormalised routing
or a shared expert is refused at declare.
@@ -895,10 +905,10 @@ reads a bf16 table. The token embedding, linears, router and expert tables are b
| `blk.N.ffn_exp_w2.E.weight` (odd N) | `encoder.layers.N.mlp.experts.mlp.w2` | [768, 3072] | slice E, transpose |
| not declared (odd N) | `encoder.layers.N.mlp.experts.bias` | [768] | not mapped |
The checkpoint stores `w1` and `w2` as one stacked tensor each, `[24576, 768]`; `E` takes the
expert's dim-0 slice, and `w2` is transposed to `[768, 3072]` for the grouped GEMM. Every expert
has two group slots, one for each projection. Nothing else is mapped: there is no final norm, no
pooler, no position table and no output head.
The checkpoint stores `w1` and `w2` as one stacked tensor each, `[24576, 768]`; expert `E` is rows
`[E * 3072, (E + 1) * 3072)`, and `w2`'s block is transposed to `[768, 3072]` for the grouped GEMM.
Every expert has two group slots, one for each projection. Nothing else is mapped: there is no
final norm, no pooler, no position table and no output head.
**The recipe.** The checkpoint is f32 (1.9 GB).
@@ -907,15 +917,14 @@ rad-convert <checkpoint dir> --recipe data/recipes/nomic-embed-v2-moe-bf16.recip
-o nomic-embed-v2-moe-bf16.rad
```
It takes 3.5 s and writes a 959 MB container (907 MiB of weights). The checkpoint directory must
contain `tokenizer.json`. The recipe casts the token embedding, the token-type table, the
attention, dense MLP and expert weights to bf16 and leaves the norms and biases f32.
It writes a 959 MB container (907 MiB of weights). The checkpoint directory must contain
`tokenizer.json`. The recipe casts the token embedding, the token-type table, the attention,
dense MLP and expert weights to bf16 and leaves the norms and biases f32.
**Verified.** 20 texts against a pure-float32 reference: mean cosine 0.99995, min 0.99983 on a
gfx1201 card, with libavx and libref the same to 4 decimals. Against a Q6_K quantisation of the
same model the mean is 0.9944 (min 0.990); the Q8_0 one agrees with the reference at 0.9994, so
the Q6_K quantisation is the outlier, about 0.006 off the true model, and stored vectors from a
Q6_K server drift by about that much.
**Verified.** On 20 texts against a pure-float32 reference, on a gfx1201 card: mean cosine
0.99995, min 0.99983; libavx and libref agree with it to 4 decimals. Against the same reference a
Q8_0 quantisation of the model scores a mean of 0.9994 and a Q6_K one 0.9944 (min 0.990), so
vectors stored from a Q6_K server differ by about 0.006.
**Measured.** On one gfx1201 card, short texts take 2 ms a request at one client, 3854 requests/s
at 64 concurrent clients and 4400 texts/s for a batch of 32 in one request; a 1354-character text
+96 -46
View File
@@ -52,7 +52,7 @@ driver. [`DOCKER.md`](DOCKER.md) covers it, with compose files per model.
| Optional | ROCm with `hipcc`, for AMD device kernels; without it you get the host backend. Set `ROCM_PATH` if ROCm is not at `/opt/rocm` |
| With a card | Resizable BAR on (Above 4G Decoding and Resizable BAR in the firmware setup). The host writes every dispatch's arguments into VRAM there. On a card whose BAR is smaller than its VRAM they stay in pinned host memory and every dispatch reads them over the link: on R9700s, Qwen3.8-27B fp8 decode steps take 0.4-1.8% longer at `--tp 1` and 2 than with the arguments in VRAM. Peer access needs the large BAR too, so at `--tp 2` and above such a card takes the collectives through host memory (§4.7) |
| Optional | OpenMP, used by the host kernel libraries if present |
| Optional | `libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libswresample-dev` (ffmpeg 6+), for image, video and audio input. The probe is `RAD_WITH_FFMPEG` (`ON` fatal, `OFF` off, default `AUTO`): built without them the engine boots normal, serves text, and refuses every image/video/audio part with HTTP 500 — the configure log is the only warning (`radiance: no libavformat ...`). `GET /diagnostics` shows `media decoders` |
| Optional | `libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libswresample-dev` (ffmpeg 6+), for image, video and audio input. CMake option `RAD_WITH_FFMPEG`: `AUTO` (default) uses them when found, `ON` fails the configure without them, `OFF` builds without. A build without them starts and serves text, and refuses every image, video and audio part with HTTP 500; the only warning is the configure log line `radiance: no libavformat ...`. The diagnostics report says which (`media decoders`; `host.media` in `GET /diagnostics`) |
| Optional | `clang++` (or ROCm's), for `tests/r4d_emu` when the C++ compiler is g++; CMake 3.25+ for `CMakePresets.json` |
| Shell harnesses | `curl` and `jq` |
@@ -93,10 +93,10 @@ cmake --build build -j
ctest --test-dir build -L fast -j8 --output-on-failure
```
A ROCm SDK installed outside `/opt/rocm` — a userspace SDK tree under a virtualenv, a core-only
system install — needs more than `ROCM_PATH`: hipcc is found, then device compilation dies inside
`cuda_wrappers/cmath` with `Could not find standard C++ header 'cmath'`, because ROCm's clang
does not pick up the distro gcc's libstdc++ headers on its own. The flags that make it work:
A ROCm SDK installed outside `/opt/rocm` (a userspace SDK tree under a virtualenv, or a core-only
system install) needs more than `ROCM_PATH`. hipcc is found, but device compilation fails inside
`cuda_wrappers/cmath` with `Could not find standard C++ header 'cmath'`, because ROCm's clang does
not pick up the distro gcc's libstdc++ headers on its own. Configure with:
```sh
ROCM=/path/to/_rocm_sdk_devel # the SDK root (the venv's site-packages/_rocm_sdk_devel)
@@ -108,11 +108,11 @@ cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
export LD_LIBRARY_PATH=$ROCM/lib:$LD_LIBRARY_PATH
```
`--gcc-install-dir` takes the distro gcc's directory (the installed gcc-15's; after a distro gcc
upgrade it must be repointed, and the configure cached in `build/CMakeCache.txt` reset with
`-c`). The device-lib path is where the SDK tree keeps `amdgcn/bitcode` (under `lib/llvm/` in a
userspace SDK, `$ROCM/amdgcn/bitcode` in a core system install). The flags are not needed for a
full `/opt/rocm` install, and `DOCKER.md`'s container sidesteps them.
`--gcc-install-dir` is the distro gcc's directory (gcc 15 in the example). After a gcc upgrade,
repoint it and reset the configure cached in `build/CMakeCache.txt` (`-c`). The device-lib path is
where the SDK keeps `amdgcn/bitcode`: under `lib/llvm/` in a userspace SDK, `$ROCM/amdgcn/bitcode`
in a core system install. A full `/opt/rocm` install needs none of these flags, and the container
in `DOCKER.md` avoids them.
### 1.3 Check that it works
@@ -368,7 +368,7 @@ planes, with the tokeniser and chat template.
**A recipe decides what is quantised**, in rules from weight names to quantisers. Without one,
every weight keeps the checkpoint's encoding, which suits a bf16 or block-fp8 checkpoint served at
its own precision. Flash-Next's four-bit experts need one:
its own precision (Qwen3.8-Flash-Next-FP8 included). Flash-Next's four-bit experts need one:
```sh
rad-convert /srv/models/Qwen/Qwen3.8-Flash-Next -o /srv/models/rad/flashnext-w4.rad \
@@ -835,6 +835,22 @@ for the gather (no libr4d) the table is read on the host: `vram` is refused, and
locked huge pages, which also needs a memlock limit that large (`--ulimit memlock=-1` in Docker,
`LimitMEMLOCK=infinity` under systemd).
`--ngram-placement ram=DIR` makes the pinned copy a file, `DIR/ngram-<id>.tab`, in a tmpfs, mapped
`MAP_SHARED` and pinned for the cards as `ram` pins it, so two engines on separate card sets
(`ROCR_VISIBLE_DEVICES`) hold one table in host memory. The first engine to start fills the file
from the container; a second finds it complete, checks samples of it against its own container and
only pins it. The `<id>` is a hash of the container's path, size and mtime and the table's place in
it, so a file never serves another model. A weight under 32 MiB the gather reads beside the table
(its scale) keeps a private pinned copy, since its file would be mostly header. The engine that
leaves last deletes the file, and one that leaves while another still holds it waits up to a second
for it, so two engines stopped together still remove it; after a crash a complete file stays and is
reused, or removed by hand. `DIR` must be a tmpfs (`/dev/shm`, or a tmpfs mounted for it, sized for
the table); `ram=DIR` needs the card gather kernel and the driver's SVM API, and is refused
otherwise. The driver counts a shared page against every process that pins it, so with two engines
the pinned total is twice the table: set `amdgpu.no_system_mem_limit=1` (the cap is RAM less 1/64
and 1.5 GiB) or the second pin can be refused. The kernel charges the tmpfs pages to the memory
cgroup of the engine that filled them.
**`--weights-disk-tier`** serves a model larger than the card and the host pool together, with every
step paced by the drive. A routed expert that fits neither lives only in the container. Before each
routed layer's first expert op, on every pass, the engine reads all that layer's on-disk experts into
@@ -1193,30 +1209,32 @@ snapshot lets it skip at least 256 tokens of that head, the request takes one wh
ends, at the cost of one chunk split, and the requests after it resume there. A conversation's
next turn has only its own earlier turn past that point, so it splits nothing extra.
A prefix hit answers exactly as the same prompt prefilled cold, by default
(`--prefix-resume exact`). A kernel can round a row differently at another chunk
length (the fp8 GEMM's split-K count is chosen from `M`, spec §17), so a hit that
recomputes its tail in other chunks than a cold prefill can flip a near-tie in
greedy text. The hit therefore resumes only where an idle server's cold prefill of
that prompt starts a chunk: every `--max-num-batched-tokens` tokens (rounded down
to the chunk quantum), or every `--checkpoint-interval` when that is smaller. A
prompt's tail snapshot is taken where its last chunk starts, a boundary the chunk
already ends on, so it costs a copy and no step. An exact repeat re-prefills the
cold run's last chunk; an appended turn, that chunk and what the turn added: up to
one chunk more than `--prefix-resume nearest`, which resumes at the deepest
snapshot or block and splits a prompt's last chunk at its last quantum boundary.
The interval must be a multiple of the chunk when it is larger; otherwise it is
rounded up, and startup says so:
**Where a hit resumes** (`--prefix-resume`). A kernel can round a row differently at another
chunk length (the fp8 GEMM's split-K count is chosen from `M`, spec §17), so a hit that recomputes
its tail in other chunks than a cold prefill can flip a near-tie in greedy text. Two modes:
- `exact` (the default): a hit answers exactly as the same prompt prefilled cold. It resumes only
where an idle server's cold prefill of that prompt starts a chunk: every
`--max-num-batched-tokens` tokens (rounded down to the chunk quantum), or every
`--checkpoint-interval` when that is smaller. A prompt's tail snapshot is taken where its last
chunk starts, a boundary the chunk already ends on, so it costs a copy and no step. An exact
repeat re-prefills the cold run's last chunk; an appended turn re-prefills that chunk and what
the turn added.
- `nearest`: a hit resumes at the deepest snapshot or block, and a prompt's tail snapshot is at
its last quantum boundary. A turn re-prefills up to one chunk less than under `exact`.
Under `exact` an interval larger than the chunk must be a multiple of it; otherwise it is rounded
up, and startup says so:
```
--checkpoint-interval 6144 resolves to 8192: --prefix-resume exact needs it a multiple of the
4096-token prefill chunk (--max-num-batched-tokens 4096) ...
```
It is an idle-server property, as greedy batching is: a prefill that shares its
steps with other requests or decode rows (`--busy-prefill-chunk`,
`--prefill-interleave`) is cut differently, and a request's own checkpoint
(`/v1/systemone`'s shared head) resumes where it was asked.
Exactness holds on an idle server, as greedy batching does: a prefill that shares its steps with
other requests or decode rows (`--busy-prefill-chunk`, `--prefill-interleave`) is cut
differently, and a request's own checkpoint (`/v1/systemone`'s shared head) resumes where it was
asked.
**One prefill sequence in two pieces.** At two ranks, on `qwen35_fp8` (and `qwen35_w8a8`, built
from it, where its norms do not write rotated int8 codes) and on `gemma3`'s MXFP4 trunk with the
@@ -1296,10 +1314,15 @@ head inside the target checkpoint, which needs no flag. `radiance --draft-model`
says so. Measure speculation by 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 after a prefix hit it cannot draft until its window has slid past the hit, which on a
chat's follow-up turn is most of the reply. Such a hit is therefore ended one drafter window before
the end of the prompt, at a checkpoint, and the window is recomputed; the reply is the same. A hit
whose nearest checkpoint below that point would give back more than two windows is kept whole.
cache. Where a hit resumes from a window snapshot (a model whose sliding layers the cache does not
index and that keeps no linear state, as the Gemma 4 31B under gemma4_bf16; the 26B-A4B declares
its sliding layers full and takes no snapshot), the snapshot carries the drafter's window with the
trunk's, so the hit leaves it whole and it drafts from the first decoded token. Elsewhere (a
model with linear state, as Qwen3.8), after a prefix hit it could not draft until its window had
slid past the hit, which on a chat's follow-up turn is most of the reply. Such a hit is therefore
ended one drafter window before the end of the prompt, at a checkpoint, and the window is
recomputed; the reply is the same. A hit whose nearest checkpoint below that point would give back
more than two windows is kept whole. The startup line `draft floor` says which applies;
`radiance:draft_refills_total` counts the hits ended early and `radiance:draft_refill_tokens_total`
the tokens recomputed.
@@ -1332,14 +1355,31 @@ behind the packet processor's barrier bit, which saves most of the launch gap be
kernels. The bytes are the same. Plain decode measured slower with them, so they stay off there
and on every other model; the startup report's `chained launches` row says which and why.
**Draft trees.** Where the model's plugin measured a gain (the Gemma 4 31B with DFlash2: +7%
single-stream decode and +6-9% aggregate at 1-16 users on 4x R9700, +4% and +6-12% on two,
BetterBench with thinking off), a block drafter's proposals are verified as a tree: grown best-first
over the drafter's candidates, the deepest path the target agrees with is accepted, and its K and V
move into place. A tree changes no token, only how many drafts land a step; the startup report's
`draft trees` row says when it is on. Under a tree `--num-speculative-tokens` counts the tree's
nodes, grown over the block the drafter was trained at. A request with a grammar (`response_format`,
tools) speculates on a tree too: each row is masked against the grammar after its own ancestors.
`--draft-coupling on` samples one path, so a coupled drafter proposes the chain.
**A shorter block under load: `--draft-short-from N`.** A block drafter's block is paid for by
every drafting sequence, whatever each one verifies. At one sequence a long block pays; at many, its
drafter rows and its weaker first positions cost more than the extra drafts bring. A drafter that also
serves a shorter block declares it (PLUGIN.md §11); DFlash2 declares a block of 4 (3 drafts) wherever its
own is longer, on `qwen35_fp8` and `gemma3`. With `--draft-short-from N` the engine runs that short block
once N sequences decoded in the step just run, and the drafter's own block again only once the count
falls two below N, so a load wavering at N does not change the pass shape every step. `0`, the default,
never switches. Startup names what it will run:
own is longer, on `qwen35_fp8` and `gemma3`, and the Gemma 4 31B's block-16 DFlash2 drafter, as a tree of
15 nodes, a block of 8 (a 7-node tree over it). With `--draft-short-from N` the engine runs that short block
once N sequences decoded in the step just run, and the drafter's own block again once the count
falls two below N or to one sequence, where the long block pays. From N of 3 on, a load wavering at
N does not change the pass shape every step; at 2, a load between one and two sequences does, which
costs only the other shape's pass. `0` never
switches. `auto`, the default, never switches a chain and switches a tree drafter
from 2: a tree's nodes are verify rows every drafting sequence pays for, which a wide tree's extra nodes
repay at one sequence and not at many; it switches back at one decoding sequence. At the short block the
drafter grows a tree of its own over the shorter pass, at most `block - 1` nodes. Startup names what it
will run:
```
speculation: from 16 decoding sequences on, 'dflash2' runs its short block of 4 row(s), 3 token(s)
@@ -1572,6 +1612,17 @@ hit. Snapshots never take VRAM: each is copied to host memory after the step tha
back before the step that resumes from it. `/sessions` shows what is stored, where, and whether the
linear half is served.
On a model with sliding-window layers and no linear state (Gemma 3, and the Gemma 4 31B as gemma4_bf16
declares it), the cache does not
index the sliding layers, so a hit resumes only from a window snapshot, taken a block short of a
prompt's end, where the next turn's rendering still agrees. Under `--prefix-resume nearest` one is
taken at the end of every prompt of 528 tokens or more (with `--checkpoint-interval` under 512,
from that interval plus a block). Under `exact` it is taken at the start of the prompt's last
chunk, once that lies at least one checkpoint interval in, so a conversation whose prompts stay
under one prefill chunk reuses nothing there; serve such a model with `--prefix-resume nearest`
where short chats matter more than bit-identical hits. A shorter prompt is recomputed: its
prefill is cheap, and its snapshot would take a slot from a longer conversation.
**How many snapshots.** The snapshot store (`--checkpoint-slots`) is shared by every conversation,
running or not, and a conversation without a snapshot under its next prompt reuses nothing. With
`auto`, the default, each of `--max-num-seqs` gets what `--checkpoint-policy` keeps for one
@@ -1987,7 +2038,7 @@ by 0.002-0.003 nats.
| `--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 |
| `--prefill-span N` | 1 | checkpoint intervals one step may carry of a prefill alone in its step, from the prompt's second interval on; needs `--max-num-batched-tokens` of N intervals. Every other step is planned at the budget less the extra intervals, and the checkpoints inside a span are not written (§4.5) |
| `--checkpoint-slots N` | auto | linear-state (hybrid) or sliding-window snapshots the server may hold at once, in total, not per sequence. They live in pinned host memory, allocated at startup: one slot is a snapshot of every rank's shard (113 MB on Flash-Next at `--tp 2`, 144 MiB on Qwen3.8-27B; on Gemma 4 31B the 1024-token window of every sliding layer, 406 MiB at `--tp 2`). `auto` gives each of `--max-num-seqs` what `--checkpoint-policy` keeps for a `--max-model-len` session plus one (10 at 200K tokens under geometric backoff), within an eighth of host memory and what the host can pin; a floor of 8 (or what the policy wants, if fewer) outranks `--host-headroom-mib`, which gives back exactly the shortfall down to 1 GiB rather than take the store to none, and the startup line says so. The startup line and the report say what it chose and why (§4.8). A full store retires its least recently used snapshot. A count is taken as given: a store the host memory cannot hold or pin stops the start, and a table placed in host memory leaves room for it; `0` serves with none, every prefix hit then prefilling from the start |
| `--checkpoint-slots N` | auto | linear-state (hybrid) or sliding-window snapshots the server may hold at once, in total, not per sequence. They live in pinned host memory, allocated at startup: one slot is a snapshot of every rank's shard (113 MB on Flash-Next at `--tp 2`, 144 MiB on Qwen3.8-27B; on Gemma 4 31B the 1024-token window of every sliding layer, 406 MiB, and with its DFlash2 drafter that drafter's 2048-token window too, 487 MiB). `auto` gives each of `--max-num-seqs` what `--checkpoint-policy` keeps for a `--max-model-len` session plus one (10 at 200K tokens under geometric backoff), within an eighth of host memory and what the host can pin; a floor of 8 (or what the policy wants, if fewer) outranks `--host-headroom-mib`, which gives back exactly the shortfall down to 1 GiB rather than take the store to none, and the startup line says so. The startup line and the report say what it chose and why (§4.8). A full store retires its least recently used snapshot. A count is taken as given: a store the host memory cannot hold or pin stops the start, and a table placed in host memory leaves room for it; `0` serves with none, every prefix hit then prefilling from the start |
| `--checkpoint-policy NAME` | geometric-backoff | also `tip-only`, `keep-all` |
| `--prefix-resume MODE` | exact | `exact`: a prefix hit resumes only where an idle server's cold prefill of the prompt starts a chunk, and a prompt's tail snapshot is taken where its last chunk starts, so a hit answers bit-identically to a cold run; an interval past the chunk is rounded up to a multiple of it. `nearest`: the deepest snapshot or block, up to a chunk less re-prefilled a turn |
| `--no-prefix-cache` | prefix cache on | disable prefix caching |
@@ -2009,8 +2060,8 @@ by 0.002-0.003 nats.
|---|---|---|
| `--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-short-from N` | 0 | a block drafter that declares a shorter block runs it from N decoding sequences on, its own block again two below; 0 never (§4.6) |
| `--draft-coupling MODE` | off | `on`: a linear MTP drafter with a 2-bit candidate head (Qwen3.8-Flash-Next) samples each proposal from its reranked top-8 and the sampler maximally couples the target's draw to it. The output distribution is unchanged and a fixed seed yields other tokens than `off`. The head's law is taken at temperature 1, so it pays at high request temperatures and costs at low ones: on Flash-Next TP2 at 2x R9700, tokens per decode step +18% at temperature 1.0 and c1, +11% at 0.7 and c4, -4% at 0.3. Greedy rows are unchanged. A DFlash2 drafter (Qwen3.5/3.8) couples its candidate walk instead: each position is sampled from the softmax of the walk's own scores over its best eight candidates, at temperature `RADIANCE_DFLASH_Q_TEMP` (default 0.6, where acceptance peaked); on Qwen3.8-27B MXFP4 TP2 at 2x R9700 and request temperature 1, tokens per verify step +8% on held-out prompts at c4 (3.53 to 3.82) and decode +2..8% per stream at c1/c4. Any other drafter is refused at startup |
| `--draft-short-from N` | auto | a block drafter that declares a shorter block runs it from N decoding sequences on, its own block again two below or at one sequence; 0 never; auto never for a chain and 2 for a tree drafter, which then verifies the short block's nodes (§4.6) |
| `--draft-coupling MODE` | off | `on`: a linear MTP drafter with a 2-bit candidate head (Qwen3.8-Flash-Next) samples each proposal from its reranked top-8 and the sampler maximally couples the target's draw to it. The output distribution is unchanged and a fixed seed yields other tokens than `off`. The head's law is taken at temperature 1, so it pays at high request temperatures and costs at low ones: on Flash-Next TP2 at 2x R9700, tokens per decode step +18% at temperature 1.0 and c1, +11% at 0.7 and c4, -4% at 0.3. Greedy rows are unchanged. A DFlash2 drafter (Qwen3.5/3.8) couples its candidate walk instead: each position is sampled from the softmax of the walk's own scores over its best eight candidates, at temperature 0.6 (where acceptance peaked); on Qwen3.8-27B MXFP4 TP2 at 2x R9700 and request temperature 1, tokens per verify step +8% on held-out prompts at c4 (3.53 to 3.82) and decode +2..8% per stream at c1/c4. Any other drafter is refused at startup |
| `--draft-model PATH` | | not implemented: merge the drafter at convert time |
**Server**
@@ -2304,12 +2355,11 @@ returns the text as both `prompt` (vLLM) and `content` (llama-server).
completions and chat answer 501. One input is one vector and must fit one step
(`--max-num-batched-tokens`); a longer one is refused with `context_length_exceeded`.
nomic-embed-text-v2-moe is converted from its f32 checkpoint with `rad-convert <checkpoint dir>
nomic-embed-text-v2-moe converts from its f32 checkpoint with `rad-convert <checkpoint dir>
--recipe data/recipes/nomic-embed-v2-moe-bf16.recipe -o nomic-embed-v2-moe-bf16.rad` (959 MB);
the directory must contain `tokenizer.json`. The `search_query: ` and `search_document: ` prefixes
are the client's text and the engine adds neither; the checkpoint's prompt names work through
`prompt_name`. The checkpoint's shared `experts.bias` tensors are not applied and stay in the
checkpoint.
the directory must contain `tokenizer.json`. The engine adds neither the `search_query: ` nor the
`search_document: ` prefix: the client sends it, or names the checkpoint's prompt with
`prompt_name`. The checkpoint's shared `experts.bias` tensors are not applied.
```sh
# text, a batch of texts, or token ids
@@ -3592,7 +3642,7 @@ is the part of a log to paste into an issue. Its sections:
warning is also printed as a `W` line of its own.
```
I STARTUP REPORT -- radiance 1.13.0
I STARTUP REPORT -- radiance 1.14.0
I CONFIGURATION -- every option, the value in force, and where it came from
I --model /models/flashnext.rad [command line]
I --tp 2 [command line]
+31 -2
View File
@@ -464,7 +464,25 @@ at h128/gqa8 up to q_len 16 by reading each kv head for two query groups of 4 (a
then holds each kv head once). Since no host library declares the op, a plugin that asks for it
learns whether a card serves the geometry.
libref has no row for any of them, deliberately. An architecture asks for a fusion and declares
Tree verification (`rad_drafter_tree`, abi/rad_builder.h) adds one operand to both: the step's
`RadBatch::spec_parent`, `[rows]` i32.
| op | params | operands |
|---|---|---|
| `attn_paged_tree` | `q_len`(range) `head_dim` `gqa` `block_size`/der `causal` `window` `q_dtype` `kv_dtype` `scale`:f64/opt `max_ctx`/opt `n_head`/opt `max_seqs`/opt `prefill_fp8`/opt | `q`, `kv_cache`, `block_table`, `seqused`, `k_descale`?, `v_descale`?, `cu_seqlens`? → `out`; `spec_parent` |
| `attn_paged_qrow_tree` | `q_len`(range) `head_dim` `gqa` `block_size`/der `causal` `window` `q_dtype` `kv_dtype` `scale`:f64/opt `max_ctx`/opt `n_head`/opt `max_seqs`/opt `prefill_fp8`/opt | `q`, `kv_cache`, `block_table`, `seqused`, `k_descale`?, `v_descale`?, `cu_seqlens`? → `out`; `spec_parent` |
A row whose `spec_parent` is -2 is an ordinary causal row. Any other row is a node of its sequence's
verify block, and its entry names its parent by row within the sequence's rows (`cu_seqlens`), -1
for the block's first row, every parent before its child. Inside the block (keys from
`seqused - q_len` on) such a row sees itself and its ancestors only; before it, every key as an
ordinary row does, except that a window is measured from the block's first position plus the row's
depth, the position its token takes once its path is committed. Causal layers only. libref serves
`attn_paged_tree`; libr4d `attn_paged_qrow_tree` at h256/gqa2 on the split-KV decode kernel and at
every geometry of the windowed kernels, to 64 rows a block.
Of the ops above, libref serves only `attn_paged_tree`, which is not a fusion but `attn_paged`'s
tree form. It has no row for any of the fusions, deliberately. An architecture asks for a fusion and declares
the chain where it does not resolve (`rad_op_resolved`); a reference row would make it resolve
everywhere, so a model loaded without the serving library would resolve to the reference and be
refused at serve, instead of running the chain on libr4d or libavx. libr4d declares them with
@@ -2728,7 +2746,7 @@ greedy request's row (draw mode 0) keeps `dflash_select`'s tokens (`status = 0`)
another card, or a position whose eight cannot form a `Q`, takes the walk's argmax (`status = -1`)
and the ordinary verify. `Q_l` depends on the committed text and on `x_0 .. x_{l-1}`, never on the
verify, and is stored exactly, which is all the coupling needs to be lossless; `q_temp` (the
architecture's, `RADIANCE_DFLASH_Q_TEMP` on Qwen3.5/3.8) moves acceptance only. Each edge is eight
architecture's, 0.6 on Qwen3.5/3.8) moves acceptance only. Each edge is eight
partial `fmaf` chains over contiguous slices of the rank, added in order, so the device kernel and
the host oracle agree bit for bit.
@@ -3194,6 +3212,17 @@ candidates, and what enters the head from the trunk.
| op | params | operands |
|---|---|---|
| `dflash_select` | `M` `steps` `top_k` `rank` `n_vocab` `anchor_stride`/opt `dtype` | `cand`, `unary`, `hp`?, `anchor`, `pred`w, `succ`w → `tokens` |
| `dflash_tree` | `M` `steps` `top_k` `rank` `n_vocab` `anchor_stride`/opt `nodes` `temp`:f64/opt `dtype` | `cand`, `unary`, `hp`?, `anchor`, `pred`w, `succ`w → `tokens`, `parents` |
`dflash_tree` grows the same lattice into a tree of `nodes` nodes instead of walking one path
(`rad_drafter_tree`). Node 0 is the anchor at lattice position -1 with log probability 0. A node at
position l with token t has a child for every candidate c at l + 1 whose id is in the vocabulary,
scored as `dflash_select` scores c after t; with x = score / `temp` (default 1) over those
candidates, the child's log probability is its parent's plus x - logsumexp(x). Best-first: each
round takes the not-yet-taken child of a taken node with the largest log probability, ties to the
one pushed first (lower parent, then lower c), until `nodes` are taken. Taken node j (1-based, so
every parent comes before its child) is `tokens[s, j-1]`, and `parents[s, j-1]` its parent's node
index, 0 for the anchor. A frontier that runs dry pads with token 0 under the last node.
`dflash_conv` is the drafter's grouped convolution (coefficient add and every tap in one pass):
+4 -3
View File
@@ -388,9 +388,10 @@ says so with `RAD_ARCH_SERVES_IMPORTS(0)` (`qwen35_w8a8` does), and imports keep
- **A block drafter may serve a shorter block.** `rad_drafter_short_block(b, block)`, called once
after `rad_declare_drafter`, says the plugin declared its query pass at `block` rows a sequence as
well as at `RadDrafterDecl::block`, with the same anchor convention, so the core may stage a step
at either; the short block proposes `block - (RadDrafterDecl::block - depth)` tokens. The builder
refuses it without a block drafter, at or above the drafter's own block, and where it would
propose nothing. The engine runs it under `--draft-short-from` (GUIDE §4.6) and reads row `s` of
at either; the short block proposes `block - (RadDrafterDecl::block - depth)` tokens. A tree
drafter (`rad_drafter_tree`, called first) grows a tree of its own over the shorter pass, at most
`block - 1` nodes, and its short block needs only 2 rows. The builder refuses it without a block
drafter, at or above the drafter's own block, and where it would propose nothing. The engine runs it under `--draft-short-from` (GUIDE §4.6) and reads row `s` of
the proposals at `s * proposal_pitch`; a block drafter's `proposal_pitch` defaults to its
depth (a row holds the whole block's proposals and a short block fills its front) and is refused
below it. The pass's block is `n_tok / n_seq`; a block the plugin has no ops for should fail the
+5 -4
View File
@@ -191,10 +191,11 @@ drops blocks.
## Checking
There is deliberately no switch that forces dense attention above the bound, where it is not the
model the checkpoint was trained as. libref implements all five QSA ops — `ref_qsa_block_key`,
`ref_qsa_score`, `ref_qsa_select`, `ref_qsa_tail_store`, `ref_qsa_work` (`libref/ref_qsa.cpp`) — so
each device kernel has a row to compare against; what no oracle gives is the whole-subsystem
comparison, a dense run against a sparse one above the bound. Changes are checked with:
model the checkpoint was trained as. libref implements all five QSA ops (`ref_qsa_block_key` in
`libref/ref_attn.cpp`; `ref_qsa_score`, `ref_qsa_select`, `ref_qsa_tail_store` and `ref_qsa_work`
in `libref/ref_qsa.cpp`), so each device kernel has a row to compare against. No oracle gives the
whole-subsystem comparison, a dense run against a sparse one above the bound. Changes are checked
with:
- **`r4d_selftest` oracles**: `qsa_block_key` and `qsa_score` against f64 evaluations,
`qsa_work` and `qsa_tail_store` against a host walk of the batch, `qsa_select` against a host
+9
View File
@@ -974,3 +974,12 @@ scripts/mctools.sh && scripts/mcstream.sh
`tools/kbench-analysis.sh` produces the static- and dynamic-analysis fragment that
`rad-kbench --analysis` splices into its report. `tools/ops_doc_check.sh` is the `ops_doc` test: it
checks `docs/OPS.md` against the schemas the plugins declare.
`rad-chatparse` (built into the build's `bin/`) answers where a tool call goes wrong without loading
weights. `rad-chatparse --request REQ.json --rad MODEL.rad --reply R.txt` renders one OpenAI chat
request as the server would (the container's template or `--override-chat-template`,
`--chat-template-kwargs`, the plugin's declared reply format, or the template's own with
`--no-plugin`), then reads each reply file as the model's output: parsed whole, parsed through the
SSE stream as a client reassembles it, and run through the request's tool-call grammar. It prints one
JSON object; the exit status is 1 when the two parses disagree or the grammar refuses a token.
`--render-raw T.jinja --context CTX.json` renders a template with any context.
+7 -8
View File
@@ -9,14 +9,13 @@ All numbers: paired within-session windows, bar ≥0.5% + sign test, geometry
`--prefill-span 2 --tp-wire wht6 --placement all_vram` iq4r MoE unless stated.
Every "dead" row is a *measured* dead — the mechanism, not a guess.
Shorthand used in the table and the prose (glossed once, used everywhere):
`pp` prefill; `c1/c2/c8/c16` concurrency (live streams) 1/2/8/16; `M` rows in a collective
(batch tokens at a step, rows in a MoE launch); `I` `--checkpoint-interval`; `T` tokens
(`T<=25` at most 25 tokens); `ti8` the int8 peer wire (`--tp-wire wht6`'s coding); `FK` the
MoE fast band; `W4` the 4-bit weight format; `iq4r` the shipped MoE quantisation; `hc_write`
the fused all-reduce + residual-write row; `pp64K` a 64 K-token prefill; `QSA` the sparse
indexer (docs/QSA.md); `L0..L3` kill levels, defined under *Kill levels*; `W#`/`R#` the
experiment rows of this table.
Shorthand: `pp` prefill; `c1/c2/c8/c16` concurrency (live streams) 1/2/8/16; `M` rows in a
collective (batch tokens at a step, rows in a MoE launch); `I` `--checkpoint-interval`; `T` tokens
(`T<=25` at most 25 tokens); `ti8` the int8 peer wire (`--tp-wire wht6`'s coding); `FK` the MoE fast
band; `W4` the 4-bit weight format; `iq4r` the shipped MoE quantisation; `hc_write` the fused
all-reduce + residual-write row; `pp64K` a 64 K-token prefill; `QSA` the sparse indexer
(docs/QSA.md); `L0..L3` kill levels, defined under *Kill levels*; `W#`/`R#` the experiment rows of
this table.
## The table
-270
View File
@@ -1,270 +0,0 @@
# HYV3 W4 decode optimizations
These changes optimize the existing HYV3 path and shared asymmetric W4/W5 and signed-I4 expert
kernels. They do not change the canonical `.rad` weight encodings, precision, default split-K
selection, or speculative decoding settings.
## Scope and affected paths
| Change | Affected paths | What remains to measure |
| --- | --- | --- |
| Compact one-row W4/W5 epilogue | Callers of the asymmetric W4/W5 GEMM at one live row and a compatible tile; includes Gemma callers | Fresh whole-model W4/W5 comparisons outside HYV3 |
| BF16-to-F16 narrowing inside W4 GEMM | Non-rotated group-128 asymmetric W4 `LinearFP8` decode through 64 rows | Other models using this path; Gemma's separate a4 graph still keeps its cast |
| Fragment-tiled expert I4 and one-row register loads | Per-128-scale signed-I4 experts, including plain and Hadamard-rotated formats | Other models/recipes that actually use this encoding, plus prefill and TP regressions |
| Fused Q/K prologue and residual/shared-combine folding | HYV3's graph; TP2 keeps separate routed/shared reductions | Fresh TP2 whole-model A/B; other models affected by shared-kernel changes |
Subgroup-scaled codebooks retain their row-major packing. In particular, the served Flash-Next
W5DN64 recipe is not evidence for the per-128 I4 kernel: its routed experts use a different
subgroup-scaled path. No speedup is claimed for it or for any unmeasured model.
## Historical HYV3 measurements
These are earlier measurements of the original optimization branch, **not a benchmark of this
rebased PR**. They establish motivation only.
- One Radeon AI PRO R9700 (`gfx1201`), TP1, full-GPTQ W4 HYV3.
- BF16 KV, 65,536 maximum context, one sequence, 4,096 batched tokens, no drafter or launch cache.
- Matched 10,030-token prompt and 2,000 generated tokens, temperature zero; reported decode
medians are from three repetitions.
- The frozen request SHA-256 is
`e04af05fd7952b5c1e8a38927bb53ab8621ca3e90a2713285eb98122c849ed47`.
The first repetition was uncached; later repetitions reused a 16-token prefix.
- The frozen prompt repeatedly requests the word `alpha`, and the generated answer repeats it.
This is a narrow synthetic workload, not representative prose, code or tool-use throughput.
| Historical stage | Median decode tokens/s |
| --- | ---: |
| Initial model path | 90.290 |
| Fresh pre-packing control after earlier graph work | 95.392 |
| Coalesced per-128 I4 expert packing | 103.364 |
| Rebuilt cast-free graph | 111.922 |
| Final untuned optimization stack | 115.678 |
The frozen answer SHA-256 was
`caca914b1bced70b2f9d8bf32d476179f18cef456201b02f55f16b9863bedbf0` in every repetition.
That establishes parity for this answer, not numerical or semantic equivalence on arbitrary input. An intermediate 104.744 tokens/s
cast-fusion result used a stale architecture plugin and must not be used to quantify removal of
graph casts. A separate launch-cache experiment near 120.5 tokens/s changed reduction order and
is not part of this patch.
The earlier native-tool comparison was unmatched: the untuned stack scored 102/113 exact and
112/113 executable cases versus 105/113 and 113/113 in an older baseline. The matched release-tag
A/B below supersedes it for this PR validation: both arms scored 102/113 and 112/113, with identical
per-case results. This remains a small curated subset, not a broad quality test.
## Validation on the rebased optimization branch
The full-suite GPU, layout and reference results below were recorded with the candidate based on
merged main `2d2f638`. The PR was later rebased onto `d650eca` and then onto current `origin/main`
`96bc046`. The full unit, GPU and inference suites have not been rerun on that latest base. Its
`radiance` target remains blocked by the missing KV-stream headers noted below; focused validation
of the latest source is recorded separately here.
### Code-review follow-up on current main
The review found that removing the explicit BF16-to-F16 graph cast changed CPU/reference results for
BF16 values in F16's subnormal range. The host backends now explicitly narrow BF16 activations to
F16 before W4/W5 asymmetric GEMM, preserving the old cast semantics. This does not change the HIP
kernel path.
On the latest rebased source (`origin/main` `96bc046` plus this PR):
- Built the updated `libref`, `libavx`, and `rad-avx-check` host plugins, plus the complete `gfx1201`
`libr4d` HIP plugin and `r4d_selftest`. The full Radiance engine build is still blocked by the
missing upstream KV-stream headers.
- The new direct `libref` regression test passed 7 checks: BF16-subnormal W4 output matched the
explicit-F16 input byte-for-byte and produced BF16 `0x3900`.
- `rad-avx-check --op gemm_nt_q` passed 26 generated geometries and 46 hand-built cases at scalar,
AVX and AVX2 levels, with four-thread reruns byte-identical. This CPU exposes AVX2 but not AVX-512.
- Stored-layout parity passed 1,145 checks over 20 cases.
- On the authorized GPU, focused W4 checks passed 341/341, including finite and raw-bit BF16-to-F16
cast parity. The signed-I4/MoE `moe_gemm_w4a8` test had 647 passes, zero failures and 12 expected
skips for unsupported aligned prefill tiles above the 512-expert run-map limit (the harness exits
2 when skips occur).
- A short post-fix HYV3 full-GPTQ W4 compatibility smoke on the existing release-plus-PR deployment
build returned `42`; it was stopped afterward, the temporary port was free, and no serving route
was changed. That build does not include the updated CPU plugins, so this smoke is not evidence
for the CPU fix or a current-main A/B.
### Non-target model dispatch checks (Flash-Next and Qwen3.8-27B)
These graph-only checks used the local artifacts and the ABI-compatible release-plus-PR engine; the
engine exits after `declare`, before placing or loading model weights. The latest-source engine still
cannot be built because of the unrelated KV-stream integration gap.
- **Qwen3.8-Flash-Next IQ4R (QFN):** the graph declared 2,054 ops and contained 98
`moe_gemm_q` bands at `w4nl64a8h`; all resolved to the existing `libr4d` row
`moe_gemm_w4a8`. This shared row is selected for QFN, so its decode geometry was benchmarked below.
The new `moe_w4_rows_kernel` is not selected: QFN's W4NL64 format maps to `moe_gemm_launch<2>`,
while its dispatch is guarded by `if constexpr (W4 == 1)`. For W4NL64, the modified loader wrapper
takes its `W4 != 1` branch and calls the previous `w4_load_w` implementation.
- **Qwen3.8-27B MXFP4:** the graph declared 1,821 ops, with 329 MXFP4 `gemm_nt_q` bands (plus one
W2A8 band); it selected existing `gemm_mxfp4a8_*` rows. It had no `moe_gemm_q`, asymmetric W4 or
W5 bands. The PR's new expert-I4/W4/W5 paths are therefore not selected for this model; its
MXFP4 rows are unchanged.
No benchmark was needed for an untouched path.
For QFN's shared W4NL64 row, `r4d_selftest --perfmoe 1 12 512 10 23 --cold 256` was run three
times per arm on the same `gfx1201` device. It uses QFN's TP2 rank-0 gate/up and down widths, one
decode token, 512 experts, top-10 routing, and 23% pooled experts. Baseline is `origin/main`
`96bc046`; candidate is that base plus this PR. The decode-selected forms had matching output
hashes and no measurable regression:
| QFN W4NL64 decode projection | Baseline median | PR median | Change |
| --- | ---: | ---: | ---: |
| Gate/up, two-K-block decode form | 23.60 us | 23.50 us | -0.4% |
| Sorted down decode form | 17.10 us | 17.00 us | -0.6% |
This is an op-level microbenchmark with synthetic weights at the exact QFN geometry, not a
whole-model QFN performance or quality A/B. Logs: `/tmp/pr237-qfn-debug-graph.log`,
`/tmp/pr237-qfn-moebench-{candidate,baseline}-cold{1,2,3}.log`, and
`/tmp/pr237-qwen27-debug-graph.log`.
- Release and ASan/UBSan/leak architecture suites, including HYV3 TP1/TP2 graph checks: passed
before the base advance.
- `gfx1201` `libr4d`, `r4d_selftest`, and all three HYV3 plugins: compiled.
- Stored-layout parity: 1,145 checks over 20 cases passed, including independent canonical nibble
addresses, GPTQ and rotated experts, subgroup codebooks and unaffected dense formats.
- Reference arithmetic: 136,622 checks over 254 cases passed with the incomplete upstream
inventory/sweep cases excluded. The new exhaustive BF16-add/cast-chain case passed separately.
The unfiltered reference suite's three failed assertions were reproduced with unchanged upstream
test source: an operation-count mismatch and missing sweep geometry for `kv_store_streamed` and
`kv_resolve`.
- Full rebased GPU selftest on the designated last R9700 (`gfx1201`, UUID
`GPU-7f082536d27449f3`): 9,057 `ok` results, 194 skips, and two failing assertions in one
`hc_read_e4m3` test case at M=2048; overall exit 1. The same untouched HC-read test family
failed with the pre-follow-up baseline plugin at M=2048 and M=700 (the particular stream/form
varied). The PR does not change that kernel or test. This is not a clean full-suite pass.
- Focused GPU checks passed for `gemm_w4a16_asym_nt_m64`, `moe_gather_bf16`,
`qkv_norm_rope_kv_store_h128_bf16` (including byte parity to the split norm/RoPE/store chain),
and `rmsnorm_bf16`. The signed-I4 `moe_gemm_w4a8` case had no failures; its exit status was the
harness's intentional-skip status for unsupported large-expert aligned tiles. The full run also
exercised its HYV3 top-8 gate/up and down cases without failures.
The latest-source `radiance` target build stops at `ctx.cpp:6`, `kvbind.cpp:4`, `issue.cpp:22`,
and `tierexec.cpp:4`: the runtime includes `kvstream/bind.h`, `kvstream/stage.h` and
`kvstream/plan.h`, but current `main` has no engine-side `core/kvstream/` module. This blocks
building the matching ABI-30 HIP engine needed for whole-model tests. The older available GPU
engine is ABI 27 and refuses the ABI-30 plugin; the current-main host build has no HIP backend.
Accordingly, no fresh HYV3 or Qwen inference A/B ran.
The user's local Qwen `.rad` was inspected without downloading anything:
`/mnt/gostar_data/models/StillDeadcode/qwen3.8-27b-mxfp4/qwen3.8-27b-mxfp4.rad` is a 19.4 GB
`Qwen3_5ForConditionalGeneration` container with `n_expert=0` and group-32 MXFP4 weights (SHA-256
`a4908940c568f5f9dd24e88f46aefe9ac2ae07dfec023a2eaa1d14dcaa3df4f8`). Its graph-only dispatch check
found only unchanged MXFP4 rows, not this PR's asymmetric W4/W5 or per-128 I4 paths. A prior
release-tag compatibility smoke answered `42`; neither check is an affected-model A/B. The current-main
engine still cannot be built because the KV-stream sources are missing. No model was downloaded and
no llama-swap route was edited.
### Release-tag plus PR build experiment
To isolate the later mainline KV-stream integration, a temporary worktree was based on release tag
`v1.12.0`, then given the HYV3 model-support patch (from `32881da` to `79487d2`) and the PR #237
delta (`d650eca` to this PR head). One context conflict in `libr4d/r4d_layout.cpp` came from a
post-release MXFP4-gated wrapper absent from the tag; the resolution kept the release's unrelated
MXFP4 code and applied the PR's I4 layout changes. No changes were made to the published branch for
this experiment.
- Full Release host build: passed (694 targets).
- Full `gfx1201` HIP build: passed (809 targets).
- Focused `arch_test`, `chat_test`, `chatparse_test`, and `checkpoint_test`: 4/4 passed.
Follow-up validation used only the third R9700 (GPU index 2, UUID
`GPU-7f082536d27449f3`):
- `gemm_w4a16_asym_nt_m64`: 341 checks passed, zero failures or skips.
- `moe_gemm_w4a8`: 647 checks passed, zero failures, 12 expected skips for unsupported aligned
prefill tiles at 640 experts (the run-map limit is 512); HYV3 top-8 gate/up and down geometries
were exercised. The selftest exits 2 when skips are present.
- The release+PR server loaded the local full-GPTQ W4 HYV3 container at 4096 context on loopback
port 18100. `/health` was OK and a chat request asking for 6×7 returned `42`. The process was
stopped afterward and the port was confirmed free; no route was changed.
### Full-suite, performance and quality A/B (completed on the release-tag stack)
The full CTest suite on the release+HYV3-support+PR candidate passed **121/121** tests, including
83 unit tests and all 10 GPU-labelled tests. The full `r4d_selftest` passed on a standalone rerun
and again in the final complete suite. An earlier full-suite attempt had an intermittent
`hc_read_e4m3` assertion; the same untouched family also failed on the baseline run, while four
isolated baseline/candidate reruns passed 38/38 each. The final full-suite run was clean.
A matched TP1 full-GPTQ W4 A/B used the exact frozen 10,030-token prompt and 2,000-token decode
request (`e04af05f...`), on the third R9700, BF16 KV, one sequence, 65,536 context, 4,096 batched
tokens, and no launch tune or speculative decoding. The reference was release `v1.12.0` plus HYV3
model support; the candidate added only PR #237's delta. Each arm had three repetitions, with the
same 16-token prefix-cache behavior after the first run.
| Arm | Median decode tokens/s | Median prefill tokens/s | Answer SHA-256 |
| --- | ---: | ---: | --- |
| v1.12.0 + HYV3 support (baseline) | 76.567 | 7,876.292 | `caca914b...` |
| v1.12.0 + HYV3 support + PR #237 | 109.618 | 7,926.569 | `caca914b...` |
That is **+43.17% median decode throughput** and **+0.64% prefill throughput** on this narrow
synthetic workload; all six generated-answer hashes were identical. The speed result is specific
to this matched release-tag comparison, not a claim about other models or current-main performance.
Quality comparisons on the same two builds:
- Greedy output hashes matched **12/12** fixed probes.
- Teacher-forced evaluation on the frozen eight-document, 578-position corpus measured mean KL
`7.61e-8`, maximum KL `1.57e-6`, **100% top-1 agreement**, and identical PPL `2.875200`.
- The 113-case native-tool BFCL subset was identical row-for-row: **102/113** exact calls,
**112/113** execution successes, and zero API errors on both arms. This is a curated subset, not
broad capability evidence.
#### Same-build cross-card diagnostic
At the user's request, I reran the same candidate executable, `.rad` artifact, launch flags, and
three 2,000-token repetitions on two individual R9700s. The frozen 10,030-token benchmark used the
same per-repetition prefix scheme on both cards; no launch tune or drafter was enabled. The model
was loaded separately on each card, with no other Radiance process using either device.
| Device | Median decode tok/s | Median prefill tok/s | Answer SHA-256 |
| --- | ---: | ---: | --- |
| PCI `0000:06:00.0`, UUID `GPU-048200e09844fd51` | 118.380 | 8,077.674 | `caca914b...` |
| PCI `0000:0f:00.0`, UUID `GPU-7f082536d27449f3` | 109.834 | 8,011.282 | `caca914b...` |
The same candidate was **7.2% slower on the designated PCI `0f:00.0` card**. A fresh confirmation
on that card measured **110.311 tok/s**, within 0.44% of the initial 109.834 tok/s result. The older
115.678 tok/s untuned run was on PCI `06:00.0`, so the earlier 115-versus-109 comparison was
confounded by card/operating-point differences, not evidence that splitting the branch caused a
regression. All three R9700 UUIDs are configured for PPT0=210 W in
`/usr/local/sbin/gpu-power-caps`; its AMD cap loop runs before the separate NVIDIA stage where the
service fails. So a different *configured* cap is not established as the cause. Per-run live
cap/clock telemetry was not captured; card-specific boost, thermal/board behavior, or silicon
variation could still matter. PCIe bandwidth is not established as the cause. Raw-request repeats
that reused 10,000 cached prompt tokens are retained separately and excluded from this comparison.
Additional compatibility smokes using the same candidate build passed for the local Qwen4Exp W5
container (returned `42`; prompt-lookup drafted 6 tokens and accepted 1), Qwen Flash-Next IQ4R
(TP1 and TP2 launchers, answered `42`), Qwen3.8 27B MXFP4 (answered `42`), Breeze-TTS-2 (valid
24 kHz mono PCM), and HYV3 (answered `42`). The verified deployment build was moved intact to
`/mnt/gostar_data/radiance-builds/radiance-v1.12-hyv3-pr237/build-gfx1201`; all six local model
launchers were syntax-checked and updated to use it. The W5 launcher dropped a stale
`--draft-coupling on` option rejected by this container (it declares no linear drafter); its
six-token prompt-lookup setting remains. These are smoke tests, not matched performance/quality
results for those models. No model was downloaded and no llama-swap route was changed.
Logs, summaries and raw rows are under
`/mnt/gostar_data/radiance-calib/hyv3-pr-validation-20261025/pr237/` and
`/mnt/gostar_data/radiance-calib/hyv3-w4-round2-20261024/` (labels `release-v112-baseline` and
`release-v112-pr`).
## Integration caveat and scope of claims
The successful full builds, full test suite and A/B above use the release-tag stack because the
current-main source still lacks the engine-side `core/kvstream/` headers introduced by upstream
`486c933`; it therefore cannot produce the matching ABI-30 HIP engine. That unrelated upstream
build break remains outside this PR, so the A/B must not be described as a current-main-vs-PR run.
The PR is validated and ready for review against the buildable release-tag stack, but after the
upstream KV-stream integration is restored, current-main builds/tests should be rerun.
Performance and quality claims are limited to the HYV3 TP1 full-GPTQ W4 A/B above. The Qwen W5,
IQ4R and MXFP4 runs were compatibility smokes only; no broad speedup or quality claims are made for
other model families or formats. The native BFCL corpus is also a small safe subset, not a broad
quality benchmark.
The cold-weight diagnostics are `r4d_selftest --perfw4`, `--perfw4bf16`, `--perfbf16` and
`--perfhyv3moe`; see [libr4d/README.md](../../libr4d/README.md). Their byte/canonical checks and
shape-specific timings do not replace whole-model performance or quality comparisons.
+27 -23
View File
@@ -1,25 +1,27 @@
# DeepSeek-V4.1-Flash: a .rad straight from the release (no GGUF converter)
# DeepSeek-V4.1-Flash: a .rad from the release (no GGUF converter)
The official DeepSeek-V4.1-Flash release converts with `rad-convert` alone: no llama.cpp GGUF is
built as an intermediate, and no separate drafter directory is grafted. The pieces are in the tree:
built as an intermediate, and no separate drafter directory is grafted. The pieces below prepare
and convert the release. Serving the container needs the `deepseek41` architecture plugin, which
this tree does not include yet.
- `data/engram_tables.py` builds the Engram hash tables from the release's own `tokenizer.json` and
`config.json`, reimplementing the tokenizer's ByteLevel decode and the normaliser sequence
(NFKC, NFD, strip marks, lowercase, collapse spaces, sentinel) and the PCG64 multipliers and
prime buckets. Validated against HF `tokenizers`: 0 mismatched token ids of 129280, compressed
vocab 99092, the release's two Engram layers [1, 14]. It writes `engram-tables.safetensors`.
`config.json`. It reimplements the tokenizer's ByteLevel decode, the normaliser sequence (NFKC,
NFD, strip marks, lowercase, collapse spaces, sentinel), the PCG64 multipliers and the prime
buckets. Against HF `tokenizers`: 0 mismatched token ids of 129280, compressed vocab 99092, the
release's two Engram layers [1, 14]. It writes `engram-tables.safetensors`.
- `data/imatrix_merge.py` fuses the imatrix entries llama.cpp's converter writes split
(`ffn_gate_exps`, `ffn_up_exps`) into the plugin's fused `ffn_gate_up_*`, summing the two halves
(and `shexp`): 1184 entries carried through, 160 fused for 40 layers. IQ1_S refuses a fused
weight without one.
- `data/recipes/deepseek41-ud-iq1s.recipe` is the UD-IQ1_S per-tensor mix, as rules for libquant's
`ggml` quantiser, so the release converts to the same encodings the GGUF gives.
(and those of `shexp`): 1184 entries carried through, 160 fused for 40 layers. IQ1_S refuses a
fused weight without one.
- `data/recipes/deepseek41-ud-iq1s.recipe` is the UD-IQ1_S per-tensor mix as rules for libquant's
`ggml` quantiser, so the release converts to the same encodings the GGUF has.
- `rad-convert --chat-template FILE` bakes a template into the container's vocab section. The
release carries no `chat_template.jinja` and its `tokenizer_config.json` names none, so without
this flag an HF-direct container answers `/v1/chat/completions` with 501. Trailing newlines are
stripped as for a sibling template, and an unreadable or empty file is refused, not skipped.
release carries no `chat_template.jinja` and its `tokenizer_config.json` names none, so a
container converted without this flag answers `/v1/chat/completions` with 501. Trailing newlines
are stripped as for a sibling template, and an unreadable or empty file is refused.
## The three steps
## Conversion
```
# 1. the Engram tables, from the release's tokenizer (not a GGUF)
@@ -28,19 +30,21 @@ python3 data/engram_tables.py <HF release dir> engram-tables.safetensors
# 2. fuse the imatrix's split gate/up entries
python3 data/imatrix_merge.py imatrix_unsloth.gguf_file imatrix-merged.gguf
# 3. convert; the template is the model's own, baked into the container
# 3. convert, with a chat template for the model baked into the container
rad-convert <HF release dir> --add engram-tables.safetensors \
--recipe data/recipes/deepseek41-ud-iq1s.recipe \
--imatrix imatrix-merged.gguf --tokenizer <HF release dir>/tokenizer.json \
--chat-template chat_template.jinja -o deepseek-v4.1-flash-ud-iq1s.rad
```
Measured on the release (DeepSeek-V4.1-Flash-1017, fp8 with e8m0 per 32×32 blocks, MXFP4 experts):
plan 32701 weights / **251.07 GiB**, conversion **251.13 GiB in 2h11m** on this host, and the
container serves on 4× R9700 at TP4 with its DSpark metadata (block 5, 128 experts, targets
37/38/39) and Engram baked. Quality of the converted container, greedy, thinking off: HE 154/164 =
.939 (the native UD-IQ1_S reference .963, McNemar p = .125), GSM 194/200 = .970 (reference .960).
From DeepSeek-V4.1-Flash-1017 (fp8 with e8m0 scales per 32x32 block, MXFP4 experts) the plan is
32701 weights, 251.07 GiB, and the container 251.13 GiB. The `deepseek41` plugin serves it on 4x
R9700 at `--tp 4` with its DSpark metadata (block 5, 128 experts, targets 37/38/39) and the Engram
tables baked in. Quality, greedy, thinking off: HumanEval 154/164 = 0.939 (the native UD-IQ1_S
reference 0.963, McNemar p = 0.125), GSM 194/200 = 0.970 (reference 0.960).
Serving: nothing else is needed now that the template is baked. A container built before this flag
needed `--override-chat-template FILE` at serve time; the file has to be a Radiance-renderable
template (the release's own is; llama.cpp-only jinja such as `dict()` in a GGUF's template is not).
## Serving
A container converted with `--chat-template` needs no template at serve time. One converted
without it needs `--override-chat-template FILE`; the file must be a template radiance renders
(the release's own is; llama.cpp-only Jinja, such as `dict()` in a GGUF's template, is not).