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:
claudeandClaude Opus 5.5 committed 2026-11-02 05:45:50 +01:00
1 parent bfb1ebd1dd
commit 175f0bbd33
8 files changed
+160 -15

No files matched your search

+60 -5
View File
@@ -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));
}