This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/libr4d/r4d_attn_paged_h256_gqa6_bs4.hip
T
picoder 7cf4c005e1 TP4 for Qwen3.8-Flash-Next: unfused chain, four refusals answered
World 4 refused at declare on two counts and at boot on a third the audit
found; the fourth is unchanged by design.

- rad_arch.h: a world above the KV head count replicates the heads in rank
  pairs instead of dividing them. Geom gains kv_off; each rank declares
  n_head_kv 1 and gqa 6. A world that is not a multiple of the head count
  is still refused, by name.
- rad_block_attn_gated_fp8.h: k/v pass the row span LinearFP8 already
  takes, gated on world > n_head_kv_all so an even shard is untouched and
  TP2 declares byte-identically.
- qwen4exp_fp8.cpp: above two ranks the ranks own whole experts (5 blocks
  of 128 do not cut four ways); the parity tables stay two-rank and the
  router stays replicated.
- libr4d: attn_{prefill,decode}_h256_gqa6_bs4 rows and their TU -- the
  gqa8 body at ratio 6, page 4. No fused form is instantiated at this
  geometry; the unfused pair is what resolves.
- libr4d: r4d_ar_gather_Nrank.hip. The vocab-parallel sampler declares an
  all_gather at any world > 1 and libr4d shipped only the 2-rank row, so a
  TP4 boot was refused by the reference-kernel gate rather than served
  wrong. The wide one-shot all-reduce with the reduction removed.
- rad_block_attn_gated.h / rad_block_attn_fp8.h: refuse a world above the
  KV head count. They read n_head_kv and declare no span, so they would
  have booted and read half a KV head -- fluent wrong text.
- tests/arch_test.cpp: the four-rank declare test, and the fake records
  the shard span the real builder stores.
- README, ARCHITECTURES: TP4 in the present tense, with the costs named
  and the rate against TP2 left unmeasured.
2026-10-04 21:47:44 +02:00

44 lines
2.9 KiB
Plaintext

// R4D attention at SIX queries per KV head, head_dim 256 -- the same QSA layers of
// Qwen3.8-Flash-Next that r4d_attn_paged_h256_gqa12.hip serves at two ranks, served at FOUR: the
// two KV heads are replicated across the rank pairs, so each rank answers 6 queries for the one KV
// head it holds and the ratio the constraint table gates on is 6 rather than 12.
//
// Four lines of geometry and the dispatch itself, because r4d_attn_paged_gqa8.hip's kernels are
// templates on `gqa` and that unit is the parameterised body. What the ratio changes is
// exactly two bounds, and both are in the ROW table rather than here:
//
// the decode verify width 64 / gqa = 10, against 5 at gqa 12 and 8 at gqa 8. A workgroup holds
// 64 (query, head) rows and carries q_len * gqa of them, so this is
// the WIDEST of the three legs: MTP's K=3 verify is q_len 4 and fits
// either ratio, and a draft block of six or seven positions -- which
// the gqa12 leg has to send to the prefill kernel -- fits the decode
// kernel here.
// a prefill block's width 384 / gqa = 64 query positions, against 32 at gqa 12 and 48 at
// gqa 8.
//
// NO head_dim 128 LEG, for the gqa12 file's reason: nothing in scope is gqa 6 at 128, and an
// instantiation nothing resolves is a kernel nobody has run. R4D_ATTN_H128 leaves those four entry
// points out of this translation unit entirely rather than shipping them untested.
#define R4D_ATTN_GQA 6
#define R4D_ATTN_H128 0
// THE KV PAGE IS FOUR TOKENS HERE, AND IT IS THE ONLY GEOMETRY IN THIS LIBRARY WHERE IT IS NOT 16.
//
// Qwen3.8-Flash-Next's QSA indexer selects 4-TOKEN BLOCKS of the key history. With a page of 4 a
// selected block IS a page, so the selection is a paged block table and the sparse attention is
// this kernel with a different table -- instead of a new attention kernel, which is the most
// expensive kind of kernel in this tree to get right. docs/QSA.md is the decomposition. The page
// is 4 at this ratio for exactly the reason it is 4 at gqa 12 -- the model's page, not the
// parallelism's; what TP4 changes is the queries a head, not the storage.
//
// IT COSTS NOTHING. A page size is pure storage, so the only thing it can move is the block-table
// walk -- `NB = TILE / BS` entries a tile instead of one, four instead of one at TILE 16 -- and at
// a realistic context that is inside the noise of the step, with identical output either way.
//
// THE ROWS HAVE TO AGREE. `C_EQ("block_size", 4)` on all four gqa6-bs4 rows is what makes the core
// size the pages at 4 (RadKVGroupDecl carries no block size on purpose -- it is taken off the
// resolved kernel). A row that says 16 against this define is a kernel that refuses at issue
// rather than at declare.
#define G8_BLOCK_SIZE 4
#include "r4d_attn_paged_gqa8.hip"