Archived
17f0eae42058e2cc98a0029052d40d3229ed362c
45
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d8b9ce3a32 |
gemma4: a GPTQ calibration tap and recipe for the 31B's w4a8 container, whose tool calls then close their strings
Rounded to nearest, the 31B's w4a8 trunk leaves streamed tool calls inside their string arguments: after `sku:<|"|>MS-110` it prefers `**,` (58%) to the string's close (41%; bf16 ~1.0), and BetterBench's order request stalled in 10 of 20 tries. This adds what it takes to make the same container (same grid, kernels and size) with the trunk's int4 codes chosen by GPTQ against the bf16 model's own activations. - arch/gemma4: with RADIANCE_CALIB_DIR set, the plugin serving the 31B's bf16 checkpoint sums the Gram of every dense linear's bf16 input over the corpus a server is fed (gram_accum into a PERSIST [K, K] f32 buffer a tap) and writes the files at RADIANCE_CALIB_TOKENS, as arch/gemma3's tap does: q|k|v's and gate|up's input whole from rank 0, o_proj's and down's this rank's columns as `<stem>.part`, which libquant places on the diagonal. The files carry the names the w4a8 container gives the weights (gemma4_bf16's attn_qkv, attn_o, ffn_gate_up, ffn_down), so a GPTQ recipe converting that container reads them with calib=DIR. RADIANCE_G4_CALIB_LAYERS=lo:hi records a slice of layers (the 31B's taps are ~364 MiB a layer a rank at --tp 4, and 60 layers of them do not fit beside the bf16 weights). Under the tap a step runs whole and on one lane; without RADIANCE_CALIB_DIR nothing changes. - data/recipes/gemma4-31b-dense-bf16-w4a8g-df2.recipe: the -df2 recipe with `gptq codes=i4 group=128 scale=f16 rule=search calib=$CALIB` on the trunk's four linears. - docs/GEMMA4-31B-GPTQ.md: the route, the corpus, how to run it, and the measurements. Measured (1.11.0, the same tap and recipe): by GPTQ the close is 99.8% and no try stalls; KL against bf16 on the model's own turns falls from 0.341 to 0.251 (the w8a8 container 0.226), at the same speed. The convert takes 75 minutes with OpenBLAS in the image (#220; an estimated days without). A container made this way is on Hugging Face as Ashlyn4202025/gemma4-31b-w4a8-gptq-dflash2, and with the block-16 drafter as Ashlyn4202025/gemma4-31b-w4a8-gptq-dflash2-b16. Tests: engine_e2e takes the tiny Gemma 4 (shaped like the 31B) through the whole route at --tp 2: the tap's files, by name and width on each rank; rad-convert with the two shipped recipes, every trunk linear fitted and none rounded to nearest; and the GPTQ container's KL against the bf16 model on held-out documents more than three times below the round-to-nearest one's (0.0018 against 0.0105). With rank 0's and rank 1's .part blocks swapped the margin is 2.2 times, which fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
66c86b9f89 |
speculation: a group the window snapshot restores is no hole in a drafter's KV after a prefix hit
On Gemma 4 (sliding layers the prefix cache does not index, no linear state) a hit resumes the trunk's window from a window snapshot. The check for a hole in a block drafter's own KV after a hit counted every paged group the prefix cache does not index, the trunk's windowed one included, so it found a hole the snapshot fills. z-lab's DFlash drafter keeps a full-attention cache, which the prefix cache indexes; with that false hole its floor sat at the hit, and with no window to slide it was declined for the rest of every turn after a hit (on the 31B: 1.00 tokens a step on those turns, 4.25 with this). The scheduler now counts a group the snapshot restores (IKVManager::window_snapshot, the KV manager's KVGroupPlan::win_snap) as no hole, and the startup line says how many: `draft floor: 3 paged group(s), 2 prefix-cached, 1 in the window snapshot -> a hit leaves no hole`. A drafter's own windowed group is not in the snapshot, so DFlash2 and every model with linear state are unchanged. Tests: sched_test (a full-attention drafter drafts at once after a hit the window snapshot resumes, and with the trunk's window counted as a hole never drafts again that turn; the fixture gains a full-attention trunk). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
64c652f01e |
speculation: an MTP head's first draft reads its cache only up to where it sits
The history pass has a row for every position a verify could commit; rows past the last committed one repeat it, and the run's last row is draft round 1's input. The card gave that pass the run's whole length as its context. Attention places row j of a q_len-row run at seqused - q_len + j and reads keys up to there, so after a verify that accepted acc < n_spec drafts, round 1 also read the n_spec - acc positions after its own: slots the head's layer had not written for this sequence (last step's speculative rounds, or whatever the block held before it was handed out). Its proposal then followed those bytes. Positions 2 and on were right: each round is one row whose context ends at its own position. This fits #221 (Qwen3.8-Flash-Next, position-1 acceptance 0.01-0.16 after a few short conversations sit in the prefix cache, healthy with --no-prefix-cache, after a restart and on long conversations): with the default lending cache the pool hands out blocks it lent the expert slab once cached blocks pass the live mark, and their unwritten slots hold expert bytes; above 2051 tokens the head's QSA path bounds each query by its own position. On the reporter's model (TP2, their flags, 32 distinct short chats on a fresh engine) 1.12.0 falls to p1 0.352 from request 9; with this change p1 is 0.953, as with --no-prefix-cache (0.955), replies identical. The context now ends at the last committed position. Earlier rows of the pass count lower than their positions, but nothing reads their output (the head goes on with draft_out_ids only), and every row's K and V still store at its own position's slot. Tests: advance_test (no row of a history pass or a round counts past its own position, and the run's last row sits exactly at it, for every acceptance and lead; fails before: the last row at 204 for a head at 201; and right after a 1-2 token prompt, where the rows nothing reads count before the sequence's start, every row still stores at its own position and the last sits at the committed one); ref_test (rows of a paged-attention run that sit before the context's start return zeros, not NaN, and the rows after them stay exact). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
bf6c019571 |
engine: stream a step's tokens before the drafter's passes behind it end
Since 1.11.0 a block drafter's context and query passes (DFlash, DFlash2), like a serial drafter's rounds (MTP), are queued behind the step before its readback, and the host waited for all of them before it read the sampled ids. The ids' copy was already issued ahead of the passes, but the commit that streams the tokens came only after the passes had run: every token, the first one included, reached the client a drafter's passes late. The copy now has an event of its own (tok_end_). collect_step waits on it, the commit streams the tokens while the card runs the passes, and the step loop waits for the step's end (step_end_) right after the commit, before finish_*_drafter reads the slots and before anything else is issued. The commit issues no device work, so whatever it releases is in use only by the passes that wait covers, and the next work that could reuse it is issued after the wait. KL mode and embedding programs keep the old wait; RADIANCE_IDS_EARLY=0 restores it, for an A/B. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
f55570e351 |
sched: no step issued ahead behind a step that ends every request it carries
A pipelined engine issues each step's successor before the step is read back: block drafters (DFlash, DFlash2) since 1.11.0, serial MTP and decoding without a drafter since 1.0.0. The step that emits a request's last token therefore had one more step queued behind it, for a request its commit then finishes. That step verifies nothing, yet the card runs its whole forward pass and the drafter's context pass behind it, and a request that arrives once the last token is out -- a single-stream client's next turn, sent as the reply ends -- waits for all of it before its prefill starts. On Qwen3.8-27B ParoQuant int5 with DFlash2 on one R9700 that is about one decode step (34-53 ms) of TTFT on every back-to-back request (#225: 105 -> 139 ms); for 127 requests 1.12.0 ran 806 decode steps, all issued ahead, against 1.8.1's 680. Scheduler::step_next_locked, beside the other rules for issuing ahead and before the next step's KV is reserved, now issues nothing when the step just issued ends every request it carries: when it can bring each to its max_tokens (certainly with the token it emits, possibly with the drafts it verifies: output + 1 + drafts >= max_tokens), or, most likely, when those drafts hold an end-of-generation id (ignore_eos requests excepted). The engine hands the scheduler the end-of-generation ids at start (set_eog), the sorted list the card's acceptance reads. A guess that misses (a drafted end the verify rejects, too few drafts accepted to reach max_tokens) costs one step built after the commit instead of before it. Ends it does not predict still leave one step behind: an end the verify chose itself, a stop string, the context limit. Without a drafter only max_tokens ends are caught, exactly. At -v the commit names each request that ended with a step issued ahead behind it (finish reason, its last step's tokens and accepted drafts, output against max_tokens, whether its drafts held an end). Tests: sched_test pins both halves (a drafted end issues and reserves nothing; a request whose next token is its last, or whose token and accepted drafts could reach max_tokens, issues nothing; an ignore_eos request's drafted end, drafts without an end, and a request that every draft accepted would leave a token short still issue ahead; of two requests one going on, both issue ahead); the test of a request finishing under a step issued ahead now ends it on an end of text the scheduler cannot see coming. engine_e2e_test: two 32-token replies without a drafter are 62 decode steps, all issued ahead, not 64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
5e8bae8ae6 |
libr4d, arch, deploy: coded overlap all-reduces, multi-user verify tuning, the split junction, a compose file
The prefill overlap's lane all-reduces coded losslessly at ~12.2 bits a value; the verify step's GEMM, norm and all-reduces tuned for 17-64 rows; at 4-16 rows each GPU norms its own rows between a reduce-scatter and an int8 all-gather; deploy/compose/gemma4-31b-w4a8-df2-tp4.yaml. Squashed from: - libr4d: the four-rank exact two-shot coded at ~12.2 bits a bf16 value, for the lane row - libr4d: the prefill overlap's lane all-reduces coded by default - libr4d: decode-sized two-shots take fewer blocks - libr4d: gemm_w4a8_nt_m64 at multi-user verify heights (33-64 rows) -- narrower row tiles, wider N - libr4d: rmsnorm_quant_i8's register form at 512 threads too (33 to 72-120 rows) - libr4d: ar_rmsnorm_quant_i8_4rank's `sp`, the all-reduce split around the junction - arch/gemma4_bf16: the 31B's junctions take libr4d's `sp` at 4-16 rows at four ranks - deploy/compose, README: Gemma 4 31B with RedHatAI's DFlash2 drafter on four cards Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
ab2b3be6c0 |
core, libr4d, arch: chained launches with block drafters, more prefill overlap, weight reads beside the all-reduces
Chained launches on the AQL backend (a dependent kernel waits on a queue counter in its own prologue), on by default where the model's plugin measured a gain with its block drafter (the Gemma 4 31B and 26B); the prefill overlap runs attention per slice with narrower lane-1 reductions; the next GEMM's weight is read into the on-die cache beside each all-reduce at decode heights. Squashed from: - core, libr4d: chained launches -- dependent kernels wait in their prologue, not behind the barrier bit - core, libr4d: chain a kernel by its name, not by the row that launched it - libr4d, core: chained forms hold nothing across their body - libr4d: a chained kernel's prologue polls its counter less often after the first few tries - core/sched: the advance kernel's chained form - docs: GUIDE lists RADIANCE_CHAIN; chained launches stay opt-in - core/device: a chained packet behind a chained one keeps its barrier bit while a plain one may run - libr4d: qkv_norm_rope and its kv_store fold as chained forms - libr4d: the split-KV decode attention and its merge as chained forms - libr4d: the four-rank fused junction's tail form as a chained form - libr4d: the attention, prologue and junction chained forms hold nothing across their body - libr4d: the 31B's windowed attention and quant_act_i8 as chained forms; r4d_chain.h stubs for the host emulator - libr4d: DFlash2's kernels as chained forms - libr4d: chained forms for the decode tail - abi, core, arch: chained launches on by default where the plugin measured a gain with its drafter - arch/gemma4_bf16: the prefill overlap's lane-1 all-reduces take the narrow launch (`overlap` 1) - arch/gemma4_bf16, libr4d: the prefill overlap runs attention per slice; kv_len_trim - abi, core, libr4d: RAD_LAYOUT_ANY, and a device-only weight read (prefetch) - arch: read the next GEMM's weight into the cache beside each collective at decode heights Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
1bb7ad3ef9 |
The series' PR beneath, composed (a copy; it drops out when it lands)
#159's tree (a full fence on four-rank prefill-sized all-reduces), which the maintainer will merge by hand in the next release, as the integration branch composed and tested it. Not for review here: review the last commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
cb5a69ac3f |
engine: a block drafter on the card's acceptance -- its passes queued behind the step, the next step issued ahead
A block drafter (DFlash) ran its two passes after the commit, staged from the committed sequence: the verify, a host wait and the commit, the context and query passes, a second host wait for the proposals, then the next step's build and issue, with the cards idle through each host turn and the ranks starting every pass at different times. Pipelining was off for block drafters. It now takes the serial drafters' path (sched/advance.h). After the trunk's ranks join, the acceptance runs on every rank (ADV_ACCEPT). block_begin runs before the commit (on_card): the context pass mirrors the trunk step, whose positions the host knows (a row issued ahead continued from the committed end, as commit() reads it); the query block's rows are device rows staged at the furthest anchor acceptance could leave, with the KV reservation that far, and ADV_BLOCK puts the anchor (the token the verify chose) and the masks at the card's committed end. After the query pass, ADV_BTAKE takes the proposals into each StepSlot behind the anchor, which is the token row the next verify reads (ADV_TRUNK), so issue_ahead verifies them with no host round trip. The slots come back with the step's one readback; finish_block_drafter checks the card's acceptance against the host's, as the serial driver does, publishes the proposals and moves the drafter's filled range. RADIANCE_DRAFT_BLOCK_HOST=1 keeps the host's driver, for the A/B, and has a row in GUIDE.md's environment table. On libref with the tiny 31B-shaped checkpoint (and one doctored so its drafter is right part of the time) the two drivers give the same replies, the same draft acceptance and the same sampled text, and greedy matches plain decoding. sched_test runs 24 pipelined steps against the host's driver: the same trunk steps and the same context and query passes, positions, lengths and slots (the context pass's token ids aside, which that pass does not read); advance_test covers the two modes and the chain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
015cba8837 |
libr4d, arch: the 31B and DFlash2 with fewer launches a step, same bytes
Attention reads q and the gqa-8 drafter's KV in place (attn_paged_qrow); the 31B's attention prologue stores k and v itself (qkv_norm_rope_kv_store); DFlash2's norm/rope/cache-store chains and add-then-norm pairs run as one launch each. Carries the launch-cliff padding until that PR merges. Squashed from: - libr4d: attn_paged_qrow on the split-KV decode kernel -- h256/gqa2, and h128/gqa8 by two groups a kv head - arch: the 31B's sliding layers and its drafter read through attn_paged_qrow where a card serves it - libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms - libr4d: qkv_norm_rope describes its operands, so rad-kbench and rad-tune can time it - libr4d, arch/gemma4_bf16: qkv_norm_rope_kv_store -- the 31B's prologue stores k and v itself - libr4d, arch/common: qkv_norm_rope takes v_norm; DFlash2's query pass folds its q/k chain - libr4d, arch/common: qkv_norm_rope takes n_head 0; DFlash2's context pass folds its key chain - libr4d, arch/common: add_rmsnorm; DFlash2 issues each residual add with the norm after it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
04e5480387 |
arch, data/recipes, libr4d: the 31B's prefill overlap, q|k|v as one linear, RedHatAI's DFlash2, its fc split
The 31B's prefill steps of 1024 rows or more run as two slices with each slice's all-reduces beside the other's compute; q, k and v as one linear where the container holds them so; the 31B serves RedHatAI's DFlash2 speculator; DFlash2's fc projection is split over the ranks, bit for bit. Squashed from: - arch/gemma4_bf16: a prefill step in two slices, each slice's reductions on the second lane - arch/gemma4_bf16: q, k and v as one linear where the container holds them so - data/recipes: the 31B -df recipes make q, k and v one linear (blk.*.attn_qkv) - arch/gemma4: the 31B serves RedHatAI's DFlash2 speculator (gemma-4-31B-it-speculator.dflash2) - libr4d: gemm_nt_q takes split_n, and all_gather lands rows at a wider output pitch - arch/common: DFlash2's fc split over the ranks as windows of block-aligned rows, bit for bit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
bdb37d5d16 |
arch: Gemma 4 31B with z-lab's DFlash drafter
Gemma 4's DFlash drafter moves into arch/common so both Gemma 4 plugins declare it, on the int8 grid too; the 31B declares it beside its w4a8 / w8a8 trunk when the container carries one; the w4a8 and Q8 -df recipes and compose files; the tests. Squashed from: - arch: Gemma 4's DFlash drafter into arch/common, for both Gemma 4 plugins, and on the int8 grid - arch: z-lab's DFlash drafter beside the 31B's w4a8 / w8a8 trunk, its gqa-8 attention at gqa 4 - data/recipes: gemma4-31b with DFlash, the w4a8 trunk with a block-fp8 drafter, and Q8 - tests: the 31B with its DFlash drafter declares the chains where libr4d's fused ops are not declared - tests: the 31B's steps with its DFlash drafter lint clean, on both grids, at one, two and four ranks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
239da14d17 |
libr4d, arch/gemma4_bf16: the four-rank all-reduce by message size, and the 31B's junction fold to 16 rows
The four-rank exact all-reduce picks its transport and block count by message size, for every tp-4 model; the four-rank fused junction gains its tail form (the two-shot with the junction after it), which the 31B takes up to 16 rows. Carries rmsnorm_quant_i8's register form until that PR merges. Squashed from: - libr4d: the four-rank all-reduce's fold a word at a time, 16-row standalone all-reduces on the two-shot, counters in L2 - libr4d: the standalone four-rank all-reduce takes the exact two-shot from 32768 elements - libr4d: the four-rank exact all-reduce's two-shot takes 2 blocks at a DFlash2 verify, not 4 - libr4d: the all-reduce rows' nblocks axis offers 2 and 4 - libr4d: rmsnorm_quant_i8 at decode heights loads the row's operands before its reductions - libr4d: the four-rank fused junction's tail form -- the two-shot with the junction after it - arch/gemma4_bf16: the four-rank fold up to 16 rows, on libr4d's tail form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
61266c812b |
libr4d: a full fence on four-rank prefill-sized all-reduces, for a rare fresh-start divergence
On a freshly started 31B server at four ranks (4x R9700), the first greedy reply now and then flipped a near-tie: 1 of 8 fresh starts after scribbling the cards' memory. Per-op output hashes located the divergence at a prefill all-reduce that read a peer's scratch before that peer's words had landed: the first reuse of a double-buffered slot, inputs identical on every rank. A full system fence on every thread before the flag (drain 1), or after it (acq 1), cured it on the cards (26 of 26 fresh starts). The per-wave store wait, the publisher's single writeback and Relaxed Ordering off on every link did not. The mechanism below the fence is not known. r4d_cfg_ar now takes drain 1 for a four-rank message of RADIANCE_AR_FENCE_FROM elements or more (default 131072: 24 rows of the 31B's 5376, above any verify height and below every prefill chunk). Decode and verify all-reduces keep the per-wave store wait and pay nothing; 0 turns the fence off. Two-rank all-reduces never take it: Qwen3.8-27B's prefill at tp 2 paid 4.5% for it, and no two-rank fresh start ever flipped. GUIDE.md lists the switch. Bytes are unchanged either way; only when the flag goes out moves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3ef9ce33ae |
core/sample: issue sample_temp only where some row is scaled
The decode timeline shows sample_temp at ~10 us a step on the 31B at tp 4: a launch over every row's whole vocabulary shard (up to 256 workgroups a row) whose rows all return at once, since a greedy request under a split vocabulary has temperature 0 and a plain sampled one 1, and the kernel leaves both as they are. Sampler::run now issues it only when a chain row has another temperature; every other row's logits are untouched either way, so the tokens are the same. The request check's note on greedy chain rows now says when run() issues the stage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
104c81f005 |
libr4d, core: two first-launch races that could change a fresh server's first reply
Counter blocks: the per-(stream, output) counter blocks of the fp8a8 split-K finisher (split_ctr), the gated delta-net conv (ru_conv_ctr), the mxfp4a8 decode GEMM and the hc mix are zeroed with hipMemset, which queues on HIP's null stream and returns before it lands. The engine launches on queues of its own that need not wait for that stream, so the first launch on a new block could run beside its own zeroing: a split-K finisher counting arrivals while the memset reset the count gives that one launch a wrong output. r4d_moe.hip's router counters and the all-reduce's IPC allocations already wait; these four now do too (hipDeviceSynchronize, once per block). Seen as a greedy reply that differed on the first request of a freshly started 31B DFlash2 server (2 of 13 fresh starts on 4x R9700, 2026-10-17; every later request matched): the drafter's fp8a8 GEMMs take split_ctr blocks on their first launch, and a draft that differs moves the verify blocks, whose rounding the target's greedy choice can feel at a near-tie. No value changes otherwise. Weight transfers: resolve_weight puts the mover's `ready` wait on the issuing lane's stream, but remembered the generation it waited on per weight for the whole context. A weight resolved first on lane 1 then had its wait on lane 1 only, and the lane-0 GEMM resolving it next skipped its own and could read the slot before the copy landed. The Gemma 4 26B-A4B's dense arm is such a weight: a decode step issues it on lane 1, beside the routed arm, and an overlapped prefill on lane 0. waited_gen_ is now per lane, one record for each of the context's two lanes (set_lane admits 0 and 1 only), indexed by lane_ like the other per-lane state: at worst one more stream wait. Inert where no transfer is in flight (static weights, the 31B on four cards); it matters wherever weights stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
82aec1766c |
libr4d: the windowed attention's split merge loads a group ahead, and its WMMA prefill does less work a key tile
The merge: the 31B's global layers merge their split-KV partials in merge_body (r4d_attn_paged_window.hip), one wave a row, four splits at a time into one accumulator chain: ~9.4 us a layer on 4x R9700 in the decode timeline. Each group's loads went out only after the previous group's FMAs, so a row paid one L2 round trip a group. Group g + 1's loads now go out before group g's FMAs (two register groups in turn; 175 VGPRs at head_dim 512, no spill). The FMAs and their order are unchanged, so the bytes are too. The prefill kernel: attn_wmma_kernel (the 31B's global layers at prefill, ~1.1-1.5 ms a 1024-row slice on 4x R9700) does three things a tile that change no byte: - fp8 V widens to its f16 pairs with v_cvt_pkrtz: every e4m3 value is exact in f16, so the pack's rounding and f16_bits' clamp (unreachable under 448) leave the same bits, for 2 instructions a pair instead of ~10. - A tile wholly inside [lo, hi) and, causal, at or before the block's first position is visible to every valid row, so it takes its scores without the per-key masks. - With an fp8 cache, a wave whose rows all kept their running max (corr exactly 1) skips the rescale of O^T: x * 1 = x. One-card microbenchmark of the three with the skip on both caches (the kernel against the shipped one, random operands, a 1024-row slice at the end of the context): head_dim 512 gqa 8 fp8 cache 1481 -> 1295 us at context 4096, 657 -> 531 at 2048, 2220 -> 1785 at 6144; head_dim 256 gqa 2 fp8 675 -> 544, bf16 589 -> 511. Every output byte-identical to the shipped kernel's at all four instantiations (512/8 and 256/2, fp8 and bf16). The skip measured ~4% at head_dim 512 with an fp8 cache, but with bf16 its split loop ran ~10% slower than the fused one (1634 against 1427 us at context 4096; v_cvt and the interior path alone: 1318), so bf16 keeps the fused loop. fp8x16_f16, left with no caller, is removed. The pack is f16x2_exact: v_cvt_pkrtz on gfx12, f16_bits elsewhere (the host SIMT emulator, tests/r4d_emu, compiles this unit as C++), the same bits since neither rounds a value exact in f16; r4d_emu_attn passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
dffec0b770 |
libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms
On gfx1201 a launch whose wavefronts fall in the last 32 before a multiple of 2048 (every wave slot of the R9700's 64 CUs x 2 SIMDs x 16) runs about five times slower than the same work one workgroup wider, whatever the kernel does. A launch-count sweep on one card (2026-10-17): 256-thread workgroups take 27.6 us at 253 to 256 of them and 5.2 us at 252 or 257, for a norm, an LDS-only kernel and a plain copy alike; 128- and 512-thread workgroups hit it at the same wavefront counts. An empty kernel does not, and moving the data does not move it. The 31B lands on it: qkv_norm_rope at a tp-4 verify is 16 rows x 16 heads of 8 wavefronts, exactly a full card (21 us a call against ~6 expected; kbench's one-card 4-row point, 256 workgroups, 17.4 us against 5.3 at 8 rows), and a drafter's 256-row head norm through rmsnorm likewise (21.9 us). r4d_cliff_rows(rows, per_row, waves) is the row count to launch: `rows` when clear of the window, else the first count past it. qkv_norm_rope, rmsnorm and rmsnorm_p launch that many and return at once in a row at or past the real count, so every result is the same bytes. r4d_selftest's qkv_norm_rope case gains 8 rows of the head-256 class (32 heads a row: 256 workgroups, padded). The window's two numbers are the R9700's, named as such in r4d_common.h, and apply on every target libr4d builds for (RDNA4 only). They are not derived from the device: no other card has been measured, and HIP's multiProcessorCount counts WGPs, not CUs, on RDNA. On an RDNA4 part with fewer CUs a launch padded here costs one idle row and gives the same bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
13a917910f |
libr4d: rmsnorm_quant_i8 at decode heights loads the row's operands before its reductions
The kernel re-read its row from memory in each of three passes, each behind a barrier, so a row cost three dependent round trips: 11 us a launch at any height on gfx1201 against a 4.2 us launch floor. Every pass partitions the row the same way, so at 1024 threads (M <= 32, n <= 8192) each thread now loads its own columns of the branch row, the residual and both gains in one go and keeps them in registers; only the fragment-order store crosses threads, through LDS as before. Same sums in the same order and the same per-element arithmetic, so the same bytes. 8.2 us a launch in a four-card microbenchmark at 1, 4, 8 and 16 rows of 5376. The row gains a reg axis (1 the new form and the default, 0 the old), and the selftest checks both forms against the unfused chain at M=8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3251975384 |
arch/gemma4_bf16: the embedding scale as the reference rounds it, 73.5 and not 73.32
Gemma4TextScaledWordEmbedding multiplies the looked-up rows by `embed_scale.to(weight.dtype)`, which is sqrt(5376) rounded to bf16: 73.5. gemma4_bf16 multiplied the trunk's embedding by the unrounded 73.32, and the assistant head's entry, which reads the trunk's embedding module, did the same. The first layer's norm hides a 0.25% scale, but the residual stream every later layer adds to does not. arch/gemma4 has taken the bf16 value since it was written (53.0 at 2816). Both now take embed_scale(n_embd), the bf16-rounded value. arch_test's two checks of the scale expect 73.5, and its three pinned gemma4_bf16 graphs move with the `mult` they record; no other model's pin moves. On 4x R9700 at tp 4 the replies move against main's, as a 0.25% scale on the residual stream would (7 of 7 long prompts, drafter off). A drafter trained on the reference's hidden states tracks the corrected stream better: z-lab's DFlash drafter (the next change) accepts 2.88 tokens a step over seven 2-6K-token prompts against 2.71 with the scale unrounded, and 5.21 against 4.91 on a code prompt (270 against 259 tok/s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
5f78a1d0cd |
libr4d, arch/gemma4_bf16: at four ranks the 31B's junctions carry the all-reduce in front of them
ar_rmsnorm_quant_i8_4rank is the wide family's exact four-rank one-shot with the junction (the residual add, the sandwich norm and the int8 quantiser) as its epilogue, as ar_hc_write_4rank is that one-shot with hc_write. The reduce is the standalone exact all-reduce's arithmetic element by element (fp32 from zero, ranks ascending, one rounding to bf16), so the reduced row matches it to the bit, and the junction is rmsnorm_quant_i8's over that row. It shares the standalone all-reduce's transport and instance and ends the engine's link hold itself, as docs/TP4.md asks of a new collective row. Every block takes one handshake, a system-scope release by its first thread and a system-scope acquire by every wave. Both fences are needed: on 4x R9700 behind an EPYC root complex, dropping either left the readers with stale scratch on nearly every element. `nblocks` 2 and 4 (fewer handshakes, each block owning several rows) are tune points, off by default. r4d_selftest's case of the same name holds every rank's reduced row, residual, output, codes and scales byte for byte to all_reduce followed by rmsnorm_quant_i8 on four cards, at 1, 8, 40 and 97 rows of 5376 and 64 rows of 2816. r4d_selftest is now installed in the image, so a card box can run the rows' checks without a build tree. At four ranks a 31B decode step issued 121 standalone all-reduces, 119 of them followed by a separate norm launch. The plugin now declares ar_rmsnorm_quant_i8_4rank for steps of up to 4 rows (kAr4FoldRows), where it serves every junction but the last layer's feed-forward one: a decode step issues 2 standalone reductions. Taller steps, every speculative verify among them, issue the pair (the all-reduce, then rmsnorm_quant_i8): a one-shot sends three times the message a rank, and at 16 rows the standalone all-reduce's exact two-shot beats the fold's per-row handshakes. On 4x R9700 (the w4a8 container, tp 4, two rounds): plain decode 90 / 90 / 89-90 tok/s against 86 / 87 / 86 for code / prose / story, and 85 against 82 after a 6442-token prompt, +4.7%; a DFlash verify at 16 rows measured 300 tok/s on the pair against 276 on the fold, hence the band. Both paths give the same bytes. Where no library declares the fold, every step issues the pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
c527863248 |
arch/gemma4: the dense arm on the second lane beside the routed arm, in a step that runs whole
The two feed-forward arms of a Gemma 4 MoE layer read the same normed residual and meet only at the feed-forward join; issued one after the other, the dense arm's three launches -- gate_up, act_mul, down, ~36 us under --profile-ops at a 26B-A4B decode step on 4x R9700 -- wait behind the routed arm's ~120 every layer. At a few rows its GEMMs are latency-bound, nowhere near the bandwidth the experts' GEMMs take. In a step that runs whole -- every decode and verify step, and a prefill chunk too short to cut -- the dense arm now rides the second lane: issued behind a join from lane 0 (the attention join is its producer), beside the routed arm on lane 0, and joined back before the feed-forward reduction reads both. Its rows of the join buffer and the routed arm's are disjoint. No collective rides it, so the reductions keep lane 0 here and lane 1 in a cut prefill chunk, and a step's collectives are on one lane as before. h, gate_up, ffn and ff2 are named to rad_buf_concurrent. Off with the overlap's switch, RADIANCE_GEMMA4_OVERLAP=0, which now keeps every step on one stream; a startup note says which. arch_test: a decode step issues the dense arm's three launches a layer on lane 1 and every all-reduce on lane 0, two joins a layer, and nothing on the two lanes that touches a common element unordered; a 4095-token chunk the same; the cut chunks keep lane 1 for their reductions alone. GUIDE.md's switch and ARCHITECTURES.md say so. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
7a1ae22690 |
gemma4k, arch/gemma4: norm_add_norm_route -- the attention join writes the routed arm's inputs
The 26B-A4B's router reads rmsnorm(x) * w_r * hidden^-0.5 and its experts rmsnorm(x) * w_e, quantised to E4M3 for the fp8 gate_up: an `rmsnorm` and an `rmsnorm_quant_fp8` a layer, each reading back the x norm_add_norm has just written and taking the sum of squares it has just taken. At decode that is 60 launches a step (8.3 and 7.8 us under --profile-ops on 4x R9700); at a prefill, eleven passes of each a layer per 20K-token request. norm_add_norm_route is norm_add_norm, then from the norm factor it already holds the router's row by rmsnorm's expression, ((x * s) * w_r) * mult, and the experts' codes as rmsnorm_quant_fp8 writes them: the bf16-rounded norm, a scale of amax * (1 / 448) a 128 columns (1 for an all-zero group), the value times its reciprocal clamped to +-448, one v_cvt_pk_fp8_f32. Element i is thread i % 256 at slot i / 256, so a group is four waves at one slot -- a wave's max, then the four through LDS. Its own name rather than optional operands on norm_add_norm: the codes need whole 128-column groups, which the plain join does not, and the arch falls back cleanly where it does not resolve. A device row and a host arm (one helper with norm_add_norm's), the schema, OPS.md. arch/gemma4 asks for it on every layer whose gate_up is block fp8 -- the user's fp8gu container, every layer -- and then issues neither op_rnorm nor op_enorm; it declares both still, and norm_add_norm and the chain behind it, for where it does not resolve. The routed arm's two norm gains are declared ahead of the attention join now, which names them. The overlap takes either join. A startup note counts the layers that take it. The same rounding as the chain, but for the order a sum of squares is added in, as every join here: g4k_emu holds the kernel to a chain summed in its block order bit for bit -- x, y, the router's row, every code and scale -- at the 26B-A4B's 2816 at four heights, at 128, 3072, 3200 and 6144, and with an all-zero group; against the host arm, no code more than a step off. The emulator gains v_cvt_pk_fp8_f32, through the project's saturating encoder. arch_test: with fp8 gate_up experts the route op resolves on all six layers, a decode step issues it and no rmsnorm_quant_fp8 and one rmsnorm fewer a layer; refused, norm_add_norm and both launches; a tp-4 prefill through the overlap issues it a slice and keeps every reduction ordered. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
efff69be1d |
arch/gemma4: the drafter's residual add, norm and quantiser in one rmsnorm_quant_fp8 launch
Every input of a drafter layer was three launches after its all-reduce: `add` (x += h), `rmsnorm` (x -> h) and `quant_act_fp8` (h -> hq | hs), ~8 us each under --profile-ops on 4x R9700 and a few unprofiled, twice a layer -- thirty a draft pass, every decode step. libr4d's `rmsnorm_quant_fp8` is that chain in one pass where it takes the residual operand (the fused_add_rms_norm form): the norm of the bf16-rounded sum, the codes of the bf16-rounded norm, which its row states is the chain's function. The drafter now issues it for both inputs of every layer, the attention input of layer 0 with no residual -- x as the embedding left it -- and the last layer's trailing add stays, ahead of the final norm, which no quantiser follows. Nineteen launches fewer a draft pass. Where nothing serves the op the chain is declared and issued as before. A draft is verified whatever it is, so this cannot change what is accepted. arch_test: a draft pass issues ten rmsnorm_quant_fp8 and one add, the residual operand x and the delta h past layer 0 and x alone at it; refused, the chain's ten adds and fifteen quantisers. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
34ee08ea5e |
arch/gemma4: a prefill chunk in two slices, the all-reduces on the second lane beside the compute
On gemma-4-26B-A4B at tp 4 on 4x R9700 the all-reduces were 47% of a 20K-token prefill under --profile-ops (957 of 2020 ms): a layer reduces T x E after attention and both arms' 2T x E after the feed-forward, at ~16.5 GB/s a rank on the link, against ~8 ms of compute a layer at the average chunk. Run whole, the two take turns. A chunk of two routed passes or more (4096 tokens) now runs as two slices, and every trunk all-reduce rides the runtime's second lane (rad_lane) beside the other slice's compute: slice A's attention reduction under slice B's output projection, slice B's under slice A's two arms, slice A's feed-forward reduction under slice B's arms, and slice B's under the next layer's join and projections of slice A. Attention runs whole -- it reads every row's keys. A model of the measured times puts it at up to a quarter off an unprofiled prefill; --profile-ops syncs every op and cannot show it. The same bits as the whole step: the cut is a whole number of routed passes, so the routed arm makes the passes the whole step makes, and both slices are at least one pass, above every row band the sliced kernels have (the GEMM's 16 and 64, the reduction's one-shot edge) -- core's rule four for the second lane. The slice's partials sit dense-then-routed in its own run of the join buffer, so each slice's feed-forward reduction is one message. The order: a reduction is issued on lane 1 behind a join from lane 0, its producer; lane 0 joins lane 1 back before the consumer and before the next reduction is issued, since a join orders behind everything its lane has issued. The embedding's reduction stays on lane 0, ahead of everything lane 1 is first joined behind, so the collectives keep one order on every rank. The two buffers reduced in place are named to rad_buf_concurrent. Taken where the joins are fused, the wire is exact and there is more than one rank; RADIANCE_GEMMA4_OVERLAP=0 runs every chunk whole, and the startup note says which. A decode step never takes the lane. routed() takes a run of rows and the join row its partial lands at; attention between the projections and the output projection moves into attend(), which both paths issue. arch_test records the lane of each issue and where each join sits, and a new test holds a 6-layer 26B-A4B with the DFlash taps, at tp 4: no two issues on different lanes that touch a common element go unordered (taking every operand as read and written; dropping one wait makes it count six), lane 1 carries the trunk's 4 x 6 reductions at the slices' sizes and nothing else, the slices issue the whole step's rows by op and its routed passes, a 4095-token chunk and a decode step stay on one lane. GUIDE.md has the switch, ARCHITECTURES.md the paragraph. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
743b7e1a6a |
arch/gemma4: the DFlash head reads a block-fp8 copy of the table where the container holds one
The drafter's head was `gemm_nt` over the target's bf16 table -- 352 MiB a rank at tp 4, every draft
pass, 566 us of a 26B-A4B decode step under --profile-ops on 4x R9700: the widest read on the draft
path, and the "first thing to change once the model runs" its own comment named.
A container may now hold the table a second time as `dflash.draft_head.weight`, block fp8 -- one
checkpoint tensor, two logical weights, as rad_block_dflash2.h does it -- made by the recipe line
dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16
which the three gemma4-26b-a4b -df recipes now carry. Where the copy is there, the head is
quant_act_fp8 over the gathered rows and gemm_nt_q over the copy at fp8a8: half the bytes, for 176
MiB a rank more. The copy is row-sharded exactly as the table, so a rank's rows are the same
vocabulary slice and row_topk's vocab_off, the all_gather and pair_argmax are unchanged. Drafts are
verified, so the coarser logits change what is proposed and never what is accepted --
draft_n_accepted says whether they propose worse; there is no rerank against the bf16 table yet.
Where the copy is not there -- every container converted before this, or one whose recipe made it
something other than block fp8 -- the head reads the bf16 table exactly as before. The decision is
the stored encoding's (weight_enc on the copy's name), and the copy's name map entry alone writes
nothing: rad-convert walks the declared weights. The startup note names the head in use. The
block-fp8 test moves to one helper, which the routed experts' encoding check now uses too.
arch_test: with the copy's encoding block fp8, the copy is declared and the head is gemm_nt_q over
it from the quantised rows; without, nothing is declared and the head is gemm_nt over the table;
a draft pass issues the head once either way. ARCHITECTURES.md says so.
Not yet run on the cards; it needs a container converted with the new recipe line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
73c3dc38be |
gemma4k, arch/gemma4: attn_paged_qrow -- q in the fused row only where gemma4k reads it
8772d5b handed the sliding layers' attn_paged q as a column slice of the fused [q|k|v] row. gemma4k reads that; libr4d's paged attention reads q only dense and refuses the slice with RAD_E_STRIDE, which stops the engine at the first step. Under attn_paged the first library in --kernels wins, so the slice was only safe with gemma4k ahead of libr4d -- and the deploy script's default order (libr4d,gemma4k,libavx) took the server down at layer 0's attention on both profile runs. gemma4k now declares the same kernels a second time under attn_paged_qrow: attn_paged's schema field for field, with q read at its own row pitch. Only gemma4k declares it, so it resolves there or nowhere. The sliding layers ask for it once; where it resolves they read q in place (no lift), and where it does not -- a hierarchy without gemma4k, or RADIANCE_GEMMA4_FUSE=0 -- q is lifted into a dense block by a `cast` again and attn_paged reads that, which every attention library takes. The lift's buffer is declared only then, since an unnamed buffer is live for the whole program. A miss is the swa group's first op carrying a block_size, and answers rad_kv_block_size with the RAD_KV_BLOCK it declares, as attn_paged would. No libref row, as the joins. The kernel order still matters for speed -- gemma4k first is the order this model was measured with (ARCHITECTURES.md) -- but no longer for whether the server runs. A startup note says which form was taken. arch_test: the slice reaches attn_paged_qrow and never attn_paged; refused, every sliding layer lifts q for attn_paged; a decode step issues either form; and the three older gemma4 tests count the sliding layers' attention under its new name. docs: OPS.md's row and paragraph (and a line of the joins' text reflowed to the width, as one of gemma4.cpp's), ARCHITECTURES.md's kernel paragraph, which now names expert_scale too, and GUIDE's FUSE row. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
e173365823 |
gemma4k: the sandwich joins issue every load first
A barrier is a fence, so a load written after a reduction waits for it. norm_add_norm fetched the residual and both gains phase by phase, join_add_scale the residual, three or four gains and the layer scalar, so each paid a global round trip per phase on top of its reductions: --profile-ops on 4x R9700 has them at 13.2 and 17.8 us a call at decode, 30 of each a step, where a launch that does nothing costs ~7. Now every operand of the row is in flight at once before the first reduction, the two arm norms share one barrier pair (block_sum2: each value takes block_sum's butterfly and wave order), and a thread holds 12 elements where the row fits -- n <= 3072, Gemma 4 26B's 2816 among them -- and kMaxPer's 24 past that, instead of 24 always. The arithmetic is the same expressions in the same order; a sum's terms past n were +0 and are gone. g4k_emu: both joins at the edge between the two widths (3072, 3073), with and without the next norm, bit for bit against the chain as every other case. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
76dd0019ac |
libr4d: logit_softcap spreads a row over blocks
One 256-thread block a row: at Gemma 4's tp 4 a row is a 65536-wide vocabulary shard and a step has a decode's few rows, so a handful of blocks walked 256 elements a thread of tanhf each. --profile-ops on 4x R9700: 82.7 us a decode step and 85.6 us for the prefill's single row, for 256 KiB of f32 a row -- four times the drafter's row_topk over a row as wide (18.6 us). Both legs now put a row on up to 64 blocks, eight elements a thread (32 blocks at 65536). Elementwise, so no bit moves; libr4d's selftest and rad-kbench's libref comparison hold it as before. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
a378b41abb |
libr4d: the exact two-shot all-reduce takes every prefill-sized message
R4D_AR_TWOSHOT_WIDE_MAX_ELEMS was 20971520 -- a 4096-token chunk of a 5120-wide residual -- and the band above it went back to the one-shot, which sends (ws-1)*N bytes a rank where the two-shot sends 2*(ws-1)/ws*N. At the default --max-num-batched-tokens 8192, Gemma 4 26B-A4B's attention reduce is 8192 x 2816 = 23M elements and its feed-forward reduce, which carries both branches for their own post-norms, 46M: both over the bound, so every full prefill chunk went one-shot at twice the bytes. --profile-ops on 4x R9700, tp 4, a 20489-token prefill (chunks of 8192, 8192, 4105) fits one link rate across all of it: the attention reduces 16.8 ms the three calls (two one-shot, one two-shot) and the feed-forward reduces ~37 ms (all one-shot), 1.6 s of the 2.7 s prefill. The same rate with every call two-shot is ~9 and ~19 ms: about 0.8 s less a 20k prefill. The bound guards the kernel's int word offsets and nothing else -- the scratch already holds a full message per slot (r4d_ar_entry.hip build()), twice what the two-shot uses -- so it is now 2^28 elements, 2^26 words at fp32. The fold is the one-shot's, fp32 in ascending rank order, so the band edge moves no bits. Fewer bands also means one scratch set less: the old 20971520 band was its own instance, ~335 MiB a rank at tp 4. plugin_test: a 16384-token chunk is two-shot to its end, and the one-shot still takes a message past the bound. r4d_selftest's three-rank pattern walks a 46137344-element message, past the old ceiling. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
0d95046f6f |
gemma4k, arch/gemma4: expert_scale -- per_expert_scale on the routing weights in one launch
Gemma 4 multiplies each renormalised routing weight by per_expert_scale of the expert it chose. In the conventional vocabulary that is an `embed_lookup` of the [n_expert, 1] table by the ids and a `mul` into the weights -- two launches a MoE layer, a few dozen elements each at decode (--profile-ops: ~0.26 and ~0.22 ms a step across the 30 layers). gemma4k's `expert_scale` is the pair as one kernel, ew = bf16(ew * w_e[id]), with an id outside the table reading 0 as embed_lookup's missed row does: one product rounded once, so the pair's value bit for bit. Like the joins it has no libref row on purpose, so arch/gemma4 falls back to the pair wherever gemma4k is not loaded, and RADIANCE_GEMMA4_FUSE=0 turns it off with them. 30 launches a step the fewer. g4k_emu: device and host rows against the pair over 32 shapes -- top-k 1 and 8, pitched rows, pads and one-past-the-end ids, rows past M untouched -- every element equal. arch_test: a decode step scales in one launch, and in two with it refused. docs/OPS.md: the row and its paragraph; GUIDE: what the switch now covers. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
29f981fd6c |
arch/gemma4: route a decode step in one launch -- libr4d's fused router, top-k and sort
At decode heights the router GEMM (128 x 2816), its top-k and the expert sort are each one small workgroup's work behind a full dispatch: --profile-ops put the three at ~0.27, 0.29 and 0.24 ms a step across the 30 MoE layers. libr4d already fuses them for the Qwen MoE blocks -- `router_topk_scatter` for the pair, `router_gemm_topk_scatter` with the GEMM in front -- and documents both as byte-identical to the launches they replace, so the routing does not move. arch/gemma4 now asks for them as rad_block_moe_fp8.h does: the pair up to the sort's single-workgroup bound (1024 routing slots, 128 rows at top-8), the GEMM form up to the skinny GEMM's decode band (64 rows), and the separate ops for a pass past either, declared regardless. The per-expert scale and the experts' input norm sit between them in the issue order and read only the ids and weights the fused op writes. Two launches a MoE layer the fewer at decode, 60 a step. arch_test: a decode step routes with the fused op; refused, with the pair; both refused, with the three separate ops -- and the per-expert scale and the gather run in every case. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
171dcee15b |
gemma4k, arch/gemma4: the feed-forward join writes the next layer's input norm
join_add_scale takes an optional gain `w_n` and output `y` (both or neither) and, given them, writes y = rmsnorm(x) * w_n over the residual it has just stored -- the next layer's input_layernorm, or the final norm after the last layer. Those norms read the x the join writes and nothing else, so each was a launch of its own and a second read of the row; now it is a fourth reduction in a block that already holds x in registers. On the 26B-A4B that is 30 launches a forward pass the fewer (29 input norms and the final norm), at decode a step's worth of ~8 us launches. Rounding where the chain rounds: y is taken over the bf16 x the join stores, with libr4d's expression, so g4k_emu holds it to the chain bit for bit (+next cases, decode to prefill heights, odd widths and pitches) and to the host arm within a flipped rounding. arch/gemma4 declares every layer's input-norm gain ahead of the layers so a join can name the next one's; where a join resolves, the norm it replaces is neither declared nor issued, and where it does not, the chain is as before. docs/OPS.md: the row and its paragraph. arch_test: fused, the only x -> h rmsnorm is layer 0's and every join writes h; refused, all thirteen come back. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3a48ee78de |
arch/gemma4: the sliding layers' attention reads q in the fused qkv row
The q lift -- a `cast` copying q out of the fused [q|k|v] projection into a dense block -- was there because libr4d's paged attention reads q only dense. gemma4k's takes q at any row pitch (its head_view, and g4k_emu's q-pitch-slice cases), and gemma4k serves all of Gemma 4's attention, so the slice goes straight in: one launch and a [T, q] copy less on each of the 25 sliding layers, every step. With libr4d ahead of gemma4k its attention refuses the slice by name (RAD_E_STRIDE) rather than reading it wrong. arch_test: no copy between projection and attention, and the attention reads `qkv_s`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
9967158d4a |
docs: gemma4 -- the architecture, its kernels, converting it, its two switches
ARCHITECTURES.md: a `gemma4` section in the file's form -- the 26B-A4B's geometry, the readings
that stay plausible when wrong (proportional rope is not a partial rotary, K is V, the router reads
the residual, per-arm post-norms, the bf16 embedding scale, the FULL sliding group, the drafter's
causality), tensor parallel, fp8 experts, which kernel library serves what, and what is not
declared. Its table gains the arch/gemma4 row, and the gemma4_bf16 row is corrected: that plugin
claims ("gemma4", "compressed-tensors"), not ("gemma4_bf16", "i4").
GUIDE.md: converting gemma-4-26B-A4B-it with its drafter, and RADIANCE_G4K_WMMA /
RADIANCE_GEMMA4_FUSE in the tooling table. IMPLEMENTATION.md: gemma4k/ in the layout.
KERNELS.md is rad-kbench's and is not edited here; it wants regenerating on a card with gemma4k
loaded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
753e9c598b |
data/recipes: gemma4-26b-a4b with DFlash -- fp8 gate_up, 768-padded fp8 experts, bf16 experts
The three containers arch/gemma4 has been served from, each with the usage header the in-tree recipes carry: - gemma4-26b-a4b-df: the routed experts' gate_up block fp8, their down bf16 (K = 704 is not whole 128-blocks), the drafter's linears block fp8. The measured container. - gemma4-26b-a4b-df-pad768: both expert projections fp8, from a checkpoint whose experts were padded 704 -> 768 before conversion (zero rows of gate and up, zero columns of down: exact). The padding is described rather than shipped: the tool that did it is Python and stays out of the tree. - gemma4-26b-a4b-df-bf16x: only the drafter quantised -- the bf16 reference for the KL mode. The rules are the ones the containers were converted with; only the headers are new. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
c2bd41fe95 |
arch/gemma4: Gemma 4 text with z-lab's DFlash drafter -- the 26B-A4B MoE and the dense sizes
Claims ("gemma4", ""): a container converted from Google's bf16 checkpoint, the recipe choosing
what is fp8. gemma4_bf16 keeps ("gemma4", "compressed-tensors"), the CT-INT4 dense release; the
two do not overlap. Serves gemma-4-26B-A4B-it (128 experts of 704, top 8) and the dense sizes
without per-layer embeddings, with a DFlash block-diffusion drafter merged at convert time.
The readings that stay plausible when wrong, each explained at its site:
- Proportional rope is not a partial rotary: the full layers rotate the first 64 frequency pairs
of the 512-wide head at theta^(-2j/512), pair j = channels (j, j + 256), declared as full-width
NeoX with the frequencies past pair 63 divided by 1e30 through the YaRN ramp `rope` carries.
- K is V on the full layers: V is the un-normed, un-rotated k projection, so its norm is issued
before the key norm overwrites `k`.
- The router reads the residual through a gainless rmsnorm times its `scale` times hidden^-0.5,
and per_expert_scale multiplies after the renormalised top-k.
- Two post-norms a layer's feed-forward, one an arm, each arm's partial reduced before its norm;
both partials share one [2T, n_embd] buffer so one all-reduce carries them.
- The embedding scale is sqrt(hidden) rounded to bf16 (53.0, not 53.066).
- The sliding layers' KV group is RAD_KV_FULL with the window on the attention op: a WINDOW
group is not prefix-cached, and on this tree a hit on one re-prefills; FULL keeps the hit.
- fp8 experts are two tables by parity, so a rank holds an even count; down at K = 704 cannot be
fp8 (whole 128-blocks), hence the 768-padded recipe.
- The sharded draft head's merge is pair_argmax at R = 2 on the wire.
- The drafter's tap copy is declared at the end of the layer it taps, where it is issued. The
buffer planner takes liveness from declaration order; declared once after the trunk, it let the
plan share `dflash_src` with `moe_edn`, which every MoE layer writes, whenever the sizes
allowed. At --max-num-seqs 16 they did, and on the cards DFlash accepted 2% of its drafts
(97 tok/s against 135 with speculation off and 186 with the taps intact), the text fluent
throughout.
The sandwich joins are asked for as norm_add_norm / join_add_scale (gemma4k) and declared as the
rmsnorm / add chain where nothing serves them; RADIANCE_GEMMA4_FUSE=0 asks for the chain. The
reply format is the shared one (arch/rad_gemma4_chat.h), so tool calls are parsed in the engine;
the plugin as measured declared reasoning only and left calls to an out-of-tree sidecar, so the
call path is untested on this plugin's containers.
arch_test: the MoE trunk declares both arms and six of each join; both KV groups FULL with the
window on the op; the full layers' rope over the whole head with the ramp at 63.5..64; with the
joins refused, the chain is declared and issued instead; both Gemma 4 plugins export one format;
with a DFlash drafter, `dflash_src` is live from the first tap layer (its range overlaps
`moe_edn`'s, so no plan can share them) and a step writes each tap once.
Measured on 4x R9700 at TP4 (gemma-4-26B-A4B-it + DFlash, gate_up experts block fp8), with
gemma4k and --draft-window adaptive: a story at T 1 177 tok/s, greedy thinking 572 tok/s, code at
T 0 319-334 tok/s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
368d0363eb |
arch: Gemma 4's reply format into arch/common, for both Gemma 4 plugins
Two plugins are about to serve Gemma 4 -- gemma4_bf16 the CT-INT4 dense release and arch/gemma4 the bf16 / fp8-expert containers -- and the reply format is the model's, not the weights': the thought channel, and calls written as a name and one object in Gemma's dialect of JSON. One declaration in the shared header library (installed as <arch/rad_gemma4_chat.h>), so the two cannot drift apart and the reply-format tests read what both export. The declaration moves unchanged, from gemma4_bf16::chat_format_decl() to rad::arch::gemma4_chat_format(); chatparse_gemma4_test follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
846e52148a |
tests: g4k_emu -- gemma4k's kernel source on the host, every GPU thread a fiber
gemma4k builds for gfx12 only and its two joins have no libref oracle, so nothing on a machine without the card, and nothing in rad-kbench, would ever run its kernels. g4k_emu compiles the .hip sources as host C++ against a HIP shim: every GPU thread a fiber, __syncthreads and every cross-lane op a barrier (one not reached uniformly is reported as a deadlock), the WMMA operand layouts gfx12's. Checked against a port of libref's ref_attn_paged (attention, fixed cases and a random sweep over every compiled geometry), against the host rows (pair_argmax), and against the unfused chain bit for bit (the joins). Registered in CTest under the label g4k_emu, on x86-64 with a clang: the kernels use ext_vector_type and the fiber switch is SysV inline assembly. Under a clang C++ compiler they are ordinary targets. The docker image compiles host C++ with g++, so there g4k_emu/run.sh builds the same tests with the HIP compiler, ROCm's own clang++, and runs them as one test -- so wherever gemma4k is built, this runs, the image's host-test stage included. About 40 s at the default 40-case sweep (50 s through run.sh, which compiles too); `g4k_emu_attn sweep 200` is the long run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
833173cc04 |
gemma4k: Gemma 4's kernels beyond libr4d -- paged attention, pair_argmax, the sandwich joins
A kernel library beside libr4d, gfx12 only, and AHEAD of it for Gemma 4: `--kernels gemma4k,libr4d,...`. Its own library rather than rows in libr4d: a smaller change, its own gfx12 gating, and no churn in libr4d's row table; folding it in can follow. - attn_paged at head_dim 256 and 512, gqa 1/2/4/8, bf16 or fp8 cache, any window, causal or not. One scalar kernel serves decode, verify and prefill, with a split-KV path whose merge is one wave a row (live pieces found by ballot, four at a time; a piece that saw no key writes only its max and sum); a WMMA prefill kernel takes a query of at least 64 rows and 32 a sequence on average -- Q and K bf16, P and V f16 (bf16 P measured 0.25% of the V range in error), the denominator summed from the rounded P. RADIANCE_G4K_WMMA=0 keeps every launch on the scalar kernel. - pair_argmax, device and host, described as libref describes it so rad-kbench checks both. - norm_add_norm and join_add_scale, ops of its own (docs/OPS.md, a new subsection): each one kernel for a post-norm / residual add / pre-norm chain, rounding where the chain rounds. libref has no row for them on purpose -- a reference row would resolve them where gemma4k is not loaded and the architecture would never fall back to the chain -- and no row declares `replaces`, since rad-kbench assembles a replaced chain from the fusing library's own rows. WHY FIRST. libr4d on this tree also has rows at h256/gqa2 and h512/gqa8, Gemma 4's own geometries, written for the dense 31B (which has no drafter) and not measured on the 26B-A4B or under a DFlash verify; the hierarchy is absolute, so the first library takes them. These rows are the ones every Gemma 4 number below was measured with. No other row overlaps libr4d's (the h256 gqa4/gqa8 rows take a window only), so putting this library first takes nothing else from it. The softcap is libr4d's and libavx's `logit_softcap`. Measured on 4x R9700, gemma-4-26B-A4B-it + z-lab DFlash, TP4: decode attention 3.234 -> 0.104 ms a step on the full layers and 1.906 -> 0.722 on the sliding ones (the split-KV merge); a 20,489-token prefill 4.01 -> 2.83 s (the WMMA kernel); rad-kbench against libref 176/176. Not yet run on the cards: the joins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
d0f6f332ff |
ops: pair_argmax in libref and libavx -- the sharded draft head's top-1, one id a row
A vocab-sharded draft head proposes each position's argmax: every rank takes its slice's top-R as (id, value) pairs, an all_gather puts them side by side, and something picks the winner. row_topk_merge does that with an R-wide answer; a block drafter wants ONE id a row, written contiguously into the token buffer it verifies, and a rank cannot send R = 1 -- a row-interleaved all_gather moves whole 16-byte words and a pair is 8 bytes. pair_argmax is the merge at R = 1 over world_size * R pairs: largest value, ties to the lower id, a negative id a pad, -1 and -inf for a row with nothing valid, `val` optional. The Gemma 4 DFlash head is its caller (arch/gemma4, later in this series) and gemma4k its device kernel. libref is the oracle and the schema's first declarer; libavx carries the host row, because an op the placement puts on the host cannot run on a reference (avx_check holds libavx to libref's vocabulary). Both scalar: n is sixteen pairs at TP8. docs/OPS.md: the row and a paragraph beside row_topk_merge's. ref_test: ties to the lower id in any slot, a pad carrying the row's largest value dropped, an all-pad row, all-negative values, `idx` at a pitch of two with the slots between untouched, and `val` absent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
29bfe8f00c |
sched: --draft-window adaptive applies to block drafters
The adaptive window priced only a serial head's rounds and was refused for a block drafter, on the grounds that the block is proposed in one pass. But every verified draft is still a verify row, and on a MoE whose verify reads the experts each row routes to, rows are not free (16 rows read ~10x the experts one does). A block drafter now takes the same policy with its rounds fixed: each sequence verifies the first min(D, its stop) of the block, its stop from its own measured acceptance and D from the measured step times. Prompt lookup alone keeps the fixed window and says so. Speculation stays lossless: what is verified is a prefix of the proposal. Measured on gemma-4-26B-A4B-it + z-lab DFlash (block 15), 4x R9700, TP4, together with gemma4k's split-KV merge rewrite (landed in the same build, so the two are not separated): story at T=1 95 -> 177 tok/s, greedy thinking ~360 -> 572 tok/s; code at T=0 319-334 tok/s (it verifies deep either way). tests/sched_test.cpp: the block-drafter case now expects the policy on (4 drafts verified while the estimate is the prior, 1 after 64 rejected steps, draft_verify_depth[4] and [1] both counted); the prompt-lookup-only and no-speculation cases are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
fb716830c2 |
oai: preserved_tokens on /v1/completions; find a text-tailed reasoning opener by its token
/v1/completions accepts llama-server's preserved_tokens: control tokens the completion's text keeps rather than drops. A client that renders its own template and parses its own reply (a tool-call sidecar) has no other way to see a reply format built of control tokens. Bounded like the stop strings. A thinking budget needs the reasoning block found by token. Gemma 4's opener <|channel>thought is one control token followed by text; it is now found by that first token (what a reply opening its own block writes first, and no text can spell), with the text after it counted as reasoning. An opener with a second control token in it is still refused, since its first token may open something other than the reasoning. The refusal message says why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
2381591823 |
tokenizer: end a Gemma 4 generation on <turn|> and <|tool_response>
Gemma 4 declares <eos> as its eos but ends a turn on <turn|>, and a tool-calling turn on <|tool_response> (the opener of the result the caller supplies, written after the model's last <tool_call|>). Neither was in kEogNames, so every Gemma 4 reply ran to max_tokens. llama.cpp's loader lists both for this vocabulary. A vocabulary that has <|tool_response> as a control token also has </s> as ordinary text (llama.cpp concludes the same); ending on it would cut a reply that writes the HTML tag, so </s> is not an end-of-generation token there. This branch already ends a generation on every id generation_config.json names (c65fabe), which covers both tokens for a container that carries `generation.eos_token_id`. The spellings here cover one that does not, and the </s> rule is new either way: the eos list never names </s> for Gemma 4, but kEogNames did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
c37f47cc78 |
libref, libavx: logit_softcap calls std::tanh on a float, not std::tanhf
std::tanhf is in <cmath> only from libstdc++ 14; against 13 (Ubuntu 24.04's) the host build stops at libref and all four libavx levels. std::tanh's float overload is tanhf, so the arithmetic is the same to the bit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |