arch, data/recipes, libr4d: the 31B's prefill overlap, q|k|v as one linear, RedHatAI's DFlash2, its fc split

The 31B's prefill steps of 1024 rows or more run as two slices with each slice's all-reduces
beside the other's compute; q, k and v as one linear where the container holds them so; the 31B
serves RedHatAI's DFlash2 speculator; DFlash2's fc projection is split over the ranks, bit for bit.

Squashed from:

- arch/gemma4_bf16: a prefill step in two slices, each slice's reductions on the second lane
- arch/gemma4_bf16: q, k and v as one linear where the container holds them so
- data/recipes: the 31B -df recipes make q, k and v one linear (blk.*.attn_qkv)
- arch/gemma4: the 31B serves RedHatAI's DFlash2 speculator (gemma-4-31B-it-speculator.dflash2)
- libr4d: gemm_nt_q takes split_n, and all_gather lands rows at a wider output pitch
- arch/common: DFlash2's fc split over the ranks as windows of block-aligned rows, bit for bit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-21 09:48:20 +02:00
1 parent bdb37d5d16
commit 04e5480387
21 files changed
+1805 -199

No files matched your search

+24 -11
View File
@@ -1262,17 +1262,30 @@ inline const RadKVGroupBatch* kv_batch(const RadBatch* b, rad_kvgroup group) {
* layer, head, feed-forward, norm and rotary geometry of the container's `draft.` config, split
* over the ranks, and a plain RMS norm. A drafter is a second model, so nothing is defaulted: a
* config that does not describe one is refused, naming `what` (spec §17). So is a vocabulary
* other than the target's, since a drafter reads the target's embedding and lm_head. */
* other than the target's, since a drafter reads the target's embedding and lm_head.
*
* The layer config sits at the top of `draft.` in z-lab's and SpecForge's checkpoints, and under
* `draft.transformer_layer_config.` in vLLM's speculators format (RedHatAI's DFlash2 drafters),
* whose top level holds the speculator's own keys instead (drafter_layer_prefix). */
inline const char* drafter_layer_prefix(const RadModelMeta* meta) {
if (rad_meta_geti(meta, "draft.num_hidden_layers", 0) > 0) return "draft.";
if (rad_meta_geti(meta, "draft.transformer_layer_config.num_hidden_layers", 0) > 0)
return "draft.transformer_layer_config.";
return "draft.";
}
inline int drafter_geom(Geom& dg, const Geom& target, const RadModelMeta* meta, const char* what) {
dg = target;
dg.n_layer = rad_meta_geti(meta, "draft.num_hidden_layers", 0);
dg.head_dim = rad_meta_geti(meta, "draft.head_dim", 0);
dg.n_head_all = rad_meta_geti(meta, "draft.num_attention_heads", 0);
dg.n_head_kv_all = rad_meta_geti(meta, "draft.num_key_value_heads", 0);
dg.n_ff_all = rad_meta_geti(meta, "draft.intermediate_size", 0);
dg.eps = (float)rad_meta_getf(meta, "draft.rms_norm_eps", 0.0);
dg.theta = (float)rad_meta_getf(meta, "draft.rope_parameters.rope_theta",
rad_meta_getf(meta, "draft.rope_theta", 0.0));
const char* pre = drafter_layer_prefix(meta);
char key[160];
auto k = [&](const char* name) { std::snprintf(key, sizeof key, "%s%s", pre, name); return key; };
dg.n_layer = rad_meta_geti(meta, k("num_hidden_layers"), 0);
dg.head_dim = rad_meta_geti(meta, k("head_dim"), 0);
dg.n_head_all = rad_meta_geti(meta, k("num_attention_heads"), 0);
dg.n_head_kv_all = rad_meta_geti(meta, k("num_key_value_heads"), 0);
dg.n_ff_all = rad_meta_geti(meta, k("intermediate_size"), 0);
dg.eps = (float)rad_meta_getf(meta, k("rms_norm_eps"), 0.0);
const double th = rad_meta_getf(meta, k("rope_theta"), 0.0);
dg.theta = (float)rad_meta_getf(meta, k("rope_parameters.rope_theta"), th);
dg.wadd = dg.wadd_qk = 0.0f;
if (dg.n_layer <= 0 || dg.head_dim <= 0 || dg.n_head_all <= 0 || dg.n_head_kv_all <= 0 ||
dg.n_ff_all <= 0 || !(dg.eps > 0.0f) || !(dg.theta > 0.0f)) {
@@ -1283,11 +1296,11 @@ inline int drafter_geom(Geom& dg, const Geom& target, const RadModelMeta* meta,
(long long)dg.head_dim, (long long)dg.n_ff_all, (double)dg.eps, (double)dg.theta);
return RAD_E_INVAL;
}
RAD_ARCH_TRY(yarn_from(dg, meta, "draft.", dg.head_dim));
RAD_ARCH_TRY(yarn_from(dg, meta, pre, dg.head_dim));
RAD_ARCH_TRY(divide_or_fail(dg.n_head_all, dg.world, "draft num_attention_heads", &dg.n_head));
RAD_ARCH_TRY(divide_or_fail(dg.n_head_kv_all, dg.world, "draft num_key_value_heads", &dg.n_head_kv));
RAD_ARCH_TRY(divide_or_fail(dg.n_ff_all, dg.world, "draft intermediate_size", &dg.n_ff));
const long long dvocab = rad_meta_geti(meta, "draft.vocab_size", dg.n_vocab_all);
const long long dvocab = rad_meta_geti(meta, k("vocab_size"), dg.n_vocab_all);
if (dvocab != dg.n_vocab_all) {
fprintf(stderr, "radiance: the %s drafter claims a %lld-token vocabulary and the target "
"has %lld; it reads the target's embedding and lm_head\n",
+119 -21
View File
@@ -69,10 +69,21 @@
* q/kv and gate_up shard by row, o and down by column with an all-reduce: ten collectives per
* draft pass, each 5120 * block * 2 bytes (80 KiB at block 8), below the lossy wire's floor.
*
* fc [n_embd, n_taps*n_embd], 262 MiB in fp8 at Qwen3.8's width, read whole by the
* context pass every step. Split by rows over the ranks and all-gathered, and
* kept bit for bit. Each rank hands over an equal share of c's columns
* (n_embd / world) and computes the fewest whole 128-row scale blocks that cover
* it (the 31B at tp 4: 1344 columns a rank inside 11 blocks, 1408 rows, against
* 42 blocks whole), a row span of the one stored weight
* (DenseFP8::declare_slice), so no reconvert. The GEMM takes its K split from
* the whole width (OPS.md's `split_n`), so each output is summed as the unsplit
* fc sums it, and the all-gather reads each rank's window out of its wider rows
* (an input pitch) and writes c whole. A GEMM cannot write a column slice (the
* narrow fp8 kernel's store is tight), which is why the windows are the
* gather's to cut. One rank, or an fc off block fp8, keeps it whole.
*
* Replicated:
*
* fc [n_embd, n_taps*n_embd], 262 MiB. Column-sharding would halve it but add an
* all-reduce to the prefill path.
* conv weights projection and base kernel, 26 MiB a layer. The convolution spans the whole
* replicated hidden row, so every rank needs every coefficient.
* codebooks [n_vocab, 256], 127 MiB each, gathered by global token id. Only 128 rows are
@@ -127,6 +138,10 @@ struct Dflash2 {
/* the context pass */
rad_buf src = 0; /* [max_tok, n_taps * n_embd] the trunk's taps, read only */
rad_buf c = 0; /* [max_tok, n_embd] fc's output, then normed in place */
/* [max_tok, fc_rows] the block-aligned rows of a split fc this rank computes, whose
* fc_share-wide window at fc_off is gathered into c. The block declares it (only when it
* splits fc); leave it 0. */
rad_buf cpart = 0;
/* K and V are separate buffers because of the per-head k norm: `rmsnorm` takes one row
* pitch, and K heads inside a fused [K|V] row are head_dim apart within a token but
* 2*kv_dim apart between tokens. libr4d refuses such an operand (libr4d/r4d_model.cpp,
@@ -191,10 +206,17 @@ struct Dflash2 {
* MXFP4 accepts ~1% fewer tokens per step than fp8 and saves ~1.5 ms of a ~34 ms step.
* Quantisation can only change acceptance, since every draft is verified. */
DenseFP8 w_fc{};
/* fc split by rows (see SHARDING): w_fc is this rank's fc_rows block-aligned rows, holding its
* fc_share output columns at row fc_off. fc_rows 0: w_fc is the whole fc, replicated. */
int64_t fc_share = 0, fc_rows = 0, fc_off = 0;
rad_weight w_hnorm = 0, w_norm = 0;
rad_weight w_selp = 0, w_pred = 0, w_succ = 0;
rad_weight w_tok = 0; /* the target's embedding table */
rad_weight w_dh = 0, w_dhs = 0; /* the 2-bit copy of the target's lm_head */
rad_weight w_dh = 0, w_dhs = 0; /* the 2-bit (or 8-bit) copy of the target's lm_head */
/* The copy is int8 with an f16 scale per (row, 128 of K) where the recipe made it so (the
* 31B's: the head read at w8a8, so the selector sees the candidates an 8-bit head ranks), and
* the 2-bit grid otherwise. Set by declare from the copy's encoding. */
bool head_i8 = false;
/* per-layer weights */
rad_weight w_anorm[MAX_LAYERS] = {}, w_fnorm[MAX_LAYERS] = {};
@@ -209,6 +231,7 @@ struct Dflash2 {
/* context-pass ops */
rad_op op_cfc = 0, op_cnorm = 0, op_crope = 0, op_cstore = 0;
rad_op op_cgath = 0; /* the split fc's all-gather */
rad_op op_ck[MAX_LAYERS] = {}, op_cv[MAX_LAYERS] = {}, op_cknorm[MAX_LAYERS] = {};
/* Activation quantisers, one per activation that feeds a linear. Weightless, so one declaration
@@ -284,9 +307,38 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
if (qrows <= 0 || srows <= 0) return RAD_E_INVAL;
/* ---------------------------------------------------------------- model-scope weights */
RAD_ARCH_TRY(w_fc.declare(b, nm, nm.f("dflash.fc"), g.n_embd, cfg.n_taps * g.n_embd,
RAD_ACCESS_PER_TOKEN, RAD_SHARD_NONE, grp_model(),
{ nm.ckpt("%s.fc.weight", ck) }));
{
const int64_t K = cfg.n_taps * g.n_embd;
const char* fwn = nm.f("dflash.fc.weight");
RAD_ARCH_TRY(map_linear(b, fwn, { nm.ckpt("%s.fc.weight", ck) }));
/* Split only block fp8 (an MXFP4 GEMM's K split is its own), into equal shares of whole
* 16-byte words (the gather's unit). */
RadEncoding fe{};
const RadEncPlane* fsc = nullptr;
const bool fp8 = weight_enc(b, fwn, &fe) && rad_enc_is(&fe, "affine") && fe.n_planes == 2 &&
!fe.transform[0] && fe.plane[0].dtype == RAD_F8E4M3 &&
(fsc = rad_enc_plane(&fe, "scale")) && fsc->block[0] == RAD_FP8_BLOCK &&
fsc->block[1] == RAD_FP8_BLOCK;
const int64_t share = (g.world > 1 && g.n_embd % RAD_FP8_BLOCK == 0 &&
g.n_embd % g.world == 0 && (g.n_embd / g.world) % 8 == 0)
? g.n_embd / g.world : 0;
if (fp8 && share > 0) {
const int64_t B = RAD_FP8_BLOCK;
const int64_t lo = share * g.rank / B * B;
const int64_t hi = (share * (g.rank + 1) + B - 1) / B * B;
fc_share = share;
fc_rows = hi - lo;
fc_off = share * g.rank - lo;
RAD_ARCH_TRY(w_fc.declare_slice(b, nm, nm.f("dflash.fc"), fwn, lo, hi, K,
RAD_ACCESS_PER_TOKEN, grp_model()));
if (!w.cpart)
w.cpart = decl_b(b, nm.f("df_cpart"), g.act_dtype, { g.max_tok, fc_rows });
} else {
RAD_ARCH_TRY(w_fc.declare(b, nm, nm.f("dflash.fc"), g.n_embd, K, RAD_ACCESS_PER_TOKEN,
RAD_SHARD_NONE, grp_model(), { nm.ckpt("%s.fc.weight", ck) },
{}, true));
}
}
RAD_ARCH_TRY(map_copy(b, nm.f("dflash.hidden_norm.weight"), nm.ckpt("%s.hidden_norm.weight", ck)));
RAD_ARCH_TRY(map_copy(b, nm.f("dflash.norm.weight"), nm.ckpt("%s.norm.weight", ck)));
RAD_ARCH_TRY(map_copy(b, nm.f("dflash.sel_proj.weight"),
@@ -321,10 +373,28 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
const int dh_split = dh_shard ? RAD_SHARD_ROW : RAD_SHARD_NONE;
const char* dhn = nm.f("dflash.draft_head.weight");
RAD_ARCH_TRY(map_copy(b, dhn, ck_lm));
w_dh = decl_view(b, dhn, nullptr, "codes", RAD_U2, {head_rows(g), g.n_embd},
RAD_ACCESS_PER_TOKEN, dh_split, grp_model());
w_dhs = decl_view(b, nm.f("dflash.draft_head.scale"), dhn, "scale,zero", RAD_F16,
{head_rows(g), g.n_embd}, RAD_ACCESS_PER_TOKEN, dh_split, grp_model());
/* The 8-bit form: int8 codes, one f16 scale per (row, 128 of K), symmetric, which gemm_nt_q
* reads at w8a8 against the same quant_act_i8 activation (without its asum). */
{
RadEncoding e{};
const RadEncPlane* sc = nullptr;
head_i8 = weight_enc(b, dhn, &e) && rad_enc_is(&e, "affine") && e.n_planes == 2 &&
!e.transform[0] && e.plane[0].dtype == RAD_I8 && e.plane[0].block[1] == 1 &&
(sc = rad_enc_plane(&e, "scale")) && sc->dtype == RAD_F16 &&
sc->block[0] == 1 && sc->block[1] == DF_W2_GROUP;
}
if (head_i8) {
w_dh = decl_view(b, dhn, nullptr, "codes", RAD_I8, {head_rows(g), g.n_embd},
RAD_ACCESS_PER_TOKEN, dh_split, grp_model());
w_dhs = decl_view(b, nm.f("dflash.draft_head.scale"), dhn, "scale", RAD_F16,
{head_rows(g), g.n_embd / DF_W2_GROUP}, RAD_ACCESS_PER_TOKEN, dh_split,
grp_model());
} else {
w_dh = decl_view(b, dhn, nullptr, "codes", RAD_U2, {head_rows(g), g.n_embd},
RAD_ACCESS_PER_TOKEN, dh_split, grp_model());
w_dhs = decl_view(b, nm.f("dflash.draft_head.scale"), dhn, "scale,zero", RAD_F16,
{head_rows(g), g.n_embd}, RAD_ACCESS_PER_TOKEN, dh_split, grp_model());
}
if (!w_dh || !w_dhs) return RAD_E_INVAL;
/* ---------------------------------------------------------------- per-layer weights */
@@ -422,7 +492,21 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
RAD_INT("group", RAD_FP8_BLOCK), RAD_STR("dtype", g.dtype)),
RAD_NOWEIGHTS),
{w.src}, {w.srcq, w.srcs});
op_cfc = w_fc.gemm(b, crows, g.n_embd, cfg.n_taps * g.n_embd, {w.srcq, w.srcs}, {w.c});
if (fc_rows) {
/* The split (SHARDING above): this rank's block-aligned rows into `cpart`, its window of
* them gathered into `c`. The GEMM takes its K split from the whole width. The gather
* rides the trunk's all-reduce instance (the same numel bound, so the same instance). */
op_cfc = w_fc.gemm(b, crows, fc_rows, cfg.n_taps * g.n_embd, {w.srcq, w.srcs}, {w.cpart},
g.n_embd);
op_cgath = rw(b, RAD_OP(b, "all_gather",
RAD_PARAMS(RAD_INT("world_size", g.world),
RAD_INT("numel", crows * g.n_embd),
RAD_STR("dtype", g.dtype), RAD_INT("row", fc_share)),
RAD_NOWEIGHTS),
{w.cpart}, {w.c});
} else {
op_cfc = w_fc.gemm(b, crows, g.n_embd, cfg.n_taps * g.n_embd, {w.srcq, w.srcs}, {w.c});
}
/* In place, like the per-head q/k norms below: a row's scale is computed before the row is
* written. */
op_cnorm = rw(b, RAD_OP(b, "rmsnorm",
@@ -643,12 +727,19 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co
RAD_INT("group", DF_W2_GROUP), RAD_STR("dtype", g.dtype)),
RAD_NOWEIGHTS),
{w.sel_h}, {w.dq, w.ds, w.dsum});
op_dlogits = rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, srows), RAD_INT("N", head_rows(g)),
RAD_INT("K", g.n_embd), RAD_INT("group", DF_W2_GROUP),
RAD_STR("dtype", "w2a8")),
RAD_WEIGHTS(w_dh, w_dhs)),
{w.dq, w.ds, w.dsum}, {w.dlog});
op_dlogits = head_i8
? rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, srows), RAD_INT("N", head_rows(g)),
RAD_INT("K", g.n_embd), RAD_INT("group", DF_W2_GROUP),
RAD_STR("dtype", "w8a8")),
RAD_WEIGHTS(w_dh, w_dhs)),
{w.dq, w.ds}, {w.dlog})
: rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, srows), RAD_INT("N", head_rows(g)),
RAD_INT("K", g.n_embd), RAD_INT("group", DF_W2_GROUP),
RAD_STR("dtype", "w2a8")),
RAD_WEIGHTS(w_dh, w_dhs)),
{w.dq, w.ds, w.dsum}, {w.dlog});
/* Sharded, the top-R runs over this rank's plane, reports global ids and also writes the pair
* plane the gather moves. Replicated, `vocab_off` is omitted: an optional parameter present
* with value 0 is a different declaration from an absent one. */
@@ -731,8 +822,14 @@ inline void Dflash2::context(RadCtx* c, const RadBatch* batch) const {
/* As wide as the prefill chunk, one launch per op (the fp8a8 pair covers every M). */
RAD_ISSUE_N(c, op_qsrc, T, brows(w.src, T), brows(w.srcq, T), brows(w.srcs, T));
RAD_ISSUE_N(c, op_cfc, T, brows(w.srcq, T), brows(w.srcs, T), RAD_W(w_fc.w), RAD_W(w_fc.s),
brows(w.c, T), RAD_NONE, w_fc.bref());
if (fc_rows) {
RAD_ISSUE_N(c, op_cfc, T, brows(w.srcq, T), brows(w.srcs, T), RAD_W(w_fc.w), RAD_W(w_fc.s),
brows(w.cpart, T), RAD_NONE, w_fc.bref());
RAD_ISSUE_N(c, op_cgath, T, bcol(w.cpart, fc_off, fc_share, T), brows(w.c, T));
} else {
RAD_ISSUE_N(c, op_cfc, T, brows(w.srcq, T), brows(w.srcs, T), RAD_W(w_fc.w), RAD_W(w_fc.s),
brows(w.c, T), RAD_NONE, w_fc.bref());
}
RAD_ISSUE_N(c, op_cnorm, T, brows(w.c, T), RAD_W(w_hnorm), brows(w.c, T));
RAD_ISSUE_N(c, op_qc, T, brows(w.c, T), brows(w.cq, T), brows(w.cs, T));
@@ -843,9 +940,10 @@ inline void Dflash2::step(RadCtx* c, const RadBatch* batch) const {
* whole. */
RAD_ISSUE_N(c, op_dquant, S, brows(w.sel_h, S), brows(w.dq, S), brows(w.ds, S), RAD_B(w.dsum));
/* The trailing operand is mxfp4's optional reference, absent here. Operands are positional,
* so an absent optional one is RAD_NONE, not a shorter list. */
* so an absent optional one is RAD_NONE, not a shorter list. The 8-bit head is symmetric and
* takes no asum. */
RAD_ISSUE_N(c, op_dlogits, S, brows(w.dq, S), brows(w.ds, S), RAD_W(w_dh), RAD_W(w_dhs),
brows(w.dlog, S), RAD_B(w.dsum), RAD_NONE);
brows(w.dlog, S), head_i8 ? RAD_NONE : RAD_B(w.dsum), RAD_NONE);
/* RAD_NONE fills the unused `pairs` slot. Sharded, this rank's top-R are only candidates and
* the merge overwrites `cand`/`unary`. */
if (op_dmerge) {
+34 -2
View File
@@ -1521,15 +1521,47 @@ struct DenseFP8 {
int access, int shard, RadWeightGroup grp,
std::initializer_list<const char*> src,
std::initializer_list<int64_t> row_parts = {}, bool mapped = false);
/* `gemm_nt_q` over this weight, `fp8a8` or `mxfp4a8` as it was declared, ranged M 1..hi. */
/* Rows [lo, hi) of the stored block-fp8 weight `src_wn` (codes and scale plane; mapped by
* whoever declared it), read as an [hi - lo, K] weight named `<base>`: a row slice that need
* not be a rank's even share, and may be the same rows on every rank. Whole 128-row blocks,
* so each slice's codes and scales are the stored ones. fp8 only: an MXFP4 linear's GEMM
* splits K by its own rule. A slice issued with `gemm(..., split_n)` set to the stored width
* computes the stored linear's outputs to the bit. */
int declare_slice(RadBuilder* b, Names& nm, const char* base, const char* src_wn, int64_t lo,
int64_t hi, int64_t K, int access, RadWeightGroup grp) {
if (lo < 0 || hi <= lo || lo % RAD_FP8_BLOCK || hi % RAD_FP8_BLOCK || K % RAD_FP8_BLOCK)
return RAD_E_INVAL;
mx = false;
ref = 0;
const char* wn = nm.f("%s.weight", base);
const char* sn = nm.f("%s.scale", base);
const bool own = !std::strcmp(wn, src_wn); /* the stored weight's own name */
w = decl_view(b, wn, own ? nullptr : src_wn, "codes", RAD_F8E4M3, { hi - lo, K }, access,
RAD_SHARD_ROW, grp);
s = decl_view(b, sn, src_wn, "scale", RAD_BF16, { fp8_blocks(hi - lo), fp8_blocks(K) },
access, RAD_SHARD_ROW, grp);
if (!w || !s) return RAD_E_INVAL;
RAD_ARCH_TRY(rad_weight_shard_span(b, w, lo, hi));
return rad_weight_shard_span(b, s, lo / RAD_FP8_BLOCK, hi / RAD_FP8_BLOCK);
}
/* `gemm_nt_q` over this weight, `fp8a8` or `mxfp4a8` as it was declared, ranged M 1..hi.
* `split_n`, when set, is the stored width a row slice takes its K split from (docs/OPS.md). */
rad_op gemm(RadBuilder* b, int64_t hi, int64_t N, int64_t K,
std::initializer_list<rad_buf> reads, std::initializer_list<rad_buf> writes) const {
std::initializer_list<rad_buf> reads, std::initializer_list<rad_buf> writes,
int64_t split_n = 0) const {
if (mx)
return rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, hi), RAD_INT("N", N), RAD_INT("K", K),
RAD_INT("group", RAD_MX_GROUP), RAD_STR("dtype", "mxfp4a8")),
RAD_WEIGHTS(w, s, ref)),
reads, writes);
if (split_n > 0)
return rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, hi), RAD_INT("N", N), RAD_INT("K", K),
RAD_INT("group", RAD_FP8_BLOCK), RAD_STR("dtype", "fp8a8"),
RAD_INT("split_n", split_n)),
RAD_WEIGHTS(w, s)),
reads, writes);
return rw(b, RAD_OP(b, "gemm_nt_q",
RAD_PARAMS(RAD_RANGE("M", 1, hi), RAD_INT("N", N), RAD_INT("K", K),
RAD_INT("group", RAD_FP8_BLOCK), RAD_STR("dtype", "fp8a8")),
+48
View File
@@ -159,6 +159,54 @@ inline bool dflash_probe(const RadModelMeta* meta, RadArchProbe* out) {
return true;
}
/* The same for a DFlash2 drafter, for a plugin that serves rad_block_dflash2.h (the 31B's): its
* anchor predicts nothing either, so the depth is the trained block less one, 7 for RedHatAI's
* gemma-4-31B-it-speculator.dflash2 (block_size 8). */
inline bool dflash2_probe(const RadModelMeta* meta, RadArchProbe* out) {
if (dflash_kind(meta) != 2) return false;
const long long bs = dflash_block(meta);
if (bs <= 1) return false;
out->draft_depth = (int)(bs - 1);
out->draft_depth_fixed = 1;
return true;
}
/* A DFlash2 drafter's trunk taps, as the layers whose output the trunk copies into `dflash_src`.
*
* vLLM's speculators format names them `aux_hidden_state_layer_ids`, counted as vLLM captures
* them: id i is the residual stream entering layer i, so the output of layer i - 1 (id n_layer,
* which `--include-last-layer` emits, is the last layer's output). z-lab's `target_layer_ids` count
* the layer whose output is taken. RedHatAI's 1 17 29 47 59 are this trunk's layers 0 16 28 46
* 58. Id 0 would be the embedding, which no layer outputs, and is refused. */
inline int dflash2_taps(const RadModelMeta* meta, const RadBuildCtx* ctx, int64_t n_layer, int* out,
int max) {
if (ctx->max_spec <= 0 || dflash_kind(meta) != 2) return 0;
const char* aux = rad_meta_gets(meta, "draft.aux_hidden_state_layer_ids", nullptr);
int n = 0;
if (aux) {
int raw[16];
const int m = parse_layer_ids(aux, n_layer + 1, raw, max < 16 ? max : 16);
for (int i = 0; i < m; ++i) {
if (raw[i] < 1) {
fprintf(stderr, "radiance: gemma4: the DFlash2 drafter taps aux hidden state 0, the "
"embedding, which no trunk layer outputs\n");
return RAD_E_UNSUPPORTED;
}
out[n++] = raw[i] - 1;
}
} else {
const char* ids = rad_meta_gets(meta, "draft.dflash_config.target_layer_ids", nullptr);
if (!ids) ids = rad_meta_gets(meta, "draft.target_layer_ids", nullptr);
n = parse_layer_ids(ids, n_layer, out, max);
}
if (n <= 0) {
fprintf(stderr, "radiance: gemma4: the DFlash2 drafter names no trunk layer this model has; "
"it is paired with a different target\n");
return RAD_E_UNSUPPORTED;
}
return n;
}
/* ============================================================== the block */
struct Dflash1 {