--kv-cache-dtype fp8_v4 | k6_v4 (RadBuildCtx::kv_quant, RadArchProbe::kv_quant_ok; ABI 23)

The flag sets the trunk's cache to E4M3 plus a RAD_KVQ_* layout; a plugin offers the layouts it
serves in its probe and the server refuses any other, naming the plugin. qwen35_fp8 offers both
at head_dim 256, gqa 6, and declares the group at head_dim 200 / 176 (the row's bytes / 2), so
the core sizes pages as for fp8; a drafter's cache stays fp8. Qwen3.8-27B on two R9700s, KL
against bf16 on 17 long documents: fp8 0.039963 (518,800 tokens of KV), fp8_v4 0.040076
(664,400), k6_v4 0.039965 (755,184); prefill and decode at fp8's speed. ABI 23: two trailing
fields, the layout table regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-19 15:28:21 +02:00
1 parent c00a650bce
commit 1823ccd5e9
14 files changed
+238 -20

No files matched your search

+1 -1
View File
@@ -194,7 +194,7 @@ Three groups, which is why hybrid KV groups are first-class:
| group | kind | geometry |
|---|---|---|
| full attention | `RAD_KV_FULL` | 16 layers, head_dim 256, 4 KV heads; block size from the resolved kernel |
| full attention | `RAD_KV_FULL` | 16 layers, head_dim 256, 4 KV heads; block size from the resolved kernel. `--kv-cache-dtype fp8_v4` / `k6_v4` (`qwen35_fp8` only) declare it at head_dim 200 / 176, the bytes of a token's quantised row over two (docs/OPS.md) |
| GDN recurrent state | `RAD_KV_LINEAR` | 48 layers, 48 states of 128 x 128 |
| GDN conv state | `RAD_KV_CONV` | 48 layers, 2*16 + 48 = 80 heads x 128 = 10240 channels, a rolling `conv_width - 1 + n_spec` window |
+18 -1
View File
@@ -783,6 +783,23 @@ widths, and the flag sets every attention cache of the deployment, a drafter's (
included. The delta-net state and the QSA indexer's key tail are recurrent state and keep their own
widths.
`fp8_v4` and `k6_v4` narrow the trunk's attention cache further, in groups of 32 dimensions with an
f16 scale each: `fp8_v4` keeps K in E4M3 and stores V as int4, `k6_v4` stores K as int6 too. A token
then costs 25/32 or 22/32 of what fp8 costs, and a drafter's cache stays fp8. libr4d has their
kernels for Qwen3.8-27B's attention (head_dim 256, gqa 6), so the plugin offers them there and the
server refuses them, naming the plugin, anywhere else. On two R9700s at the serve flags of
`qwen3.8-27b-mxfp4.yaml` with `--max-num-batched-tokens 2048` and 12 GiB a card left to another
engine, against the bf16 model on 17 long log-analysis documents (60 368 scored positions):
| `--kv-cache-dtype` | KV pool | mean KL | top-1 | 41k-token prefill | decode, 1 / 16 streams |
|---|---|---|---|---|---|
| `fp8` | 518 800 tokens | 0.039963 | 94.03% | 9.76 s | 134-140 / 550-555 tok/s |
| `fp8_v4` | 664 400 (+28%) | 0.040076 | 94.03% | 9.76 s | 130-139 / 553-557 |
| `k6_v4` | 755 184 (+46%) | 0.039965 | 94.06% | 9.84 s | 136-138 / 553-561 |
The decode spread is run to run; the three are the same speed there. Each layout's row and the
kernels that read it are in [OPS.md](OPS.md#the-kv-cache-operand).
**Many sequences.** Every model here serves `--max-num-seqs` up to 32. A sequence holds only the
blocks its tokens occupy, but two costs exist per sequence regardless:
@@ -1322,7 +1339,7 @@ still verified by the adapter, so output is exact and only the acceptance rate c
| flag | default | |
|---|---|---|
| `--gpu-headroom-mib N` | 96 | VRAM left unclaimed on every card |
| `--kv-cache-dtype T` | bf16 | `bf16` or `fp8` |
| `--kv-cache-dtype T` | bf16 | `bf16`, `fp8`, or on Qwen3.8-27B `fp8_v4` or `k6_v4` (§4.4) |
| `--host-pool-mib N` | 0 | pinned host tier (weights) |
| `--host-headroom-mib N` | 4096 | host RAM left free for the system when startup pins host memory — kept for the unpooled allocations, staging and page cache (§4.3) |
| `--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 (§4.3) |
+19
View File
@@ -812,6 +812,25 @@ declares bound it lower.
`RadKVGroupBatch` carries the slot mapping, the block table and the sequence lengths, but the pool
base belongs to the block manager, not the batch.
**`kv_dtype` `fp8_v4` and `k6_v4`** (device-only) are the quantised layouts of
`--kv-cache-dtype` (`RadBuildCtx::kv_quant`). A head's dims are grouped by 32, each group with an
f16 scale (its absmax over the largest code), codes two's complement. A token's row in a head, at
head_dim HD:
| bytes | `fp8_v4` (25 HD / 16) | `k6_v4` (22 HD / 16) |
|---|---|---|
| K | [0, HD): E4M3, as `fp8_e4m3` | [0, HD/2): the codes' low four bits; [HD/2, 3HD/4): their high two bits, a word per 16 dims whose byte j holds dims 2j, 2j+1 in bits 0-3 and 8+2j, 9+2j in bits 4-7 |
| V | [HD, 3HD/2): int4 codes, dim d in the nibble at bit 4 (d mod 2) of byte d/2 | [3HD/4, 5HD/4): the same |
| scales | [3HD/2, 25HD/16): V's (absmax / 7) | [5HD/4, 21HD/16): K's (absmax / 31); [21HD/16, 22HD/16): V's |
The group is declared at `RAD_F8E4M3` with head_dim the row's bytes / 2, so the core sizes pages
as it does for fp8, and the cache operand's last extent is the row. The ops take the model's
head_dim. libr4d's rows are `kv_store_fp8v4` / `kv_store_k6v4`,
`qk_norm_rope_gate_kv_store_fp8v4` / `_k6v4` (byte-identical to the prologue and the store, as at
the other widths), and `attn_prefill_h256_gqa6_{fp8v4,k6v4}` and `attn_decode_h256_gqa6_{fp8v4,k6v4}`,
which widen the codes to f16 in a tile's staging. `r4d_selftest` holds the stores to an exactly
representable set and the attention rows to its inline oracle.
### `qk_norm_rope_gate` (device-only)
| op | params | operands |