Archived
radiance 1.5.0
- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a prefix hit on a sliding-window model resumes instead of prefilling again. deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards - ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations, as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made with the PR builds is refused: convert it again with --reuse <old container> - Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16 checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe), and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9 - a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD request by name), the library that made it, and its stack, which addr2line resolves against the binary - the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and startup refuses all three with what replaced them. The compose files no longer mount /data, and .env no longer needs RADIANCE_STATE - --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A full host tier now drops its least recently used conversations - --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and gives its VRAM to the KV cache, read over the link once an image - timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival to the first and the last token, queueing and tokenisation included - a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the slots it had already freed: after it every recall failed, the cache stayed short until a restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and always finishes - a tool result or tool-call arguments that are not JSON are no longer refused as nesting past 1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the bound, since nothing else is parsed into a tree - the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and 1.5 GiB), not ttm.pages_limit - --embedding-placement auto, removed in 1.3.0, is refused with what replaced it - for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary without declaring it
This commit is contained in:
commit
b93b531f63
127 files changed
+9609
-4796
No files matched your search
+130
-1
@@ -14,7 +14,8 @@ into the id an architecture plugin claims.
|
||||
| `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/embgemma2` | `embeddinggemma2` | *(empty)* | EmbeddingGemma 2: a bidirectional encoder with Gemma 4's vision tower and audio conformer, pooled to one vector |
|
||||
| `arch/gemma4_bf16` | `gemma4_bf16` | `i4` (group-128 codes, f16 scale) | Gemma 4 31B dense (text): two attention classes — sliding-window and proportional-RoPE global (`attention_k_eq_v`) — over one GemmaRMSNorm stream, GELU ffn, two KV groups, softcapped logits, tied scaled embedding; served from a CT-INT4 (QAT w4a16) checkpoint. Optional draft head: Google's assistant (`rad-convert --draft-model`), a serial head with no cache of its own (`rad_drafter_shared_kv`) |
|
||||
| `arch/gemma4_bf16` | `gemma4` | `compressed-tensors` | Gemma 4 31B dense (text): two attention classes — sliding-window and proportional-RoPE global (`attention_k_eq_v`) — over one GemmaRMSNorm stream, GELU ffn, two KV groups, softcapped logits, tied scaled embedding; served from a CT-INT4 (QAT w4a16) checkpoint as group-128 int4 codes with an f16 scale. Optional draft head: Google's assistant (`rad-convert --draft-model`), a serial head with no cache of its own (`rad_drafter_shared_kv`) |
|
||||
| `arch/gemma4` | `gemma4` | *(empty)* | Gemma 4 text from Google's bf16 checkpoint — the 26B-A4B MoE (a dense and a routed arm side by side) and the dense sizes without per-layer embeddings — with z-lab's DFlash drafter; routed experts bf16 or block fp8, as the recipe chose |
|
||||
|
||||
This document is the geometry of each, and the handful of readings that are **arithmetically
|
||||
silent** — wrong in a way that produces fluent output and no error anywhere.
|
||||
@@ -447,3 +448,131 @@ The traps:
|
||||
is a real one; the processor stages exactly those plus zero frames to whole rows, which
|
||||
reproduces every row the reference keeps.
|
||||
|
||||
---
|
||||
|
||||
# `gemma4` — Gemma 4 text, and its DFlash drafter
|
||||
|
||||
`arch/gemma4` serves a container converted from Google's bf16 checkpoint (`Gemma4ForConditionalGeneration`
|
||||
or `Gemma4ForCausalLM`), the recipe choosing what is fp8: gemma-4-26B-A4B-it, and the dense sizes
|
||||
without per-layer embeddings. The CT-INT4 31B release is `arch/gemma4_bf16`'s. A z-lab DFlash
|
||||
drafter is merged at convert time (`--draft-model`); the recipes are
|
||||
`data/recipes/gemma4-26b-a4b-df*.recipe`. The reference is transformers' `modeling_gemma4`.
|
||||
|
||||
```
|
||||
gemma-4-26B-A4B-it
|
||||
30 layers, hidden 2816, vocab 262144 tied to the embedding, rms_norm_eps 1e-6
|
||||
layer_types: five sliding_attention then one full_attention, five times
|
||||
sliding 16 heads / 8 kv x 256, rope theta 1e4 over the whole head, window 1024
|
||||
full 16 heads / 2 kv x 512, PROPORTIONAL rope theta 1e6 over a quarter of it, K = V
|
||||
attention scale 1: q and k RMS-normed per head with a gain, v with none
|
||||
sandwich norms, plain gains (x_hat * w)
|
||||
the feed-forward is two arms reading the same residual, summed:
|
||||
dense pre_feedforward_layernorm -> gate|up 2112 (gelu-tanh) -> down -> post_feedforward_layernorm_1
|
||||
routed router -> softmax -> top 8 of 128 -> renormalised -> * per_expert_scale[expert];
|
||||
pre_feedforward_layernorm_2 -> 128 experts of 704 (gelu-tanh) -> post_feedforward_layernorm_2
|
||||
sum -> post_feedforward_layernorm -> residual add
|
||||
layer_scalar multiplies the residual stream at the end of every layer
|
||||
embedding * sqrt(2816) as a bf16; final norm; tied head; final_logit_softcapping 30
|
||||
DFlash a small Qwen3-shaped block drafter: an anchor and block - 1 mask tokens denoised in one
|
||||
pass over the trunk's hidden states at target_layer_ids; drafts read off the TARGET's head
|
||||
```
|
||||
|
||||
The readings that stay plausible when wrong:
|
||||
|
||||
- **Proportional rope is not a partial rotary.** The full layers rotate the first 64 frequency
|
||||
pairs of the 512-wide head at theta^(-2j/512) — the exponent divides by the HEAD — with pair j
|
||||
channels (j, j + 256), and leave the other 192 pairs at frequency zero. `rope` with
|
||||
`rotary_dim` 128 pairs (j, j + 64) at theta^(-2j/128): a different function that still produces
|
||||
fluent text. The plugin declares a full-width NeoX `rope` whose frequencies past pair 63 are
|
||||
divided by 1e30 through the YaRN ramp `rope` already carries, a step at 63.5..64.
|
||||
- **V on a full layer is the un-normed, un-rotated k projection**, RMS-normed with a unit gain, so
|
||||
the value norm reads `k` before the key norm writes it.
|
||||
- **The router does not read the feed-forward's input.** It reads the residual stream through a
|
||||
gainless norm times its own `scale` vector times hidden^-0.5, while the experts read
|
||||
pre_feedforward_layernorm_2's output. `per_expert_scale` multiplies the weight AFTER the
|
||||
renormalised top-k.
|
||||
- **The arms' two post-norms are per arm**, so under tensor parallel each arm's partial sum is
|
||||
reduced before its norm. The partials share one [2T, hidden] buffer, dense rows first -- each
|
||||
slice's own run of it when a prefill chunk is cut in two -- so one all-reduce carries both.
|
||||
- **The embedding scale is sqrt(hidden) rounded to bf16**: 53.0, not 53.066. The drafter reads the
|
||||
same scaled embedding.
|
||||
- **The sliding layers' KV group is `RAD_KV_FULL`**, with the window on the attention op. A
|
||||
`RAD_KV_WINDOW` group is not prefix-cached, so a hit on it reuses nothing and re-prefills; as
|
||||
FULL the hit is kept. The planner gives every paged group the same block count, so the recycling
|
||||
a window group would buy is worth nothing here.
|
||||
- **The drafter's sliding layers are causal and its full layer is not**, and its logits' softcap
|
||||
is ignored on purpose: a draft is an argmax and the cap is strictly increasing.
|
||||
|
||||
**Tensor parallel.** Heads split by rank, o and down by column with an all-reduce, the vocabulary
|
||||
by row. The full layers' two KV heads are replicated past two ranks. Routed experts are
|
||||
expert-parallel, 128 / world whole experts a rank, because a 704-wide expert has no block-aligned
|
||||
width split; the router is replicated, so every rank agrees on the routing without a collective.
|
||||
The drafter's head is vocab-sharded with the trunk's: each rank's top-2 are all-gathered and
|
||||
`pair_argmax` picks the winner (two a rank, because a row-interleaved `all_gather` moves 16-byte
|
||||
words and one pair is 8 bytes).
|
||||
|
||||
**The prefill overlap.** At more than one rank, a prefill chunk of two routed passes or more (4096
|
||||
tokens, at the 2048-token pass) runs as two slices, and the trunk's all-reduces ride the runtime's
|
||||
second lane beside the other slice's compute: slice A's attention reduction runs under slice B's
|
||||
output projection, slice B's under slice A's two arms, and so on through the layer. Attention runs
|
||||
whole, since it reads every row's keys. The cut is a whole number of routed passes and both slices
|
||||
are above every row band the sliced kernels have, so the step issues the same kernels over the
|
||||
same rows and its output is the whole step's, bit for bit. On 4x R9700 the reductions were 47% of
|
||||
a 20K-token prefill under `--profile-ops`; a model of the measured times puts the overlap at up to
|
||||
a quarter off an unprofiled prefill. The per-op profile syncs every op, so it cannot show it --
|
||||
time a prefill without `--profile-ops`. A step that runs whole -- every decode and verify step --
|
||||
takes the second lane for the dense arm instead, beside the routed arm, which needs nothing of it
|
||||
until the feed-forward join: at decode the dense arm's GEMMs are a few rows, latency-bound and far
|
||||
from the bandwidth the experts take, and its reductions stay on lane 0. On two R9700s the sliced
|
||||
prefill gives the whole chunk's text and logprobs exactly, at 2048- and 8192-token chunks; the
|
||||
startup notes say which form each step takes.
|
||||
|
||||
**The draft head in fp8.** The drafter's head is the widest read on the draft path: the target's
|
||||
bf16 table, 352 MiB a rank at tp 4, every draft pass. A container converted with the line
|
||||
`dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16` (the three `-df` recipes
|
||||
carry it) stores a block-fp8 copy of the table under that name, and the head reads the copy at
|
||||
fp8a8 instead -- half the bytes, for 176 MiB a rank more. Drafts are verified, so the coarser
|
||||
logits can change what is proposed and never what is accepted; `draft_n_accepted` says whether
|
||||
they propose worse. A container without the copy reads the bf16 table as before, and the startup
|
||||
note names which head is in use.
|
||||
|
||||
**FP8 experts.** The experts are ~90% of the weight bytes, so each projection is served as the
|
||||
container holds it, per layer: bf16 by `moe_gemm`, block fp8 by `moe_gemm_q`. gate_up `[1408, 2816]`
|
||||
is whole 64-row tiles and 128-blocks. down `[2816, 704]` is not — the fp8 grouped GEMM reads K in
|
||||
whole 128-column blocks — so it stays bf16 unless the checkpoint's experts were padded to 768 before
|
||||
conversion (zero rows of gate and up, zero columns of down: exact). The fp8 tables are split by
|
||||
expert parity, so a rank holds an even number of experts.
|
||||
|
||||
**Kernels.** libr4d serves all of the trunk's attention on its windowed kernels -- the sliding
|
||||
layers (h256, gqa 2) and the full layers at gqa 8, 4 and 2 (one or two, four, eight ranks) --
|
||||
plus `pair_argmax` and the fusions: the two sandwich-norm joins (`norm_add_norm`,
|
||||
`join_add_scale`), `norm_add_norm_route` -- on a layer whose gate_up is block fp8, the attention
|
||||
join writing the router's input and the experts' fp8 codes from the norm it already takes, in place
|
||||
of an `rmsnorm` and an `rmsnorm_quant_fp8` -- `expert_scale`, and `attn_paged_qrow`, the sliding
|
||||
layers' attention reading q where the fused qkv projection left it. The plugin declares each one's
|
||||
unfused form where nothing serves it -- the rmsnorm / add chain, `embed_lookup` + `mul`, a `cast`
|
||||
lifting q for `attn_paged` -- and the startup notes say which were taken. libref and libavx do not
|
||||
declare these ops, so the plugin asks whether one is declared before it asks for it
|
||||
(`rad_op_declared`), and a deployment without libr4d's device rows -- a CPU-only build, the host
|
||||
backend -- runs the chains. On a card the fused joins and libr4d's chain differ by the order of
|
||||
the chain's reductions, not bit for bit: the joins round as the host chain does (tests/r4d_emu).
|
||||
The drafter's residual add, norm and fp8 quantiser of x are one libr4d `rmsnorm_quant_fp8` launch
|
||||
an input (ten a draft pass), and the `add` / `rmsnorm` / `quant_act_fp8` chain where nothing serves
|
||||
it. The sliding layers' attention stays on the windowed kernel because only it reads q in place:
|
||||
plain `attn_paged` at h256/gqa2 -- the dense 31B's sliding layers -- takes libr4d's h256/gqa2
|
||||
leg, which rad-kbench times at 0.26-0.71 of the windowed kernel at decode and 0.43-0.67 at
|
||||
prefill. A drafter head sharded over more than one rank needs `pair_argmax` on the card.
|
||||
|
||||
**A drafter that is not working still writes fluent text.** Every draft is verified, so a broken
|
||||
drafter costs speed and nothing else: judge it by `draft_n_accepted` (about a third of `draft_n` on
|
||||
prose, at about two tokens a step), not by the reply. The trap that showed it: the buffer planner
|
||||
takes liveness from DECLARATION order, so the tap copy into `dflash_src` is declared at the end of
|
||||
the layer it taps, where it is issued. Declared once after the trunk, it let the planner share
|
||||
`dflash_src` with `moe_edn`, which every MoE layer writes, whenever the sizes allowed it
|
||||
(`--max-num-seqs 16` did): 2% acceptance, slower than no speculation, and nothing in the text to
|
||||
say so. arch_test holds the two live ranges to overlap.
|
||||
|
||||
**Not declared.** The vision tower (`arch/embgemma2` declares Gemma 4's, for an encoder): a container
|
||||
that carries one is served with `--mm-max-patches 0`. An fp8 attention or dense arm — under a tenth
|
||||
of the weight bytes, and the dense arm's 2112 is not whole 128-blocks either.
|
||||
|
||||
Reference in new issue
Block a user