Commit Graph
101 Commits
Author SHA1 Message Date
mici81andClaude Opus 5.5 96bc0465b3 attn prefill h256: the small-launch KV split for every GQA geometry
The KV split of the head-256 / GQA-6 prefill kernel (few workgroups -> split the KV walk into segments,
f32 partials, the split-KV merge with a cu span) now serves every head-256 prefill row: GQA 12
(4-token pages: fp8, bf16, fp8_v4, k6_v4), GQA 6 with 4-token pages (the same four), GQA 8, GQA 4 and
GQA 2 (fp8, bf16). The fewer KV heads a rank holds, the more it matters: at TP 2 Qwen4-Exp (GQA 12) and
Qwen3.5-35B-A3B (GQA 8) keep one KV head per rank, so a 53-row tail runs 2 workgroups on 32 WGPs.

The host side (the law, the scratch sweep, the scratch-capped count, R4D_PREFILL_SPLITS, the merge
launch) moves into r4d_attn_prefill_split.h; each unit passes its own geometry (query rows per workgroup
= 24 * 16 / gqa, tile 48). The GQA-6 unit is refactored onto it with the same law (Qwen3.8-27B in the
engine: greedy top-5 logprobs bit-identical before and after at 300 positions after 25k and 41k prompts).

Left unsplit: GQA-2 launches with a sliding window (the partition has no window floor; a 1024 window
walks at most ~26 tiles), the lossy e4m3 legs, and the head-128 / head-64 legs sharing the bodies.

Split count, one sequence, N query rows -> S: GQA 12 with 1 KV head: 1-32 -> 32, 53 -> 16, 160 -> 6,
1024 -> 1; GQA 8 with 1 KV head: 53 -> 16, 345 -> 4; GQA 2 with 4 KV heads: up to 160 -> 8. Scratch at
declare at most 25.4 MB per row. Split vs unsplit: at most 0.000488 (fp8 KV) and 0.0039 (bf16, fp8_v4,
k6_v4; about 1 bf16 ulp).

Tests: the split tests generalised over geometry for all 18 split rows (query lengths 1-640 over 8k-20k
keys, empty segments, ragged batches, pipelined pieces, poisoned scratch, oracle rows at each tile edge,
declare-time scratch): 1782 ok; the mixed-step case over 9 geometry x cache pairs: 54 ok. Every kernel
that existed before is byte-identical (311 of 311).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 09:25:35 +01:00
hugypufyandClaude Opus 5.5 dab34da373 libr4d: gemm_m2xfp4a8_decode and gemm_m2xfp4a8_tiled -- the MXFP4 x fp8 GEMMs with the m2xfp4 meta plane folded into the e4m3 staging table
Two gemm_nt_q rows at dtype m2xfp4: a split-K decode kernel that stages the weight through LDS,
and a tiled prefill kernel after the mxfp4a8 one. The relayout appends the [K/32][N] meta plane to
the fragment-order codes and r4d_m2xfp4.h's e4m3 staging table takes the subgroup multiplier as a
second index, so the WMMAs and the epilogue are the mxfp4 kernels'. The decode row keeps its own
per-output arrival counters, as mxd_out_ctr does. r4d_emu_m2xfp4 runs both kernels on the host,
and r4d_selftest and kbench (a 4e-2 tolerance for the k = 3 rounding) cover the rows. The raw
entry points are declared in r4d_m2xfp4.h, beside the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 09:24:01 +01:00
mici81andClaude Opus 5.5 6a7824a837 attn prefill h256 gqa6: split the KV walk when the launch has too few workgroups
The prefill attention kernel gives each workgroup 64 query rows of one KV head and walks the whole
causal context serially. A launch with few query rows therefore has few workgroups: the tail chunk
of a prompt (53 rows) or a follow-up turn of a few hundred tokens runs 2-10 workgroups on 32 WGPs,
each walking up to 188k keys (17.7 ms per layer at 188k).

When kv_heads * qtiles * seqs is below the WGP count, the launch now splits the KV range into S
segments (blockIdx.x = qtile * S + segment), writes unnormalised f32 partials (O, m, l) in the
decode partial layout and merges them with the existing split-KV combine. S is the smaller of one or
two rounds of workgroups, capped by the context's tiles and the declared scratch. A segment past a
workgroup's causal end still writes an empty partial; the merge reads every segment it counts.
The merges take a SPAN parameter so a launch over part of a step (pipelined pieces) only rewrites its
own rows; the decode instances are unchanged (identical ISA).

R4D_PREFILL_SPLITS: unset/0 = the law, 1 = off, N = force N (debug/tuning).

Measured on 2x Radeon AI PRO R9700, Qwen3.8-27B MXFP4, TP 2, k6_v4 KV:
- r4d_selftest --perfpaged, off -> on: 53 rows over 40k 3.71 -> 0.47 ms, 80 rows 3.64 -> 0.68 ms,
  345 rows 3.80 -> 1.79 ms, 1024 rows 4.29 -> 4.29 ms (no split).
- Engine, 188k prompt, time to first token: 62.78 -> 62.54 s (the tail chunk).
- KLD vs the bf16 reference: chunk 64 0.040384 -> 0.040337, chunk 2048 0.040237 -> 0.040220;
  top-1 agreement 93.985 -> 93.998 %. Split vs unsplit outputs differ by at most 1 bf16 ulp.
- With R4D_PREFILL_SPLITS=1 the engine is bit-identical to before (top-5 logprobs, 100 positions).

Tests: attn_split_case / attn_split_scratch_case for k6_v4, fp8_v4, fp8 and bf16 KV (q 1-345 over
8k-20k keys, empty segments, ragged batches, pipelined pieces), scratch poisoned; 410/410 ok.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 09:20:22 +01:00
mici81andClaude Opus 5.5 2721f7c951 MXFP4 gated fold: review fixes and docs
The parts of the series' review rounds that concern the fold, carried over when the series was
split:

- gemm_mxfp4a8_gated_gemv: operand dtypes checked, the activation scale grid read as the gemm_nt_q
  rows read it (mx_ascale_grid), row pitches checked against the widths; the arrival counters are
  zeroed before any launch reads them (the memset is on the null stream, which the engine's
  streams need not wait for).
- The layout hooks refuse an operand the gated row does not have; the GeGLU chain refuses
  out_bf16 (its bf16 plane is a temporary there).
- r4d_selftest: the reference plane through the gemv row's own hook must be the same bytes; the
  small gated cases at K 256.
- libr4d/README.md and docs/TOOLS.md: the row, and --perfmxd's fold timing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:59:53 +01:00
mici81andClaude Opus 5.5 cbc299417e gemm_mxfp4a8_gated_gemv: a block per gate/up tile pair, the group quantised by its last block
One block a 128-column group left the grid at n / 128 blocks (68 at Qwen per rank on 32 WGPs) and
the fold lost to the pair it replaces. Now the gemv row grid and K order, the bf16 product and
row amaxes through the op scratch, an arrival counter per group keyed on the output. Byte for
byte the old fold (selftest, twice into one output); r4d_selftest launch_row sizes scratch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:59:53 +01:00
mici81andClaude Opus 5.5 a596f68782 gemm_nt_q_gated_mx at gelu_tanh: the GeGLU MLP's gate_up, gelu_mul and quant_act_fp8 in one launch
TranslateGemma's MLP over MXFP4 runs gate_up, gelu_mul into a bf16 plane and quant_act_fp8 over it
before down. The gated fold now takes act gelu_tanh: gelu_mul's tanh GELU with its constants, the
product rounded to bf16 as gelu_mul stores it, then quant_act_fp8's quantiser (the same arithmetic as
gated_quant_fp8's). Byte-identical to the three-op chain (selftest at M = 1, 4, 8 on TranslateGemma's
per-rank gate_up, the smallest shape and the per-row scale); the replaces-hook gives the chain. The
GeGLU form writes no out_bf16: the chain's bf16 plane is gelu_mul's own output, which the hook cannot
hand to an optional operand, and the shim refuses one.

The gemma3 plugin declares the fold at up to 8 rows when both MLP linears are MXFP4 and no
calibration tap reads the bf16 plane.

TranslateGemma alone, speculation 7, two rounds each: one stream 144.5 / 144.9 -> 151.5 / 150.5 t/s,
four streams (32 rows a step, past the band) unchanged; greedy translations identical.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:59:53 +01:00
mici81andClaude Opus 5.5 f16854499c decode launches: gate_up + gated_quant_fp8 folded for MXFP4 (gemm_nt_q_gated_mx)
A decode step on Qwen3.8-27B at TP2 issues 631 kernels a card, and a dependent kernel costs the card
3.5-6.4 us in a replayed graph on gfx1201 however little it does, so launches are about 13 % of a
step.

- gemm_nt_q_gated_mx: gemm_nt_q_gated over an OCP-MXFP4 weight (b_ref after b_scale; a new op, not
  an optional operand on the old one). Row gemm_mxfp4a8_gated_gemv: M <= 8, a block per 128-column
  group of the gated output, a wave per gate or up tile running all of the gemv WMMA form's partials
  in its order, then gated_quant_fp8's epilogue -- byte-identical to gemv + gated_quant_fp8
  (selftest, M = 1..8, Qwen's and TranslateGemma's gate_up). The MLP block declares it for a plain
  MXFP4 gate_up when a loaded library declares the op (libref does not), so a CPU-only engine takes
  the pair. Layout hooks map its b_ref (operand 4) to gemm_nt_q's index, so the weight is stored once.
  The fold: 82.5 us against 81 + 4.6 for the pair at Qwen's gate_up, 98.8 against 104 + 4.7 at
  TranslateGemma's.
- --perfmxd times gated_quant_fp8 and the fold beside the gemv row at a gate_up shape.

Greedy texts of four prompts, speculation 0 and 3, identical to the production build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:59:53 +01:00
C_Tamas 486c933161 device and plugin boundary: kv_resolve, the streamed store rows, ABI 30 2026-10-25 09:58:04 +01:00
Deadcode 5a9ce4912b radiance 1.12.0
New models:
- Fish Audio drama-3: speech with speaker tags and inline direction, voices cloned from reference
  clips (the `references` field of /v1/audio/speech and the streaming session), two cards
- Gemma 4 E2B/E4B (KV-shared layers, per-layer embeddings, clipped vision linears), with
  NVIDIA-Nemotron-3.5-Bolt-E4B in bf16 with DFlash and vision on one card, and E4B recipes

Speed:
- MXFP4 GEMMs for one to 64 rows and a tiled prefill GEMM at TN=4 from 1024 rows: the 27B MXFP4
  with DFlash2 decodes about 1% faster at c1, 5% at c4 and 14% at c16
- The fp8 and int8 LM heads read their weight once for 65 to 128 rows
- A prefill step of one sequence runs in two pieces on a second lane at two ranks (qwen35_fp8,
  gemma3): a 45K-token prompt on the 27B fp8 in 15.1 s instead of 16.2 s
- Gemma 3's fused all-reduce junctions also under a lossy wire
- --draft-short-from N: a block drafter runs its shorter block from N decoding sequences on
  (off by default; with 8 on the 27B MXFP4: c8 +12%, c16 +18%, c64 +32%, c1 unchanged)
- --tp-attn-split rows: GLM-5.3-Flash's MLA attention split by rows over the ranks, 18 to 21%
  faster prefill; lossy, `heads` stays the default
- --draft-coupling on: Qwen3.8-Flash-Next's MTP drafter samples its proposals from its reranked
  top-8 and the target's draw is coupled to it; pays at high temperatures (c1 at T 1.0: 155 ->
  178 tok/s), costs at low ones; off by default

Features:
- Edited prompts on windowed models (Gemma 4) reuse their prefix: periodic window snapshots, and
  snapshot-backed prefix KV kept across recomputes (an edited tail on Gemma 4 31B: 96 s -> 2.6 s)
- DELETE /sessions/<label> and DELETE /sessions?id=<id> forget one stored conversation
- --state-cache-dtype f16: the delta-net state cache at half the memory (qwen35 plugins; lossy)

Fixes:
- A browser's CORS preflight allows DELETE

Changes: Plugin ABI 27: out-of-tree plugins must be rebuilt. The environment switches the PRs
added are flags now (--tp-attn-split, --draft-coupling, --state-cache-dtype).
2026-10-24 13:12:28 +02:00
mici81andClaude Opus 5.5 4ec175549c pipelined prefill: review fixes
The parts of the series' review rounds that concern the pipelined prefill and the second lane,
carried over when the series was split:

- qwen35_fp8: a trunk whose norms write rotated int8 codes (qwen35_w8a8 where libr4d serves the
  `_had_quant_i8g` forms) prefills serially -- the boundary norms on the second lane issue the E4M3
  pair only, and before the fix libr4d refused them for the int8 op, failing every one-sequence
  prefill step of 1024 rows or more; a pipelined step whose bounds have no storage fails the step
  rather than falling back on one rank only.
- The three- and eight-rank overlap all-reduce rows accept every tunable pin their wide rows accept
  (r4d_selftest checks it).
- rad_builder.h: the window joins lane 1 into lane 0 at its end only, so an op declared before it
  must not be issued again while lane 1 has work pending.
- tests: arch_test for the w8a8 trunk; plugin_test's lane-row comment.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 48e41fda1e the narrow overlap all-reduce at three and eight ranks only on request: R4D_AR_LANE_3_8
The three- and eight-rank `overlap` rows (ar_twoshot_3rank_exact_lane, ar_twoshot_3rank_ti8_lane,
ar_twoshot_8rank_exact_lane) took the four-rank lane rows' narrow launch for every collective a plugin
issues beside compute: qwen4exp's --prefill-span, gemma4's prefill trunk overlap and the image and
video plugins' second-lane collectives included. That changed a default above two ranks without a
measurement, and a narrow grid can lose there too: where the all-reduce is the longer of the two (a
large message, slow or shared links, seven peers to feed at eight ranks) the step waits on a slower
collective. They now launch exactly as the wide rows by default (tArTs38Lane holds tAr's defaults: the
same grid, the same bits, the same time); R4D_AR_LANE_3_8=1, read once at load, gives them the
four-rank lane's four blocks of 1024. The bits are the same either way.

r4d_selftest checks the defaults both ways (failed before the change: nblocks 4 where the wide rows'
rule is 0). GUIDE §4.7 (with what to set and what it may gain or cost), §4.5, the environment table,
OPS, TP3 and libr4d/README say it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 284feda3a6 pipelined prefill past two ranks on request: RADIANCE_PREFILL_PIPELINE, narrow all-reduce at three and eight
- One switch for qwen35_fp8's and gemma3's pipelined prefill, RADIANCE_PREFILL_PIPELINE=auto|on|off
  (arch/common/rad_prefill_pipe.h), in place of RADIANCE_QWEN35_PIPE / RADIANCE_GEMMA3_PIPE. auto
  (or unset) pipelines at two ranks, where it is measured; on also at three, four and eight, with a
  declare note that it is not yet measured on such hardware; off never. Another value is noted and
  taken as auto.
- libr4d: the narrow `overlap` all-reduce rows at three and eight ranks, as the four-rank ones are:
  the wide two-shot rows' entry points (exact at three and eight, ti8 at three) at tArTs4Lane's
  launch, so the collective beside the other piece's compute does not take the card (a wide one
  slows the GEMM beside it 1.45-2.1x and ate the whole gain at two). Bit-identical to the wide rows
  by construction; neither launch is tuned on three or eight cards, which this rig does not have.

arch_test: at four and eight ranks a 2048-row step of one sequence is serial unless asked; asked,
it runs in two pieces on every rank with every collective on the second lane at `overlap` 1 and
the embedding's whole (failed before the change: the step stayed serial).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 73b1d039a0 gemma3: a prefill step of one sequence in two pieces, block boundaries on the second lane
qwen35_fp8's pipelined prefill on Gemma 3's MXFP4 trunk at two ranks: every block runs a piece
at a time on lane 0 (the attention over its own query bounds and positions, the GeGLU MLP), and the
work between two blocks a piece at a time on lane 1 -- the block's all-reduce at `overlap` 1, its
post-norm and the fp8 junction (the add and the next norm with its quantiser), after the last block
the add, the DFlash2 taps and the final norm. RADIANCE_GEMMA3_PIPE=0 turns it off.

- Every q|k|v and gate|up reads one shared E4M3 input pair under the pipeline (the junctions write
  it), so the second lane's buffers cost one pair, not one a linear (rad_buf_concurrent keeps them
  live for the whole program).
- A window KV group's seqused counts from its rebased first block, so the first piece's cannot be
  its position: it is the group's seqused less the second piece's rows, computed on the card by a
  new libr4d op, sub_i32 (y = x - s[0], int32; documented in OPS.md, a selftest case). The first
  try used the position and faulted on a 12k prompt past the 1024-token window.
- G3Linear and G3JunctionFP8 row-sliced forms; each block's overlap all-reduce.

Bit for bit the serial step: TranslateGemma's KL recordings at chunk 2048 and one sequence a step
(so a document's steps from 1024 rows pipeline) compare equal with the pipeline on and off. Prefill
on two R9700s, chunk 2048: 6k tokens 1.27 -> 1.21 s, 12k 2.48 -> 2.42 s; at chunk 1024 (pieces of
512) no gain, so a deployment wants 2048 (against 1024: -9 % / -7 %). arch_test: a 2048-row TP2
step runs in pieces with its collectives on lane 1 and the shared pair; RADIANCE_GEMMA3_PIPE=0 runs
it serially.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 57d2cb4043 review fixes of the pipelined prefill (independent review)
- pipe_ready: past the batch's and the build's own conditions (the same on every rank), a
  rank-local failure -- no pinned host memory for the bounds table, or its copy failing -- now
  fails the step instead of running it serially. A serial step on one rank beside a pipelined
  one on the other issues different collectives on the shared all-reduce instance: a hang or a
  wrong sum.
- declare frees the previous build's pinned bounds table before resetting the model.
- NormQuantFP8: the slicing comment back above step(); step_plain() gets its own.
- r4d_rows: the TN axis's help text says the new crossover (M >= 1024).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 fb880cbc2d MXFP4 decode rows: review fixes and docs
The parts of the series' review rounds that concern these rows, carried over when the series was
split:

- gemm_mxfp4a8_decode: the 64-wide slab is chosen by the split the launch runs (a pin or a tuned
  point included), as before the register kernel; the header states the split-row bound the rule
  applies (ks*M = 1024).
- r4d_selftest: the priority order of the MXFP4 rows is checked (gemv / gemv_wide over decode,
  decode_shortk over gemv_wide, decode over tiled); gemv_wide's numeric cases at K 256 and at 56
  rows; the M-invariance check names the decode_shortk corner it does not cover.
- Comments: gemv_wide's two-tile condition (N >= 4096, K >= 3072, an even tile count), the
  decode_shortk corner's bit change at M = 33, decode_shortk in the list of rows whose state is
  keyed on the output.
- libr4d/README.md: the rows by row count, with the measurements behind each band;
  docs/TOOLS.md: r4d_selftest and its --perfmxd mode.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 f3429d8c13 gemm_mxfp4a8_decode_shortk: the decode kernel at 33..64 rows of a wide, short weight, above gemv_wide
gemv_wide's blocks hold three or four row tiles over the whole K, so on a short K the cross-wave
reduction of a block outweighs its WMMAs, and on a wide N there are many such blocks. Swept over 24
per-rank shapes (Qwen3.8 and TranslateGemma at TP1/2/4/8, 1B/4B/8B-class dense) at 24..64 rows, each
row timed alone: gemv_wide is at least upstream's decode kernel everywhere except N >= 8192 with
K <= 2560 past 32 rows, where it lost by 7..30 % (19456 x 2560 at 64 rows 131.8 us against upstream's
104.5; 16384 x 2048 92.8 / 76.1; 9728 x 2560 74.1 / 67.4). This decode kernel takes that corner:
93.3, 68.6 and 52.5 us. A row of its own (same entry, scratch hook and tunables as the decode row,
priority 59, constraints M 33..64, N 8192..36864, K <= 2560) rather than a rule in the gemv entry,
so the planner's choice stays a table lookup. Narrower N stays with gemv_wide (5120 x 2176 at 40
rows 39.2 against 52.8), as does every shape of the models we serve. r4d_selftest: five numeric
cases over the corner, both activation grids and parts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 b66752adcc libr4d: gemm_mxfp4a8_gemv_wide, the gemv row's WMMA form at 9 to 64 rows
The WMMA form takes up to four 16-row tiles a wave: each weight word of a chunk is loaded and folded
once and multiplied with every tile's activation fragment, so the weight streams once from DRAM to
registers whatever the row count, with no LDS staging. A row's sum is its tile's WMMA chain alone, so
its bits are the same at every tile count: the first row is bit-identical from M = 1 to 64 (selftest),
across the gemv row (M <= 8) and the new gemv_wide row (9 <= M <= 64, K % 128 == 0, same entry and
priority). Several streams with speculation land there (4 x (1 + 7) = 32, 16 x (1 + 3) = 64).

--perfmx against the decode row that served 9..64 before (us, Qwen3.8-27B / TranslateGemma per-rank
decode shapes): down 51-80 vs 56-105, ssm_out 27-42 vs 30-55, attn_qg 40-63 vs 44-74, TranslateGemma
down 61-97 vs 66-123, o 22-35 vs 25-51, gate_up at 24-48 rows 110-141 vs 145-170; gate_up at 48-64
rows about even (Qwen) or behind (TranslateGemma at 64, 171 vs 153).

Selftest: gemv_wide at RT 2..4, both activation grids, a partly live tile, parts; the M-invariance check
runs the wide row under the gemv row's selection (mxfp4a8_numeric's any_row).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 75b4d0baa7 libr4d: gemm_mxfp4a8_gemv, the MXFP4 x fp8 GEMM for one to eight rows
One stream's decode (M = 1 + the draft depth) is a pure weight stream; the decode row stages the
weight through LDS and leaves narrow projections at a third to two thirds of DRAM bandwidth. The new
row (priority 58; M <= 8, K % 64, N % 16; the same packed weight bytes as every MXFP4 row) keeps the
weight in registers: WMMA from register fragments when K % 128 == 0, v_dot4 otherwise. The form and
the wave count per block depend on K alone, so a row's output bits do not depend on M (a verify
step's first row equals the plain decode of it). The scale and reference planes must be 4-byte
aligned.

Selftest: every reachable instantiation (both forms, both activation grids, M = 1..8, tile counts
divisible by 4, by 2 only and odd, parts), the output prefilled with NaN, an odd column stride, and
the first row's bits against M for gemv and decode. --perfmx times the MXFP4 rows at one shape.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
Deadcode 9eaf10da6e radiance 1.11.0
New models:
- GLM-5.3-Flash reads pictures: its vision tower and processor (--image-tokens sets the budget),
  with decode kernels for a few rows and the DSA indexer split over the ranks
- Sage-A1.5 (fp8 and MXFP4) with its vision tower and a DFlash2 drafter
- Unlimited-OCR (bf16)
- Gemma 4 31B with z-lab's DFlash and RedHatAI's DFlash2 drafters; at four cards its all-reduces
  are fused with the junctions, overlapped with the compute and sent compressed
- Ornith-1.5-35B-A3B w4a8 compose files

Speed:
- Block drafters (DFlash, DFlash2) accept their drafts on the card, and the next step is issued
  ahead
- The four-rank all-reduce is faster for every --tp 4 model
- qwen35_w8a8: the norms and SiLU write the int8 linears' operands directly
- --attn-prefill-fp8 off|qk|pv|both: fp8 QK and PV legs for the h256 prefill attention (about +20%
  prefill on a 221K-token prompt for the 27B MXFP4 at TP2); lossy, off by default

Features:
- Control vectors: --control-vector off|on|disabled (disabled by default), a per-request switch,
  and the published Qwen3.8-Flash-Next refusal-direction vector (its license is in NOTICE)
- Krea 2: the `rebalance` request field, as ComfyUI's ConditioningKrea2Rebalance
- Cards with a small PCI BAR run, with kernel arguments kept in host memory
- Dashboard: live acceptance figures; statsdump rotates its file at a size cap
- KV caches every rank holds whole (GLM-5.3's latent and index caches) take one host-tier slot

Fixes:
- Long conversations taking turns no longer fall back to an early snapshot: a host-tier restore
  makes room as memory pressure does and waits a step for the previous turn's release (two
  conversations of 142K and 147K tokens sent back to back: 31.3 s per turn before, 2.8 s now)
- Kernels before Linux 6.16 (amdgpu below 3.64) no longer hang at startup: virtual memory
  management is turned off there, with a warning
- Gemma 4 dense scales its token embeddings as Hugging Face does (bf16), which changes its output
- The four-rank all-reduce fences prefill-sized messages, for a rare divergence after a fresh start
- GLM-5.3: every refusal names the setting and the reason; its template keeps string content
- Several pictures in one request no longer refuse processors that take one image at a time

Changes: Plugin ABI 26: out-of-tree plugins must be rebuilt. The environment switches the PRs
added are fixed rules or flags now (R4D_ATTN_FP8 is --attn-prefill-fp8).
2026-10-23 11:57:52 +02:00
mici81andClaude Opus 5.5 b90723eabe logits_gemm_fp8: 65..128 rows in one pass, the head read once
lm_wmma_kernel held at most four 16-row tiles a wave, so past 64 rows the launcher made passes of 64
and read the fp8 head again for each. With MH = 2 the workgroup's eight waves split into two M halves
of four tiles over 64 weight rows that share one staged tile: Qwen3.8's per-rank head (124160 x 5120)
at 128 rows 3059 -> 1984 us, TranslateGemma's 3242 -> 2036 us; 65..128 rows -33..-39 %, 160..256
-26..-37 %, 64 and fewer unchanged. Same scale blocks, WMMAs and K order per output: the same bytes.
r4d_selftest: the heads' numeric cases at 65..150 rows, --perf times the head up to 256 rows, and
R4D_PERF_ONLY=<row> times one row alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:23:58 +00:00
NunzeandClaude Opus 5.5 87701cb6b8 libr4d: mla_attn_rows_bf16 -- one key load for all 64 heads of a query row
A third mla_attn row, at 64 heads. A workgroup takes one query row and all its heads, four waves
to each group of sixteen, and loads each 16-token key chunk once for all of them, where the
matrix row loads it once a tile of sixteen. The scores are K Q^T, tokens as the tile's rows and
heads as its columns, so a head's running maximum and denominator stay in its lane; the waves of
a group each take a quarter of the latent's dot products and add the four partials in one order,
and the probabilities reach the value product through a permlanex16 swap instead of LDS. The
next chunk's keys are fetched into registers while the current one is multiplied, two barriers a
chunk. A row's bytes do not depend on the other rows of the batch. Under 32 rows the launcher
runs the matrix row's kernel; r4d_mla_rows_pin_form, a test hook, pins the element-wise key load,
32 heads a workgroup, the rows kernel at any row count, or the matrix row's kernel at every row
count (the form a KL measurement needs to tell this kernel's share of a row split's difference).

Measured on gfx1201 (r4d_selftest --perfmla, one sequence past the DSA budget at 16k of
context, 513 blocks): 512 rows x 64 heads take 3.9 ms, 35 TFLOP/s, against 12.3 ms on the
matrix row, and the 4096 rows x 8 heads they stand for in a TP8 prefill chunk 14.0 ms on the
paired union tile. Against the wave row the output stays within the matrix row's tolerance
(max abs 2.4e-4 at 513 blocks).

r4d_selftest checks it against libref at 1 to 33 rows, 32 and 64 heads, every fill and both key
loads, and times it against the matrix row (--case mla_attn_rows_bf16, --perfmla at 64 heads).
r4d_emu_mla runs it on the host against an f64 softmax, its forms bit for bit against each
other, a run of rows against the same rows of the whole batch, and a mixed TP step (decodes, a
verify window, a prefill past the budget, a fresh chunk) split by heads over the matrix row and
by rows over this one, at runs that do and do not divide the step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 09:58:07 +00:00
NunzeandClaude Opus 5.5 f909576d09 libr4d: logits_gemm_bf16_cols -- the bf16 head without a block per column at n_embd 4096
logits_gemm_bf16 runs a 256-thread block per vocabulary column. At n_embd 4096 a thread makes two
16-byte weight loads before the block-wide sum, and each row widens both operands for its own
product: GLM-5.3's TP8 slice (19360 columns) took 303 us at six rows and 1133 at 24, where a verify
pass of eight streams lands, against 235 at one.

The new row runs a wave per four columns: lane l takes, in turn, threads 32q + l of the old
block for q = 0..7 -- the same 8-wide k chunks summed from 0 and added in k order, the same lane
butterfly per q, the eight wave sums added in q order from 0 -- so each column gets the old row's
bytes. bf16 widens to f32 exactly, so each weight is widened once for every row and each
activation once for every column. It outranks the block row at n_embd 4096 only; the block row
is unchanged and serves every other width.

Measured at the TP8 slice (r4d_selftest --perflogits), us:

  rows                 1      6      8     16     24     48
  logits_gemm_bf16  239.1  303.2  378.2  741.4 1133.2 2354.5
  ..._cols          235.5  247.5  250.4  404.5  635.6 1220.1

Two columns a wave and 16 rows a pass measured slower. r4d_selftest compares both rows byte for
byte from one row to past one 8-row chunk, at a vocabulary off the column step and a pitched
activation with a NaN and a signed zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 15:26:57 +02:00
NunzeandClaude Fable 5.1 afe5318259 dsa_score: row_part -- score one run of a step's query rows, and rebase cu for the selection after it
With `row_part` p, `score` holds R rows and row i is query row p * R + i; `q`, `q_scale` and
`gate` stay the whole step's, so a run is the unsplit op's rows bit for bit. A row past the last
sequence scores -inf, so every rank's run can be the same length whatever the step's. The optional
output `cu_part` receives cu - p * R, under which qsa_select runs over the run's own rows (pos
offset by p * R) and finds each row's sequence unchanged; qsa_select itself is untouched.

This is what an indexer split over tensor-parallel ranks by query rows needs from the op: the
scoring is the only per-row work in GLM-5.3's indexer that grows with the context.

libr4d offsets the query operands and compares row0 + r against cu; libref and libavx index the
same way. Without `row_part` nothing changes. Tests: the selftest scores each case's rows in equal
runs and holds every run to the unsplit rows' bytes and cu_part to the rebased bounds; ref_test
checks a run, a run past the step and a short query plane; r4d_emu_dsa (r4d_dsa.hip now runs on
the emulator) splits decode rows beside a prefill chunk at 2, 4 and 8 ranks, selects with the
rebased bounds and joins the runs as the all_gather does, byte for byte against the unsplit
scorer and selection, ties and signed gates included.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 15:24:05 +02:00
AshlynandClaude Opus 5.5 5e8bae8ae6 libr4d, arch, deploy: coded overlap all-reduces, multi-user verify tuning, the split junction, a compose file
The prefill overlap's lane all-reduces coded losslessly at ~12.2 bits a value; the verify step's
GEMM, norm and all-reduces tuned for 17-64 rows; at 4-16 rows each GPU norms its own rows between
a reduce-scatter and an int8 all-gather; deploy/compose/gemma4-31b-w4a8-df2-tp4.yaml.

Squashed from:

- libr4d: the four-rank exact two-shot coded at ~12.2 bits a bf16 value, for the lane row
- libr4d: the prefill overlap's lane all-reduces coded by default
- libr4d: decode-sized two-shots take fewer blocks
- libr4d: gemm_w4a8_nt_m64 at multi-user verify heights (33-64 rows) -- narrower row tiles, wider N
- libr4d: rmsnorm_quant_i8's register form at 512 threads too (33 to 72-120 rows)
- libr4d: ar_rmsnorm_quant_i8_4rank's `sp`, the all-reduce split around the junction
- arch/gemma4_bf16: the 31B's junctions take libr4d's `sp` at 4-16 rows at four ranks
- deploy/compose, README: Gemma 4 31B with RedHatAI's DFlash2 drafter on four cards

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 03:00:48 -05:00
AshlynandClaude Opus 5.5 ab2b3be6c0 core, libr4d, arch: chained launches with block drafters, more prefill overlap, weight reads beside the all-reduces
Chained launches on the AQL backend (a dependent kernel waits on a queue counter in its own
prologue), on by default where the model's plugin measured a gain with its block drafter (the
Gemma 4 31B and 26B); the prefill overlap runs attention per slice with narrower lane-1
reductions; the next GEMM's weight is read into the on-die cache beside each all-reduce at decode
heights.

Squashed from:

- core, libr4d: chained launches -- dependent kernels wait in their prologue, not behind the barrier bit
- core, libr4d: chain a kernel by its name, not by the row that launched it
- libr4d, core: chained forms hold nothing across their body
- libr4d: a chained kernel's prologue polls its counter less often after the first few tries
- core/sched: the advance kernel's chained form
- docs: GUIDE lists RADIANCE_CHAIN; chained launches stay opt-in
- core/device: a chained packet behind a chained one keeps its barrier bit while a plain one may run
- libr4d: qkv_norm_rope and its kv_store fold as chained forms
- libr4d: the split-KV decode attention and its merge as chained forms
- libr4d: the four-rank fused junction's tail form as a chained form
- libr4d: the attention, prologue and junction chained forms hold nothing across their body
- libr4d: the 31B's windowed attention and quant_act_i8 as chained forms; r4d_chain.h stubs for the host emulator
- libr4d: DFlash2's kernels as chained forms
- libr4d: chained forms for the decode tail
- abi, core, arch: chained launches on by default where the plugin measured a gain with its drafter
- arch/gemma4_bf16: the prefill overlap's lane-1 all-reduces take the narrow launch (`overlap` 1)
- arch/gemma4_bf16, libr4d: the prefill overlap runs attention per slice; kv_len_trim
- abi, core, libr4d: RAD_LAYOUT_ANY, and a device-only weight read (prefetch)
- arch: read the next GEMM's weight into the cache beside each collective at decode heights

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 03:00:48 -05:00
AshlynandClaude Opus 5.5 1bb7ad3ef9 The series' PR beneath, composed (a copy; it drops out when it lands)
#159's tree (a full fence on four-rank prefill-sized all-reduces), which the maintainer will merge
by hand in the next release, as the integration branch composed and tested it. Not for review
here: review the last commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 02:59:52 -05:00
AshlynandClaude Opus 5.5 015cba8837 libr4d, arch: the 31B and DFlash2 with fewer launches a step, same bytes
Attention reads q and the gqa-8 drafter's KV in place (attn_paged_qrow); the 31B's attention
prologue stores k and v itself (qkv_norm_rope_kv_store); DFlash2's norm/rope/cache-store chains
and add-then-norm pairs run as one launch each. Carries the launch-cliff padding until that PR
merges.

Squashed from:

- libr4d: attn_paged_qrow on the split-KV decode kernel -- h256/gqa2, and h128/gqa8 by two groups a kv head
- arch: the 31B's sliding layers and its drafter read through attn_paged_qrow where a card serves it
- libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms
- libr4d: qkv_norm_rope describes its operands, so rad-kbench and rad-tune can time it
- libr4d, arch/gemma4_bf16: qkv_norm_rope_kv_store -- the 31B's prologue stores k and v itself
- libr4d, arch/common: qkv_norm_rope takes v_norm; DFlash2's query pass folds its q/k chain
- libr4d, arch/common: qkv_norm_rope takes n_head 0; DFlash2's context pass folds its key chain
- libr4d, arch/common: add_rmsnorm; DFlash2 issues each residual add with the norm after it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:48:20 +02:00
AshlynandClaude Opus 5.5 04e5480387 arch, data/recipes, libr4d: the 31B's prefill overlap, q|k|v as one linear, RedHatAI's DFlash2, its fc split
The 31B's prefill steps of 1024 rows or more run as two slices with each slice's all-reduces
beside the other's compute; q, k and v as one linear where the container holds them so; the 31B
serves RedHatAI's DFlash2 speculator; DFlash2's fc projection is split over the ranks, bit for bit.

Squashed from:

- arch/gemma4_bf16: a prefill step in two slices, each slice's reductions on the second lane
- arch/gemma4_bf16: q, k and v as one linear where the container holds them so
- data/recipes: the 31B -df recipes make q, k and v one linear (blk.*.attn_qkv)
- arch/gemma4: the 31B serves RedHatAI's DFlash2 speculator (gemma-4-31B-it-speculator.dflash2)
- libr4d: gemm_nt_q takes split_n, and all_gather lands rows at a wider output pitch
- arch/common: DFlash2's fc split over the ranks as windows of block-aligned rows, bit for bit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:48:20 +02:00
AshlynandClaude Opus 5.5 239da14d17 libr4d, arch/gemma4_bf16: the four-rank all-reduce by message size, and the 31B's junction fold to 16 rows
The four-rank exact all-reduce picks its transport and block count by message size, for every
tp-4 model; the four-rank fused junction gains its tail form (the two-shot with the junction after
it), which the 31B takes up to 16 rows. Carries rmsnorm_quant_i8's register form until that PR
merges.

Squashed from:

- libr4d: the four-rank all-reduce's fold a word at a time, 16-row standalone all-reduces on the two-shot, counters in L2
- libr4d: the standalone four-rank all-reduce takes the exact two-shot from 32768 elements
- libr4d: the four-rank exact all-reduce's two-shot takes 2 blocks at a DFlash2 verify, not 4
- libr4d: the all-reduce rows' nblocks axis offers 2 and 4
- libr4d: rmsnorm_quant_i8 at decode heights loads the row's operands before its reductions
- libr4d: the four-rank fused junction's tail form -- the two-shot with the junction after it
- arch/gemma4_bf16: the four-rank fold up to 16 rows, on libr4d's tail form

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:47:23 +02:00
AshlynandClaude Opus 5.5 61266c812b libr4d: a full fence on four-rank prefill-sized all-reduces, for a rare fresh-start divergence
On a freshly started 31B server at four ranks (4x R9700), the first greedy reply now and then
flipped a near-tie: 1 of 8 fresh starts after scribbling the cards' memory. Per-op output hashes
located the divergence at a prefill all-reduce that read a peer's scratch before that peer's words
had landed: the first reuse of a double-buffered slot, inputs identical on every rank. A full
system fence on every thread before the flag (drain 1), or after it (acq 1), cured it on the cards
(26 of 26 fresh starts). The per-wave store wait, the publisher's single writeback and Relaxed
Ordering off on every link did not. The mechanism below the fence is not known.

r4d_cfg_ar now takes drain 1 for a four-rank message of RADIANCE_AR_FENCE_FROM elements or more
(default 131072: 24 rows of the 31B's 5376, above any verify height and below every prefill chunk).
Decode and verify all-reduces keep the per-wave store wait and pay nothing; 0 turns the fence off.
Two-rank all-reduces never take it: Qwen3.8-27B's prefill at tp 2 paid 4.5% for it, and no
two-rank fresh start ever flipped. GUIDE.md lists the switch. Bytes are unchanged either way; only
when the flag goes out moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 02:31:40 -05:00
C_Tamas cd1f2f59cc docs, comments, tests: a consistency pass after the kernel move and the 404
Stale text that outlived the fixes around it: the deleted unit's filename in
libr4d's gated-residual comments, hc_project missing from that unit's header,
"THE SPEED PROJECTION" heading the page's control-vector code, ABI 22 comments
beside a table that says 23, a projection_test header crediting rad-kbench with a
case it does not have, a comment stating the wrong scale arithmetic, a duplicated
<cstring>, and GUIDE's "off in all cases" (the admin switch flips it). libavx's
README transcript is refreshed from a real run (807 checked, at every level).

And the test the alias order needed: a body carrying both `control_vector` and
`experimental_speed_projection`, with the field's own name winning.
2026-10-21 09:26:17 +02:00
C_Tamas f3979aa538 docs, tests: say what the branch does, and test what the docs say
Review found four places where the branch's prose had outrun its code:

  - docs/GUIDE.md 4.10 promised that an incompatible sidecar "stops startup" two
    sentences after promising it is "reported and skipped" (the code warns and
    serves without it), and claimed deployment-level bit-identity for a request
    without the vector, which the PR explicitly withdraws. Both now say what the
    engine does; the wording is core/cvec.h's, which already had it right.
  - cvec_test claimed discovery order and a range past the model in the PR, but
    neither case existed. Both are there now, reusing the file writer and load()
    the file already had, so discovery -- the branch's policy choice -- has
    coverage at all.
  - the libr4d row descriptions still said "experimental speed projection" after
    the naming commit, and pointed at the unit that no longer exists;
    ref_hc.cpp's comment had a duplicated clause.
  - /stats' `n_layers` reported the direction count (47 of 48 layers); it is the
    model's layer count now, with first/last carrying the range.

The alias is read before the field's own name, so a request that sends both is
read as `control_vector`, and engine.cpp's /server_info comment is back above
engine_info.
2026-10-21 09:26:17 +02:00
C_Tamas 459dd4f42d vocabulary: hc_project -- a control vector's direction, projected out of the wide stream
h[s] -= scale * (h[s] . v) * v        for each of the hyper-connection streams s

llama.cpp's --cvec-mode project semantics: the dot is per stream, because the patch applies it to
the [n_embd, hc, tokens] view where mul_mat(v, cur) reduces over dim 0. v is one layer's unit
direction (f32), scale is the norm its file stored, and 'on' is a per-row int32 switch: a zero row
is skipped without a read or a write, so an unprojected request is byte-identical to a deployment
with no vector loaded.

libref is the oracle and the host fallback, libavx carries it at every ISA level, libr4d (one
workgroup per (row, stream), LDS reduction) serves the card. docs/OPS.md gains the row and the
operation's three facts.
2026-10-21 09:26:17 +02:00
eddie168168andClaude Opus 5.5 d999524054 libr4d: rmsnorm_had_quant_i8g, ar_rmsnorm_had_quant_i8g, gated_had_quant_i8g -- producers that write rotated int8 codes
An i8a8h linear quantises its own input from the bf16 plane with had_quant_act_i8g, so a decode
step of the int8 Qwen3.8-27B issues 288 of them after the norms and the silu product. These three
device ops write those codes from the producer instead:

- rmsnorm_had_quant_i8g and ar_rmsnorm_had_quant_i8g (exact and wire=6): norm_quant_row gains an
  HI8 form, r4d_fwht_wave<128> and then quant_group<I8>, on the lane mapping, rotation and rounding
  had_quant_act_i8g uses.
- gated_had_quant_i8g: the gated kernel's existing ROT && I8 instance, which the shim refused.

Each writes the bytes its producer followed by had_quant_act_i8g writes. They are ops of their own,
not a flag on the fp8 forms, as gated_had_quant_fp8 is: a rotated and a plain quantiser must not be
substitutable. n % 128 == 0; device only, so a graph falls back to the pair where they are not
declared.

r4d_selftest checks each against its pair byte for byte (plain, with the residual add and the
residual it leaves, and the gated product) and that each refuses E4M3 codes. The all-reduce form
is skipped like ar_rmsnorm_quant_fp8, since it needs a peer rank.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:25:39 +02:00
AshlynandClaude Opus 5.5 13a917910f libr4d: rmsnorm_quant_i8 at decode heights loads the row's operands before its reductions
The kernel re-read its row from memory in each of three passes, each behind a barrier, so a
row cost three dependent round trips: 11 us a launch at any height on gfx1201 against a 4.2 us
launch floor. Every pass partitions the row the same way, so at 1024 threads (M <= 32, n <= 8192)
each thread now loads its own columns of the branch row, the residual and both gains in one go
and keeps them in registers; only the fragment-order store crosses threads, through LDS as
before. Same sums in the same order and the same per-element arithmetic, so the same bytes.
8.2 us a launch in a four-card microbenchmark at 1, 4, 8 and 16 rows of 5376.

The row gains a reg axis (1 the new form and the default, 0 the old), and the selftest checks
both forms against the unfused chain at M=8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:24:39 +02:00
AshlynandClaude Opus 5.5 5f78a1d0cd libr4d, arch/gemma4_bf16: at four ranks the 31B's junctions carry the all-reduce in front of them
ar_rmsnorm_quant_i8_4rank is the wide family's exact four-rank one-shot with the junction (the
residual add, the sandwich norm and the int8 quantiser) as its epilogue, as ar_hc_write_4rank is
that one-shot with hc_write. The reduce is the standalone exact all-reduce's arithmetic element by
element (fp32 from zero, ranks ascending, one rounding to bf16), so the reduced row matches it to
the bit, and the junction is rmsnorm_quant_i8's over that row. It shares the standalone
all-reduce's transport and instance and ends the engine's link hold itself, as docs/TP4.md asks of
a new collective row.

Every block takes one handshake, a system-scope release by its first thread and a system-scope
acquire by every wave. Both fences are needed: on 4x R9700 behind an EPYC root complex, dropping
either left the readers with stale scratch on nearly every element. `nblocks` 2 and 4 (fewer
handshakes, each block owning several rows) are tune points, off by default.

r4d_selftest's case of the same name holds every rank's reduced row, residual, output, codes and
scales byte for byte to all_reduce followed by rmsnorm_quant_i8 on four cards, at 1, 8, 40 and 97
rows of 5376 and 64 rows of 2816. r4d_selftest is now installed in the image, so a card box can run
the rows' checks without a build tree.

At four ranks a 31B decode step issued 121 standalone all-reduces, 119 of them followed by a
separate norm launch. The plugin now declares ar_rmsnorm_quant_i8_4rank for steps of up to 4 rows
(kAr4FoldRows), where it serves every junction but the last layer's feed-forward one: a decode step
issues 2 standalone reductions. Taller steps, every speculative verify among them, issue the pair
(the all-reduce, then rmsnorm_quant_i8): a one-shot sends three times the message a rank, and at 16
rows the standalone all-reduce's exact two-shot beats the fold's per-row handshakes.

On 4x R9700 (the w4a8 container, tp 4, two rounds): plain decode 90 / 90 / 89-90 tok/s against
86 / 87 / 86 for code / prose / story, and 85 against 82 after a 6442-token prompt, +4.7%; a
DFlash verify at 16 rows measured 300 tok/s on the pair against 276 on the fold, hence the band.
Both paths give the same bytes. Where no library declares the fold, every step issues the pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:22:06 +02:00
zivius 4e750fed01 libref, libavx, libr4d: conv1d's stride and cu_div, and vq_encode -- a causal codec encoder's downsampling (the left pad the reach less the stride, every sequence a whole number of strides, the bounds read in samples at every rate) and one step of its residual quantiser, the code of greatest cosine and the residual it leaves (Fish Audio's codec encoding a reference) 2026-10-21 01:00:13 +02:00
zivius 346efdeb2e libref, libavx, libr4d: rvq_embed's clamp -- a code past a codebook smaller than the heads that wrote it reads the codebook's last row, as Fish Audio's codec reads its 1024-entry residual codebooks 2026-10-20 23:07:33 +02:00
zivius 0c35fc8070 libref, libavx, libr4d: cfg_topk_sample's top_p and ras_pick -- Fish Audio's nucleus over the whole candidate set, cut before the top-k, and its repetition-aware choice between two draws 2026-10-20 23:07:16 +02:00
Deadcode 4246a1dd04 radiance 1.10.0
LoRA for image and video generators:
- civitai and Hugging Face adapter files as published: kohya, ComfyUI and diffusers/PEFT key names;
  LoRA, LoCon, LoHa, LoKr and full-weight diffs; DoRA, OFT and Tucker are refused by name
- stacked per request with a strength each, through the `loras` field or <lora:name:strength> tags
  in the prompt; --lora-dir serves every file in a directory, GET /v1/loras lists them, and
  --max-loras / --max-lora-rank size the slots on the card (generators default to rank 64)
- Krea 2, Qwen-Image 2.1, FLUX.3 [klein], MiniMax H3, LTX-2.5, Anima and SDXL

New models:
- Anima (base, aesthetic and turbo): Cosmos-Predict2 DiT with the Qwen3-0.6B text encoder and the
  Qwen-Image VAE, on one card
- Stable Diffusion XL and its single-file finetunes (Illustrious, NoobAI including V-Pred, Pony),
  read as civitai ships them, with the Euler, Euler a and DPM++ 2M samplers

Recipes:
- q38-27b-mxfp4-df2: any bf16 Qwen3.8-27B or finetune at MXFP4 with the DFlash2 drafter
- Krea 2 finetunes from civitai: scripts/krea2_native.py reads Krea's own key names, and
  krea-2-fp8-unscaled keeps a plain-fp8 file's codes exactly

Changes: --max-num-batched-tokens defaults to 2048 (was 8192). Plugin ABI 25: out-of-tree plugins
must be rebuilt.
2026-10-20 21:05:16 +02:00
Juup 912c57cb21 unlimitedocr: prefill and decode performance work
- sam_attn: tile queries and hoist the relative-position dots; the tower
  drops from 0.44-2.09 s to 0.10-0.36 s per tile.
- processor: split OCR patch/LUT staging across rows, then make both bicubic
  passes and the LUT append AVX2 (bit-exact, 1.15-1.38x host preprocessing).
- tower: batch the DeepEncoder across every tile segment of an encode pass.
  Patch embed, the 12 SAM blocks, neck, the 24 CLIP blocks and the projector
  run once per batch of up to 8 tiles (4 at the 64 grid); sam_attn and
  attn_dense stay segment-independent through B+1 cu tables, and position
  tables are host-staged PERSIST planes. B == 1 emits the old graph.
  Fix the newline layout: the reference expands image_newline over every map
  row, while the copy read past the one-row vector; with a multi-tile batch
  that made the trailing cells live data and the decoder dropped the text at
  the right margin of every line.
- attn: instantiate attn_paged_qrow at head_dim 128 (bf16 and fp8 caches) and
  read OCR's q slice of the fused q|k|v plane in place, keeping the dense cast
  as the fallback when the library does not serve the qrow row.
- tests: h128 attention emulator cases, a batched-tower arch test, an AVX2
  bit-identity test, and a 15 s arch_test CPU budget for the image.

Measured through the router at 256 tokens: 8-page TTFT 4157 -> 1327 ms, 640
page 608 -> 284 ms, 8 concurrent pages 17.6 -> 4.26 s wall; decode unchanged
at ~344 tok/s. Parse gate 0.9901 text / 1 px on the deployed image.
2026-10-20 15:28:34 +00:00
Juup 859efc7208 review: apply the Unlimited-OCR code-review findings
The 2a1ca01..f308216 range's 45 review findings (12 performance, 33 quality)
are applied: ABI 23 for the RadBatch append, the fused q|k|v projection, the
batched patch-embed GEMM and pitched layout copies, the sam_attn w-dot hoist
with an alignment-gated vector row path and NaN poisoning for malformed
segments, the fused quick_gelu act, and the R-SWA/scheduler/drafting gates.

Quality items: stale comments corrected, env reads hoisted, the ngram_window
negative refusal, the parts-form chat template instruction, the whitelist
fallback warning, and the segmented R-SWA refusal of the fixed/runtime window
mix.

The 3.2 MB generated resample header becomes a 9.6 MB little-endian blob
(tests/data/golden/uocr_resample_golden.bin) read by a small loader;
resample_golden.py emits and round-trip-verifies it.

One perf-med item (AVX2 bicubic passes/LUT patch staging in the processor) is
left as the follow-up the review itself recommends; the code says why.

Verified: ninja -C build-review -k 0; host ctest 89/89; GPU r4d_selftest
0 failures, kbench/kbench_moe and the card tests pass.
2026-10-20 07:06:18 +00:00
Juup 52637ec186 unlimitedocr: tiled/base e2e parity, per-segment tower layout, n-gram whitelist
The pass packer now keeps a view and its one-cell separator in one pass, and
RadBatch carries each segment's grid host-side (enc_seg_h/enc_seg_w) so the
DeepEncoder no longer reads device coordinates to pick a geometry. The tower
lays out a line of n tiles as kMap rows of n*kMap features plus one newline
cell, accepts an earlier chunk of a longer line, and emits the learned
view_seperator for an explicit 4x4 separator rather than any square segment.

The device sam_attn resamples a rel_pos table that is not 2*tile-1 rows on
read (the 127-row global tables serve a 40-grid block as 79), matching
libref/libavx. The n-gram ban gains the reference's optional whitelist
(5th operand, OAI keys, generation_config alias) with range/dtype checks.

Gates: tiled e2e stage cosines 0.9994-1.0, det/text 0.9901 with every
coordinate within 1 px; two-page 0.9917 within 2 px; device selftest
sam_attn (incl. 127->79) and ngram whitelist (1344 columns) 0 mismatches.
2026-10-20 07:04:01 +00:00
Juup fad4ba7f1a unlimitedocr: the DeepEncoder tower, R-SWA ring KV and the n-gram ban
DeepEncoder (arch/common/rad_block_sam.h): the checkpoint's SAM ViT-B/16,
neck and CLIP ViT-L/14 producing its 16x17+1 row layout, with a new
`sam_attn` op for the windowed, zero-padded SAM attention and its
decomposed relative-position bias (libref oracle, libavx kernel, libr4d
kernel and selftest). The plugin declares the tower when the container
records `radiance.encoder`, and splices its rows over the placeholders
after embed_lookup.

BOS: the chat path adds BOS when the rendered template does not already
start with it. This checkpoint's template is a bare concatenation and its
tokenizer states add_bos_token, so without it every position was off by
one and the det boxes came out wrong. A media run's placeholders shift
with it.

R-SWA: RAD_KV_RING, paged like a window group but with a per-sequence
floor armed at admission. adv_groups now computes the same clamped
seqused and modulo ring slots the builder stages; the mismatch read the
block table's -1 padding and faulted the card. Prefill stays causal;
prefix cache, checkpoints and speculation are off for the group.

Sampling: sample_ngram_ban in libref/libavx/libr4d and the host chain,
the request knobs, and the container's generation config (35 over 128).

Processor: the checkpoint's grid/mode selection, its tall-last tie order,
Pillow's bicubic pass order, and goldens generated from its own code.

Tools: --mm-max-patches auto-detection accepts a tower stated as per-width
tables under vision_config.image_size, and rad-convert records
radiance.encoder.

Verified: tower stages match the checkpoint's code (rows cos 0.9998), the
device sam_attn selftest is within tolerance, the R-SWA device repro
returns text, a GPU e2e reproduces the reference's first det block, and
the host suite is 88/89 (known webp decode baseline).
2026-10-20 07:04:01 +00:00
Juup 543cba7416 unlimitedocr: the decoder plugin, the fused router ops and an h128 MHA attention leg
The text side of Unlimited-OCR: a 12-layer, 1280-wide decoder, 10 query heads over 10 KV
heads at head_dim 128, a dense layer 0 and 64 routed experts (top-6, softmax, no
renormalisation) plus one ungated shared arm in layers 1-11. arch/unlimitedocr_bf16/
carries its own plain-Llama bf16 attention, the shared MoE block in its bf16
external-input mode, and the tied LM head; data/recipes/unlimited-ocr-bf16.recipe is the
bf16 passthrough convert. core/format/checkpoint.cpp learns n_routed_experts, so n_expert
is read from the checkpoint's own key.

The router is issued as one op rather than a selection and a sort: libref gains
router_topk_scatter and router_gemm_topk_scatter (the second with the shared expert's
one-column gate at N = 1), libavx composes both from its router/gemm/scatter kernels, and
both get sweep geometries and the gate-absent/gate-present tests.

libr4d had no head_dim 128 leg at ratio 1, so every attn_paged band of this geometry
resolved to no kernel and the server refused to start on device.
r4d_attn_paged_h128_gqa1.hip instantiates the generic body at GQ 1 for both legs; the
rows and the selftest cases come with it.

Device numbers, one R9700 (gfx1201, HIP 7.16), bf16 weights and KV, no reference-kernel
fallback: a 523-token prompt prefills at 35.0-35.8k tok/s (15 ms) and a 4043-token prompt
at 54.2k tok/s (75 ms); decode is 351-354 tok/s (2.82-2.85 ms/token) at short context and
315 tok/s at 4k. r4d_selftest is 0 failures; the host suite is 86/87, the miss being
mm_test's lossless-webp decode, which fails on this box in code this change does not touch.
2026-10-20 07:03:49 +00:00
Deadcode 685ec5bd85 radiance 1.9.0
New models:
- LTX-2.5 (base and distilled): video with a stereo soundtrack from text or from text and a first
  frame, on one card, with its duration head, tiled VAE decoding, the diffusion decoder and the x2
  latent upsampler
- Krea 2 Raw and Turbo, and FLUX.3 [klein] and its base: text to image, and for FLUX.3 edits from up
  to ten reference pictures, on one card
- GLM-5.3-Flash from AMD's Quark MXFP4 export, on eight cards (John McDonough, Nunze)
- Gemma 3 / TranslateGemma 27B with an optional DFlash2 drafter (mici81)

Engine:
- --kv-cache-dtype fp8_v4 and k6_v4 for Gemma 3 and Qwen3.8-Flash-Next (mici81)
- the rotated int8 trunk (i8a8h) for Qwen3.8-27B (eddie168168)
- eight-rank all-reduce bands, weighted shards and pieces (Nunze); --host-headroom-mib (sfjes)
- the dashboard shows the single-stream decode floor and its most recent window (Memoria)

Fixes: prefix-cache reservations kept until their save lands (baKon), tool calls in Responses
namespaces (#119), system messages merged when a template refuses several (#137), a prefill
continued with no open step (#127), calibration of a Gram accumulation (#122), JSON Schema patterns
read unanchored (davetha), GLM-style tool calls, the KV floor counting every sequence's state.
Plugin ABI 24.
2026-10-19 21:58:07 +02:00
NunzeandJohn McDonough 78c58841bf libr4d: GLM-5.3's kernels -- mHC, KDA, the DSA indexer, MLA, f32-scaled FP8, MXFP4 experts
The device rows for GLM-5.3-Flash's ops, at its geometry and at TP4 and TP8 slices:

- mhc_pre / mhc_post / mhc_contract, and mhc_pre_partial / mhc_pre_finish, which run mhc_pre's
  own projection and finishing kernels with its chunk-sum order, so the pair is byte-identical
  to mhc_pre at n 4096, hc 4, chunk 2048.
- kda_update_k128_v128_bf16, one, two or four value rows a wave, both state forms.
- dsa_pool_fp8, dsa_query_fp8 and dsa_score_fp8 (fp8 WMMA, 32 heads of 128).
- mla_attn: a matrix row whose WMMA tile holds a query's heads, or pairs eight heads of two
  neighbouring queries over the union of their page tables, above the wave row; mla_project
  with up to eight rows a thread or wave.
- gemm_nt_f32 and router_sigmoid_topk in tiled and one-wave-a-row forms; gemm_fp8a8_f32scale
  and moe_gemm_fp8a8_f32scale read f32 block scales in place; moe_gemm_mxfp4a8 decodes e2m1 into
  exact E4M3 bytes for fp8 WMMA, with an expert-major decode form and a wide prefill form.
- swiglu_clamped, and the device-only fusions of GLM's MoE block: swiglu_clamped_quant_fp8,
  router_sigmoid_topk_scatter, and moe_scatter_inv / moe_gather_inv, which pass the gather's slot
  table from the sort instead of rebuilding it.

moe_gather takes f32 routing weights in its column-per-thread kernel. The sort and the gather
kernels move from r4d_moe.hip into r4d_moe_sort.h and r4d_moe_gather.h, so the fused router and
gather instantiate the same code.

Every form that replaces another gives its bytes: tests/r4d_emu runs the kernels on the host
(test_f32, test_fp8f32, test_kda, test_mhc, test_mla, test_moefuse, test_moemx), r4d_selftest
compares them on a card against libref and against each other, and plugin_test pins the
mla_attn band. docs/OPS.md states what libr4d serves.

Co-Authored-By: John McDonough <18016200+JohnCMcDonough@users.noreply.github.com>
2026-10-19 20:13:47 +02:00
John McDonough c8311068d0 qsa_select: signed -- a ranking for indexers whose scores can be negative
qsa_select ranks max(score, 0) and treats a score at or below -1e30 as dead: QSA's block scores
are sums of relus, so the clamp changes nothing there. GLM-5.3's DSA indexer weights its heads by
signed gates, and its block scores can be negative; ranked through the clamp, every negative block
ties at zero and the selection is wrong. `signed` 1 ranks finite scores as they are (-0 tying +0)
and treats nonfinite ones as dead; absent or 0 is the ranking as it was. libref, libavx and libr4d
take it together, since the three declare one schema. docs/OPS.md; tests/r4d_emu/test_qsa.cpp
runs both rankings against the reference.
2026-10-19 20:13:47 +02:00
mici81andClaude Opus 5.5 c00a650bce libr4d: fp8_v4 and k6_v4 caches -- stores, folded prologues, h256/gqa6 attention
Two narrower layouts of an attention cache, a head's dims in groups of 32 with an f16 scale:
fp8_v4 (E4M3 K, int4 V; 25 * head_dim / 16 bytes a token and head) and k6_v4 (int6 K, int4 V;
22 / 16). kv_store and qk_norm_rope_gate_kv_store write them (the folds byte-identical to the
pairs); attn_prefill / attn_decode at h256 gqa6 widen the codes to f16 in a tile's staging, V a
key pair's 8 dims a thread fetched a tile ahead and widened with packed f16 (one rounding, a
dword store holding both keys), K6's high bits laid out so one mask and shift join them to the
low nibbles. r4d_selftest: the stores against an exactly representable set, the folds, and the
attention rows against the inline oracle extended to the layouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:28:21 +02:00
mici81andClaude Opus 5.5 f92cce07f1 libr4d: Gemma 3's rows -- windowed h128/gqa2 attention, qkv_norm_rope at h128 without a value norm, ar_rmsnorm_post_quant_fp8
- r4d_attn_paged_h128_gqa2w.hip: decode and query-tiled prefill at head_dim 128, gqa 2,
  window >= 1, instantiations of the h256/gqa6 templates with WIN = 1 (as h256_gqa2 for
  Gemma 4); the h128/gqa2 rows keep window 0.
- qkv_norm_rope: head_dim 128, and an optional v_norm (0 leaves v alone).
- ar_rmsnorm_post_quant_fp8: ar_rmsnorm_quant_fp8 with a post-norm of the reduced sum against
  w_post before the residual add (the sandwich junction), exact wire only. Its own op: an
  optional seventh operand on ar_rmsnorm_quant_fp8 broke every plugin issuing its six.
r4d_selftest: the windowed rows against the inline oracle over a history past the window, and
qkv_norm_rope at h128 / v_norm 0 byte-identical to its chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:44:46 +02:00