radiance 1.14.0

New models and formats:
- libr3d: a kernel library for RDNA3 (gfx11) cards
- nomic-embed-text-v2-moe (the nomicbert plugin)
- Gemma 4 E2B with its per-layer MLP width, and Google's unmodified E2B/E4B directories in bf16
- DeepSeek-V4.1-Flash converted straight from its release: the Engram tables, the fused imatrix and
  rad-convert --chat-template for a release that ships no template
- GGUF Q8_0, Q4_K and Q6_K tensors import as their planes; rad-convert writes them without a recipe
- Qwen3.8-Flash-Next-FP8 converts and serves through qwen4exp_fp8

Speed:
- hc_read's decode kernels as one grid (34.7 -> 25.2 us at 4 rows) and its tiled up-mix pipelined
- gemm_fp8a8: the narrow form's scales staged through LDS (Flash-Next int8 at 32 rows 83.6 -> 68.3
  us), the gated three-tile form at 8 waves (gate_up at 48 rows 272.9 -> 180.6 us)
- Qwen3.8-27B: the delta net's out-projection read beside its decode recurrent update (x1 19.40 ->
  19.10 ms a step), and the verify's split-KV attention sized by context depth (x3 at 180K 42.4 ->
  40.3 ms a step)
- Hy-Memory (HYV3) decode: fused QK norm, RoPE and KV store, residual adds folded into the norms,
  coalesced one-token expert GEMMs
- spechub: the coupled verify walks the live candidates only (151 -> 31 us a launch)

Speculation:
- DFlash2: lossless coupled acceptance at T > 0 (--draft-coupling on)
- A block drafter's proposals verified as a tree, on by default for the Gemma 4 31B's DFlash2, with
  a block-16 tree that runs its short block under load

Features:
- Decode-hot residency: --draft-expert-placement host, --expert-profile, --expert-pin-top, and
  --expert-stats FILE for the routed experts each layer selects
- --ngram-placement ram=DIR: one n-gram table shared by engines on separate cards
- Prefix cache: --prefix-resume exact (default) resumes a hit on the cold run's own chunk grid, so it
  answers bit-identically; snapshots at a head other prompts share, from 528-token prompts, and for
  tip-only one drafter window below the tip; hits on models whose KV groups have different block
  sizes; the snapshot store keeps a floor of 8 ahead of --host-headroom-mib
- Typed tool-call argument tags; rad-chatparse --request renders and reads back one request as the
  server does
- MiniMax-H3: keyframes ride a latent upscale
- Gemma 3's fused all-reduce junction on the lossy wire

Fixes:
- A speculative step shorter than its band (an MTP step of 4 rows at gqa 8) no longer stops the
  engine with a scratch refusal at issue (#293)
- --p2p off: prefill back to 1.12.0's rate; 1.13.0's push check read a host-memory slot over the link
  twice (#323)
- A chat template that cannot render a conversation is refused at load, not mid-request
- imatrix entries found under llama.cpp's spelling; the W4A8 prefill's tail scale read; the GDN conv
  kernels on an f32 weight; dense integer rows at the group they compute (a Q8_0 weight at group 32)
- --expert-profile refuses a profile recorded on another model
- hc_read's one-grid wait traps past its deadline instead of reading a stale value

Changes: Plugin ABI 31, unchanged. RADIANCE_DRAFT_TREE, DFLASH2_TREE_NODES, DFLASH2_TREE_TEMP and
DFLASH_Q_TEMP are gone (trees run where the probe says they pay; temperatures 1.25 / 0.6).
This commit is contained in:
Deadcode committed 2026-10-29 12:04:24 +01:00
1 parent 481fcd5df0
commit 4a61d7296b
160 files changed
+8790 -6819

No files matched your search

+67 -71
View File
@@ -2,8 +2,8 @@
*
* The row table (r3d_rows.cpp) and the operand descriptions (r3d_shapes.cpp) are pure host C++ and
* include only this file and the ABI; the launch shims include r3d.h and so <hip/hip_runtime.h>.
* The split lets the constraint table compile and be checked without ROCm, and is why every shim is
* declared here rather than beside its definition.
* The split lets the constraint table compile and be checked without ROCm, which is why every shim
* is declared here rather than beside its definition.
*
* Nothing in this header may include r3d.h.
*/
@@ -15,56 +15,53 @@
/* ================================================================== the priority ladder
*
* The selector ranks candidate rows by an integer priority (spec §2.1); where two rows of one op
* can match a geometry, it decides which serves. Each group states the reason for its order.
* Values are spaced by ten so a row can be slipped between two without renumbering.
* match a geometry, it decides which serves. Each group states the reason for its order. Values are
* spaced by ten so a row can be inserted between two without renumbering.
*
* libr3d ships one row per (op, dtype) pair far more often than libr4d does: the matrix work runs
* on the dot2 path, whose lane map takes a dtype as a template argument, so the kernel that serves
* bf16 serves f16 as is, and there is nothing to specialise a second row for. Where two rows of
* one op do exist, the reason is the geometry, and it is written next to the pair.
* Most ops have a single row: the matrix work runs on the dot2 path, whose lane map takes the dtype
* as a template argument, so the kernel that serves bf16 also serves f16. Where one op has two
* rows, the reason is geometry and is stated next to the pair.
*/
enum {
/* The common case: this op, these dtypes, one row. Nothing competes with it. */
/* One row for the op; nothing competes with it. */
R3D_PRIO_ONLY = 50,
/* `attn_paged` is banded on q_len, and the decode row's bound (q_len <= 16) is a bucket
* boundary, not a partition: a speculative verify at 8 query tokens matches the prefill row
* too, and the decode kernel -- split-KV, one head group a workgroup, no query tile -- is the
* faster one there. Decode therefore outranks prefill, as it does in libr4d. */
/* `attn_paged` is banded on q_len, and the decode row's bound (q_len <= 16) overlaps the
* prefill row: a speculative verify at 8 query tokens matches both, and the decode kernel
* (split-KV, one head group per workgroup, no query tile) is faster there. Decode outranks
* prefill, as in libr4d. */
R3D_PRIO_ATTN_DECODE = 70,
R3D_PRIO_ATTN_PREFILL = 60,
/* The skinny bf16 GEMM's band is M <= 16 and the tiled one's starts at M >= 16, so the two
* meet at exactly 16 rows and the skinny kernel wins there (it keeps the whole weight stream
* in flight with one wave a row and has no LDS staging to pay for). The overlap is deliberate:
* a caller that wants the tiled kernel at 16 rows asks with M=17, the same convention libr4d
* uses at its own m64/tiled boundary. */
/* The skinny bf16 GEMM's band is M <= 16 and the tiled one's starts at M >= 16. At 16 rows the
* skinny kernel wins: it keeps the whole weight stream in flight with one wave per row and has
* no LDS staging. The overlap is deliberate; a caller that wants the tiled kernel at 16 rows
* asks with M=17, as at libr4d's m64/tiled boundary. */
R3D_PRIO_GEMM_M16 = 60,
R3D_PRIO_GEMM_TILED = 40,
/* The vocab is a GEMM whose N is the vocabulary: one row, M <= 16, split-K across the whole
* card. The tiled GEMM has no row for these N, so this priority only decides against a future
* tiled vocab row. */
/* The vocab GEMM (N = the vocabulary): one row, M <= 16, split-K across the whole card. The
* tiled GEMM has no row for these N, so this priority only matters against a future tiled
* vocab row. */
R3D_PRIO_VOCAB_M1 = 60,
/* An fp8 weight row and an int8 weight row never compete: no dtype string reaches both, and a
* container's encoding picks which is legal. */
/* An fp8 weight row and an int8 weight row never compete: no dtype string reaches both, and
* the container's encoding picks which is legal. */
R3D_PRIO_GEMM_FP8 = 60,
/* The sampler stages are one row each, on one dtype (f32 logits), so there is nothing to rank.
* The name is here so a second row for a stage -- an i8 logits form, say -- has a ladder to
* join. */
/* One row per sampler stage, on f32 logits, so there is nothing to rank yet. A second row for
* a stage (an i8 logits form, say) would rank against this value. */
R3D_PRIO_SAMPLE = 50
};
/* ================================================================== the dtype codes a C
* launcher takes
*
* The launchers in r3d.h take a dtype as an int, because a `__global__`'s dtype has to be a runtime
* value for the ops that are one kernel over several (cast, fill, dequant) and a compile-time one
* everywhere else. These are the codes; they are libr3d's own, not rad_types.h's RAD_DT_* (a
* launcher's argument list is a private contract between a shim and its kernel, and the kernel
* switch reads better over a dense 0..n than over the ABI's sparse enum). Every shim translates. */
* The launchers in r3d.h take a dtype as an int: it is a runtime value for the ops that are one
* kernel over several dtypes (cast, fill, dequant) and a template argument everywhere else. The
* codes are libr3d's own, not rad_types.h's RAD_DT_*, because the launcher signature is private to
* a shim and its kernel and a dense 0..n switches more cleanly than the ABI's sparse enum. Every
* shim translates. */
enum {
R3D_DT_BF16 = 0,
R3D_DT_F16 = 1,
@@ -103,16 +100,16 @@ static inline int r3d_dt_size(int code) {
/* The activation an `act` parameter names, as the kernels' template argument. */
enum { R3D_ACT_SILU = 0, R3D_ACT_SIGMOID = 1, R3D_ACT_GELU = 2 };
/* rope's `mode`, same numbering as libref's kModes. libr3d's kernel implements neox and gptj; the
* rows' constraints say so, so a model that needs mrope is not routed here. */
/* rope's `mode`, numbered as libref's kModes. Only neox and gptj are implemented, and the rows'
* constraints say so, so a model that needs mrope is not routed here. */
enum { R3D_ROPE_NEOX = 0, R3D_ROPE_GPTJ = 1 };
/* ================================================================== the row table's entry points
*
* Declared here so r3d_rows.cpp, which is host code built without ROCm, can name them; each is
* defined beside its kernel, in the unit named below, and is documented there. A shim is a
* `RadLaunchFn`: operands read with r3d_args.h, dtype from the tensor, row count from the operand.
* A shape hook is a `RadShapeFn`: the extent and content domain of one operand (r3d_shapes.cpp).
* Declared here so r3d_rows.cpp, host code built without ROCm, can name them. Each is defined and
* documented beside its kernel, in the unit named below. A shim is a `RadLaunchFn`: operands read
* with r3d_args.h, dtype from the tensor, row count from the operand. A shape hook is a
* `RadShapeFn`: the extent and content domain of one operand (r3d_shapes.cpp).
*/
extern "C" {
@@ -145,7 +142,6 @@ int r3d_rad_dequant (const RadArgs* a, RadStream s);
/* --- r3d_gemm_bf16_nt_m16.hip, r3d_gemm_fp8a16_nt_m1.hip --- */
int r3d_rad_gemm_nt_bf16_m16 (const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_fp8 (const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_i8 (const RadArgs* a, RadStream s);
/* --- r3d_shapes.cpp --- */
int r3d_shape_rmsnorm (const RadParam* p, int n_p, int operand, RadOpdDesc* out);
@@ -174,15 +170,15 @@ int r3d_shape_gemm_nt (const RadParam* p, int n_p, int operand, RadOpdDe
int r3d_shape_gemm_nt_q (const RadParam* p, int n_p, int operand, RadOpdDesc* out);
int r3d_shape_gemm_nt_q_mxfp4a8(const RadParam* p, int n_p, int operand, RadOpdDesc* out);
/* --- r3d_attn_paged_h128.hip, r3d_vocab_bf16.hip, r3d_sample_f32.hip --- */
/* --- r3d_shapes.cpp: the fused-op, attention and sampler shape hooks --- */
extern "C" int r3d_shape_silu_mul (const RadParam*, int, int, RadOpdDesc*);
extern "C" int r3d_shape_attn_paged (const RadParam*, int, int, RadOpdDesc*);
extern "C" int r3d_shape_gemm_nt_q_gated (const RadParam*, int, int, RadOpdDesc*);
/* The vocab projection at w2a8, decode. The layout hook is this library's scoped exception to
* "no layout hooks" (the other two are the fp8 weight's and the logits head's, below): it repacks
* nothing, it presents the container's `scale` and `zero` planes as the single joined `b_scale`
* operand the way rad_planes stores them, transcribed from
* ref_layout_gemm_q. Without it the plan has a placement with no reader. */
/* r3d_gemm_nt_q_w2a8.hip: the w2a8 vocab projection's layout hook, one of the library's three
* (with the fp8 weight's and the logits head's, below). It repacks nothing: it presents the
* container's `scale` and `zero` planes as the single joined `b_scale` operand the way rad_planes
* stores them, transcribed from ref_layout_gemm_q. Without it the plan would have a placement with
* no reader. */
extern "C" int r3d_layout_gemm_nt_q_w2a8(const RadParam*, int, int, const RadEncoding*,
const int* sel, const RadTensor* planes, int n_planes,
RadLayout*);
@@ -202,8 +198,9 @@ extern "C" int r3d_shape_sample_ngram_ban (const RadParam*, int, int, RadOpdDes
extern "C" int r3d_shape_sample_mask (const RadParam*, int, int, RadOpdDesc*);
extern "C" int r3d_shape_sample_logprobs (const RadParam*, int, int, RadOpdDesc*);
/* --- r3d_sample_f32.hip: the draw spine (row_topk, argmax, temp, topk, pick, the four narrowings)
and r3d_model_bf16.hip's pre-filters (penalties, dry, ngram_ban, mask, logprobs) --- */
/* --- r3d_gemm_nt_q_w2a8.hip, r3d_gemm_fp8a8_gated.hip, r3d_dflash_f32.hip; r3d_sample_f32.hip's
draw spine (row_topk, argmax, temp, topk, pick, the four narrowings) and
r3d_sample_pre_f32.hip's pre-filters (penalties, dry, ngram_ban, mask, logprobs) --- */
int r3d_rad_gemm_nt_q_w2a8 (const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_gated (const RadArgs* a, RadStream s);
int r3d_rad_dflash_select (const RadArgs* a, RadStream s);
@@ -222,44 +219,39 @@ int r3d_rad_sample_ngram_ban (const RadArgs* a, RadStream s);
int r3d_rad_sample_mask (const RadArgs* a, RadStream s);
int r3d_rad_sample_logprobs (const RadArgs* a, RadStream s);
/* --- r3d_model_bf16.hip: the fused MLP activation and the fused norm-quantiser --- */
/* The paged attention's two entry points, banded on q_len: the decode kernel is split-KV over the
* cache with one head group a workgroup, the prefill kernel stages a 16-token query tile. */
/* --- r3d_attn_paged_h128.hip: the paged attention, banded on q_len. The decode kernel is
* split-KV over the cache with one head group per workgroup; the prefill kernel stages a 16-token
* query tile. */
int r3d_rad_attn_decode_h128 (const RadArgs* a, RadStream s);
int r3d_rad_attn_prefill_h128 (const RadArgs* a, RadStream s);
/* --- r3d_vocab_bf16.hip: the vocabulary projection, both heights. The shape hook is a
* transcription of ref_logits_gemm_shape -- three plain tensors, nothing joined -- so the band the
* engine declares is the band kbench fills, which is the opposite of the w2a8 row's null hook: there
* the describable byte count is the trap, here it is the point. */
/* --- r3d_gemm_fp8a8_tiled.hip: the quantised GEMM above the decode heights, and the reader for
* the container's fp8 weight: codes and per-128x128 scale as two planes behind `b_scale`. The
* reference's own gemm_nt_q hook answers nothing for this dtype -- ref_layout_gemm_q reads zp_grid,
* and zp_grid has no fp8a8 entry -- which is why the row carries its own. */
* the container's fp8 weight: codes and per-128x128 scale as two planes behind `b_scale`. The row
* carries its own layout hook because the reference's gemm_nt_q hook answers nothing for this
* dtype (ref_layout_gemm_q reads zp_grid, which has no fp8a8 entry). */
int r3d_rad_gemm_nt_q_fp8_tiled (const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_w2a8_tiled (const RadArgs* a, RadStream s);
extern "C" int r3d_layout_gemm_q_fp8_weight(const RadParam*, int, int, const RadEncoding*,
const int*, const RadTensor*, int, RadLayout*);
/* --- r3d_gemm_mxfp4a8.hip: the OCP-MXFP4 weight against the fp8 activation, both heights. The
* weight is two plain u8 planes -- e2m1 codes [N, K/2] and the e8m0 scale [N, K/32] -- so the row
* reads them in place and carries no layout hook; the shape hook is its own because the weight's
* two planes are not the fp8 grid's E4M3 codes and block scale. */
* weight is two plain u8 planes (e2m1 codes [N, K/2], e8m0 scale [N, K/32]) read in place, so the
* row has no layout hook. Its shape hook is separate because these planes are not the fp8 grid's
* E4M3 codes and block scale. */
int r3d_rad_gemm_nt_q_mxfp4a8_m16 (const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_mxfp4a8_tiled(const RadArgs* a, RadStream s);
/* --- r3d_gemm_inta8.hip: the symmetric int4 and int8 weight grids at decode heights. The weight
* is signed codes (I4, two a byte, or I8, one a byte) against a plain f16 scale per (row, 128 of
* K) -- no zero point and no a_sum, so both planes are read in place and the rows carry no layout
* hook. */
* is signed codes (I4 two per byte, or I8) with a plain f16 scale per (row, 128 of K). No zero
* point and no a_sum, so both planes are read in place and the rows have no layout hook. */
int r3d_rad_gemm_nt_q_w4a8_m16(const RadArgs* a, RadStream s);
int r3d_rad_gemm_nt_q_w8a8_m16(const RadArgs* a, RadStream s);
int r3d_shape_gemm_nt_q_w4a8(const RadParam* p, int n_p, int operand, RadOpdDesc* out);
int r3d_shape_gemm_nt_q_w8a8(const RadParam* p, int n_p, int operand, RadOpdDesc* out);
/* The three writers that go with the three plane hooks, one per row, each delegating to
* rad_planes_relayout: the loader converts a quantised weight into the joined operand the plan names
* at load, and only the row that reads it can say how. See abi/rad_abi.h. */
/* The relayout writers for the three layout hooks, each delegating to rad_planes_relayout. The
* loader converts a quantised weight into the joined operand the plan names, and only the row that
* reads it can say how. See abi/rad_abi.h. */
extern "C" int r3d_relayout_logits_head(const RadParam*, int, int, const RadEncoding*, const int*,
const RadTensor*, int, void*, int64_t);
extern "C" int r3d_relayout_gemm_q_fp8_weight(const RadParam*, int, int, const RadEncoding*,
@@ -267,18 +259,22 @@ extern "C" int r3d_relayout_gemm_q_fp8_weight(const RadParam*, int, int, const R
extern "C" int r3d_relayout_gemm_nt_q_w2a8(const RadParam*, int, int, const RadEncoding*,
const int*, const RadTensor*, int, void*, int64_t);
/* --- r3d_vocab_bf16.hip: the vocabulary projection, both heights. Its shape hook
* (r3d_shapes.cpp) transcribes ref_logits_gemm_shape, three plain tensors with nothing joined, so
* the band the engine declares is the band kbench fills. */
int r3d_rad_logits_gemm_bf16 (const RadArgs* a, RadStream s);
/* The head's reader: `output.weight` at a llama_dense_fp8 checkpoint is E4M3 codes and a bf16 scale
* per 128x128 block, stored as two container planes behind the one `lm_head` operand, and the mapped
* tier will not place a weight a loaded library cannot read in place. Transcribed from
* ref_layout_head (libref's own logits row carries that hook), with the statics it uses inlined
* beside it. It moves no byte: a round-trip through its relayout writer (above) reproduces the
* planes byte for byte, and that writer exists for the round-trip, not for a move. */
/* The head's layout hook: `output.weight` at a llama_dense_fp8 checkpoint is E4M3 codes and a bf16
* scale per 128x128 block, stored as two container planes behind the one `lm_head` operand, and the
* mapped tier does not place a weight a loaded library cannot read in place. Transcribed from
* ref_layout_head, with the statics it uses inlined. It moves no bytes: a round-trip through its
* relayout writer (above) reproduces the planes exactly, and the writer exists for that
* round-trip. */
extern "C" int r3d_layout_logits_head(const RadParam*, int, int, const RadEncoding*,
const int*, const RadTensor*, int, RadLayout*);
int r3d_rad_gemm_nt_bf16_tiled (const RadArgs* a, RadStream s);
int r3d_shape_logits_gemm_bf16 (const RadParam*, int, int, RadOpdDesc*);
/* --- r3d_model_bf16.hip: the fused MLP activation and the fused norm-quantiser --- */
int r3d_rad_silu_mul (const RadArgs* a, RadStream s);
int r3d_rad_rmsnorm_quant_fp8 (const RadArgs* a, RadStream s);
int r3d_shape_rmsnorm_quant_fp8 (const RadParam*, int, int, RadOpdDesc*);