radiance 1.11.0

New models:
- GLM-5.3-Flash reads pictures: its vision tower and processor (--image-tokens sets the budget),
  with decode kernels for a few rows and the DSA indexer split over the ranks
- Sage-A1.5 (fp8 and MXFP4) with its vision tower and a DFlash2 drafter
- Unlimited-OCR (bf16)
- Gemma 4 31B with z-lab's DFlash and RedHatAI's DFlash2 drafters; at four cards its all-reduces
  are fused with the junctions, overlapped with the compute and sent compressed
- Ornith-1.5-35B-A3B w4a8 compose files

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

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

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

Changes: Plugin ABI 26: out-of-tree plugins must be rebuilt. The environment switches the PRs
added are fixed rules or flags now (R4D_ATTN_FP8 is --attn-prefill-fp8).
This commit is contained in:
Deadcode committed 2026-10-23 11:57:52 +02:00
210 files changed
+14363 -2138

No files matched your search

+310 -72
View File
@@ -110,6 +110,8 @@ static const RadParamSpec pAttnPaged[] = {
* Absent, the shim falls back to the tensors, which exist only at issue. */
P_INTO("n_head"),
P_INTO("max_seqs"),
/* e4m3 products a caller accepts (docs/OPS.md): 1 Q.K^T, 2 P.V, 3 both; absent is 0. */
P_INTO("prefill_fp8"),
};
static const RadOperandSpec oAttnPaged[] = {
{ "q", RAD_OPD_IN, 0 },
@@ -206,6 +208,28 @@ static const RadOperandSpec oAttnNa3d[] = { { "q", RAD_OPD_IN, 0 }, { "k", RAD_O
{ "v", RAD_OPD_IN, 0 }, { "geom", RAD_OPD_IN, 0 },
{ "out", RAD_OPD_OUT, 0 } };
/* Unlimited-OCR's SAM tower (r4d_sam_attn_bf16.hip): windowed attention with a decomposed relative
* position. The two tables are weights, [2*L-1, head_dim] with L the window or the grid. */
static const RadParamSpec pSamAttn[] = {
P_INT("M"),
P_INT("head_dim"),
P_INT("n_head"),
P_INT("grid_h"),
P_INT("grid_w"),
P_INT("window"),
P_F64("scale"),
P_STR("dtype"),
};
static const RadOperandSpec oSamAttn[] = {
{ "q", RAD_OPD_IN, 0 },
{ "k", RAD_OPD_IN, 0 },
{ "v", RAD_OPD_IN, 0 },
{ "cu_seqlens", RAD_OPD_IN, 0 },
{ "out", RAD_OPD_OUT, 0 },
{ "rel_pos_h", RAD_OPD_WEIGHT, 0 },
{ "rel_pos_w", RAD_OPD_WEIGHT, 0 },
};
/* Not docs/OPS.md's `qk_norm_rope` (qkv in place, `theta`): this kernel splits a packed [q|gate]
* projection per head, writes q, k and the gate to three destinations, and takes a precomputed
* cos/sin table. Hence its own op name. */
@@ -724,10 +748,6 @@ static const RadOperandSpec oGemmNt[] = {
{ "y", RAD_OPD_OUT, 0 },
};
/* `pb1` and `pb2` are ParoQuant's, read by the mxfp4a8 rows and the 4- and 5-bit asymmetric rows
* (w5a16, w4a16_asym, w4a8i8_asym, w5a8i8): weight rows [0, pb1), [pb1, pb2) and [pb2, N) each
* meet their own copy of the activation, side by side in a row of `a` ([M, parts * K]). 0 leaves a
* bound out. Absent on other grids, where a fused projection has one activation. */
/* `add_rmsnorm` is `add` (x += a) followed by `rmsnorm` of the x it wrote (docs/OPS.md). */
static const RadParamSpec pAddRmsNorm[] = {
{ "M", RAD_P_INT, RAD_REQUIRED },
@@ -762,6 +782,10 @@ static const RadParamSpec pPrefetch[] = {
static const RadOperandSpec oPrefetch[] = {
{ "w", RAD_OPD_WEIGHT, 0 },
};
/* `pb1` and `pb2` are ParoQuant's, read by the mxfp4a8 rows and the 4- and 5-bit asymmetric rows
* (w5a16, w4a16_asym, w4a8i8_asym, w5a8i8): weight rows [0, pb1), [pb1, pb2) and [pb2, N) each
* meet their own copy of the activation, side by side in a row of `a` ([M, parts * K]). 0 leaves a
* bound out. Absent on other grids, where a fused projection has one activation. */
static const RadParamSpec pGemmNtQ[] = {
{ "M", RAD_P_INT, RAD_REQUIRED },
{ "N", RAD_P_INT, RAD_REQUIRED },
@@ -2177,6 +2201,19 @@ static const RadOperandSpec oDry[] = {
{ "history", RAD_OPD_IN, 0 },
{ "breakers", RAD_OPD_IN, 1 },
};
/* The n-gram ban's own plane: one i32 {n-gram length, window} pair a row (n 0 = off, window <= 0
* = the whole staged history). A plane beside `params` rather than fields in it, because the
* params row is the fixed 24-word RadSampleParams every sampler op shares. */
/* `whitelist` is optional: a bitmask plane a row (a SET bit exempts that column from the ban,
* the reference's whitelist), [M, ceil(n_vocab/32)] i32/u32, contiguous. Absent, nothing is
* exempt. */
static const RadOperandSpec oNgramBan[] = {
{ "logits", RAD_OPD_INOUT, 0 },
{ "params", RAD_OPD_IN, 0 },
{ "history", RAD_OPD_IN, 0 },
{ "ngram", RAD_OPD_IN, 0 },
{ "whitelist", RAD_OPD_IN, 1 },
};
static const RadOperandSpec oTemp[] = {
{ "logits", RAD_OPD_INOUT, 0 },
{ "params", RAD_OPD_IN, 0 },
@@ -2764,7 +2801,8 @@ static const RadOpSchema kSchemas[] = {
"op, not gelu, because gated feed-forwards are trained with the tanh form and the "
"unary gelu is the exact erf one."),
SCHEMA("act_mul", pActMul, oBinary,
"y = act(a) * b, the activation (silu, gelu, gelu_tanh) rounded to y's dtype before "
"y = act(a) * b, the activation (silu, gelu, gelu_tanh, sigmoid or quick_gelu) rounded "
"to y's dtype before "
"the product: silu_mul with its two halves in two operands."),
SCHEMA("seg_mean", pSegMean, oSegMean,
"Row s of y is the mean of x's rows [cu_seqlens[s], cu_seqlens[s+1]), summed in f64 "
@@ -2911,6 +2949,13 @@ static const RadOpSchema kSchemas[] = {
"DRY: penalise, once, each token that would extend a suffix of the history that has "
"occurred before, by its longest such repeat -- what stops a model looping on a phrase "
"rather than on a token. Tokens the breaker plane marks are exempt."),
SCHEMA("sample_ngram_ban", pPenal, oNgramBan,
"the windowed no-repeat-ngram ban: every token completing an n-gram the last `window` "
"tokens of the row's history contain is set to -infinity. `ngram` is one i32 "
"{n, window} pair a row; the window bounds the n-gram's START index, as in the "
"reference, window <= 0 searches the whole span and n 0 is off. The optional "
"`whitelist` bitmask exempts a token whose column bit is set; absent, nothing is "
"exempt."),
SCHEMA("sample_temp", pMVocab, oTemp,
"per-request temperature. temp <= 0 leaves the row untouched; greedy is sample_argmax."),
SCHEMA("sample_mask", pMVocab, oMask,
@@ -2966,6 +3011,11 @@ static const RadOpSchema kSchemas[] = {
SCHEMA("attn_na3d", pAttnNa3d, oAttnNa3d,
"3-D neighborhood attention over the voxels of geom = (T, H, W): each query sees the "
"kt x kh x kw window centred on it, shifted inward at the border."),
SCHEMA("sam_attn", pSamAttn, oSamAttn,
"Unlimited-OCR's SAM tower attention: per cu segment of grid_h*grid_w rows, pad to "
"multiples of `window` with zero rows, tile into window x window windows (0 = the whole "
"segment) and attend each tile to all of its rows. logits = scale*q.k + q.Rh[i_h,j_h] + "
"q.Rw[i_w,j_w], softmax in f32, out = sum p*v, pad rows dropped."),
SCHEMA("qk_norm_rope_gate", pQkNormRopeGate, oQkNormRopeGate,
"split [q|gate] per head, QK RMS norm over the head, partial NeoX RoPE and the gate "
"copy, in one pass. Not docs/OPS.md's qk_norm_rope: different operands, and a "
@@ -3534,8 +3584,6 @@ static const RadOpSchema kSchemas[] = {
"box (copy) or each `group` packed channels averaged (mean); `add` adds into y."),
SCHEMA("pix_patch", pPixPatch, oPixPatch,
"an image [H, W C] to patch rows [H/p, (W/p) C p p], order wh or hw."),
SCHEMA("patch_pix8", pPixPatch, oPixPatch,
"patch rows [R, w C p p] to RGB bytes [R p, w p C] by to_rgba8's rule."),
SCHEMA("vol_index", pVolIndex, oVolIndex,
"a volume's voxel coordinates (t, i, j), component-major."),
SCHEMA("tile_grid", pTileGrid, oTileGrid,
@@ -3545,7 +3593,7 @@ static const RadOpSchema kSchemas[] = {
"one tile's voxels out of a volume, box (t, h, w, t0, y0, x0)."),
SCHEMA("tile_stitch", pTileStitch, oTileStitch,
"decoded tiles to RGB bytes: diffusers' in-place blend_v then blend_h, then blend_t "
"across time bands, each tile kept to its stride, patch_pix8's bytes."),
"across time bands, each tile kept to its stride, to_rgba8's bytes."),
SCHEMA("stft_logmel", pStftMel, oStftMel,
"each channel's causal log-mel spectrogram from a windowed DFT basis and a mel "
"filterbank, every stored tensor rounded to y's dtype."),
@@ -3585,6 +3633,30 @@ static const RadConstraint cAttnPrefillFp8[] = {
C_EQ("window", 0), C_EQ("head_dim", 256), C_EQ("gqa", 6), C_EQ("block_size", 16),
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "fp8_e4m3"),
};
/* The e4m3 product legs: the exact row's geometry over the same cache, and only for a caller whose
* `prefill_fp8` states that leg set. */
#define C_ATTN_PREFILL_FP8(kv) \
C_EQ("window", 0), C_EQ("head_dim", 256), C_EQ("gqa", 6), C_EQ("block_size", 16), \
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", kv)
static const RadConstraint cAttnPrefillFp8Qk8[] = { C_ATTN_PREFILL_FP8("fp8_e4m3"),
C_EQ("prefill_fp8", 1) };
static const RadConstraint cAttnPrefillFp8Pv8[] = { C_ATTN_PREFILL_FP8("fp8_e4m3"),
C_EQ("prefill_fp8", 2) };
static const RadConstraint cAttnPrefillFp8QkPv8[] = { C_ATTN_PREFILL_FP8("fp8_e4m3"),
C_EQ("prefill_fp8", 3) };
static const RadConstraint cAttnPrefillFp8v4Qk8[] = { C_ATTN_PREFILL_FP8("fp8_v4"),
C_EQ("prefill_fp8", 1) };
static const RadConstraint cAttnPrefillFp8v4Pv8[] = { C_ATTN_PREFILL_FP8("fp8_v4"),
C_EQ("prefill_fp8", 2) };
static const RadConstraint cAttnPrefillFp8v4QkPv8[] = { C_ATTN_PREFILL_FP8("fp8_v4"),
C_EQ("prefill_fp8", 3) };
static const RadConstraint cAttnPrefillK6v4Qk8[] = { C_ATTN_PREFILL_FP8("k6_v4"),
C_EQ("prefill_fp8", 1) };
static const RadConstraint cAttnPrefillK6v4Pv8[] = { C_ATTN_PREFILL_FP8("k6_v4"),
C_EQ("prefill_fp8", 2) };
static const RadConstraint cAttnPrefillK6v4QkPv8[] = { C_ATTN_PREFILL_FP8("k6_v4"),
C_EQ("prefill_fp8", 3) };
#undef C_ATTN_PREFILL_FP8
static const RadConstraint cAttnPrefillBf16[] = {
C_EQ("window", 0), C_EQ("head_dim", 256), C_EQ("gqa", 6), C_EQ("block_size", 16),
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
@@ -3732,11 +3804,12 @@ static const RadConstraint cAttnPrefillH64G4Bf16[] = {
C_EQ("window", 0), C_EQ("head_dim", 64), C_EQ("gqa", 4), C_EQ("block_size", 16),
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
};
/* The windowed kernels (r4d_attn_paged_window.hip): head_dim 256 and 512, 1/2/4/8 queries per KV
* head, any window, causal or not. Gemma 4's sliding layers are h256/gqa2 with a 1024-token
* window, its full layers h512 at gqa 8 (TP1/TP2), 4 (TP4) or 2 (TP8). One kernel serves every
* q_len (splitting the key range when there are too few tiles to fill the card), so `q_len` cuts
* no band. `causal` and `window` are runtime fields; block_size is derived: 16.
/* The windowed kernels (r4d_attn_paged_window.hip): head_dim 128, 256 and 512, 1/2/4/8 queries per
* KV head, any window, causal or not. Gemma 4's sliding layers are h256/gqa2 with a 1024-token
* window, its full layers h512 at gqa 8 (TP1/TP2), 4 (TP4) or 2 (TP8); h128/gqa1 is Unlimited-OCR's
* MHA decoder. One kernel serves every q_len (splitting the key range when there are too few tiles
* to fill the card), so `q_len` cuts no band. `causal` and `window` are runtime fields; block_size
* is derived: 16.
*
* h256 at gqa 4 and 8 take a window only (C_GE 1), leaving the window-0 band to the gqa4 / gqa8
* legs above. At h256/gqa2 these rows overlap the sliding leg's bands and rank below it
@@ -3746,6 +3819,7 @@ static const RadConstraint cAttnPrefillH64G4Bf16[] = {
C_EQ("head_dim", HD), C_EQ("gqa", G), C_EQ("block_size", 16), C_GE("causal", 0), \
C_GE("window", WMIN), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", KV), \
};
R4D_WIN_C(cWinH128G1Bf16, 128, 1, "bf16", 0) R4D_WIN_C(cWinH128G1Fp8, 128, 1, "fp8_e4m3", 0)
R4D_WIN_C(cWinH256G1Bf16, 256, 1, "bf16", 0) R4D_WIN_C(cWinH256G1Fp8, 256, 1, "fp8_e4m3", 0)
R4D_WIN_C(cWinH256G2Bf16, 256, 2, "bf16", 0) R4D_WIN_C(cWinH256G2Fp8, 256, 2, "fp8_e4m3", 0)
R4D_WIN_C(cWinH256G4Bf16, 256, 4, "bf16", 1) R4D_WIN_C(cWinH256G4Fp8, 256, 4, "fp8_e4m3", 1)
@@ -3901,6 +3975,27 @@ static const RadConstraint cAttnDecodeH128G8Bf16[] = {
C_EQ("window", 0), C_EQ("head_dim", 128), C_EQ("gqa", 8), C_EQ("block_size", 16),
C_GE("causal", 0), C_LE("q_len", 8), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
};
/* head_dim 128 at ratio ONE: plain MHA (the Unlimited-OCR decoder, 10 query heads over 10), from
* r4d_attn_paged_h128_gqa1.hip. The decode leg caps at 64 query rows, which at this ratio is a
* plain q_len <= 64; the prefill leg has no query-row cap. */
static const RadConstraint cAttnPrefillH128G1Fp8[] = {
C_EQ("window", 0), C_EQ("head_dim", 128), C_EQ("gqa", 1), C_EQ("block_size", 16),
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "fp8_e4m3"),
};
static const RadConstraint cAttnPrefillH128G1Bf16[] = {
C_EQ("window", 0), C_EQ("head_dim", 128), C_EQ("gqa", 1), C_EQ("block_size", 16),
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
};
static const RadConstraint cAttnDecodeH128G1Fp8[] = {
C_EQ("window", 0), C_EQ("head_dim", 128), C_EQ("gqa", 1), C_EQ("block_size", 16),
C_GE("causal", 0), C_LE("q_len", 64), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "fp8_e4m3"),
};
static const RadConstraint cAttnDecodeH128G1Bf16[] = {
C_EQ("window", 0), C_EQ("head_dim", 128), C_EQ("gqa", 1), C_EQ("block_size", 16),
C_GE("causal", 0), C_LE("q_len", 64), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
};
/* Two queries per KV head at head_dim 128 (Qwen3-1.7B, Qwen3-ASR's decoder): the gqa8 pair's
* constraints with the ratio and the decode verify width changed together. A decode workgroup
* holds 64 (query, head) rows, so q_len <= 32 at gqa 2. */
@@ -3963,9 +4058,20 @@ static const RadConstraint cCastNarrow[] = {
* bidirectional with any window, or a text encoder's causal prompt. gqa 1 at 256 and 512 is
* attn_dense_small_h256's and the wide kernel's. */
/* Causal or not at head_dim 64: a vision tower's heads, and a codec's sliding causal layers. */
/* KEY RENAME. libr4d writes C_IN("q_dtype","bf16") and C_IN("kv_dtype","bf16"); docs/OPS.md's
* `attn_dense` has one `dtype` because nothing about a dense bf16 tower is mixed-precision. The
* predicate -- "bf16, and nothing else" -- is unchanged. */
static const RadConstraint cAttnDenseH64[] = {
C_EQ("head_dim", 64), C_EQ("gqa", 1), C_IN("dtype", "bf16"),
};
/* Unlimited-OCR's SAM tower (r4d_sam_attn_bf16.hip): one block per (segment, tile, head), a thread
* a query row, q and the output accumulator in registers; only head_dim 64 is instantiated and a
* rel_pos table that is not 2*tile-1 rows is linear-resampled on read (get_rel_pos), so the 127-row
* global tables serve a 40-grid block as 79 rows. */
static const RadConstraint cSamAttn[] = {
C_EQ("head_dim", 64), C_IN("dtype", "bf16"),
};
static const RadConstraint cAttnDenseH256G2[] = {
C_EQ("head_dim", 256), C_EQ("gqa", 2), C_IN("dtype", "bf16"),
};
@@ -4582,7 +4688,6 @@ static const RadConstraint cQuantActI8[] = {
static const RadConstraint cRmsNormQuantI8[] = {
C_DIV("n", 16), C_LE("n", 30720), C_IN("dtype", "bf16"),
};
/* head_dim 256 or 512: a workgroup is one head, a thread one channel. */
static const RadConstraint cAddRmsNorm[] = {
C_GE("n", 1), C_IN("dtype", "bf16"),
};
@@ -4592,6 +4697,7 @@ static const RadConstraint cKvLenTrim[] = {
static const RadConstraint cPrefetch[] = {
C_GE("bytes", 1),
};
/* head_dim 256 or 512: a workgroup is one head, a thread one channel. */
static const RadConstraint cQkvNormRope[] = {
C_GE("head_dim", 256), C_LE("head_dim", 512), C_DIV("head_dim", 256), C_IN("dtype", "bf16"),
};
@@ -4828,8 +4934,7 @@ static const RadTunable tAttnSplit[] = {
/* ------------------------------------------------------------------- all-reduce launch geometry
*
* Four independent axes of the handshake: nblocks, nthreads, drain and acq. (`pub` is 1 in every
* arm but the four-rank junction's, tArQ84, where it is an axis.) nblocks 0 scales with the message
* and clamps; drain 3 is
* arm, a constant in r4d_cfg_ar.) nblocks 0 scales with the message and clamps; drain 3 is
* s_wait_storecnt, the correct wait for the fine-grained uncached IPC scratch.
*
* rad-tune cannot reach these rows: the two-rank kernels need a real peer over IPC and rad-tune
@@ -4847,11 +4952,10 @@ static const int64_t kArAcq[] = { 0, 1 };
/* `ts_min`: from this many elements the four-rank exact one-shot hands the message to the exact
* two-shot on the same instance (the same per-element fold, so the same bytes): a rank then sends
* 1.5x the message instead of 3x, for a second handshake. 32768 is about six rows of 5376, so an
* 8-row DFlash2 verify's all-reduces take the two-shot too (on 4x R9700, 2026-10-17: 297 -> 303
* tok/s code, long decode 447 -> 460, against 65536 that kept them one-shot); a 16-row verify's
* already did. 0 keeps the one-shot to its band's top. Read only by that
* adapter; declared by every all-reduce table so one RADIANCE_TUNE=all_reduce:ts_min=N pin is legal
* for every row the op resolves to. */
* 8-row DFlash2 verify's all-reduces take the two-shot too (on 4x R9700 the 31B decoded 2-3% faster
* than at 65536, which kept them one-shot), as a 16-row verify's do. 0 keeps the one-shot to its
* band's top. Read only by that adapter; declared by every all-reduce table so one
* RADIANCE_TUNE=all_reduce:ts_min=N pin is legal for every row the op resolves to. */
static const int64_t kArTsMin[] = { 0, 16384, 32768, 65536, 131072, 262144 };
static const RadTunable tAr[] = {
{ "nblocks", kArNblocks, NELEM(kArNblocks), 0, "blocks in the grid. 0 = scale with the message and clamp" },
@@ -4860,28 +4964,20 @@ static const RadTunable tAr[] = {
{ "acq", kArAcq, NELEM(kArAcq), 0, "acquire fence after the flag read" },
{ "ts_min", kArTsMin, NELEM(kArTsMin), 32768, "elements from which the four-rank one-shot takes the exact two-shot; 0 = never" },
};
/* The four-rank fused junction (ar_rmsnorm_quant_i8_4rank): tAr's axes, its own value sets.
* On 4x R9700 over PCIe P2P a junction costs about 22 us at one row of 5376 and 57 us at sixteen
* (--profile-ops): it is bound by its handshakes, not its bytes.
*
* Every block takes one handshake, a system-scope release by its first
* thread and a system-scope acquire by every wave. Both are needed: on 4x R9700 behind an EPYC
* root complex, dropping either (an acq 2 and a pub 2 that were here, r4d_selftest 2026-10-16 and
* -17) left the readers with stale scratch on nearly every element, so the peers' stores do not
* reach them past the writer's L2 without the writeback. What can move is how many handshakes a
* call takes: fewer blocks (2 or 4, each owning several rows) take fewer. The defaults are the
* forms that have run on cards; the others are for RADIANCE_TUNE until they have. None of them
* changes the result. */
/* The four-rank fused junction (ar_rmsnorm_quant_i8_4rank): tAr's axes with its own block counts,
* and `tail`. A one-shot junction is bound by its handshakes, not its bytes (on 4x R9700 over PCIe
* P2P about 22 us at one row of 5376 and 57 us at sixteen). Every block takes one handshake, a
* system-scope release by its first thread and a system-scope acquire by every wave; without
* either, the readers see stale scratch on those cards, so no point drops one. What can move is
* the handshake count: fewer blocks (2 or 4, each owning several rows) take fewer. Only the
* defaults have run on cards. No axis changes the result. */
static const int64_t kArQ84Tail[] = { 1, 0 };
static const int64_t kArQ84Nblocks[] = { 0, 2, 4, 8, 16, 24 };
static const int64_t kArQ84Acq[] = { 0, 1 };
static const int64_t kArQ84Pub[] = { 1 };
static const RadTunable tArQ84[] = {
{ "nblocks", kArQ84Nblocks, NELEM(kArQ84Nblocks), 0, "blocks in the grid. 0 = one a row, clamped" },
{ "nthreads", kArNthreads, NELEM(kArNthreads), 1024, "unused: the norm's width sets the block for bit-exactness" },
{ "drain", kArDrain, NELEM(kArDrain), 3, "store-drain wait before the flag: 3 = s_wait_storecnt, 1 = vmcnt" },
{ "acq", kArQ84Acq, NELEM(kArQ84Acq), 0, "acquire after the flag read: 0 system invalidate a wave, 1 full fence" },
{ "pub", kArQ84Pub, NELEM(kArQ84Pub), 1, "release before the flag store: 1 one system writeback" },
{ "acq", kArAcq, NELEM(kArAcq), 0, "acquire after the flag read: 0 system invalidate a wave, 1 full fence" },
{ "tail", kArQ84Tail, NELEM(kArQ84Tail), 1, "from 5 to 32 rows: the standalone two-shot with the junction as its tail, a block a row (no handshake or launch of its own); 0 = the one-shot" },
};
/* The four-rank two-shots beside compute: four blocks of 1024. A pipelined Flash-Next prefill at
@@ -5749,6 +5845,20 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_sample_dry, nullptr, nullptr, nullptr,
r4d_shape_sample_dry },
{ "sample_ngram_ban_f32", "sample_ngram_ban", "sample",
"the windowed no-repeat-ngram ban (Unlimited-OCR's SlidingWindowNoRepeatNgramProcessor): every "
"token that would complete an n-gram the last `window` tokens of the row's history contain is "
"set to -infinity",
"any vocabulary; ONE BLOCK A ROW, the search positions dealt across its threads, the n-1-token "
"prefix staged in LDS. Integer comparisons and one constant store, so it is bit-identical to "
"libref; the same column written by two positions is an idempotent -infinity",
"f32 logits in place, i32 history, i32 {n, window} per-row pair",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cSampleVoc), NOTUNE,
/* No `opd_shape`: r4d_shapes.cpp declares the sampler's shapes, and the oracle (libref) describes
* this op for the tools that ask. */
nullptr, nullptr, r4d_rad_sample_ngram_ban },
{ "sample_temp_f32", "sample_temp", "sample",
"per-request temperature",
"any vocabulary; a row with temp <= 0 or exactly 1 is skipped whole",
@@ -5870,6 +5980,37 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
/* Lossy: they match only a caller whose `prefill_fp8` accepts their legs. */
{ "attn_prefill_h256_gqa6_fp8kv_qk8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query rounded to e4m3 after the scale, fp8-e4m3 kv cache with per-(seq,head) descales, "
"bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8Qk8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8_qk8, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa6_fp8kv_pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, probabilities rounded to e4m3, "
"bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8Pv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8_pv8, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa6_fp8kv_qk8pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T and P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query and probabilities rounded to e4m3, fp8-e4m3 kv cache with per-(seq,head) "
"descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8QkPv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8_qk8pv8, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa6_fp8v4", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
@@ -5879,6 +6020,39 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8v4, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_fp8v4_qk8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query rounded to e4m3 after the scale, "
"fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), "
"K as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8v4Qk8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8v4_qk8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_fp8v4_pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query, probabilities rounded to e4m3, "
"fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), "
"V as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8v4Pv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8v4_pv8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_fp8v4_qk8pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T and P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query and probabilities rounded to e4m3, "
"fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), "
"K and V as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillFp8v4QkPv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_fp8v4_qk8pv8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_k6v4", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
@@ -5888,6 +6062,39 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_attn_prefill_h256_k6v4, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_k6v4_qk8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query rounded to e4m3 after the scale, "
"k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), "
"K as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillK6v4Qk8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_k6v4_qk8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_k6v4_pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query, probabilities rounded to e4m3, "
"k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), "
"V as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillK6v4Pv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_k6v4_pv8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_k6v4_qk8pv8", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill), Q.K^T and P.V as e4m3 WMMA",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
"bf16 query and probabilities rounded to e4m3, "
"k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), "
"K and V as e4m3 in LDS, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL_FP8,
ROW(cAttnPrefillK6v4QkPv8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_k6v4_qk8pv8, nullptr, nullptr, nullptr,
nullptr },
{ "attn_prefill_h256_gqa6_bf16kv", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 256, 6 queries per kv head, paged block 16, varlen",
@@ -6087,6 +6294,44 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_attn_qrow_h128_gqa8_bf16, r4d_rad_attn_qrow_h128_gqa8_scratch,
nullptr, nullptr, nullptr },
{ "attn_prefill_h128_gqa1_fp8kv", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 128, 1 query per kv head (plain MHA), paged block 16, varlen",
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH128G1Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h128_gqa1_fp8, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h128_gqa1_bf16kv", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 128, 1 query per kv head (plain MHA), paged block 16, varlen",
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH128G1Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h128_gqa1_bf16, nullptr, nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h128_gqa1_fp8kv", "attn_paged", "attn",
"paged attention, causal or not, split-KV (decode / speculative verify)",
"head_dim 128, 1 query per kv head (plain MHA), paged block 16, q_len <= 64, no window",
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out, f16 partials",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_DECODE,
ROW(cAttnDecodeH128G1Fp8), ROW(tAttnSplit), nullptr,
nullptr, nullptr, r4d_rad_attn_decode_h128_gqa1_fp8, r4d_rad_attn_decode_h128_gqa1_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h128_gqa1_bf16kv", "attn_paged", "attn",
"paged attention, causal or not, split-KV (decode / speculative verify)",
"head_dim 128, 1 query per kv head (plain MHA), paged block 16, q_len <= 64, no window",
"bf16 query, bf16 kv cache, bf16 out, f16 partials",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_DECODE,
ROW(cAttnDecodeH128G1Bf16), ROW(tAttnSplit), nullptr,
nullptr, nullptr, r4d_rad_attn_decode_h128_gqa1_bf16, r4d_rad_attn_decode_h128_gqa1_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa8_fp8kv", "attn_paged", "attn",
"paged causal attention, query-tiled (prefill / chunked prefill)",
"head_dim 256, 8 queries per kv head, paged block 16, varlen",
@@ -6207,6 +6452,7 @@ static const RadKernelInfo kKernels[] = {
#define R4D_WIN_PAIR(HD, GQ) \
R4D_WIN_ROW(HD, GQ, bf16kv, bf16, cWinH##HD##G##GQ##Bf16, "bf16") \
R4D_WIN_ROW(HD, GQ, fp8kv, fp8, cWinH##HD##G##GQ##Fp8, "fp8-e4m3 (per-(seq,head) descales)")
R4D_WIN_PAIR(128, 1)
R4D_WIN_PAIR(256, 1) R4D_WIN_PAIR(256, 2) R4D_WIN_PAIR(256, 4) R4D_WIN_PAIR(256, 8)
R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512, 8)
#undef R4D_WIN_PAIR
@@ -6547,6 +6793,16 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
ROW(cAttnVit), NOTUNE,
nullptr, nullptr, r4d_rad_attn_vit },
{ "sam_attn_bf16", "sam_attn", "attn",
"Unlimited-OCR's SAM tower attention: windowed tiles with a decomposed relative-position term",
"head_dim 64; any grid, window and segment count (a segment is one grid_h*grid_w); q/k/v/out at "
"their own row pitch (column slices of one fused projection); rel_pos tables of any row count "
">= 1 (a table that is not 2*tile-1 rows is linear-resampled on read)",
"bf16 query / key / value / out and rel_pos tables, i32 cu_seqlens, fp32 accumulate",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cSamAttn), NOTUNE,
nullptr, nullptr, r4d_rad_sam_attn },
{ "attn_dense_h64_bf16", "attn_dense", "attn",
"dense varlen attention over cu_seqlens: bidirectional with an optional two-sided window or "
"blocks, or causal with an optional window behind",
@@ -7931,11 +8187,10 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
ROW(cArRmsNormQuantI8), ROW(tAr), nullptr,
r4d_rad_ar_ln_init, r4d_rad_ar_fini, r4d_rad_ar_rmsnorm_quant_i8 },
/* Its arithmetic is the four-rank exact one-shot's fold followed by the two-rank form's junction,
* each the code those two run. r4d_selftest's case of the same name holds it byte for byte to
* all_reduce + rmsnorm_quant_i8 on a four-card box, and the engine to a decode step's text against
* a build that issues the pair. Both have run on cards that way (the 31B's fused junctions, and
* r4d_selftest on four R9700s). */
/* Its arithmetic is the four-rank exact all-reduce's fold followed by the two-rank form's
* junction, each the code those two run, in every form (one-shot, tail, split). r4d_selftest's
* case of the same name holds each form byte for byte to all_reduce + rmsnorm_quant_i8 on a
* four-card box. */
{ "ar_rmsnorm_quant_i8_4rank", "ar_rmsnorm_quant_i8", "quant",
"the four-rank exact one-shot all-reduce and the junction after it -- post-norm of the reduced "
"sum, residual add, scalar, RMS norm and quant_act_i8's quantiser -- in one kernel",
@@ -8964,13 +9219,6 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
ROW(cGenAnyFloat), NOTUNE,
nullptr, nullptr, r4d_rad_pix_patch },
{ "patch_pix8", "patch_pix8", "elem",
"patch rows to RGB bytes: a thread a byte",
"dense 2-D operands, row pitches honoured", "bf16 or f32 x, u8 y",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cGenAnyFloat), NOTUNE,
nullptr, nullptr, r4d_rad_patch_pix8 },
{ "vol_index", "vol_index", "elem",
"a volume's voxel coordinates: a thread a voxel", "i32, a dense [3, n]", "i32",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
@@ -9308,37 +9556,27 @@ extern "C" void r4d_cfg_mxfp4_tiled(const RadArgs* a, R4dMxTileCfg* out) {
extern "C" void r4d_cfg_split(const RadArgs* a, R4dSplitCfg* out) {
out->splits = TUNE(a, tAttnSplit, "splits");
}
/* A fresh-start divergence (4x R9700 behind an EPYC root complex, 2026-10-17): on a freshly
* started 31B server, a prefill all-reduce now and then reads a peer's scratch before that peer's
* words have landed -- the first reuse of a double-buffered slot, inputs identical on every rank
* (RADIANCE_DEBUG_OPHASH) -- and the first greedy reply flips a near-tie. Every thread's full
* system fence before the flag (drain 1) cures it, as does one after it (acq 1); the per-wave
* store wait (drain 3) and the publisher's one writeback (pub 1) do not, and Relaxed Ordering off
* on every link does not. The mechanism below the fence is not known. Decode heights never showed
* it, and the fence costs them ~0.7 %, so it is taken only from RADIANCE_AR_FENCE_FROM elements
* (default 131072, 24 rows of the 31B's 5376: above any verify height, and every prefill chunk);
* 0 never. Read once. Only at four ranks, where it was seen and cured: at two (Qwen3.8-27B's
* prefill at tp 2) it cost 4.5% of prefill, and no two-rank start ever flipped. */
static long long ar_fence_from() {
static const long long v = [] {
const char* e = std::getenv("RADIANCE_AR_FENCE_FROM");
return e && *e ? std::atoll(e) : 131072LL;
}();
return v;
}
/* Four-rank collectives of at least kArFenceFromElems elements take drain 1, every thread's full
* system fence before the flag, instead of the per-wave store wait. Without it a peer has been seen
* to read stale scratch on 4x R9700 behind an EPYC root complex: a prefill all-reduce at the first
* reuse of a double-buffered slot, on a freshly started server. The publisher's single writeback
* and Relaxed Ordering off do not prevent it; the fence does, and the mechanism below it is not
* known. The threshold, 24 rows of a 5376-wide trunk, lies above every decode and verify height
* and below every prefill chunk, so decode pays nothing (the fence would cost it about 0.7%) and a
* four-rank prefill about 0.5-0.8%. Two ranks have their own handshake and never take it. The
* bytes are the same either way; only when the flag goes out moves. */
static constexpr long long kArFenceFromElems = 131072;
extern "C" void r4d_cfg_ar(const RadArgs* a, R4dArCfg* out) {
out->nblocks = TUNE(a, tAr, "nblocks");
out->nthreads = TUNE(a, tAr, "nthreads");
out->drain = TUNE(a, tAr, "drain");
out->acq = TUNE(a, tAr, "acq");
/* An axis of the four-rank junction only (tArQ84); 1 for every other row, as before. */
out->pub = TUNE(a, tArQ84, "pub");
out->pub = 1; /* not an axis; see the note at tAr */
/* Operand 0 is the message on every collective that reads this (all_reduce's x, a junction's
* [M, n] input, all_gather's source). */
const long long from = ar_fence_from();
if (from > 0 && a && a->t && a->n_t > 0 && rad_tensor_numel(&a->t[0]) >= from &&
r4d_geti_or(a, "world_size", 4) == 4) /* the four-rank rows carry no world_size */
if (a && a->t && a->n_t > 0 && rad_tensor_numel(&a->t[0]) >= kArFenceFromElems &&
r4d_geti_or(a, "world_size", a->world_size) == 4)
out->drain = 1;
}
extern "C" int r4d_cfg_ar_tail(const RadArgs* a) {