Archived
MTP coupling on qwen35_fp8's 2-bit draft head; libxe2 rows for the coupling ops
- arch: under --draft-coupling the MtpBlockFP8 draft head keeps the 2-bit logits' top 8, rescores them against the trunk's head (logit_rerank) and runs one mtp_couple_propose a round, as the Flash-Next head does; qwen35_fp8 declares the draw/state planes and a pitch-8 proposal. Off, nothing changes. - libxe2: device rows for mtp_couple_propose / mtp_couple_verify, a work-item a row over spechub's own row helpers and argument readers (built into xe2_couple.cpp). - spechub: mtp_couple_propose takes an optional q_temp (Q = softmax(score / q_temp)); exact at any value. RADIANCE_MTP_Q_TEMP sets it on qwen35_fp8 (default 1: 1.0 > 0.7 > 0.5 here). w4a16-rtn-mtp4, depth 7 adaptive, temperature 0.7: decode proxy 76.9 -> 78.8 tok/s, BetterBench decode 80.5 -> 81.7; greedy 8/8 identical with coupling on. Host tests (spechub|couple|abi|mtp) 7/7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bfb1ebd1dd
commit
175f0bbd33
8 files changed
+160
-15
No files matched your search
@@ -90,6 +90,7 @@
|
||||
#define RAD_BLOCK_MTP_FP8_H
|
||||
|
||||
#include "rad_block_attn_gated_fp8.h"
|
||||
#include "rad_spechub.h" /* RAD_MTP_COUPLE_*: the coupling wire */
|
||||
#include "rad_block_mlp_fp8.h"
|
||||
#include "rad_block_vit.h"
|
||||
|
||||
@@ -134,8 +135,16 @@ struct MtpBlockFP8 {
|
||||
rad_buf ds = 0; /* [max_logit_rows, 1] f32, one scale a row */
|
||||
rad_buf dsum = 0; /* [n_embd/group, mpad] f32, group-major (quant_act_i8's asum) */
|
||||
rad_buf dlog = 0; /* [max_logit_rows, n_vocab] bf16, the coarse logits */
|
||||
rad_buf didx = 0; /* [max_logit_rows, 1] i32, the proposed token */
|
||||
rad_buf dval = 0; /* [max_logit_rows, 1] f32, its logit */
|
||||
rad_buf didx = 0; /* [max_logit_rows, topr] i32, the proposed token (column 0) */
|
||||
rad_buf dval = 0; /* [max_logit_rows, topr] f32, its logit */
|
||||
/* --draft-coupling: the shortlist is the top kCoupleR of the 2-bit logits, rescored
|
||||
* against the trunk's head (`logit_rerank`), and each round's `mtp_couple_propose` draws
|
||||
* x ~ Q from it into column 0: [max_seqs] draws and [depth, max_seqs] states, PERSIST
|
||||
* (abi/rad_spechub.h). Zero for the ordinary argmax at topr 1. */
|
||||
rad_buf couple_draws = 0, couple_state = 0;
|
||||
int64_t topr = 1;
|
||||
/* Q's temperature over the rescored scores: exact at any value, it moves acceptance only */
|
||||
double q_temp = 1.0;
|
||||
/* The layer reuses the trunk's working set, which is dead by the time the head runs (a
|
||||
* second set would be 150 MiB). */
|
||||
AttnGatedFP8::Wire attn{};
|
||||
@@ -171,7 +180,10 @@ struct MtpBlockFP8 {
|
||||
bool media = false;
|
||||
MediaRows mrows{};
|
||||
rad_op op_norm = 0, op_dsel = 0, op_dback = 0, op_logits = 0;
|
||||
rad_op op_dquant = 0, op_dlogits = 0, op_dtopk = 0;
|
||||
rad_op op_dquant = 0, op_dlogits = 0, op_dtopk = 0, op_drerank = 0;
|
||||
/* --draft-coupling: one op a round (the ABI freezes `round` as a parameter). */
|
||||
rad_op op_couple[RAD_MTP_COUPLE_MAX_ROUNDS] = {};
|
||||
int depth = 0;
|
||||
|
||||
int declare(RadBuilder* b, Names& nm, const Geom& geom, int l, rad_kvgroup kv,
|
||||
int64_t rotary_dim, rad_weight tok_embd, rad_weight lm_head, float out_wadd,
|
||||
@@ -334,19 +346,47 @@ inline int MtpBlockFP8<Ffn>::declare(RadBuilder* b, Names& nm, const Geom& geom,
|
||||
RAD_WEIGHTS(w_dh, w_dhs)),
|
||||
{w.dq, w.ds, w.dsum}, {w.dlog});
|
||||
|
||||
const bool couple = w.couple_draws || w.couple_state;
|
||||
if (couple && (!w.couple_draws || !w.couple_state || w.topr < 2 || g.world > 1 ||
|
||||
g.max_spec < 1 || g.max_spec > RAD_MTP_COUPLE_MAX_ROUNDS))
|
||||
return RAD_E_UNSUPPORTED;
|
||||
op_dtopk = rw(b, RAD_OP(b, "row_topk",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_logit_rows),
|
||||
RAD_INT("N", mtp_draft_rows(g.n_vocab_all)), RAD_INT("R", 1),
|
||||
RAD_INT("N", mtp_draft_rows(g.n_vocab_all)), RAD_INT("R", w.topr),
|
||||
RAD_STR("dtype", g.dtype)),
|
||||
RAD_NOWEIGHTS),
|
||||
{w.dlog}, {w.didx, w.dval});
|
||||
if (couple) {
|
||||
/* The coarse shortlist rescored exactly against the trunk's head (already resident),
|
||||
* so Q is the softmax of the target's own logits over it; in place over idx/val. */
|
||||
op_drerank = RAD_OP(b, "logit_rerank",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, g.max_logit_rows), RAD_INT("R", w.topr),
|
||||
RAD_INT("n_vocab", g.n_vocab), RAD_INT("n_embd", g.n_embd),
|
||||
RAD_INT("vocab_off", g.vocab_off), RAD_STR("dtype", g.dtype)),
|
||||
RAD_WEIGHTS(w_lm));
|
||||
if (!op_drerank) return RAD_E_INVAL;
|
||||
const rad_buf rd[2] = { w.hout, w.didx };
|
||||
const rad_buf wr[2] = { w.didx, w.dval };
|
||||
RAD_ARCH_TRY(rad_op_reads(b, op_drerank, rd, 2));
|
||||
RAD_ARCH_TRY(rad_op_writes(b, op_drerank, wr, 2));
|
||||
depth = (int)g.max_spec;
|
||||
for (int round = 1; round <= depth; ++round) {
|
||||
op_couple[round - 1] = rw(b, RAD_OP(b, "mtp_couple_propose",
|
||||
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_F64("q_temp", w.q_temp)),
|
||||
RAD_NOWEIGHTS),
|
||||
{ w.didx, w.dval, w.couple_draws }, { w.didx, w.couple_state });
|
||||
if (!op_couple[round - 1]) return RAD_E_INVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Keep `hout` live through the head's last op: it is the next round's input, and if only the
|
||||
* lm_head's first op read it, the planner could give its bytes to later ops (silently lowering
|
||||
* acceptance). */
|
||||
{
|
||||
const rad_op last = q2 ? op_dtopk : op_logits;
|
||||
const rad_op last = !q2 ? op_logits : op_couple[0] ? op_couple[depth - 1] : op_dtopk;
|
||||
if (rad_op_reads(b, last, &w.hout, 1) < 0) return RAD_E_INVAL;
|
||||
}
|
||||
return RAD_OK;
|
||||
@@ -413,6 +453,21 @@ inline void MtpBlockFP8<Ffn>::step(RadCtx* c, const RadBatch* batch) const {
|
||||
brows(w.dlog, L), RAD_B(w.dsum), RAD_NONE);
|
||||
RAD_ISSUE_N(c, op_dtopk, L, brows(w.dlog, L), brows(w.didx, L), brows(w.dval, L),
|
||||
RAD_NONE); /* the `pairs` slot, absent: operands are positional */
|
||||
if (op_drerank)
|
||||
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 rescored shortlist: column 0 is what the engine reads, and a sampled row
|
||||
* replaces it with its x. Round 1 runs in the history pass (r < 0). */
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -193,6 +193,8 @@ struct Model {
|
||||
rad_buf b_mtp_e = 0, b_mtp_c = 0, b_mtp_x = 0, b_mtp_h = 0;
|
||||
rad_buf b_mtp_dq = 0, b_mtp_ds = 0, b_mtp_dsum = 0;
|
||||
rad_buf b_mtp_dlog = 0, b_mtp_didx = 0, b_mtp_dval = 0;
|
||||
rad_buf b_mtp_couple_draws = 0, b_mtp_couple_state = 0;
|
||||
int64_t mtp_topr = 1;
|
||||
|
||||
/* Auxiliary hidden-state taps, declared only when the container carries a drafter that wants
|
||||
* them. A DFlash2 drafter reads the residual stream at several intermediate layers and
|
||||
@@ -1169,8 +1171,27 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
m.b_mtp_dlog = decl_b(b, nm.f("mtp_dlog"), g.act_dtype, {g.max_logit_rows, mtp_draft_rows(g.n_vocab_all)});
|
||||
/* A draft round's proposal comes out of row_topk here, never through the sampler's
|
||||
* token buffer. */
|
||||
m.b_mtp_didx = decl_b(b, nm.f("mtp_didx"), RAD_I32, {g.max_logit_rows, 1});
|
||||
m.b_mtp_dval = decl_b(b, nm.f("mtp_dval"), RAD_F32, {g.max_logit_rows, 1});
|
||||
/* --draft-coupling: a top-8 shortlist, rescored against the trunk's head, that each
|
||||
* round's mtp_couple_propose samples x ~ Q from into column 0 (rad_block_mtp_fp8.h) */
|
||||
m.mtp_topr = ctx->draft_coupling ? 8 : 1;
|
||||
m.b_mtp_didx = decl_b(b, nm.f("mtp_didx"), RAD_I32, {g.max_logit_rows, m.mtp_topr});
|
||||
m.b_mtp_dval = decl_b(b, nm.f("mtp_dval"), RAD_F32, {g.max_logit_rows, m.mtp_topr});
|
||||
if (ctx->draft_coupling) {
|
||||
if (ctx->max_spec < 1 || ctx->max_spec > RAD_MTP_COUPLE_MAX_ROUNDS) {
|
||||
rad_note(b, "--draft-coupling on: the MTP head couples at most %d rounds",
|
||||
RAD_MTP_COUPLE_MAX_ROUNDS);
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
m.b_mtp_couple_draws = decl_b(b, nm.f("mtp_couple_draws"), RAD_U32,
|
||||
{g.max_seqs, RAD_MTP_COUPLE_DRAW_WORDS}, RAD_BUF_PERSIST);
|
||||
m.b_mtp_couple_state = decl_b(b, nm.f("mtp_couple_state"), RAD_U32,
|
||||
{ctx->max_spec, g.max_seqs, RAD_MTP_COUPLE_STATE_WORDS},
|
||||
RAD_BUF_PERSIST);
|
||||
if (!m.b_mtp_couple_draws || !m.b_mtp_couple_state) return RAD_E_INVAL;
|
||||
rad_note(b, "MTP coupled: x~Q from the 2-bit head's top 8 rescored against the "
|
||||
"trunk's head, %d round(s); fixed-seed tokens are NOT preserved",
|
||||
ctx->max_spec);
|
||||
}
|
||||
}
|
||||
|
||||
/* The head reuses the trunk's working buffers (`attn_qg`, `attn_k`, the ffn planes, `h`),
|
||||
@@ -1185,6 +1206,9 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
tw.e = m.b_mtp_e; tw.c = m.b_mtp_c; tw.x = m.b_mtp_x;
|
||||
tw.dq = m.b_mtp_dq; tw.ds = m.b_mtp_ds; tw.dsum = m.b_mtp_dsum;
|
||||
tw.dlog = m.b_mtp_dlog; tw.didx = m.b_mtp_didx; tw.dval = m.b_mtp_dval;
|
||||
tw.topr = m.mtp_topr;
|
||||
if (const char* qt = std::getenv("RADIANCE_MTP_Q_TEMP")) tw.q_temp = std::atof(qt);
|
||||
tw.couple_draws = m.b_mtp_couple_draws; tw.couple_state = m.b_mtp_couple_state;
|
||||
tw.attn = tw_attn; tw.mlp = tw_mlp;
|
||||
|
||||
MtpHead::Src ts{};
|
||||
@@ -1238,7 +1262,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
dd.kind = RAD_DRAFT_SERIAL;
|
||||
dd.depth = ctx->max_spec;
|
||||
dd.proposal = m.b_mtp_didx;
|
||||
dd.proposal_pitch = 1;
|
||||
dd.proposal_pitch = m.mtp_topr; /* the pick is column 0 */
|
||||
dd.mask_token = -1;
|
||||
RAD_ARCH_TRY(rad_declare_drafter(b, &dd));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user