95 Commits
Author SHA1 Message Date
mici81andClaude Opus 5.5 bd3fa646bc libr4d: hc_read decode forms G, S and kernel B3 back, B3 without a lane branch after its WMMA
2.0.0 dropped #396's hc_read decode forms. With ROCm 7.2.1 (clang 22) they gave NaN logits (#413's report);
ROCm 10.1 was fine. The cause is kernel B3 alone: clang 22's backend sinks its WMMA up product into the
lane-divergent `if (col < RG && col < rows)` around the store of x, so the WMMA runs with part of EXEC off
(an s_and_saveexec right before the first v_wmma). In the IR the WMMA is convergent and outside the branch.
At 16 rows every lane passes the test, which is why form S at 16 rows was right.

- Forms G (1..8 rows) and S (9..16) and kernel B3 at Flash-Next's shape, the bodies of #396, chained in
  2.1's style (r4dchain / R4dUnchained), hc_rot_group<I8>. They take these rows from the fused grid and the
  tiled read; from 17 rows nothing changes.
- B3: a lane past the step's rows takes the last row and every lane stores, bit for bit what that row's own
  lane stores, so there is no branch after the WMMA.
- hc_decode_forms is #396's again (d against fp64, x within rounding up to 16 rows), with 2.1's rq dtype, a
  count of non-finite outputs (the error sums went through std::max and >, which pass NaN) and rows 9 and 12.

r4d_selftest --case hc_read_e4m3: 66 passed with ROCm 7.2.1 and with 10.1; 27 failed with 7.2.1 without
B3's change. Flash-Next on 2x R9700, ABBA, ms per decode step at 1/2/4/8/16 streams: 15.72/20.62/26.83/
37.37/51.89 -> 14.92/18.61/26.67/37.15/50.83; prefill unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:02:02 +01:00
mici81andClaude Opus 5.5 b632c72f5d sched: an overdue preempted prefill keeps its place ahead of the queue
A preempted request waiting for its whole-recompute gate (kAdmitWait) let the admission walk ask the
next request in the queue. For an overdue one that undoes the overdue path: the room it made in this
step went to a request queued behind it. With preempted prompts published, the victim forced off for
it needs almost nothing to come back, so it was re-admitted at once and forced off again on the next
step. Under KV pressure the same victim was forced off and re-admitted 26 times in 16 s while the
overdue request waited. An overdue preempted request that is still refused now stops the walk, as a
refused fresh request already does.

2x R9700, Qwen3.8-Flash-Next TP2, production flags with the KV cache cut to 6.45 GiB a card
(--gpu-headroom-mib 3072), 16 concurrent 58.6k-token prompts with 4000-token answers:
- without publishing preempted prompts:  wall 390.6 s, mean 338.5 s, 9 preemptions, 1 forced
- publishing them:                       wall 346.4 / 344.1 s, mean 306.6 / 299.8 s, 36 / 32 preemptions, 28 / 26 forced
- publishing them, with this change:     wall 331.0 / 324.4 s, mean 289.4 / 284.0 s, 8 / 9 preemptions, 1 / 1 forced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 14:59:28 +01:00
mici81andClaude Opus 5.5 12b7b7889b sched: an overdue preempted prefill is failed only when waiting cannot help
On an idle engine the overdue path failed a preempted prefill on any refusal. A restore waiting a step
for a deferred release is a wait, and so is a refusal behind requests this step already admitted (the
budget or a card went to them); both clear by the next step. With preempted prompts published, the
restore path is common: under KV pressure two of ten preempted requests failed with "overdue
preempted prefill could not be admitted with nothing running", the debug log showing "the restore
waits a step for 1 deferred release(s)" right before. The path now fails only when nothing was
admitted this step and the refusal is not such a wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 14:59:28 +01:00
mici81andClaude Opus 5.5 01c7a3334a sched: a preempted request publishes its prefix; the recompute adopts it
Scheduler::preempt_back dropped everything a request had computed: unlike
close_request it published nothing, so a preempted 96.6k-token prompt was
computed again from its first token. The publish block of close_request is
now Scheduler::publish_prefix, called by both. Its blocks stay in the cache,
so a preemption that published gives eviction its rounds back (the decode
ensure loop and the overdue path) and the cache gives them back, the newest
last, before another request is preempted. preempted_can_prefill counts the
blocks the recompute adopts from the cache (pc_->lookup), so a preempted
request is not held back for room its own cached prompt already covers.

Shared KV with RADIANCE_KV_GUARANTEE=1 (nine Qwen requests preempted for
TranslateGemma's start pool): Qwen 587 -> 458 s, TranslateGemma 139 -> 80 s;
without the guarantee unchanged (340 / 58 vs 339 / 56). Test:
a_preempted_request_publishes_its_prefix; sched 187, engine_e2e and the
related suites pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 14:59:28 +01:00
mici81 7f5218ee5f qwen4exp: decode, verify and draft passes are recorded, keyed by their split cap (issue #402)
pass_key() answered 0 for every draft and verify pass, and with a callback present the core neither
records such a pass nor gives its launches the keyed context bound, so with the MTP drafter nearly
every decode pass was issued op by op (1.17.0: 206 passes played and 508,236 issued unkeyed, where
1.15.1 played 492,894). Dropping the export would record them with the cores bucketed bound, which
2026-11-05 09:50:02 +01:00
mici81andClaude Opus 5.5 8ab6f2a8b3 libr4d: qsa_select launches its chained form from a site of its own
The emulator test reads the plain launch's kernel name (tests/r4d_emu/test_qsa.cpp), and one launch
choosing between the two kernels spelled the choice instead; r4d_emu_qsa and r4d_emu_qsa_sweep
failed on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 09:48:37 +01:00
mici81andClaude Opus 5.5 e2e9416843 qwen4exp: chained launches pay with the MTP drafter
The probe sets chain_pays, as the Gemma 4 DFlash drafter does, so the engine chains the
speculative step's launches on the AQL backend (the chained forms of the previous commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 09:48:37 +01:00
mici81andClaude Opus 5.5 b0a58b5dbf libr4d: chained forms for Flash-Next's decode step, hc_read forms G, S and B3
Every kernel of Flash-Next's speculative decode step gets a chained form (r4d_chain.h), so the
step's small launches wait on their predecessor on the card instead of behind a queue barrier:
the router and the fp8 and four-bit expert GEMMs, the gated quantisers, the delta-net recurrence
and conv, the hyper-connection write and its all-reduce gather, the attention layer's indexer,
norm/rope/gate, quantiser and gqa6 decode rows, and the tiled and fused hc_read kernels. A
chained form is taken only at steps of up to 32 token rows (kR4dChainMaxRows); above that the
waiting blocks hold room a wide predecessor needs.

hc_read at one to sixteen decode rows (hc 4, n 2560, E4M3 mixing matrices, inject gains), the
shape Flash-Next calls 97 times a pass:
- form G (1..8 rows): kernel A' as (16-column tile, stream) blocks, so a block reads its W_down
  slice once for every row of the step; the slice and the norm gain load before the chain wait,
  the dots are bf16 WMMA, and the last of a tile's blocks sums the streams in ascending order.
- form S (9..16 rows): as G, but the norm's scale is applied after the dot, so N never sits in
  LDS and one block holds every row.
- kernel B3 (both forms, lr 320): the up product as WMMA over d with W_up's exact quarter
  scales, and the mix in each lane; W_up loads before the chain wait.
From 17 rows the tiled path (now chained) stays faster.

The new forms are not byte-identical to the kernels they replace: the bf16 WMMA dots sum in
another order and S scales after the dot. Against an fp64 host reference, d is as close as the
per-row kernels' at 1..7 rows and closer than the tiled path's at 8..16 (mean error 0.13-0.14 %
of the row's RMS against 0.17 %, max 1.2-1.4 % against 1.3-2.0 %). The selftest's decode-forms
case now holds d to that reference (no further from it than the two-grid form) and x to the
two-grid form within rounding up to 16 rows, and stays byte for byte above.

Flash-Next on 2x R9700, sampled at temperature 1, 25k prompt, 500 tokens, two rounds of
1/2/4/8/16 streams: MTP depth 3 174/291/458/657/851 -> 207/339/493/647/843 tok/s; with depth 5
and the adaptive window 191/331/493/661/897 -> 218/355/494/662/893.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 09:48:37 +01:00
mici81andClaude Opus 5.5 55da38afbd libr4d: the norms' lane sum issues its reads eight at a time
1.15's kR4dSumLanes partition folds a row's sum of squares over 256 lanes
whatever the block width, so a 1024-thread decode block reads it back with a
quarter of its threads, one read at a time: a Gemma 3 sandwich norm re-reads
the 5376-wide row it has just written twice, 21 dependent loads a lane each.
TranslateGemma 27B lost 5 % of its decode (four streams 225.0 / 227.2 tok/s a
stream against 238.2 / 239.7 on 1.14; ar_rmsnorm_post_quant_fp8 3.1 -> 5.1 ms
a step under --profile-ops).

r4d_lanes_sumsq (r4d_common.h) keeps the partition and the order of the adds
and only batches the reads, eight before their adds; libr4d is built
-ffp-contract=off, so every bit stays the same (greedy Qwen 300/300 x2 and
TranslateGemma 6/6 identical to the merge without it). Used by both
lanes_sumsq copies and rmsnorm_body's two loops. TranslateGemma back to
238.9 / 239.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 20:57:42 +01:00
mici81andClaude Opus 5.5 8df9240d65 sched: the preempted-prefill gate skips a KV group that holds no blocks
Every program carries a sentinel KV group at index 0. KVGeom reads its decl.kind 0 as RAD_KV_FULL
with block size 1, while the manager's plan for it pages nothing and owns no block. The gate
(e668d49) walked every group KVGeom calls paged, so for the sentinel it wanted the whole prompt,
one block a token, out of a pool of none: a preempted request was never readmitted. The bound on
the wait (33108e4) cannot help, since preempting running requests frees nothing in that group.
engine_e2e_test's qwen35_preemption_by_recompute_changes_no_logit hung on it (the KL recording of a
small pool: one preempted document, nothing left running); with the group skipped it passes in
0.9 s. It may also be the live request in #346 that waited 710 s with gen=0.

The gate now skips a group with no blocks (total_blocks 0), as KVManager::ensure skips a group its
plan does not page.

sched_test: a_preempted_prefill_ignores_a_kv_group_that_holds_no_blocks (a group the scheduler sees
as full and the manager as empty; the preempted request stayed Preempted after the pool emptied
before the fix). 173 cases pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 12:11:13 +01:00
mici81andClaude Opus 5.5 167595a9b4 libr4d: the split-KV row sum read with fetch-inactive (#328)
The prefill KV split (6a7824a) stores each segment's row sum under `if (h == 0)`, so only half the
wave consumes `l_i += swap16(l_i)`. A compiler may sink the exchange into that half, where
v_permlanex16 with fi = 0 reads the lane's own value for the inactive partner, and the stored sum is
then twice one half's instead of the pair's: the merge normalises by the wrong total. The decode
kernel's f32-partial path has the same shape (lrow read under `if (h == 0)` only).

swap16_fi sets fetch-inactive, so the partner's half is read whatever exec says. With every lane
active it is the same exchange. Found by sabi-noema and posted by mordae in #328; this is their
helper and prefill change, plus the decode path.

The compilers I have do not sink it: in this tree's build (ROCm 10.1) and in the published 1.14.0
libr4d.so, every split instance of the h256/gqa6 prefill kernel exchanges before the `h == 0` mask.
So the fix changes the code (op_sel:[1,0] on those exchanges, a register shuffle around them) but
not the results here, and no test here can fail without it. r4d_selftest: the h256/gqa6 prefill and
decode rows, every cache layout, 453 checks, 0 failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:39:08 +01:00
mici81andClaude Opus 5.5 0792d86375 libr4d: the paged prefill attention h256 gqa6 asks for KLATE again
75b4c92 brought the kernel side of KLATE (tile t+1 K fetched once tile t has its scores) and set
P_OPT to (3954187 | O_KLATE) in this launcher; a later merge restored the old P_OPT line, so the
kernel code is there but Qwen3.8 prefill no longer takes it. This puts the bit back. Load order
only: the bytes are the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-30 10:21:34 +01:00
mici81andClaude Opus 5.5 f8e69c4825 libr4d decode split law: bound the three-wave verify floor by workgroups (#342)
49ca5ff made a three-wave verify past 16k keep at least 64 segments a sequence. The declared scratch
is the worst over every sequence count up to max_seqs, so at 256 sequences it became 64x the law's:
h256/gqa12 at max_ctx 200000 went from 7.62 to 487.5 MiB a card, and the KV pool lost that (#342:
5-8 % prefill on an expert-tiered MoE).

The floor is now min(64, 1024 / units), units = KV heads x sequences. Up to eight sequences of two
KV heads it stays 64; at 16 it is 32, at 256 two, and the declared region stays at what eight
sequences need.

Measured on 2x R9700, Qwen3.8-27B MXFP4 TP2, k6_v4, speculation 7 without the short block (every
step an 8-row verify), forced segment counts, ms a decode step:
  45k x8  64: 41.24, 32: 41.20, 16: 42.29
  45k x12 64: 57.42, 32: 57.38, 16: 59.39
  45k x16 64: 74.83, 32: 74.68, 16: 74.79
  90k x8  64: 51.79, 32: 52.02, 16: 54.42
Up to 64 segments past eight sequences changes nothing; the new floor gives x12 42 and x16 32.

r4d_selftest's split-law case pins the region at 16 sequences (100k and 32k: 32 segments) and at
256 (2); it read 64 for all three before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:16:16 +01:00
mici81andClaude Opus 5.5 ed5f990d92 qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8
decl_gated_fold_mx declared gemm_nt_q_gated_mx over 1..8 rows only, from
before libr4d had gemm_mxfp4a8_gated_gemv_wide (9..64, byte-identical to
gemv_wide followed by gated_quant_fp8, the pair it replaces). TranslateGemma
already folds to 64 through RADIANCE_G3_FOLD_ROWS; Qwen's 16-row verify steps
(two sequences at speculation 7) still ran gate_up and gated_quant_fp8 apart.

Qwen3.8-27B MXFP4 + DFlash2 at TP2 on 2x R9700, production flags, ms a decode
step, three interleaved rounds (medians), the 1..8 band -> folding to 32:

  16 rows (x2):            1k 20.96 -> 20.78 (-0.9 %), 16k 21.96 -> 21.70 (-1.2 %)
  32 rows (x4):            1k 23.97 -> 24.10 (+0.5 %), 16k 26.06 -> 25.98
  32 rows (x8 short block): 1k 24.99 -> 25.14 (+0.6 %)

and 64 rows lost 2.1 % (16k x16) on the base before this main. So the band is
16: a taller step takes exactly main's path. Where the wide row does not
resolve (K at or under decode_shortk's corner), the declaration drops to 1..8
instead of losing the fold. Greedy output is identical to main (300 tokens,
two prompts).

arch_test: qwen35_fp8_mxfp4_feed_forward_folds_verify_steps_up_to_16_rows
(one and two sequences of 8 rows fold, three to eight take the pair).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 16:21:56 +01:00
mici81andClaude Opus 5.5 a64c75eb34 qwen35_fp8: read the delta net's out-projection beside its decode recurrent update
At decode heights the recurrent update runs one workgroup per (sequence, head) and leaves the
card's memory mostly idle. Each delta-net layer now reads its out-projection (the whole weight,
7.9 MB a rank in MXFP4) into the on-die cache there, on the second lane behind a join from lane 0,
as prefetch_beside does beside the all-reduces. Up to four decode sequences and 32 rows; no read on
a step that carries a prompt's rows, at one rank, or where the deployment turns weight prefetch
off (RadBuildCtx::weight_prefetch_off: nothing is declared).

Qwen3.8-27B MXFP4 + DFlash2 at tp 2 on 2x R9700, production flags, 1k context, hwgrid ms/step,
median of five interleaved rounds, none -> whole projection:
  x1 19.40 -> 19.10 (-1.5 %), x2 20.93 -> 20.78 (-0.7 %), x4 24.26 -> 24.17 (-0.4 %),
  every round faster at each of the three;
  x8 25.22 -> 25.48 (+1.0 %, four rounds of five slower) -- hence the four-sequence ceiling;
  x16 (64 rows, no read) and 90k x4 unchanged. 4 MB reads as the whole.
Against this main (one round): x1 19.40 -> 19.15, other cells within noise.
Greedy output identical to the build without the read (300/300 tokens on two prompts, |dlogprob| 0).

arch_test: qwen35_fp8_reads_the_delta_net_out_projection_beside_its_decode_update; the qwen35_fp8
step pins move (prg_pins.py).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 10:35:38 +01:00
mici81andClaude Opus 5.5 49ca5ff9c6 libr4d decode split law: size a three-wave verify by the step's depth
The full-attention decode law gives a three-wave workgroup (q_len * gqa > 32,
an 8-row DFlash2 verify at gqa 6) 128 / units segments whatever the depth.
Three to seven sequences of Qwen3.8-27B (two KV heads a rank) then get 21..9
segments, each walking 4-18k tokens at depth, and one or two sequences stay
at 64 / 32 where 256 / 128 are faster.

The law now reads the step's depth from the block table's width (max_blocks *
block_size, capped at max_ctx; the scheduler rounds the width to the batch's
longest sequence): up to 16k tokens 128 / units as before, past 16k at least
64, past 64k 512 / units capped at 256. Declare passes no table, so the
scratch is still sized at the declared bound, the deepest the law can be
asked for; the law grows with depth, so an issue never needs more.

Qwen3.8-27B MXFP4 + DFlash2 at TP2 on 2x R9700, k6_v4, speculation 7, ms a
decode step against this main:

  x1  90k 22.07 -> 22.03   180k 25.35 -> 24.88
  x2  90k 26.83 -> 26.36   180k 33.18 -> 31.99
  x3                       180k 42.41 -> 40.33
  x4  90k 36.20 -> 34.96

Steps whose count does not change (1k x1..x8, the short block at 16k x16) are
within noise. Greedy output is identical (300 tokens, two prompts). The forced
segment sweeps behind the thresholds are in the comment.

r4d_selftest: decode_split_law_case reads the law through the decode scratch
hook's declare path, 21 batches across the depth thresholds.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 09:25:09 +01:00
mici81andClaude Opus 5.5 812cdeceb0 gemma3 + libr4d: the fused all-reduce junction on the lossy wire, for rows of whole 64-element groups
Under --tp-wire wht6 a TranslateGemma step of 2-3 sequences (16-24 rows) sent its junction as
three launches (the standalone lossy all_reduce, rmsnorm, rmsnorm_quant_fp8): the fused
ar_rmsnorm_post_quant_fp8 sent the exact wire only, and the compressed fused form needed a row of
whole 512-element chunks, which Gemma 3 27B's 5376 is not (10.5).

- r4d_fused_quant_fp8.hip: a row of whole 64-element groups that is not whole chunks ends in a
  partial chunk whose missing groups go out as zeros and are not stored back. Every real group is
  the same 64 elements as in the flat message, so its bytes and the sum are the standalone wire's.
  The (row, chunk) mapping is a template parameter (PAD, wire 6 only), so a row of whole chunks
  (Qwen3.8's 5120) runs exactly the code it ran before; as a runtime branch it cost a Qwen3.8 x4
  step 1.3-1.6 %. POST (the sandwich post-norm) on either wire.
- r4d_ar_entry.hip: K % 64 instead of K % 512 for wire 6, a size check of the padded message
  against the slot and the local pack, and the local pack's scale region a sixteenth of the slot
  instead of a thirty-second (padding adds up to 7 groups a row: a 2048-row prefill chunk would
  have overrun the old size).
- gemma3: the junction declares its lossy twin (op_ar6) and takes it up to kAr6MaxRows (24); a
  taller step keeps the standalone all-reduce, which spread over more blocks wins there (the
  fused kernel gives a block one row).

TranslateGemma-27B MXFP4 + DFlash2, 2x R9700, --tp-wire wht6 --draft-short-from 8, greedy,
aggregate tok/s, two rounds, junction limit never / 24 / any:
  2 streams (16 rows) 350.7 346.2 / 370.4 367.0 / 357.7 356.0
  3 streams (24 rows) 455.8 451.2 / 462.8 460.6 / 437.3 436.8
  4 streams (32 rows) 553.7 553.6 / 553.9 560.2 / 521.0 523.0
  8 streams (32 rows) 717.4 718.0 / 716.7 720.8 / 662.4 661.9
So 2 streams +6 %, 3 +2 %, 4 and 8 unchanged.

Bit identity: with --tp-wire-min-kb 1 (one stream's steps go out lossy) the fused path gives the
unfused one's greedy top-5 logprobs, 300 of 300 tokens, max |d| 0, on two pieces (x1 there 197.6
-> 212.6 tok/s). Qwen3.8-27B MXFP4: 300 of 300 identical on two prompts, speed unchanged.

Tests: arch_test (the lossy-wire junction test now also expects a 24-row step to fuse through the
twin, other op instances than the 8-row step's, and the 64-row prefill to stay unfused).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-28 12:20:10 +01:00
mici81andClaude Opus 5.5 b74a6b2ece spechub: mtp_couple_verify walks the live candidates only (151 -> 31 us a launch)
The sampler's candidate plane is kSampleCandidates (1024) wide and at top_k 20 about 20 entries are live,
but the coupled verify ran its eligibility scan (global memory, one entry at a time) and its sums and
walks on one thread over all 1024: 92-151 us a launch at any row count, on the critical path of every
coupled step. The workgroup now checks validity and takes the maximum in parallel (order-free, exact),
compacts the live indices in ascending order into LDS, and the serial sums and walks run over that list
in the host reference's order, so the token is the same bit for bit.

vtime (n_cand 1024, 20 live, every row bound): 151.7 / 92.8 / 100.5 -> 31.3 / 32.2 / 35.9 us at 4 / 16 /
64 rows; device == host on every row.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 18:37:28 +01:00
mici81andClaude Opus 5.5 ce79b12126 dflash2 coupled walk: Q at temperature 0.6 by default
Q's temperature (RADIANCE_DFLASH_Q_TEMP) only moves acceptance, never the
output law. Held-out tokens per verify step at request temperature 1, x4,
32 rows of the eval set, Qwen3.8-27B MXFP4 with a DFlash2 drafter fine-tuned on our traffic, our serving flags:
ordinary rule 3.52; coupled with Q at 1.0 3.71, 0.7 3.88, 0.5 3.85,
0.35 3.77. The walk's scores are flatter than the target's law, so a
sharper Q puts its mass where the target's is; 0.6 is the default now.

At 0.6, 3 interleaved rounds against the ordinary rule (64 held-out rows
at x4, and three requests at x1 and x4, 1500 tokens, T 1):
- tokens per step 3.53 -> 3.82 (+8.2 %), every round apart
  (3.50/3.49/3.61 vs 3.82/3.79/3.86); time-weighted decode +5.4 %;
- decode per stream: 0.7k prompt x1 174.1 -> 181.7 (+4.4 %), x4 144.6 -> 153.8
  (+6.4 %); 22k prompt x1 186.6 -> 191.0 (+2.3 %), x4 135.1 -> 146.2 (+8.2 %);
  41k prompt x1 186.9 -> 196.8 (+5.3 %), x4 125.8 -> 135.0 (+7.3 %);
  aggregate at x4 +5.3..+5.5 %.
Coupled at 0.6 against the ordinary rule, 5000-6000 samples of tokens 1-4
of two chat prompts: chi-square p 0.62..0.99.

The walk's kernel issues each candidate's successor slice and unary score
before the predecessor's codebook row (both are independent of it). This is
the build measured above; it moved the pass time within noise (91.3 -> 90.8
us at M 16, steps 7), and tokens, ids, x and status still match the host
oracle on all 40 random lattices (q by FP64 exp ulps, <= 4.3e-16).

ctest (the environment-only tests excluded) 105/105.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 18:37:28 +01:00
mici81andClaude Opus 5.5 cb0abe9ac7 dflash2: lossless coupled acceptance at T > 0 (--draft-coupling on)
DFlash2's drafts were the greedy walk over its candidate lattice, accepted
only when they equal the target's own sampled draw: P(y == x) instead of
rejection sampling's sum min(P, Q). --draft-coupling already did the latter
for a linear MTP head; this extends it to the block drafter.

- dflash_couple_propose (spechub plugin, device row + host oracle): after
  dflash_select, the same lattice walked again, sampled. Position l scores
  each candidate as dflash_select does (unary + low-rank edge from the
  previous token), Q_l = FP64 softmax of score / q_temp over the best eight
  in-vocabulary candidates, x_l ~ Q_l at (seed, base, KEY_DRAFT + l + 1),
  x_l is the next predecessor. Position l writes round l+1's state row, so
  the engine binds it and the sampler's mtp_couple_verify (maximal coupling,
  residual (P - Q)+) verifies it exactly as an MTP round. Q depends on the
  committed text and on x_0..x_{l-1}, never on the verify, and is stored
  exactly. Greedy requests keep dflash_select's tokens (status 0); a draw
  for another card or a Q that cannot be built takes the walk's argmax and
  the ordinary verify (status -1). The shared arithmetic is in
  abi/rad_spechub.h (rad_dflash_couple_step / _walk).
- The block driver stages one draw per drafting row before the query pass,
  reads the states back with the slots and binds them after the commit
  (Engine::bind_couple, shared with the serial driver).
- qwen35_fp8 declares the planes and the op under --draft-coupling;
  RADIANCE_DFLASH_Q_TEMP sets Q's temperature (default 1, exact at any).
- Default (flag off): no op, no plane, no change.

Gates:
- spechub_dflash_couple_test (CPU): emitted token vs P by chi-square over 3
  seeds each, Fisher-combined p 0.135..0.919, for Q = P, Q on fewer tokens
  than P, Q mostly outside P, top_k 20 + top_p 0.95, top_p 0.6, top_k 3 at
  T 0.7, peaked Q; acceptance = sum min(P, Q) within 5 sigma; the walk's
  stored Q equals the softmax of its scores (1e-5) and x follows it (p
  0.993); the whole draft/verify/bonus loop over 3 tokens matches the
  target's autoregressive law (combined p 0.62 at q_temp 1, 0.67 at 0.5,
  0.024 with every 2nd step on the ordinary verify).
- Device row vs host oracle, 40 random lattices at the production geometry
  (V 248320, K 16, R 256, steps 7/3, M 1..16): tokens, x, ids, status
  identical; q differs only by FP64 exp ulps (<= 4.3e-16 relative).
  91 us a launch at M 16, steps 7.
- Engine, Qwen3.8-27B MXFP4 TP2, our serving flags, 4-6 tokens of two chat
  prompts at T 1 / top_p 0.95 / top_k 20, 5000-11000 samples per arm:
  coupled vs ordinary speculation chi-square p 0.23..0.81 (tokens 1-4 and
  pair 1-2); both differ from no speculation on one prompt by the same
  amount (the verify-vs-decode logits, not the rule).
- Flag off, old build (up12 5dbb5dc) vs this: greedy top-5 logprob traces
  identical over 300 tokens (spec 7 and 0, two requests each), 6/6
  fixed-seed sampled texts identical.
- ctest (the environment-only tests excluded) 105/105.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 18:37:28 +01:00
mici81andClaude Opus 5.5 74e701ea17 prefix cache: a snapshot at a head other prompts share
A model with snapshots (recurrent state, or a sliding window the cache does not index) resumes a
hit only at a snapshot, and those are taken on the checkpoint interval and at each prompt's tail.
A head every request starts with -- the same system prompt or instructions in front of a different
text, as a translation service sends its pieces -- is usually shorter than an interval, and each
tail is its own, so the head was computed again by every request.

The cache now counts the blocks published right after each block (Entry::n_children) and reports
where a lookup leaves a head that at least two cached prompts already left differently
(CacheHit::branch_at; one is not enough, the next prompt could be the same conversation going on).
When nothing resumes within kSharedHeadMin (256) tokens of that point, admission sets the request's
own checkpoint there (Request::checkpoint_at, which n > 1 already uses), and the requests after it
skip the head.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 18:17:21 +01:00
mici81andClaude Opus 5.5 b6ad757bfa gemma3: the gated gate_up fold up to 64 rows (RADIANCE_G3_FOLD_ROWS), and prefetch knobs
The gate_up GEMM + gelu_mul + quant_act_fp8 fold ran only up to 8 rows; at 2-8 concurrent translations with
speculation a step is 16-64 rows and the three kernels ran apart. gemm_mxfp4a8_gated_gemv_wide (9 <= M <= 64,
K >= 2688) is gemv_wide at two column tiles a block, the gate tile j and its up tile n/16 + j: each K-wave loads both
tiles' weights and reads the activation once; the wave partials are summed in gemv_wide's order and the narrow fold's
epilogue quantises, so codes and scales are byte-identical to the unfused path. No spill (96-196 VGPRs, RT 1-4).

RADIANCE_G3_FOLD_ROWS (0 = today's 8) sets the fold band; RADIANCE_G3_PF_ROWS / _PF_MIB / _PF_EARLY expose the
prefetch beside the all-reduces (measured: no gain, defaults unchanged). Unset knobs keep the pinned graph and steps.

Measured on 2x Radeon AI PRO R9700, TranslateGemma 27B (MXFP4 GPTQ, DFlash2 drafter, speculation 7), greedy held-out
translations, aggregate tok/s, 2 interleaved rounds:
| fold ceiling | x2 | x4 | x8 |
| 8 (today) | 289.9 | 521.2 | 686.3 |
| 16 | 298.6 (+3.0 %) | 521.0 (-0.0 %) | 686.9 (+0.1 %) |
| 32 | 296.9 (+2.4 %) | 541.6 (+3.9 %) | 682.7 (-0.5 %) |
| 64 | 297.8 (+2.7 %) | 549.0 (+5.3 %) | 700.0 (+2.0 %) |

Tests: r4d_selftest gated wide fold byte-for-byte against gemv_wide + gelu_mul + quant_act_fp8 (or gated_quant_fp8)
for TranslateGemma's 21504x5376 at M 9-64 and other shapes (156 ok, 0 FAIL on gfx1201); arch_test gemma3 16/16
(defaults keep the pinned graph and steps, knobs move only what they name).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 10:08:01 +01:00
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
mici81andClaude Opus 5.5 5c1c71b147 attn gated fp8: issue a mixed step's dense attention once per band
A step that mixes decoding sequences with a prefill chunk issued the dense attention once, at band
max_q_len, so the decode rows ran through the prefill kernel: one workgroup per KV head walking the
decoder's whole context. With a decoder at 188k beside a 2048-row chunk that tail set the step time.

In a MIXED step the attention is now issued twice:
- the decode half at the decode band (served by the split-KV decode row); at most max_seqs - 1
  sequences of at most the decode band's rows, which its declared scratch covers;
- the prefill half always at the op's top band, which selects the query-tiled prefill row built for
  launches over part of a step (absolute cu from entry D, as the GDN block issues its prefill half and
  as ArPieces issues its pieces); the kernels read exact lengths from cu. At its own query length a
  chunk of 10 rows or fewer would select the decode row, which sizes its partials from the whole
  step's rows and has no cu span.
A chunk no longer than the verify blocks beside it keeps the single launch (the step is decode-
shaped). Pure decode and pure prefill steps issue exactly as before (graph pins unchanged; only the
pinned steps that contain a mixed step move).

RADIANCE_ATTN_BAND_SPLIT=0 restores the single issue.

Measured on 2x Radeon AI PRO R9700, Qwen3.8-27B MXFP4, TP 2: one sequence decoding after a 188k
prompt while a fresh 25k prompt arrives (2 rounds each):
- mixed step 510 / 508 ms -> 211 / 211 ms
- the new prompt's prefill 11.3 / 11.3 s -> 5.0 / 5.0 s (the same as beside a 0.7k decoder)
- the decoder's rate over the window 85 / 82 -> 109 / 103 tok/s
30 minutes of mixed serving load (12 decoding streams with speculation, fresh 25k / 41k prompts,
cached re-sends that prefill a few-row suffix, TranslateGemma beside): 0 errors, 0 restarts.

Tests: arch_test qwen35_fp8_issues_a_mixed_steps_attention_once_per_band (both halves' operands, the
prefill half at the top band for a short chunk, the single launch when the chunk is not longer than
the verify blocks, one issue per layer for pure steps); r4d_selftest attn_mixed_step (production
per-rank geometry, scratch bound exactly as the engine binds it per band, 15 decode sequences of 8-10
rows beside chunks of 1 to 640 rows).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 09:20:22 +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 6efffe2a59 libr4d: the split-KV decode attention (head 256, gqa 6) stages V4 without bank conflicts or serial rounds
The V4 tile's store (storeV4) wrote dim octets 8 rows = 96 dwords apart, so the octets a wave stores at once
shared banks (4-way on 32 banks), and on k6_v4 each tile's V fetch ran as three exec-masked rounds, each issued
after the previous one returned, the scale pair packed right after its loads. Now:

- the V tile is skewed: octet o's rows start 16 (o & 3) + 8 ((o >> 2) & 1) + 128 (o >> 2) halfwords later, so a
  store's octets land on distinct banks; the PV read adds the same offset, a compile-time constant a fragment
  (V4 at tile 16, contiguous layout, two or more waves; one wave keeps the plain tile, which its LDS budget
  needs);
- k6_v4: __builtin_assume(tid < NTHR) and a wave-uniform test for the partial round, so a tile's V loads issue
  as one batch, and the scale pair packed at the store, as the prefill kernel does since its own fix. fp8_v4
  keeps the tested rounds (batched there, its 4-row steps ran 6 % slower) and its pack.

Bit for bit: the same values in the same LDS cells, read in the same order.

r4d_selftest --perfdecattn on 2x R9700 (265 W), Qwen3.8-27B TP2 rank, k6_v4, sequences x rows x context,
3 interleaved rounds, medians: 1x8x100k 277.0 -> 260.1 us (-6.1 %), 1x8x200k 404.8 -> 377.7 (-6.7 %),
4x8x100k 799.4 -> 753.0 (-5.8 %), 4x8x200k 1733.3 -> 1655.3 (-4.5 %), 8x4x100k 1257.8 -> 1179.8 (-6.2 %),
16x4x41k 996.3 -> 973.4 (-2.3 %). fp8_v4 with the skew alone: -3.6 % (16x4x41k) .. -0.1 %.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:34:04 +01:00
mici81andClaude Opus 5.5 2af1079415 libr4d: the head-256 split-KV decode attention aims at 256 workgroups at one or two waves
At one or two waves a workgroup (q_len * gqa <= 32: a plain decode step, or the DFlash2 short block's
4-row verify) the 128-workgroup target leaves too few KV bytes in flight for the card's DRAM; twice as
many workgroups reach it. At three waves (an 8-row verify) more workgroups only add contention, so
those keep 128.

Qwen3.8-27B MXFP4 at TP2 on 2x R9700, k6_v4 KV:
- r4d_selftest --perfdecattn: 4 sequences x 1 row over 100k 582 -> 464 us, 1 x 1 over 100k
  264 -> 175, 16 x 4 rows over 41k 985 -> 801; 4 x 8 rows over 100k +9 % (kept at 128).
- The server's decode step at speculation 7 (the median gap between steps carrying every sequence,
  three rounds): 8 x 41k 34.01 -> 32.48 ms (-4.5 %), 16 x 25k 44.65 -> 43.19 ms (-3.3 %).

The split count already moves with the batch (8 sequences at 256 split as 4 do at 128), so the merge
sees no new partition; not bit-identical to the 128 target at the same batch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:12:58 +01:00
mici81andClaude Opus 5.5 bc272f897d arch_test: the pins of the families this branch changes, on the new base
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:47 +01:00
mici81andClaude Opus 5.5 8998349eec qwen35_fp8, gemma3: the weight reads beside the all-reduces are switched off by RADIANCE_PREFETCH_BESIDE=0
1.12.0 dropped RADIANCE_PREFETCH; the reads are now issued, or not, by prefetch_beside's own switch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:47 +01:00
mici81andClaude Opus 5.5 de53cd18c1 runtime: an op that names no buffer is not held to the second lane's window
The window keeps lane 1's concurrent buffers live only across it. A weight read into the cache
(prefetch_beside) names no buffer, so it touches nothing the window protects: it may run on lane 1
outside the window (a DFlash2 drafter's reads come after the trunk's window), and it leaves no window
work for lane 0 to join. runtime_test covers it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:47 +01:00
mici81andClaude Opus 5.5 c9f79c32d8 gemma3: weight reads beside the decode all-reduces, trunk and DFlash2 drafter
As qwen35_fp8 has them (prefetch_beside, rad_arch.h): behind the o GEMM, beside the attention
block's all-reduce, gate|up's leading 24 MB are read into the on-die cache; behind the down GEMM,
beside the feed-forward's, the next layer's q; the drafter's all-reduces take the same
(Dflash2::Config::prefetch). Decode steps of up to 32 rows, none on a step with a prompt's rows,
only at more than one rank; RADIANCE_PREFETCH=0 declares none.

TranslateGemma-27B MXFP4 + DFlash2, TP2 on two R9700s, no speculation, two rounds, x1 / x4 / x8
tok/s against none (56.8 / 182.0 / 325.0): 8 MB 63.3 / 203.1 / 354.9; 12 MB 63.0 / 202.6 / 354.9;
16 MB 63.5 / 203.9 / 356.6; 20 MB 64.1 / 204.0 / 359.4; 24 MB 64.4 / 206.4 / 359.3 (+13.4 / +13.4 /
+10.5 %); 32 MB 63.1 / 201.4 / 351.9. With speculation 7 (three rounds, greedy, medians) x1 / x4 /
x8 / x16 158.1 / 409.0 / 592.0 / 710.8 -> 177.3 / 428.4 / 592.3 / 717.6 (+12.1 / +4.7 / 0.0 /
+1.0 %). Bit for bit: a prefetch reads weights only.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:47 +01:00
mici81andClaude Opus 5.5 be85c0ba7f qwen35_fp8: weight reads beside the decode all-reduces, trunk and DFlash2 drafter
As gemma4_bf16 does (prefetch_beside): at two or more ranks, on decode steps of up to 32 rows, gate_up's
first 12 MB is read into the on-die cache beside the mixer's all-reduce and the next layer's first
projection's beside the feed-forward's; the DFlash2 drafter's reads take the same 12 MB.

Qwen3.8-27B MXFP4 + DFlash2, tp 2, 2x R9700: no speculation x1 61.2 -> 67.9 tok/s (+11 %), x4 225.0
-> 251.2 (+12 %), x8 403.7 -> 438.6 (+9 %), x16 650.8 -> 668.1 (+3 %), x32 +0.8 %; speculation 7
x1..x16 +0..+2 % for the trunk, the drafter's reads x1 +6 % (median of eight rounds); prefill
unchanged. The size and ceiling sweep is in the comment by kPrefetchBytes. RADIANCE_PREFETCH=0
declares none: arch_test's pipe-off case now sets it and still meets the serial graph pinned before
either existed. qwen35_w8a8 builds the same source; the routed (MoE) trunk takes no reads.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:47 +01:00
mici81andClaude Opus 5.5 fa7a5e4164 r4d_selftest: every push landing after its flag (the push check's regression case)
A test-only mode of the two-rank exact all-reduce (drain 4, set by
R4D_AR_TEST_LATE_PUSH=1 in the launcher, not in any tuning table): every block
publishes its flag before its push, pushes about 20 us later and stores its check
word as a release, since no flag release follows to write the bytes back. The new
case runs the 32-round sweep of ar_oneshot_2rank_exact and its host twin under it.

Without the push check the readers sum their slots' previous contents (16.5 million
of 18.5 million elements wrong on the device row, 12.9 million on the host twin);
with it every sum is exact.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:27 +01:00
mici81andClaude Opus 5.5 0044d8d201 libr4d: check that a peer's push has landed before reducing it (2-rank family)
A two-rank all-reduce or gather pushes its bytes into the peer's slot over PCIe P2P,
drains its stores and then publishes a release flag; the peer reads the slot once it
sees the flag. On 2x R9700 the bytes do not always land before the flag. With reads
streaming beside the all-reduce (prefetch), a greedy reply differed from one server
start to the next.

A probe in ar_rmsnorm_quant_fp8 compared, right after the handshake, a plain load of
the slot with a system-scope load and with the same word 100 us later: in about 1
launch in 1000 the reader saw the slot's previous contents, and the new bytes arrived
about 1 us later, sometimes more. Pushed bytes wait in the writer's L2 until a
system-scope release writes them back: with the flag sent before the push (a test
mode) and nothing after it, they stayed invisible for the whole kernel (49 ms). The
flag's release does write them back, but the writeback and the flag store reach the
peer by different paths, so the flag can arrive first. A stronger drain on the writer
(drain=1), PCIe relaxed ordering off on both cards and an HDP flush on the reader did
not change that; acq=1 hides it only by delaying the reads (and costs 12-33 % of
decode).

The writer now sums a per-dword hash (MurmurHash3's finalizer over value and index)
over what it pushes and stores the block's sum, salted with its handshake value, into
the peer's check word for (slot, block): two parity slots of fine-grained words after
the flags. The flag's release that follows writes the pushed bytes back. The reader
reads the check word, sums the same over the bytes it is about to read and, until the
two agree, takes an acquire fence, sleeps briefly and reads again; a push that never
lands traps after 2 s. A stale element and a stale check word both disagree, so the
order in which the two land does not matter. No value changes.

Kernels: ar_rmsnorm_quant_fp8 (exact and 6-bit wire), r4d_ar_oneshot_2rank_exact,
r4d_ar_hc_write, r4d_ar_gather_hc_write, r4d_ar_gather_2rank,
r4d_ar_oneshot_2rank_wht6, r4d_ar_hc_write_wht6, ar_rmsnorm_quant_i8,
r4d_ar_ln_had_quant_i8. Also: the link gate is released after the check, the exact
and gather launchers round their width to whole waves (the check's wave sum reads all
32 lanes), and ln_had's dynamic LDS ceiling leaves room for the check's static words.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 10:11:27 +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
mici81andClaude Opus 5.5 32881da9fd docs/GUIDE: two engines on one R9700 pair -- the driver's queue split (amdgpu.num_kcq) and the start order
The four compute queue slots the GUIDE names are what amdgpu leaves to user queues while it keeps four of the
card's eight for its own kernel queues. With num_kcq=0 MES maps all eight (compute_hqd_mask 0xf), two engines'
queues fit, and the weight reads beside the all-reduces can stay on. The order the engines create their
second-lane queues decides where MES places them, so the first engine should serve one request before the
second starts. Measured with Qwen3.8-27B and TranslateGemma 27B on two R9700s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:33:05 +01:00
mici81andClaude Opus 5.5 b61394e13c r4d_selftest: --perfpaged Q CTX times the paged prefill attention at every KV layout
The paged prefill attention rows (head_dim 256, gqa 6) at Qwen3.8-27B's per-rank geometry under TP2: one
sequence whose last Q of CTX tokens are the queries, causal, at fp8, fp8 K + 4-bit V, 6-bit K + 4-bit V and
bf16. A long prompt's prefill step is this at Q = the chunk (or a pipelined piece) and CTX = the tokens so
far, and nothing else times it without a server. Two R9700s at 265 W, 1024 queries ending 41040 tokens:
4.37 / 4.26 / 4.46 / 4.76 ms (fp8 / fp8_v4 / k6_v4 / bf16), 107..120 TFLOP/s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 07:33:36 +00:00
mici81andClaude Opus 5.5 75b4c92e7e libr4d: the paged prefill attention (head 256, gqa 6) without its exposed global waits
The tile loop waited out a global round trip every tile with every wave of the workgroup (the only
one on its WGP) stalled: the wide K fetch sat in a branch whose join made the compiler drain every
load in flight right after it, and the fp8_v4 / k6_v4 V scales were packed right after their
prefetch was issued, so it was waited on at once. Now the K fetch is branch-free (the launch's
thread count is stated to the compiler), the scales are packed at the store, and on the fp8 and
k6_v4 caches tile t+1's K is fetched once tile t's last m-tile has its scores (O_KLATE), so the
staging phase between the barriers only widens and stores. Load order only: the bytes are the same
(greedy texts of a server identical, r4d_selftest 8124 ok / 0 FAIL on both trees).

r4d_selftest --perfpaged on the R9700, three interleaved rounds, medians, k6_v4: 2048 queries over
100k keys 25.91 -> 21.47 ms (-17.2 %), over 160k 41.43 -> 33.97 (-18.0 %), over 25k 5.63 -> 5.45
(-3.3 %), 1024 queries over 50k 5.69 -> 5.48 (-3.7 %). fp8: -7.8 % at 100k and 160k, within noise
at 25k and 50k. bf16 (the stated thread count alone): 0 to -3.5 %. fp8_v4 keeps the old order on
all three counts: with them it gained 19 % at 100k but lost 3 % at 25k and 50k.

The gap is widest where the cache no longer holds the KV (k6_v4 at 100k is 70 MB against 64 MB of
Infinity Cache), so the round trip is a DRAM one. Qwen3.8-27B MXFP4 at tp 2, production flags,
cold prefill, three rounds: 100k 3830..3856 -> 3932..3935 tok/s, 25k 5255..5292 -> 5292.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 07:33:17 +00:00
mici81andClaude Opus 5.5 e25951c51e arch_test: the qwen35 family's pins with the a|b lane
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 15:17:21 +00:00
mici81andClaude Opus 5.5 e6fa74087a qwen35_fp8: the GDN a|b projection on the second lane at decode sizes
At decode and verify sizes (up to 64 rows) the delta net's a|b projection (gemm_nt, N = 48) is
nearly all launch cost and reads only the norm's output, as the in-projection does: it runs on the
second lane beside the in-projection and is joined back before the convolution reads `ab`. A
prefill chunk keeps one lane: there the projection is real work and the lanes would split the
bandwidth the in-projection uses. An opt-in (GdnFP8::ab_lane) set by qwen35_fp8 only, whose second
lane carries no collectives: +1.1 % one stream without speculation (three rounds each). The same
for k and v beside q|gate in the gated attention was measured and left out (-0.7 %: q|gate is a
full-bandwidth GEMM and they compete).

It costs memory: naming the two buffers concurrent gives the arena a second scratch region and the
bring-up a third queue (Qwen3.8-27B at TP2: arena 534 -> 604 MiB, queues 67 -> 100 MiB a card, KV
752k -> 746k tokens).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 14:20:38 +00:00
mici81andClaude Opus 5.5 7fa2ec0e4a arch_test: qwen35_fp8's two-rank pins for the pipelined prefill alone
The pins came from the whole series (with the gated fold and the a|b lane); this PR alone pipelines
the 4096-row budget's step to another graph, and with the pipeline off the build is upstream's serial
one, whose pin the off case now checks (main's 0x36da8d762194e24e / 0xe4022daff02ec8bd).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 acd06d2a48 docs: the pipelined prefill, the second lane's window and scratch region, the narrow all-reduce at three and eight ranks
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +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 0d2b502d51 the second lane's window (rad_lane1_window_begin / _end): concurrent buffers live across it, not the whole program
rad_buf_concurrent held a buffer for the whole program because the planner cannot tell when lane 1
runs. An architecture whose lane-1 work lies in one stretch of its declared ops now declares it, and
its concurrent buffers live across that window and their own uses, so the drafter's and the heads'
buffers share their bytes again. Ctx holds it: an op on lane 1 outside the window fails the step by
name, and the first lane-0 op past it joins lane 1 first when work is pending there. qwen35_fp8 and
gemma3 declare it from the embedding's all-reduce to the final norm. Qwen3.8 + DFlash2 at 64
sequences with speculation: activation arena 633.99 -> 526.32 MiB a card, upstream's exactly (with
the second lane's own scratch region, KV 86208 -> 93856 tokens against upstream's 95520).
arch_test's fake builder applies the window too, so the pinned steps check every plugin touches its
concurrent buffers only inside 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 0c813784a0 core: the second lane's scratch region sized by the ops it may issue
A program naming a buffer to rad_buf_concurrent got two scratch regions of the program's largest kernel
scratch each, though by Ctx::lane1_ rule 3 an op on the second lane touches only rad_buf_concurrent
buffers. Program::scratch_bytes_lane1 is the largest device scratch of such an op (or one naming no
transient buffer); the Arena takes per-region sizes, arena_plan_bytes counts them for the VRAM budget,
and Ctx::issue refuses a larger lane-1 request by name instead of overrunning the region. Qwen3.8 with
its drafter: region 1 0 B instead of 50 MiB (17 MiB without speculation).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 5838c25343 pipelined prefill: the drafter taps on the first lane, so dflash_src stays in the sharing pool
dflash_src ([max_tok, n_taps * n_embd], 100 MiB at a 2048-row chunk) was written on lane 1, so it
had to be a rad_buf_concurrent buffer, held for the whole program. Each piece of a tap layer is now
copied on lane 0 right after lane 0 has waited for that piece's feed-forward boundary, before
anything writes those rows of x again. Same copy, same bytes (pinned steps unchanged); qwen35_fp8
and gemma3. On its own it does not move the activation arena's peak, which other concurrent buffers
set; it is one buffer fewer for the second lane's window (next commit) to bound.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 ad01fcaf19 review notes of the pipelined prefill past two ranks; selftest timings warm the clocks first
Independent review of fa118d8 / 14fb72c: no defect. Notes taken:

- RADIANCE_PREFILL_PIPELINE takes 1 / true as on and 0 / false as off (the old per-arch switches
  took 0 for off; such a value must not leave the pipeline on); the header says that past two
  ranks only the two-shot band is narrow and that eight ranks pipeline on the exact wire only; the
  note says the switch allows the pipeline (gemma3 may still turn it off); "rad_arch.h" as the other
  common headers include it; comment lines rewrapped.
- plugin_test resolves the all-reduce at `overlap` 1 against the real libr4d: the two-shot band
  takes the lane row at three, four and eight ranks, exact and ti8; the one-shot band keeps the wide
  row. arch_test: every spelling of the switch, off at two ranks in all three; no three-rank arch
  case (neither test model's heads split three ways, nor do the real models' KV heads).
- r4d_selftest: gemv_wide's two column tiles at four row tiles and on the per-row scale.
- r4d_selftest: every timed pass is preceded by an untimed one. A fresh process otherwise times its
  first pass while the clocks ramp up from idle (up to 1.5x slow, +-30 % between runs); two builds
  of the same machine code read 13 % apart until both warmed.

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 28f1f2dd8c gemma3: the pipelined prefill's shared pair keeps every linear's own quantiser
The pipeline is decided before the blocks are declared, the fused fp8 junctions only after them.
Where those then did not resolve (no rmsnorm_quant_fp8, a mixed container), every q|k|v and
gate|up still read the shared pair as a shared linear with no quantiser, and the serial fallback
read whatever the last writer left there. The pair is now handed to each such linear as the
target of its own quantiser (G3Linear::q8_into / s8_into): the fused junctions write it when they
resolve, the unfused step's quantisers otherwise.

- a note says why the pipeline is off when declare turns it off;
- a missing bounds buffer fails the step on both ranks (rad_step_fail) instead of one rank
  falling back to the serial step alone.

arch_test: with rmsnorm_quant_fp8 refused at two ranks and 2048 rows the step is serial, every
q and gate|up quantises into the pair it reads (failed before: no quantiser).

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 d39e0511e7 qwen35_fp8: a prefill step of one sequence in two pieces, block boundaries on the second lane
At two ranks a prefill step of at least 1024 rows is cut into two pieces of about half
(pipe_rows: rounded up to 64, both in the whole step's band). Every block runs a piece at a
time on lane 0; the work between two blocks runs a piece at a time on lane 1: the block's
all-reduce at `overlap` 1 (the narrow lane rows), then the next block's plain norm, and after
a feed-forward that keeps its add, the add, the DFlash2 taps and the final norm. The fused
all-reduce + norm is not used there: it holds its blocks while waiting on the link and slowed
the GEMM beside it by a third (measured: no gain at all with it).

- GdnFP8, AttnGatedFP8: takes_pieces(); the dense attention gets a two-piece path (each piece
  its own rows, positions, slots and query bounds, seeing the cache up to its own end), and
  the delta net's piece path takes the caller's normed input (ArPieces::in_ready) and passes
  each piece its own context length (positions + r0), so a prompt's first chunk works.
- MlpFP8: slice() split into body() and tail(), and an overlap all-reduce (issue_ar).
- NormQuantFP8::step_plain().
- M-RoPE batches (the vision tower loaded) take it when no token's components differ: plane 0
  of rope_pos is then every token's position.
- RADIANCE_QWEN35_PIPE=0 turns it off; a wide prefill step that runs serially says why, once.

Bit for bit the serial step: Qwen3.8-27B KL recordings (k6_v4, wht6) compare equal with the
pipeline on and off, and greedy answers to three long requests (680-41k tokens, speculation 3
with the DFlash2 taps) are identical. 41k-token prefill on two R9700s: 9.00 -> 8.41 s with the
TN crossover of the next commit (-6.6 %). arch_test: the two-rank pin moves; new tests pin the
serial build under RADIANCE_QWEN35_PIPE=0 and the pieces, lanes and overlap of a wide step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:10:08 +02:00
mici81andClaude Opus 5.5 0f4c1afc38 r4d_selftest: timed passes after an untimed one; gemv_wide at two column tiles
A fresh process otherwise times its first pass while the card's clock ramps up from idle: up to
1.5x slow, and two builds of the same machine code read 13% apart until both were warm. Numeric
cases for gemv_wide's two column tiles a block at four row tiles and on the per-row scale.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +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 40d205929a r4d_selftest: --perfmxd for the dense MXFP4 rows; --perfmx is GLM-5.3's expert GEMM
Since 1.9.0 --perfmx times the MXFP4 expert GEMM (M, experts, top_k, skew). The dense rows timing
added in this series had taken the same switch and, parsed first, shadowed it.

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 d4eacec5c6 gemm_mxfp4a8_decode: the split and slab rule past 64 rows re-tuned for the register kernel
The rule was tuned with the weight staged through LDS. Past 64 rows (the multi-fragment register
kernel) it now takes the 128-wide slab always and splits K only while every split keeps 16 slabs,
towards a 48-block grid or, at K >= 8192, regardless, up to ks*M = 512 split rows. Swept every
split 1..8 at both slabs on Qwen3.8-27B's and TranslateGemma-27B's per-rank shapes at 96 and 128
rows (warmed); old against new rule, two repetitions, 80 / 96 / 128 rows:

  17408 x 5120   161 / 187 / 215 -> 161 / 175 / 197 us
  5120 x 8704    105 / 116 / 160 -> 110 / 116 / 149
  6144 x 5120     83 /  97 / 105 ->  80 /  87 / 109
  5120 x 3072     71 /  79 /  67 ->  55 /  60 /  69
  21504 x 5376   192 / 207 / 228 -> 187 / 200 / 217
  5376 x 10752   133 / 155 / 197 -> 132 / 154 / 184

Up to 64 rows the rule is unchanged. A different split changes a split row's summation order, so
these rows' bits move within the selftest's bound (gemm_mxfp4a8_decode: 86 ok).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 9daf738909 gemv_wide: two column tiles a block only from N 4096 and K 3072
Measured on smaller models' MXFP4 shapes (r4d_selftest --perfmx, clocks warmed, two repetitions),
two tiles a block lose on narrow or shallow weights -- fewer blocks than the part has units, a
short K a wave: at 32..64 rows 1024 x 2048 +7..30 %, 2048 x 2048 +6..28 %, 2048 x 4096 +4..37 %,
6144 x 1536 at 32 rows +14..30 %. From N 4096 and K 3072 every measured shape gained or held
(4096 x 2048 even; 14336 x 4096 at 64 rows 120 -> 90 us; 4096 x 7168 67 -> 55; the 27B shapes as
before), so the launcher takes two tiles there only. Bits unchanged either way.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 0fb3badc6c review notes of the MXFP4 decode GEMMs: comments, unreachable instantiations
Independent review of 675322e: no defect (the double buffers, the ratio timing against the old
kernel including a split starting mid-block and the 64-wide slab, the clamped tile, the empty
split; every variant without spills inside its waves budget). Notes taken:

- the slab rule's LDS formula was the LDS-staged kernel's; say so, and that the DTM 4 arm may no
  longer pay (not re-tuned);
- mxd_ratio's comment describes when each kernel publishes the ratio;
- gemv_wide no longer instantiates two column tiles at one row tile (unreachable: two tiles need
  more than 24 rows);
- a comment line over 100 columns.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 11:09:03 +02:00
mici81andClaude Opus 5.5 2382686d3b MXFP4 decode GEMMs past 16 rows: gemv_wide two column tiles a block, the decode row's weight to registers
Bit for bit as before, faster where several streams speculate (25 to 128 rows a step):

- gemm_mxfp4a8_gemv_wide carries two 16-column tiles a block from 25 rows. The activation is read
  per block, so one tile a block read all of it N/16 times -- 356 MB from L2 at 64 rows on a 27B's
  17408-row gate_up, against a 47 MB weight. Each activation fragment now serves both tiles; a
  tile's WMMA chain is unchanged. Four tiles spill past 32 rows.
- gemm_mxfp4a8_decode's multi-fragment kernel (17..128 rows) loads each wave's weight words straight
  to registers, as the gemv kernel does (a fragment-order word is the WMMA fragment's register), and
  double-buffers only the shared activation in LDS: one barrier a slab, the next slab's loads in
  flight across this one's WMMAs. Same fold, k-step and slab order, scale carry and epilogue; its
  whole output compared byte for byte with the LDS-staged kernel's on Qwen3.8-27B's and
  TranslateGemma-27B's per-rank shapes at 17..128 rows, both scale grids, the 64-wide slab, parts
  and forced splits (312 cases, an experiment-only selftest case).

r4d_selftest --perfmx with the clocks warmed (a first timed pass from an idle card catches them
ramping up and read up to 1.5x slow), before -> after:
  17408 x 5120   32 rows 125 -> 85 us, 64 157 -> 122, 96 205 -> 159, 128 245 -> 214
  5120 x 8704    32 rows  75 -> 56,    64  95 -> 75,  128 169 -> 139
  6144 x 5120    64 rows  70 -> 57,   128 121 -> 92
  21504 x 5376   32 rows 154 -> 111,   64 183 -> 150
  5376 x 10752   32 rows 105 -> 68,    64 123 -> 98
At 16 to 24 rows within a few percent either way (unchanged kernels there).

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
mici81andClaude Opus 5.5 9322ea0b92 docs: --draft-short-from measured on the card driver against 1.11.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 12:42:10 +00:00
mici81andClaude Opus 5.5 877e8e44e4 block drafter: the short block on the card's driver
1.11.0 runs a block drafter on the card only (issue_block_drafter). Engine::block_shape chooses the block
and the proposal count a step runs: the drafter's own, or its short block from --draft-short-from
decoding sequences on, off again two below. The card's query pass runs that block, ADV_BTAKE takes that
many proposals from the front of each row at the drafter's pitch, and the step issued ahead verifies
that many (expect_draft and finish_block_drafter read block_steps_). sched_test runs the card driver's
sequence at DFlash2's short block (4 rows, 3 proposals) against the host's reference.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:26:39 +00:00
mici81andClaude Opus 5.5 7e2d6a205d docs: --draft-short-from (GUIDE 4.6, the flag table) and rad_drafter_short_block (PLUGIN)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:25:06 +00:00
mici81andClaude Opus 5.5 634e805ce2 block drafter: proposal_pitch documented; arch_test pins with the short block
RadDrafterDecl::proposal_pitch defaults to depth for a block drafter and is refused below it (the
short block fills a row's front). arch_test: the qwen35 family's pins now that DFlash2 declares its
short block.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:24:45 +00:00
mici81andClaude Opus 5.5 da52bc8593 review fixes of the block drafter's short block (independent review)
- declare_drafter: a block drafter's proposal_pitch, now the row pitch the engine reads row s
  at, defaults to depth (it defaulted to 1, which a pitch-reading engine would take as packed
  rows: wrong drafts from the second sequence and a read past the readback) and is refused
  under depth. The engine's fallback goes.
- run_block_drafter: hysteresis -- the short block goes on at --draft-short-from decoding
  sequences and off only two below, so a load wavering at the threshold does not switch the
  block (a new pass shape, the adaptive estimates) every step. Comment: the proposals are for
  the next step.
- block_begin's comment: after a long block a short one's reservation stops short of the trunk
  step's end; the rejected rows past it land on freed pages with slot -1, which every kv_store
  drops. Named as the load-bearing rule it is.
- The --draft-short-from warning names a serial head as such; the arch_test stub returns the
  real builder's codes.
- build_test: the pitch's default and refusal.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:24:45 +00:00
mici81andClaude Opus 5.5 90e14c5015 block drafter: a short block chosen per step by load (--draft-short-from N)
A block drafter proposes its block whole, so the block's length is paid for every drafting
sequence whatever each verifies. At one sequence a long block pays: Qwen3.8-27B + DFlash2
(block 8, --draft-window adaptive) decodes one stream 135 -> 155-165 t/s against block 4. At
sixteen it does not: block 8 750-790 t/s, block 4 900, its drafter rows and weaker first
positions costing more than the extra drafts bring. --draft-window adaptive alone cannot help,
since it only shortens what each sequence verifies.

- rad_drafter_short_block(b, block): additive export (RAD_ABI_VERSION unchanged); the plugin
  declares that its query pass also runs at `block` rows a sequence. Builder validates it
  (block drafter, shorter than its own, still proposes).
- --draft-short-from N (default 0 = never): the engine stages the short block once N sequences
  decoded in the step just run (Scheduler::decoded_seqs).
- The engine reads the proposals at the drafter's declared row pitch, not at the step's count:
  dflash_select writes row s at s * pitch, and a short block fills only a row's front (with the
  pitch read as the count, every sequence but the first got the wrong tokens).
- Dflash2: a short block of 4 rows (depth 3) wherever its own is longer: its own convolution and
  selector ops at that block (every other op is per row); the query pass picks by T / n_seq and
  fails the step on a block it has no ops for. qwen35_fp8 and gemma3 declare it.
- Tests: build_test (the declaration's checks), arch_test (the qwen35 family's short query pass
  runs the short ops, a block without ops fails the step; the DFlash2 pin moves), config_test.

Measured (Qwen, speculation 7 adaptive, short block from 4 sequences, against production's
speculation 3 fixed): one stream +15-20 % (kratky) / +9 % (syslog), 4 streams +3 %, 16
streams equal (915 / 906 t/s).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:24:35 +00:00
mici81andClaude Opus 5.5 4d68a01a08 qwen35_fp8: the GDN state cache at f16 when a deployment asks (RADIANCE_GDN_STATE_F16=1)
libr4d's recurrent update and chunk scan already read the state's width off the cache; the plugin
declared it f32 unconditionally because f16 changes the generated text. A deployment may now trade
that: RADIANCE_GDN_STATE_F16=1 (exactly) declares the cache f16, anything else keeps f32, and the
declare log says so. The default does not change.

Lossy. Qwen3.8-27B (MXFP4, TP2), mean KL against the bf16 reference, f32 -> f16:

- k6_v4 KV: chunk 2048 0.040238 -> 0.040005; chunk 64 (the state stored and rounded every 64
  tokens) 0.039607 -> 0.040468, top-1 94.07 -> 94.00 %;
- fp8 KV: chunk 2048 0.039171 -> 0.039600 (+1.1 %), chunk 64 0.039327 -> 0.039690 (+0.9 %).

It halves the state pool, its host checkpoints and the state's traffic, which grows with the
decoding sequences. Decode on two R9700s, greedy, three rounds (medians, tok/s, f32 -> f16):

- no speculation: 1 stream 67.1 -> 67.5 (+0.6 %), 4 246.8 -> 253.3 (+2.6 %), 16 708.0 -> 779.5
  (+10.1 %); the rounds agree to a tenth;
- speculation 7: 1 stream 222.2 -> 215.1 (-3.2 %), 4 636.9 -> 621.0 (-2.5 %), 16 1223.8 -> 1276.7
  (+4.3 %); f16 also changes which drafts the greedy text accepts, and the text and the step were
  not separated.

So it is for many concurrent sequences where the KL is acceptable. GUIDE §4.4 has the tables.

arch_test: the state group is f32 unset, at "0" and at "yes", f16 at "1".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 11:14:38 +00:00
mici81andClaude Opus 5.5 e9d03362f0 docs: gemma3's fused all-reduce junctions under a lossy wire (ARCHITECTURES)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 18:36:17 +00:00
mici81andClaude Opus 5.5 5a7dac7ce1 gemma3: the fused all-reduce junctions under a lossy wire too, taken by the steps whose message goes out exact
Both junction kernels (ar_rmsnorm_quant_i8, ar_rmsnorm_post_quant_fp8) send the exact wire only, so
they were declared only on the exact wire. Since TranslateGemma moved to --tp-wire wht6 (19. 10.,
prefill +50 %) its decode ran every junction unfused -- all-reduce, post-norm and junction, three
launches for one -- although a decode step of a few rows goes out exact anyway (under
--tp-wire-min-kb). Now they are declared at two ranks whatever the wire and taken per step where
ar_wire_is_exact(T); a wider step keeps the lossy all-reduce, unfused. A fused step is bit for bit
the unfused exact one (the kernels are byte-identical to all_reduce).

arch_test: under a lossy wire an MXFP4 trunks decode step folds its junctions all-reduces, a
prefill chunk above the floor does not.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:25:08 +00:00
mici81andClaude Opus 5.5 58142a6638 docs: the fp8 and int8 heads past 64 rows
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:24:16 +00: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
mici81andClaude Opus 5.5 824e238996 MXFP4 tiled GEMM: review fixes, tests and docs
Carried from the series' review rounds when it was split: numeric cases for the plain kernel at a
whole row of blocks (TN=4 forced and by the rule from 1024 rows, TN=2 at the 64-wide slab), the
plain kernel's comment, and libr4d/README.md's account of the row with the measurements behind
TN=4 from 1024 rows, the slab-ahead weight load and the thin last row.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:23:51 +00:00
mici81andClaude Opus 5.5 6249462bfa gemm_mxfp4a8_tiled: a thin last row of blocks skips its padding WMMAs, in a kernel of its own
The block is 256 rows at every M, so a block the M edge cuts ran its padding rows' WMMAs on clamped
copies of the last fragment (half the only block's math at 129 rows). M whose last row holds 1..160
rows (under 1024 in all) now runs a two-body kernel whose blocks of that row skip the WMMAs of their
fragments past M: same-session A/B over 12 shapes, M 129..160 -8..-20 %, 320..384 -2..-16 % (Qwen
gate_up at 320 rows 402 -> 339 us, TranslateGemma's 513 -> 441). Every other M runs the plain kernel,
whose body declares its own LDS, so its ISA is the old kernel's instruction for instruction: guarding
inside the one kernel cost full blocks 1..15 %, handing the body the LDS by pointer 2..8 %. Per output
byte the fold, the WMMAs and their order are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:23:13 +00:00
mici81andClaude Opus 5.5 a85f87ea2f gemm_mxfp4a8_tiled: the weight loaded a slab ahead
Each slab used to load its weight words and exponents, wait for them, unpack them to LDS and only
then compute, so a DRAM round trip stood in front of every slab's unpack. The words a thread stages
are now loaded into registers right after the staging barrier, a slab ahead, and fly across the
slab's WMMAs (+1 VGPR at TN=4, no spills). Same fold, same WMMA order: bit for bit.

r4d_selftest --perfmx, warmed, at 1024 rows (a pipelined prefill's piece): Qwen3.8 gate_up
804 -> 768 us, down 443 -> 417, ssm_in 396 -> 384, ssm_out 249 -> 231, attention q|gate
306 -> 318; TranslateGemma gate_up 1063 -> 1029, down 651 -> 617; at 2048 rows 0..-4 %. Loading the
A fragments a slab ahead too (+38 VGPRs) was slower everywhere. End to end (three alternating
rounds against the production image): Qwen 41k prefill 8.57 -> 8.28 s (-3.4 %); TranslateGemma 6k
and 12k unchanged at 0.1 s; KL 0.040237.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:23:13 +00:00
mici81andClaude Opus 5.5 168a26a6b8 gemm_mxfp4a8_tiled: TN=4 from M >= 1024
TN=4 wins from 1024 rows on (r4d_selftest --perfmx, a rank's weights: Qwen3.8 gate_up
17408x5120 1105.6 -> 1080.8 us, down 5120x8704 618.5 -> 599.1, TranslateGemma gate_up
21504x5376 1395.0 -> 1273.8, its down 5376x10752 793.6 -> 799.6; 1536 rows better on all four;
512 and 768 mixed). It matters to the pipelined prefill's 1024-row pieces and to TranslateGemma's
1024-row chunks. Same bytes: Qwen's KL recording and TranslateGemma's KL (0.054628) unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 12:23:13 +00:00
mici81andClaude Opus 5.5 3e656f0b02 libr4d: review fixes -- the quantised stores apply v_scale; scales clamped so every code decodes finite; two more selftest shapes
kv_store_fp8v4 / k6v4 and the folds now read v_scale as the fp8 store does (attention already
applied v_descale). Scales are clamped to 8188 (V) and 2112 (K) so 7 or 31 times them stays an
f16: a group gone inf or NaN decodes finite, as E4M3's clamp to 448 does. r4d_selftest adds
decode at ctx 1000 (a partial last block) and q_len 7 (three waves) for both layouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:28:21 +02:00
mici81andClaude Opus 5.5 1823ccd5e9 --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>
2026-10-19 15:28:21 +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 44aecb0ab8 arch/gemma3: review fixes -- calibration declares no fused junction, so no container writes zero Grams; docs corrected
On an MXFP4 container the fused junctions skip the bf16 activations the tap reads, and q/k/v and
gate_up Grams came out zero without a word (down likewise behind gelu_mul_quant_i8). Under
RADIANCE_CALIB_DIR no junction or fused down-quantiser is declared, so any container
calibrates, unfused; checked on the production MXFP4 container. RADIANCE_G3_CALIB_LAYERS
refuses trailing characters. Docs: which trunk fuses what, the four-stream numbers' two
workloads, which sizes are tested. arch_test's world-2 check counts the post-norm op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:44:46 +02:00
mici81andClaude Opus 5.5 f2c0468335 docs, recipes, compose: TranslateGemma 27B
The gemma3 section of ARCHITECTURES.md (geometry, traps, KV groups, linears, calibration,
measurements, the DFlash2 drafter), the calibration variable and the conversion of record in
GUIDE.md, the README's models table. Recipes: the int8 calibration container (KL 0.003),
MXFP4 + GPTQ (KL 0.042, 56 tok/s a stream on two R9700s), and with a drafter. The compose file
serves a plain Gemma 3 template: TranslateGemma's own refuses the startup render's plain turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:44:46 +02:00
mici81andClaude Opus 5.5 a91a2837ff arch/gemma3: Gemma 3 dense text (TranslateGemma 27B), per-(row, 128) activation linears, DFlash2
gemma4_bf16's block structure with Gemma 3's differences (modeling_gemma3, transformers 4.57):
GemmaRMSNorm everywhere, one head geometry, scores at query_pre_attn_scalar^-0.5, linear rotary
scaling on the global layers only, the bf16-held embedding scale, no value norm, soft-capping
and YaRN refused. Linears i8a8, mxfp4a8 and w4a8i8_asym over an activation scaled per
(row, 128), beside bf16 and w4a8 / w8a8: one int8 scale a row costs KL 0.097 at w8a8 on
Gemma 3's outlier channels. Fused junctions on a quantised trunk. A calibration tap
(RADIANCE_CALIB_DIR, RADIANCE_G3_CALIB_LAYERS), the column-split linears as rank parts.
A DFlash2 drafter as qwen35_fp8 declares one; rad_block_dflash2.h applies the drafter's
input_embedding_scale through embed_lookup's mult when it is not 1, so other drafters'
graphs are unchanged. Against transformers' float32 forward on a tiny Gemma 3: KL 0.00016 on
the host backend and the cards. arch_test: 7 cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:44:46 +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
mici81andClaude Opus 5.5 cec70ad1c7 libquant: review fixes -- loops kept as the LAPACK reference (RAD_LQ_LAPACK=0) and tested against it, NaN pivots refused, 4 layer factors kept
The single-threaded loops stay beside LAPACK; RAD_LQ_LAPACK=0 takes them and
gptq_through_lapack_matches_the_loops compares the two (output error equal to rounding). A
factor whose diagonal is not finite and positive is refused, as the loops refused a NaN pivot
that dpotrf lets through. The cache keeps the 4 most recent layer factors: a MoE layer's
experts alternate between two stems. The size in the comment is the f32 factor's, 1.85 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:41:22 +02:00
mici81andClaude Opus 5.5 400bbefa13 libquant: a column-split linear's Hessian from per-rank parts
Under tensor parallelism an attention output or down projection sees only its rank's K / world
columns, so no rank can write the K x K Gram. A tap may write each rank's block as
<stem>.part; with no whole file calib_sum places the parts on the diagonal in rank order (the
cross-rank products, never formed, zero) and converts the result like a whole file. Parts that
do not cover K, or not in domain 0, are reported and the weight rounds to nearest. Tested
byte for byte against the whole block-diagonal file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:41:22 +02:00
mici81andClaude Opus 5.5 c94a0e6cc2 libquant: GPTQ's factorisations through LAPACK where OpenBLAS is found; one layer's factor at a time
At K = 21504 (a dense 27B's down projection) the single-threaded Cholesky and inverse took hours
a layer; dpotrf / dpotri take 13.5 s for all three on 24 cores, identical to 1e-14. Without
OpenBLAS nothing changes. The factor cache kept every layer's factor, 3.7 GB each at that
width, which OOM-killed a 62-layer conversion at layer 25; it now keeps one at a time (a layer's
experts arrive together and still share it). RAD_LQ_FACTOR_CACHE_ALL keeps the old behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:41:22 +02:00
mici81andClaude Opus 5.5 d82c11644e libr4d: review fixes -- a tuned ar_ln_had_quant_i8 count under the ceiling; say which gathers it cannot cap
ar_ln_had_quant_i8 clamped a tuned block count to M only; it stays under R4D_AR_MAX_BLOCKS
now, as every other entry's. The MoE hyper-connection gathers keep the minimum their LDS table
needs, which may exceed the ceiling: the comment and GUIDE say so instead of "every
collective". r4d.h states that a refused IPC export leaves the handle zeroed, out_len 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:39:53 +02:00
mici81andClaude Opus 5.5 1d1cb21e02 libr4d: R4D_AR_MAX_BLOCKS, a ceiling on collective blocks for two engines on one set of cards
Every block of a collective spins until its twin on the peer card has pushed. One engine is safe
(both cards dispatch its blocks in the same order); two tensor-parallel engines on the same
cards can deadlock, one engine's spinners filling a card while their twins wait behind the
other engine's kernel. Two TP2 engines on two R9700s hung within a minute of concurrent
prefill and the failed queue eviction froze the host. Capped in both engines so their spinners
together leave part of a card free, the cycle cannot close: 15 minutes of concurrent load
clean at 64 / 16. Only launch counts shrink; each element's sum is the same. Unset, nothing
changes. GUIDE section 8 documents it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:39:53 +02:00
mici81andClaude Opus 5.5 fb7a30cd84 libr4d: a refused IPC export is not fatal
r4d_ar_ipc_alloc exports every collective buffer with hipIpcGetMemHandle. Beside another
process holding the same cards it answers invalid argument while the allocation is fine, and
HIPOK stopped the engine. libr4d's ranks are threads of one process and share the pointer
itself, so the handle is never read: a refused export leaves it empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:39:53 +02:00
mici81andClaude Opus 5.5 df030c7483 core/text: added (non-special) tokens go through the decoder chain, as in HuggingFace
Gemma's tokenizer.json spells runs of 2-31 spaces as added, non-special tokens in U+2581
(ids 138-167). piece_at returned every user-defined token literally, so indentation and
double spaces in a Gemma reply came out as U+2581. HuggingFace runs every token it keeps
through the decoder; now a user-defined token does too, and only control and unknown
tokens stay literal. decode, the Detokenizer and TokenView change together. tokenizer_test
covers it with a Gemma-shaped tokenizer.json.

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