Archived
spec: --draft-verify token|block|traversal for the coupled MTP chain
--draft-coupling verifies each row of the chain on its own. Two lossless sequence-level verifiers accept more drafts from the same chain: Block Verification (arXiv 2403.10444) decides the whole chain at once, Traversal Verification (arXiv 2505.12398) walks a path from its last draft back to its first. --draft-verify token (default) is the engine as it was; block switches the coupling on; traversal needs it and is refused otherwise. Block: the sampler marks the consecutive bound rows of a request with the block's length (RadMtpCoupleState::blk) and mtp_couple_verify decides the block on the workgroup of its round-1 row, every FP64 sum a fixed lane tree so the result is the host reference's bit for bit. The wide-plane serial helper is a kernel of its own, which leaves couple_verify without scratch. Traversal: a new op mtp_trav_verify takes the step's topology (parent row, draft token per row) and decides a request on one workgroup, 0 bytes of scratch: the target's law as integer masses of a fixed-point exponential, the walk in FP64. Its header and kernel also handle nodes with several children (Gumbel-top-k and RheoSampling siblings); the serial head here drafts one, so that part has no producer yet and is covered by the tests only. RadMtpCoupleState grows from 152 to 168 bytes (nkids, scheme, blk), so RAD_ABI_VERSION is 41. Exactness: mtp_block_test enumerates the draft tree of a toy model and runs chi-square over the real verify code; mtp_rrs_test runs chi-square and an exhaustive enumeration of the walk (worst |joint - P| 7e-14) with negative controls that fail; spechub_device_test compares the device rows with the host rows. Measured on Qwen3.8-Flash-Next IQR-V4 (TP2, MTP chain 3, coupling) on our branch: about +1% tok/s with traversal, +4.6% at T 1.0 top_k 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b6eba80c6
commit
d0fd4aa1bb
31 files changed
+5022
-30
No files matched your search
+98
-1
@@ -1528,7 +1528,7 @@ struct HostChain {
|
||||
|
||||
HostChain(int64_t n_vocab, int64_t max_seqs, int max_spec, const VocabView* vocab = nullptr,
|
||||
int64_t max_candidates = 8, const char* second_plugin = nullptr,
|
||||
bool draft_coupling = false)
|
||||
bool draft_coupling = false, bool verify_block = false, bool verify_traversal = false)
|
||||
: nv(n_vocab) {
|
||||
/* libref alone: it is the implementation under test, and a directory scan would also
|
||||
* pick up whatever else was built beside it. */
|
||||
@@ -1571,6 +1571,8 @@ struct HostChain {
|
||||
cfg.max_hist = 64;
|
||||
cfg.max_candidates = max_candidates;
|
||||
cfg.draft_coupling = draft_coupling;
|
||||
cfg.draft_verify_block = verify_block;
|
||||
cfg.draft_verify_traversal = verify_traversal;
|
||||
if (s.declare(&b, cfg) < 0) return;
|
||||
if (b.finish() < 0) return;
|
||||
prog = std::move(b.program());
|
||||
@@ -3597,6 +3599,101 @@ TEST(the_coupled_evidence_survives_the_drafters_greedy_build) {
|
||||
CHECK_EQ(ev.rows, (int64_t)6);
|
||||
}
|
||||
|
||||
/* --draft-verify block: the chain rows bound from round 1 on, consecutively, carry the block's
|
||||
* length in `blk` (what the verify's round-1 row decides from); the bonus row and a row after a
|
||||
* gap do not, and without the flag nothing is marked. */
|
||||
TEST(block_verification_marks_the_consecutive_bound_rows_of_a_chain) {
|
||||
HostChain ch(64, 2, 3, nullptr, 8, "spechub.so", true, true);
|
||||
if (!ch.ok) {
|
||||
fprintf(stderr, " SKIP %s: libref/spechub did not load from %s/kernels\n",
|
||||
::radtest::current(), home().c_str());
|
||||
return;
|
||||
}
|
||||
SamplingParams sp;
|
||||
sp.temp = 1.0f;
|
||||
const int32_t draft[3] = { 21, 22, 23 };
|
||||
Request r = make_req(7, { 1, 2, 3 }, sp);
|
||||
r.draft = draft;
|
||||
r.n_draft = 3;
|
||||
std::string err;
|
||||
CHECK_OK(ch.s.begin_request(r.id, r.sp, &err));
|
||||
const uint64_t n_out = r.output.size();
|
||||
RadMtpCoupleState bound[3];
|
||||
couple_states(r.id, r.sp.seed, draft, 3, rad_mtp_couple_verify_pos(n_out, 1), bound);
|
||||
CHECK_OK(ch.s.set_mtp_couple(r.id, bound, 3));
|
||||
std::vector<Request*> reqs = { &r };
|
||||
CHECK_OK(ch.s.build_step(reqs));
|
||||
for (int k = 0; k < 3; ++k) CHECK_EQ(ch.s.staged_couple(k).blk, 3);
|
||||
CHECK_EQ(ch.s.staged_couple(3).blk, 0);
|
||||
|
||||
/* row 1 stale: the block is row 0 alone; row 2 is bound but past the gap, so token-wise */
|
||||
bound[1].pos += 1;
|
||||
CHECK_OK(ch.s.set_mtp_couple(r.id, bound, 3));
|
||||
CHECK_OK(ch.s.build_step(reqs));
|
||||
CHECK_EQ(ch.s.staged_couple(0).blk, 1);
|
||||
CHECK_EQ(ch.s.staged_couple(1).round, 0);
|
||||
CHECK_EQ(ch.s.staged_couple(2).round, 3);
|
||||
CHECK_EQ(ch.s.staged_couple(2).blk, 0);
|
||||
|
||||
/* the same chain without the flag is not marked */
|
||||
HostChain plain(64, 2, 3, nullptr, 8, "spechub.so", true, false);
|
||||
CHECK(plain.ok);
|
||||
CHECK_OK(plain.s.begin_request(r.id, r.sp, &err));
|
||||
couple_states(r.id, r.sp.seed, draft, 3, rad_mtp_couple_verify_pos(n_out, 1), bound);
|
||||
CHECK_OK(plain.s.set_mtp_couple(r.id, bound, 3));
|
||||
CHECK_OK(plain.s.build_step(reqs));
|
||||
for (int k = 0; k < 3; ++k) CHECK_EQ(plain.s.staged_couple(k).blk, 0);
|
||||
}
|
||||
|
||||
/* TRAVERSAL VERIFICATION THROUGH THE SAMPLER (--draft-verify traversal, abi/rad_mtp_traversal.h).
|
||||
*
|
||||
* The chain 21, 22, 23 with a point-mass draft law at every round. The sampler stages the per-row
|
||||
* topology plane (parent row, draft token) and issues `mtp_trav_verify` instead of the row-wise
|
||||
* verify. With the target peaked on 31 at every row the walk rejects the chain (the first draft's
|
||||
* ratio is ~e^-20) and the root row's token comes from the residual law, 31; with the target
|
||||
* peaked on each draft the walk accepts the whole chain and the final token is the bonus row's
|
||||
* own pick. */
|
||||
TEST(traversal_verification_walks_the_staged_chain_through_the_sampler) {
|
||||
HostChain ch(64, 2, 3, nullptr, 8, "spechub.so", true, false, true);
|
||||
if (!ch.ok) {
|
||||
fprintf(stderr, " SKIP %s: libref/spechub did not load from %s/kernels\n",
|
||||
::radtest::current(), home().c_str());
|
||||
return;
|
||||
}
|
||||
CHECK(ch.s.staged_couple_op() != RAD_NULL_HANDLE);
|
||||
SamplingParams sp;
|
||||
sp.temp = 1.0f;
|
||||
const int32_t draft[3] = { 21, 22, 23 };
|
||||
Request r = make_req(7, { 1, 2, 3 }, sp);
|
||||
r.draft = draft;
|
||||
r.n_draft = 3;
|
||||
std::string err;
|
||||
CHECK_OK(ch.s.begin_request(r.id, r.sp, &err));
|
||||
const uint64_t n_out = r.output.size();
|
||||
RadMtpCoupleState bound[3];
|
||||
couple_states(r.id, r.sp.seed, draft, 3, rad_mtp_couple_verify_pos(n_out, 1), bound);
|
||||
CHECK_OK(ch.s.set_mtp_couple(r.id, bound, 3));
|
||||
|
||||
std::vector<float> lg(4 * 64, 0.0f);
|
||||
for (int row = 0; row < 4; ++row) lg[(size_t)row * 64 + 31] = 20.0f;
|
||||
std::vector<int32_t> tok;
|
||||
CHECK_OK(ch.step({ &r }, lg, &tok));
|
||||
REQUIRE_EQ(tok.size(), (size_t)4);
|
||||
CHECK_EQ(tok[0], 31); /* the chain is rejected at its first draft: the residual's token */
|
||||
|
||||
CHECK_OK(ch.s.set_mtp_couple(r.id, bound, 3));
|
||||
std::vector<float> lg2(4 * 64, 0.0f);
|
||||
lg2[0 * 64 + 21] = 20.0f;
|
||||
lg2[1 * 64 + 22] = 20.0f;
|
||||
lg2[2 * 64 + 23] = 20.0f;
|
||||
lg2[3 * 64 + 9] = 20.0f;
|
||||
CHECK_OK(ch.step({ &r }, lg2, &tok));
|
||||
CHECK_EQ(tok[0], 21);
|
||||
CHECK_EQ(tok[1], 22);
|
||||
CHECK_EQ(tok[2], 23);
|
||||
CHECK_EQ(tok[3], 9);
|
||||
}
|
||||
|
||||
/* The planes are sized for the rows a step can sample: one per token the step carries, so never
|
||||
* more than max_tok, and never fewer than max_seqs (a drafter's greedy pass). */
|
||||
TEST(the_sampler_rows_are_bounded_by_the_steps_tokens) {
|
||||
|
||||
Reference in new issue
Block a user