radiance 1.12.0

New models:
- Fish Audio drama-3: speech with speaker tags and inline direction, voices cloned from reference
  clips (the `references` field of /v1/audio/speech and the streaming session), two cards
- Gemma 4 E2B/E4B (KV-shared layers, per-layer embeddings, clipped vision linears), with
  NVIDIA-Nemotron-3.5-Bolt-E4B in bf16 with DFlash and vision on one card, and E4B recipes

Speed:
- MXFP4 GEMMs for one to 64 rows and a tiled prefill GEMM at TN=4 from 1024 rows: the 27B MXFP4
  with DFlash2 decodes about 1% faster at c1, 5% at c4 and 14% at c16
- The fp8 and int8 LM heads read their weight once for 65 to 128 rows
- A prefill step of one sequence runs in two pieces on a second lane at two ranks (qwen35_fp8,
  gemma3): a 45K-token prompt on the 27B fp8 in 15.1 s instead of 16.2 s
- Gemma 3's fused all-reduce junctions also under a lossy wire
- --draft-short-from N: a block drafter runs its shorter block from N decoding sequences on
  (off by default; with 8 on the 27B MXFP4: c8 +12%, c16 +18%, c64 +32%, c1 unchanged)
- --tp-attn-split rows: GLM-5.3-Flash's MLA attention split by rows over the ranks, 18 to 21%
  faster prefill; lossy, `heads` stays the default
- --draft-coupling on: Qwen3.8-Flash-Next's MTP drafter samples its proposals from its reranked
  top-8 and the target's draw is coupled to it; pays at high temperatures (c1 at T 1.0: 155 ->
  178 tok/s), costs at low ones; off by default

Features:
- Edited prompts on windowed models (Gemma 4) reuse their prefix: periodic window snapshots, and
  snapshot-backed prefix KV kept across recomputes (an edited tail on Gemma 4 31B: 96 s -> 2.6 s)
- DELETE /sessions/<label> and DELETE /sessions?id=<id> forget one stored conversation
- --state-cache-dtype f16: the delta-net state cache at half the memory (qwen35 plugins; lossy)

Fixes:
- A browser's CORS preflight allows DELETE

Changes: Plugin ABI 27: out-of-tree plugins must be rebuilt. The environment switches the PRs
added are flags now (--tp-attn-split, --draft-coupling, --state-cache-dtype).
This commit is contained in:
137 files changed
+12959 -1126

No files matched your search

+55 -5
View File
@@ -130,6 +130,11 @@ struct Dflash2 {
/* Bytes of the next GEMM's weight read into the cache beside each all-reduce of the query
* pass (prefetch_beside, rad_arch.h); 0 reads none. */
int64_t prefetch = 0;
/* Also declare the short block's query pass (kShortBlock rows) for --draft-short-from; an
* architecture that does not call rad_drafter_short_block leaves it off and its graph as
* it was. */
int short_block = 0;
int64_t steps() const { return block - 1; }
int64_t ng(int64_t n_embd) const { return group ? n_embd / group : 0; }
/* The kernel projection emits [2, taps, NG] per token (prepare's set, then finish's);
@@ -260,6 +265,10 @@ struct Dflash2 {
rad_op op_gu[MAX_LAYERS] = {}, op_dn[MAX_LAYERS] = {};
rad_op op_gug[MAX_LAYERS] = {}; /* the gate_up|silu|quant fold; 0 when nothing serves it */
rad_op op_aconv[MAX_LAYERS] = {}, op_fconv[MAX_LAYERS] = {};
/* The short block's (block_lo rows a sequence): the convolutions mask at the block's first row
* and the selector strides by it, so each has an op of its own; every other op is per row. */
rad_op op_aconv_lo[MAX_LAYERS] = {}, op_fconv_lo[MAX_LAYERS] = {}, op_sel_lo = 0;
int64_t block_lo = 0;
rad_op op_qrope = 0, op_krope = 0, op_store = 0, op_attn = 0;
rad_op op_act = 0, op_ar = 0, op_add = 0, op_final = 0;
/* The residual add folded into the norm after it (add_rmsnorm), issued in place of op_add and
@@ -287,6 +296,9 @@ struct Dflash2 {
static constexpr int64_t kRerankR = 32;
int64_t top_w = 0; /* the coarse top-K's width: kRerankR or sel_topk */
rad_op op_hp = 0, op_sel = 0;
/* The short block: kShortBlock rows (depth 3, the window that pays at many sequences), when
* the drafter's own block is longer (rad_drafter_short_block). */
static constexpr int64_t kShortBlock = 4;
int declare(RadBuilder* b, Names& nm, const Geom& geom, const Config& c, int base_layer,
rad_kvgroup group, rad_weight tok_embd, const char* ck_prefix,
@@ -695,7 +707,26 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
* layers. Planned from those alone, its range would end before the coefficients' begins and
* the plan could lay one over the other. Read by the last convolution as well, it is live
* wherever the coefficients are. */
block_lo = cfg.short_block && cfg.block > kShortBlock ? kShortBlock : 0;
for (int64_t l = 0; block_lo && l < g.n_layer; ++l) {
const int i = (int)l;
op_aconv_lo[i] = rw(b, RAD_OP(b, "dflash_conv",
RAD_PARAMS(RAD_RANGE("T", 1, qrows), RAD_INT("hidden_size", g.n_embd),
RAD_INT("taps", cfg.taps), RAD_INT("group_size", cfg.group),
RAD_INT("NG", NG), RAD_INT("block_size", block_lo),
RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_acb[i])),
{w.h, w.coef}, {w.h2});
op_fconv_lo[i] = rw(b, RAD_OP(b, "dflash_conv",
RAD_PARAMS(RAD_RANGE("T", 1, qrows), RAD_INT("hidden_size", g.n_embd),
RAD_INT("taps", cfg.taps), RAD_INT("group_size", cfg.group),
RAD_INT("NG", NG), RAD_INT("block_size", block_lo),
RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_fcb[i])),
{w.h, w.coef}, {w.h2});
}
if (rad_op_reads(b, op_fconv[g.n_layer - 1], &w.attn, 1) < 0) return RAD_E_INVAL;
if (block_lo && rad_op_reads(b, op_fconv_lo[g.n_layer - 1], &w.attn, 1) < 0) return RAD_E_INVAL;
op_qrope = rope(qrows, g.n_head, w.q);
op_krope = rope(qrows, g.n_head_kv, w.k);
op_store = rw(b, RAD_OP(b, "kv_store",
@@ -909,6 +940,14 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
RAD_INT("anchor_stride", cfg.block), RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_pred, w_succ)),
{w.cand, w.unary, w.hp}, {w.tokens});
if (block_lo)
op_sel_lo = rw(b, RAD_OP(b, "dflash_select",
RAD_PARAMS(RAD_RANGE("M", 1, g.max_seqs), RAD_INT("steps", block_lo - 1),
RAD_INT("top_k", cfg.sel_topk), RAD_INT("rank", cfg.sel_rank),
RAD_INT("n_vocab", g.n_vocab_all),
RAD_INT("anchor_stride", block_lo), RAD_STR("dtype", g.dtype)),
RAD_WEIGHTS(w_pred, w_succ)),
{w.cand, w.unary, w.hp}, {w.tokens});
/* The reads beside the all-reduces, after every weight they read is declared. */
if (op_ar && cfg.prefetch > 0)
@@ -983,6 +1022,17 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
const int64_t NG = cfg.ng(g.n_embd);
const int64_t half = cfg.taps * NG; /* prepare's coefficients, then finish's */
/* The block this pass was staged at: every drafting sequence carries the same number of rows,
* the drafter's own block or its short one (rad_drafter_short_block). */
const int64_t blk = batch->n_seq > 0 && T % batch->n_seq == 0 ? T / batch->n_seq : 0;
const bool lo = block_lo > 0 && blk == block_lo;
if (!lo && blk != cfg.block) {
rad_step_fail(c, "dflash2: a query pass staged at a block this drafter has no ops for");
return;
}
const rad_op* aconv = lo ? op_aconv_lo : op_aconv;
const rad_op* fconv = lo ? op_fconv_lo : op_fconv;
RAD_ISSUE_N(c, op_embed, T, praw(batch->token_ids, RAD_I32, T), RAD_W(w_tok), brows(w.x, T));
if (op_embed_ar)
RAD_ISSUE_N(c, op_embed_ar, (int64_t)T * g.n_embd, brows(w.x, T), RAD_NONE);
@@ -1005,7 +1055,7 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
/* ---- attention, wrapped in the two halves of one convolution */
norm(op_anorm[i], op_aan[i], w_anorm[i]);
RAD_ISSUE_N(c, op_acoef[i], T, brows(w.h, T), RAD_W(w_acp[i]), brows(w.coef, T));
RAD_ISSUE_N(c, op_aconv[i], T, brows(w.h, T), bcol(w.coef, 0, half, T),
RAD_ISSUE_N(c, aconv[i], T, brows(w.h, T), bcol(w.coef, 0, half, T),
wrow_slice(w_acb[i], 0, 1, cfg.taps * g.n_embd), brows(w.h2, T));
RAD_ISSUE_N(c, op_qh2, T, brows(w.h2, T), brows(w.h2q, T), brows(w.h2s, T));
@@ -1044,14 +1094,14 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
* replicated norm, so either order gives the same result; reducing first keeps x's
* update agreed across ranks. */
if (op_ar) RAD_ISSUE_N(c, op_ar, T * g.n_embd, brows(w.h, T), RAD_NONE);
RAD_ISSUE_N(c, op_aconv[i], T, brows(w.h, T), bcol(w.coef, half, half, T),
RAD_ISSUE_N(c, aconv[i], T, brows(w.h, T), bcol(w.coef, half, half, T),
wrow_slice(w_acb[i], 1, 1, cfg.taps * g.n_embd), brows(w.h2, T));
add_pending = true;
/* ---- the feed-forward, wrapped in the other convolution */
norm(op_fnorm[i], op_afn[i], w_fnorm[i]);
RAD_ISSUE_N(c, op_fcoef[i], T, brows(w.h, T), RAD_W(w_fcp[i]), brows(w.coef, T));
RAD_ISSUE_N(c, op_fconv[i], T, brows(w.h, T), bcol(w.coef, 0, half, T),
RAD_ISSUE_N(c, fconv[i], T, brows(w.h, T), bcol(w.coef, 0, half, T),
wrow_slice(w_fcb[i], 0, 1, cfg.taps * g.n_embd), brows(w.h2, T));
RAD_ISSUE_N(c, op_qh2, T, brows(w.h2, T), brows(w.h2q, T), brows(w.h2s, T));
if (op_gug[i] && T <= gated_rows) {
@@ -1068,7 +1118,7 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
RAD_W(w_dn[i].w), RAD_W(w_dn[i].s), brows(w.h, T), RAD_NONE, w_dn[i].bref());
for (int j = 0; j < 2; ++j) prefetch_beside(c, op_pff[i][j], pff_w[i][j], T);
if (op_ar) RAD_ISSUE_N(c, op_ar, T * g.n_embd, brows(w.h, T), RAD_NONE);
RAD_ISSUE_N(c, op_fconv[i], T, brows(w.h, T), bcol(w.coef, half, half, T),
RAD_ISSUE_N(c, fconv[i], T, brows(w.h, T), bcol(w.coef, half, half, T),
wrow_slice(w_fcb[i], 1, 1, cfg.taps * g.n_embd), brows(w.h2, T));
add_pending = true;
}
@@ -1107,7 +1157,7 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
}
RAD_ISSUE_N(c, op_hp, S, brows(w.sel_h, S), RAD_W(w_selp), brows(w.hp, S));
RAD_ISSUE_N(c, op_sel, batch->n_seq, bcol(w.cand, 0, cfg.sel_topk, S),
RAD_ISSUE_N(c, lo ? op_sel_lo : op_sel, batch->n_seq, bcol(w.cand, 0, cfg.sel_topk, S),
bcol(w.unary, 0, cfg.sel_topk, S), brows(w.hp, S),
praw(batch->token_ids, RAD_I32, T), RAD_W(w_pred), RAD_W(w_succ),
brows(w.tokens, batch->n_seq));
+119 -5
View File
@@ -3,14 +3,23 @@
* complete heads shard as rows of the shared K/V weight. prepare() exposes the normalized q latent
* for the indexer; finish() consumes the indexer's selection. The caller owns the mHC residual.
*
* Under tensor parallelism the 64 heads split over the ranks (GlmTp::heads): the rows of q_b and
* kv_b, the columns of o, an all_reduce of the output; q_a, kv_a and the latent cache are
* replicated. */
* Under tensor parallelism the head form splits the 64 heads over the ranks (GlmTp::heads): the
* rows of q_b and kv_b, the columns of o, an all_reduce of the output; q_a, kv_a and the latent
* cache are replicated. From GlmTp::kSplitRows a prefill-sized step takes the row form instead
* (Wire::rows, Form::rows): each rank runs its run of the step's rows (GlmTp::run_of) through q_b,
* absorption, attention, expansion and the output projection with all 64 heads, then an
* all_gather lays the runs out as the whole step. The latent cache and the selection are whole on
* every rank already, so the split needs no other exchange. The gather moves half the bytes of
* the head form's all-reduce, and the attention loads each key once for all 64 heads of a row.
* The price is the three projections at full width on every rank (126 MB a layer); RowsWire::q
* unset declares neither them nor the form. */
#ifndef RAD_BLOCK_GLM_MLA_H
#define RAD_BLOCK_GLM_MLA_H
#include "rad_fp8.h"
#include "rad_glm_tp.h"
#include <algorithm>
#include <cmath>
#include <vector>
namespace rad {
namespace arch {
@@ -88,11 +97,28 @@ struct MlaLatent {
};
struct GlmMla {
/* How a prefill-sized step under tensor parallelism runs: `heads` keeps the head form at every
* step size and spares the full-width weights' VRAM; `rows` is the row form. The plugin
* chooses (RadBuildCtx::tp_attn_rows); the block takes the choice through whether it is given
* RowsWire buffers. */
enum class Form { heads, rows };
/* The row form's buffers, `rows_for(max_tok)` rows each. `out` (Wire::out) must hold
* world * rows_for(T) rows, since every rank's run is gathered at full length. */
struct RowsWire {
rad_buf q = 0, q_latent = 0, attn_latent = 0, out = 0;
ActFP8 attn{};
};
struct Wire {
ActFP8 input{}, q_low{}, attn{};
rad_buf q_raw = 0, kv_raw = 0, latent = 0, out = 0;
MlaLatent::Wire core{};
RowsWire rows{};
};
/* The gathered row of the row form: 4096 bf16, so a run is ceil(T / world) rows. */
static constexpr int64_t kOutRowBytes = 4096 * 2;
static int64_t rows_for(int64_t T, int world) {
return GlmTp::run_rows(T, world, kOutRowBytes);
}
Geom g{};
Wire w{};
int layer = 0;
@@ -103,6 +129,10 @@ struct GlmMla {
MlaLatent core{};
rad_weight q_gain = 0, kv_gain = 0;
rad_op op_kv_norm = 0, op_store = 0, op_ar = 0;
LinearFP8 rows_q_b{}, rows_output{};
QuantFP8 rows_quant{};
rad_weight rows_kv_b = 0;
rad_op op_rows_absorb = 0, op_rows_attn = 0, op_rows_expand = 0, op_rows_gather = 0;
int declare(RadBuilder* b, Names& nm, const Geom& geom, int l, const Wire& wire,
const char* prefix, rad_kvgroup group, bool reduce = true,
bool defer_finish = false) {
@@ -160,7 +190,69 @@ struct GlmMla {
GlmTp::mla_width(g.world), RAD_SHARD_COL, grp_layer(layer),
{ nm.ckpt("%s.o_proj.weight", prefix) }, w.attn, w.out));
if (reduce) op_ar = GlmTp::reduce(b, g, w.out);
return op_store && (!(reduce && g.world > 1) || op_ar) ? RAD_OK : RAD_E_INVAL;
if (!op_store || ((reduce && g.world > 1) && !op_ar)) return RAD_E_INVAL;
return reduce ? declare_rows(b, nm, prefix) : RAD_OK;
}
/* Declared whatever the step size, as every TP split here is: arena levels declare again at a
* smaller max_tok and must get the same graph. The gather's message bound is the all-reduce's,
* so both share one exchange instance and its scratch. */
int declare_rows(RadBuilder* b, Names& nm, const char* prefix) {
const auto& r = w.rows;
if (!r.q || g.world < 2) return RAD_OK;
if (!r.q_latent || !r.attn_latent || !r.out || !r.attn.x || r.attn.x == r.q) return RAD_E_INVAL;
const int64_t R = rows_for(g.max_tok, g.world);
const auto wg = grp_layer(layer);
/* Whole views of the head form's container entries: one stored weight each, whose
* encoding (block fp8 at f32 scales, the decoded bf16 kv_b) the views inherit. */
rows_q_b.stored = nm.f("blk.%d.attn_q_b.weight", layer);
RAD_ARCH_TRY(rows_q_b.declare(b, nm, g, nm.f("blk.%d.attn_q_b_rows", layer), 16384, 1536,
RAD_SHARD_NONE, wg, { nm.ckpt("%s.q_b_proj.weight", prefix) },
w.q_low, r.q, R));
rows_kv_b = decl_view(b, nm.f("blk.%d.attn_kv_b_rows.weight", layer),
nm.f("blk.%d.attn_kv_b.weight", layer), nullptr, RAD_BF16,
{ 64 * 2 * 256, 512 }, RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, wg);
if (!rows_kv_b) return RAD_E_INVAL;
auto project = [&](const char* mode, rad_buf in, rad_buf out) {
return rw(b,
RAD_OP(b, "mla_project",
RAD_PARAMS(RAD_RANGE("M", 1, R), RAD_INT("heads", 64),
RAD_INT("head_dim", 256), RAD_INT("latent_dim", 512),
RAD_STR("mode", mode), RAD_STR("dtype", "bf16")),
RAD_WEIGHTS(rows_kv_b)),
{ in }, { out });
};
op_rows_absorb = project("absorb", r.q, r.q_latent);
op_rows_attn =
rw(b,
RAD_OP(b, "mla_attn",
RAD_PARAMS(RAD_RANGE("M", 1, R), RAD_INT("latent_dim", 512),
RAD_INT("heads", 64), RAD_INT("blocks", core.c.blocks),
RAD_INT("block_size", 4), RAD_F64("scale", 1.0 / std::sqrt(256.0)),
RAD_STR("dtype", "bf16")),
RAD_NOWEIGHTS),
{ r.q_latent, w.core.selected, w.core.length }, { r.attn_latent });
op_rows_expand = project("expand", r.attn_latent, r.attn.x);
RAD_ARCH_TRY(rows_quant.declare(b, g, r.attn, 16384));
rows_output.stored = nm.f("blk.%d.attn_output.weight", layer);
RAD_ARCH_TRY(rows_output.declare(b, nm, g, nm.f("blk.%d.attn_output_rows", layer), 4096,
16384, RAD_SHARD_NONE, wg,
{ nm.ckpt("%s.o_proj.weight", prefix) }, r.attn, r.out,
R));
op_rows_gather = rw(b,
RAD_OP(b, "all_gather",
RAD_PARAMS(RAD_INT("world_size", g.world),
RAD_RANGE("numel", 4096, g.max_tok * 4096),
RAD_STR("dtype", "bf16")),
RAD_NOWEIGHTS),
{ r.out }, { w.out });
return op_rows_absorb && op_rows_attn && op_rows_expand && op_rows_gather ? RAD_OK
: RAD_E_INVAL;
}
/* From the TP split threshold, and while the last rank's run is not empty (always at that
* threshold for up to 8 ranks); the same answer on every rank, as the gather needs. */
bool rows_take(int64_t T) const {
return op_rows_gather && GlmTp::splits(T, g.world) &&
(g.world - 1) * rows_for(T, g.world) < T;
}
void prepare(RadCtx* ctx, const RadBatch* batch) const {
const auto* kb = kv_batch(batch, kv);
@@ -173,17 +265,39 @@ struct GlmMla {
kv_a.step(ctx, w.input, w.kv_raw, T);
q_norm.step(ctx, T);
RAD_ISSUE_N(ctx, op_kv_norm, T, brows(w.kv_raw, T), RAD_W(kv_gain), brows(w.latent, T));
q_b.step(ctx, w.q_low, w.core.q, T);
if (!rows_take(T)) q_b.step(ctx, w.q_low, w.core.q, T);
RAD_ISSUE_N(ctx, op_store, T, bcol(w.latent, 0, 256, T), bcol(w.latent, 256, 256, T),
praw(kb->slot_mapping, RAD_I32, T), kv_cache(kv, layer));
}
void finish(RadCtx* ctx, const RadBatch* batch) const {
const int64_t T = batch->n_tok;
if (rows_take(T)) {
finish_rows(ctx, T);
return;
}
core.step(ctx, T);
attn_quant.step(ctx, T);
output.step(ctx, w.attn, w.out, T);
if (op_ar) RAD_ISSUE_N(ctx, op_ar, T * 4096, brows(w.out, T), RAD_NONE);
}
/* This rank's rows [first, first + n) end to end; the last rank's run may be short, and the
* gather sends its unwritten tail rows, which land past T. */
void finish_rows(RadCtx* ctx, int64_t T) const {
const auto& r = w.rows;
const GlmTp::Run run = GlmTp::run_of(T, g.world, g.rank, kOutRowBytes);
const int64_t first = run.first, n = run.rows;
rows_q_b.step(ctx, w.q_low, r.q, T, first, n, 0);
RAD_ISSUE_N(ctx, op_rows_absorb, n, brows(r.q, n), RAD_W(rows_kv_b), brows(r.q_latent, n));
RAD_ISSUE_N(ctx, op_rows_attn, n, brows(r.q_latent, n), kv_cache(kv, layer),
brow_slice(w.core.selected, first, n, core.c.blocks),
brow_slice(w.core.length, first, n, 1), brows(r.attn_latent, n));
RAD_ISSUE_N(ctx, op_rows_expand, n, brows(r.attn_latent, n), RAD_W(rows_kv_b),
brows(r.attn.x, n));
rows_quant.step(ctx, n);
rows_output.step(ctx, r.attn, r.out, n);
RAD_ISSUE_N(ctx, op_rows_gather, run.run * 4096, brows(r.out, run.run),
brows(w.out, g.world * run.run));
}
};
}
} // namespace rad::arch
+40
View File
@@ -73,6 +73,7 @@
#include "rad_block_hc.h"
#include "rad_block_moe_fp8.h"
#include "rad_block_mtp_fp8.h" /* mtp_draft_head_q2(): one reading of the 2-bit head */
#include "rad_spechub.h" /* RAD_MTP_COUPLE_*: the coupling wire */
#include "rad_qsa.h"
#include "rad_block_vit.h"
@@ -108,6 +109,9 @@ struct MtpHcBlock {
/* Vocab-parallel pairs, declared only when the head is sharded: (int32 id, f32 value)
* pairs stored as f32, this rank's top-R and the all-gathered world * R. */
rad_buf dpair = 0, dgath = 0;
/* --draft-coupling: [max_seqs] draws and [depth, max_seqs] states, both PERSIST across
* the serial passes (round 1 resets the logical stream, not the plane). */
rad_buf couple_draws = 0, couple_state = 0;
AttnGatedFP8::Wire attn{};
MoeFP8::Wire mlp{};
QsaIndexer::Wire qsa{};
@@ -158,6 +162,9 @@ struct MtpHcBlock {
rad_op op_dsel = 0, op_dback = 0;
rad_op op_logits = 0, op_dquant = 0, op_dlogits = 0, op_dtopk = 0, op_drerank = 0;
rad_op op_dgather = 0, op_dmerge = 0;
/* --draft-coupling: one op a round. The ABI freezes `round` as a parameter, so a round
* cannot be an operand and each gets its own declared op. */
rad_op op_couple[RAD_MTP_COUPLE_MAX_ROUNDS] = {};
/* rad_arch.h's vocab-head rule, asked through the block by whoever sizes `dlog` and the pair
* planes. */
@@ -422,6 +429,25 @@ inline int MtpHcBlock::declare(RadBuilder* b, Names& nm, const Geom& geom, int l
if (!op_dgather || !op_dmerge) return RAD_E_INVAL;
}
if (!op_dquant || !op_dlogits || !op_dtopk) return RAD_E_INVAL;
/* The coupled proposal: one op a round, after the final rerank/merge, over the shortlist
* whose column 0 is the proposal. Linear chains only: x is a token, while a tree reads
* column 0 as a parent index. The engine refuses other drafters; this check keeps a
* mismatched declaration from writing tokens into a tree plane. */
if (w.couple_draws || w.couple_state) {
if (!w.couple_draws || !w.couple_state || depth < 1 ||
depth > RAD_MTP_COUPLE_MAX_ROUNDS || !op_drerank || (g.world > 1 && !op_dmerge))
return RAD_E_UNSUPPORTED;
for (int round = 1; round <= depth; ++round) {
op_couple[round - 1] = rw(b, RAD_OP(b, "mtp_couple_propose",
/* The whole vocabulary: `row_topk` reports global ids and the merge keeps
* them, while `g.n_vocab` is this rank's shard. */
RAD_PARAMS(RAD_RANGE("M", 1, g.max_seqs), RAD_INT("n_vocab", g.n_vocab_all),
RAD_INT("round", round), RAD_INT("max_rounds", depth)),
RAD_NOWEIGHTS),
{ w.didx, w.dval, w.couple_draws }, { w.didx, w.couple_state });
if (!op_couple[round - 1]) return RAD_E_INVAL;
}
}
}
/* Keep the carry `hin` live through the head's last op: it is written before the mixer and
* lm_head run, and the planner could otherwise give its bytes to them (silently lowering
@@ -429,6 +455,7 @@ inline int MtpHcBlock::declare(RadBuilder* b, Names& nm, const Geom& geom, int l
{
rad_op last = op_logits;
if (q2) last = op_dmerge ? op_dmerge : op_drerank ? op_drerank : op_dtopk;
if (op_couple[0]) last = op_couple[depth - 1];
if (rad_op_reads(b, last, &w.hin, 1) < 0) return RAD_E_INVAL;
}
return RAD_OK;
@@ -524,6 +551,19 @@ inline void MtpHcBlock::step(RadCtx* c, const RadBatch* batch) const {
RAD_ISSUE_N(c, op_drerank, L, brows(w.hout, L), RAD_W(w_lm), brows(w.didx, L),
brows(w.didx, L), brows(w.dval, L), RAD_NONE);
}
/* After the final reranked shortlist: column 0 is what ADV_TAKE reads, and a sampled row
* replaces it with its x. Round 1 runs in the history pass (r < 0), later rounds in their
* own passes. */
if (op_couple[0]) {
const int round = r < 0 ? 1 : r;
if (round < 1 || round > depth) {
rad_step_fail(c, "MTP coupled round exceeds the declared draft depth");
return;
}
RAD_ISSUE_N(c, op_couple[round - 1], L, brows(w.didx, L), brows(w.dval, L),
praw(batch->seq_ids, RAD_I32, batch->n_seq),
brows(w.couple_draws, L), RAD_B(w.couple_state));
}
} else {
RAD_ISSUE_N(c, op_logits, L, brows(w.hout, L), RAD_W(w_lm), brows(w.logits, L));
}
+47 -14
View File
@@ -762,6 +762,10 @@ struct LinearFP8 {
* this is set; otherwise the linear reads unwritten arena bytes. */
bool reads_x = false;
bool mapped = false; /* probe() made the name map; declare() does not make it again */
/* The stored weight this linear's views take when it is not `<base>.weight`: a second linear
* over one container entry, e.g. a whole projection beside its tensor-parallel slice. Set
* before declare(); no name map is made, and only block fp8 is served this way. */
const char* stored = nullptr;
/* The weight's access class (rad_builder.h): read every pass by default; a linear run once a
* request (an encoder's) says so, which lets placement keep it off the card. Set before
* declare(). */
@@ -815,8 +819,10 @@ struct LinearFP8 {
rad_weight decl_dense(RadBuilder* b, Names& nm, const char* base, const char* wn, const RadEncoding& enc,
int64_t K,
RadWeightGroup grp);
/* Rows [r0, r0 + rows) of the input into the same rows of `y`, or from row `y0` of `y` when
* that is set: a rank's run of a step's rows written to a buffer sized for the run. */
void step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, int64_t r0 = 0,
int64_t rows = 0) const;
int64_t rows = 0, int64_t y0 = -1) const;
/* A span per stacked row part (rad_weight_shard_span_parts), in weight rows; the scale plane
* gets the same spans in its rows. Call after declare(). With a 1/128 plane every span and
* total must be whole scale blocks. */
@@ -1054,9 +1060,10 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
/* Name map first: the weight's encoding, looked up through it, picks the branch below. */
const char* wn = nm.f("%s.weight", base);
if (!mapped) RAD_ARCH_TRY(map_linear(b, wn, src));
if (!mapped && !stored) RAD_ARCH_TRY(map_linear(b, wn, src));
const char* sw = stored ? stored : wn;
RadEncoding enc{};
const bool known = weight_enc(b, wn, &enc);
const bool known = weight_enc(b, sw, &enc);
const bool plain = known && rad_enc_is(&enc, "plain") && enc.n_planes == 1 &&
enc.plane[0].dtype == RAD_BF16;
@@ -1066,6 +1073,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
* constraints. */
bf16 = g.w_bf16 || plain;
if (bf16) {
if (stored) {
fprintf(stderr, "radiance: '%s' views '%s', which only a block-fp8 linear "
"may\n", wn, stored);
return RAD_E_INVAL;
}
if (known && !plain) {
char en[256];
rad_enc_format(&enc, en, sizeof en);
@@ -1105,6 +1117,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
const bool rot8 = known && linear_is_w8h(enc);
i8 = known && (linear_is_w8(enc) || rot8);
if (i8) {
if (stored) {
fprintf(stderr, "radiance: '%s' views '%s', which only a block-fp8 linear "
"may\n", wn, stored);
return RAD_E_INVAL;
}
if (a.q8_fed && rot8 != a.q8_rot) {
fprintf(stderr, "radiance: '%s' is a%s int8 weight and its input is fed codes its "
"producer wrote %s\n", wn, rot8 ? " rotated" : " plain",
@@ -1164,6 +1181,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
* codes, and (scale, zero) as `b_scale`. */
paro5 = known && linear_is_paro_w5(enc);
if (paro5) {
if (stored) {
fprintf(stderr, "radiance: '%s' views '%s', which only a block-fp8 linear "
"may\n", wn, stored);
return RAD_E_INVAL;
}
const int bits = enc.plane[0].dtype == RAD_U4 ? 4 : 5;
if (!a.x) {
fprintf(stderr, "radiance: '%s' is a rotated %d-bit weight, rotated from its input's "
@@ -1230,6 +1252,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
* whole 128s, the scale group. */
w4 = known && linear_is_w4(enc);
if (w4) {
if (stored) {
fprintf(stderr, "radiance: '%s' views '%s', which only a block-fp8 linear "
"may\n", wn, stored);
return RAD_E_INVAL;
}
if (!a.x) {
fprintf(stderr, "radiance: '%s' is a 4-bit weight, read from its input's bf16 plane, "
"and its input has none\n", wn);
@@ -1300,6 +1327,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
paro = known && linear_is_paro_mxfp4(enc);
mx = known && (linear_is_mxfp4(enc) || paro);
if (mx) {
if (stored) {
fprintf(stderr, "radiance: '%s' views '%s', which only a block-fp8 linear "
"may\n", wn, stored);
return RAD_E_INVAL;
}
if (paro) {
/* The rotation is applied to the activation, so this linear needs the input's bf16
* plane (probe() set reads_x) and quantises it itself. */
@@ -1411,10 +1443,10 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
f32_scale = fp8_scale && fp8_scale->dtype == RAD_F32;
/* One stored weight, two operands: the codes and scale plane of `<base>.weight`, block fp8 in
* the checkpoint or made so by rad-convert's recipe. */
w = decl_view(b, wn, nullptr, "codes", RAD_F8E4M3, { N, K },
w = decl_view(b, wn, stored, "codes", RAD_F8E4M3, { N, K },
access, shard, grp, rp.w, rp.n);
ws_row_div = RAD_FP8_BLOCK;
ws = decl_view(b, sn, wn, "scale", f32_scale ? RAD_F32 : RAD_BF16,
ws = decl_view(b, sn, sw, "scale", f32_scale ? RAD_F32 : RAD_BF16,
{ fp8_blocks(N), fp8_blocks(K) }, access, shard, grp, rp.s, rp.n);
if (!w || !ws) return RAD_E_INVAL;
/* An uneven slice; the scale plane takes the same slice in blocks. */
@@ -1446,10 +1478,11 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
* asymmetric integer and mxfp4 grids) are passed as RAD_NONE when unused, since the runtime checks
* the operand count against the schema (core/runtime/issue.cpp). */
inline void LinearFP8::step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, int64_t r0,
int64_t rows) const {
int64_t rows, int64_t y0) const {
if (rows <= 0) rows = T - r0;
const int64_t yr = y0 < 0 ? r0 : y0;
if (bf16) {
RAD_ISSUE_N(c, op, rows, brow_slice(a.x, r0, rows, K), RAD_W(w), brow_slice(y, r0, rows, N));
RAD_ISSUE_N(c, op, rows, brow_slice(a.x, r0, rows, K), RAD_W(w), brow_slice(y, yr, rows, N));
return;
}
if (i8) {
@@ -1458,7 +1491,7 @@ inline void LinearFP8::step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, in
brow_slice(a.s8, r0, rows, K / RAD_FP8_BLOCK));
RAD_ISSUE_N(c, op, rows, brow_slice(a.q8, r0, rows, K),
brow_slice(a.s8, r0, rows, K / RAD_FP8_BLOCK),
RAD_W(w), RAD_W(ws), brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
RAD_W(w), RAD_W(ws), brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
return;
}
/* The 4-bit weight's copies of the input start at their buffers' first row: they live only
@@ -1468,13 +1501,13 @@ inline void LinearFP8::step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, in
brow_slice(a8s, 0, rows, K / RAD_FP8_BLOCK));
RAD_ISSUE_N(c, op2, rows, brow_slice(a8q, 0, rows, K),
brow_slice(a8s, 0, rows, K / RAD_FP8_BLOCK), RAD_W(w), RAD_W(ws),
brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
return;
}
if (w4) {
RAD_ISSUE_N(c, op_a16, rows, brow_slice(a.x, r0, rows, K), brow_slice(a16, 0, rows, K));
RAD_ISSUE_N(c, op, rows, brow_slice(a16, 0, rows, K), RAD_NONE, RAD_W(w), RAD_W(ws),
brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
return;
}
if (paro5 && rot_split && rows > rot_split) {
@@ -1483,14 +1516,14 @@ inline void LinearFP8::step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, in
brow_slice(rot_s2, r0, rows, rot_parts * (K / RAD_FP8_BLOCK)));
RAD_ISSUE_N(c, op2, rows, brow_slice(rot_q2, r0, rows, rot_parts * K),
brow_slice(rot_s2, r0, rows, rot_parts * (K / RAD_FP8_BLOCK)),
RAD_W(w), RAD_W(ws), brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
RAD_W(w), RAD_W(ws), brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
return;
}
if (paro5) {
RAD_ISSUE_N(c, op_rot, rows, brow_slice(a.x, r0, rows, K), RAD_W(rot_pairs),
RAD_W(rot_angle), RAD_W(rot_scale), brow_slice(rot_q, r0, rows, rot_parts * K));
RAD_ISSUE_N(c, op, rows, brow_slice(rot_q, r0, rows, rot_parts * K), RAD_NONE,
RAD_W(w), RAD_W(ws), brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
RAD_W(w), RAD_W(ws), brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
return;
}
if (mx) {
@@ -1504,12 +1537,12 @@ inline void LinearFP8::step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, in
brow_slice(as, r0, rows, ak / RAD_FP8_BLOCK));
RAD_ISSUE_N(c, op, rows, brow_slice(aq, r0, rows, ak),
brow_slice(as, r0, rows, ak / RAD_FP8_BLOCK),
RAD_W(w), RAD_W(ws), brow_slice(y, r0, rows, N), RAD_NONE, RAD_W(wref));
RAD_W(w), RAD_W(ws), brow_slice(y, yr, rows, N), RAD_NONE, RAD_W(wref));
return;
}
RAD_ISSUE_N(c, op, rows, brow_slice(a.q, r0, rows, K),
brow_slice(a.s, r0, rows, K / RAD_FP8_BLOCK),
RAD_W(w), RAD_W(ws), brow_slice(y, r0, rows, N), RAD_NONE, RAD_NONE);
RAD_W(w), RAD_W(ws), brow_slice(y, yr, rows, N), RAD_NONE, RAD_NONE);
}
/* ================================================== an fp8 weight with no op of its own
+4 -3
View File
@@ -13,9 +13,10 @@
* row-interleaved all_gather, bit for bit the replicated projection
*
* The one rule for a run: ceil(T / world) rows, rounded up to whole 16-byte words of the gathered
* row, because an all_gather moves whole words. The indexer gathers one i32 length a row beside
* its page tables, so its runs are multiples of four rows. The last rank's run may be short, or
* lie wholly past a small step (`run_of`). */
* row, because an all_gather moves whole words. The MLA gathers 4096-wide bf16 rows, so its runs
* are ceil(T / world); the indexer gathers one i32 length a row beside its page tables, so its
* runs are multiples of four rows. The last rank's run may be short, or lie wholly past a small
* step (`run_of`). */
#ifndef RAD_GLM_TP_H
#define RAD_GLM_TP_H
#include "rad_arch.h"
-42
View File
@@ -1,42 +0,0 @@
#pragma once
// RADIANCE_PREFILL_PIPELINE: whether an architecture with a pipelined prefill (a prefill step of one
// sequence in two pieces, the collectives between blocks on the second lane, beside the other piece's
// compute) uses it.
//
// auto (or unset) at two ranks, where it was measured (Qwen3.8-27B 41k prefill -6.6 %,
// TranslateGemma-27B 6k -4.7 % at a 2048 chunk, bit for bit the serial step);
// on (1, true) also at three, four and eight ranks: libr4d has the narrow `overlap` two-shot
// all-reduce there (the wide rows' entry points at a launch that leaves the CUs to
// compute), but the step has not been measured on such hardware;
// off (0, false) never.
//
// Any other rank count has no narrow row, and a wide all-reduce beside the GEMMs ate the whole gain at
// two (it slows the GEMM 1.45-2.1x), so those stay serial. Past two ranks only the two-shot band is
// narrow: a piece small enough for the one-shot band (at most 524288 elements, e.g. 512 rows of a model
// 1024 wide) still gets the wide one-shot; and eight ranks have no lossy wire, so `on` there pipelines
// on the exact wire only.
#include "rad_arch.h"
#include <cstdlib>
#include <cstring>
namespace rad::arch {
inline bool prefill_pipeline(RadBuilder* b, int world, const char* who) {
const char* e = std::getenv("RADIANCE_PREFILL_PIPELINE");
auto is = [&](const char* v) { return e && !std::strcmp(e, v); };
const bool on = is("on") || is("1") || is("true"), off = is("off") || is("0") || is("false");
if (e && *e && !on && !off && !is("auto"))
rad_note(b, "%s: RADIANCE_PREFILL_PIPELINE=%s is not auto, on or off; taken as auto", who, e);
if (off || world < 2) return false;
if (world == 2) return true;
if (on && (world == 3 || world == 4 || world == 8)) {
rad_note(b, "%s: RADIANCE_PREFILL_PIPELINE=on allows the pipelined prefill at %d ranks, not "
"yet measured on such hardware (it still needs what the architecture checks)",
who, world);
return true;
}
return false;
}
} // namespace rad::arch