Archived
DFlash2's drafts were the greedy walk over its candidate lattice, accepted
only when they equal the target's own sampled draw: P(y == x) instead of
rejection sampling's sum min(P, Q). --draft-coupling already did the latter
for a linear MTP head; this extends it to the block drafter.
- dflash_couple_propose (spechub plugin, device row + host oracle): after
dflash_select, the same lattice walked again, sampled. Position l scores
each candidate as dflash_select does (unary + low-rank edge from the
previous token), Q_l = FP64 softmax of score / q_temp over the best eight
in-vocabulary candidates, x_l ~ Q_l at (seed, base, KEY_DRAFT + l + 1),
x_l is the next predecessor. Position l writes round l+1's state row, so
the engine binds it and the sampler's mtp_couple_verify (maximal coupling,
residual (P - Q)+) verifies it exactly as an MTP round. Q depends on the
committed text and on x_0..x_{l-1}, never on the verify, and is stored
exactly. Greedy requests keep dflash_select's tokens (status 0); a draw
for another card or a Q that cannot be built takes the walk's argmax and
the ordinary verify (status -1). The shared arithmetic is in
abi/rad_spechub.h (rad_dflash_couple_step / _walk).
- The block driver stages one draw per drafting row before the query pass,
reads the states back with the slots and binds them after the commit
(Engine::bind_couple, shared with the serial driver).
- qwen35_fp8 declares the planes and the op under --draft-coupling;
RADIANCE_DFLASH_Q_TEMP sets Q's temperature (default 1, exact at any).
- Default (flag off): no op, no plane, no change.
Gates:
- spechub_dflash_couple_test (CPU): emitted token vs P by chi-square over 3
seeds each, Fisher-combined p 0.135..0.919, for Q = P, Q on fewer tokens
than P, Q mostly outside P, top_k 20 + top_p 0.95, top_p 0.6, top_k 3 at
T 0.7, peaked Q; acceptance = sum min(P, Q) within 5 sigma; the walk's
stored Q equals the softmax of its scores (1e-5) and x follows it (p
0.993); the whole draft/verify/bonus loop over 3 tokens matches the
target's autoregressive law (combined p 0.62 at q_temp 1, 0.67 at 0.5,
0.024 with every 2nd step on the ordinary verify).
- Device row vs host oracle, 40 random lattices at the production geometry
(V 248320, K 16, R 256, steps 7/3, M 1..16): tokens, x, ids, status
identical; q differs only by FP64 exp ulps (<= 4.3e-16 relative).
91 us a launch at M 16, steps 7.
- Engine, Qwen3.8-27B MXFP4 TP2, our serving flags, 4-6 tokens of two chat
prompts at T 1 / top_p 0.95 / top_k 20, 5000-11000 samples per arm:
coupled vs ordinary speculation chi-square p 0.23..0.81 (tokens 1-4 and
pair 1-2); both differ from no speculation on one prompt by the same
amount (the verify-vs-decode logits, not the rule).
- Flag off, old build (up12 5dbb5dc) vs this: greedy top-5 logprob traces
identical over 300 tokens (spec 7 and 0, two requests each), 6/6
fixed-seed sampled texts identical.
- ctest (the environment-only tests excluded) 105/105.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
91 lines
3.6 KiB
C++
91 lines
3.6 KiB
C++
/* plugin/spechub/exports.cpp -- the plugin's export block.
|
|
*
|
|
* The whole kernel-plugin set (schema count/at, kernel count/at, ABI version, info) and nothing else.
|
|
* The rows themselves, their schemas and their argument readers are in spechub.cpp; the launches are
|
|
* spechub.hip (device) and ref_spechub.cpp (host).
|
|
*
|
|
* Reference status is per row: the library carries device rows and their host oracle, so
|
|
* `rad_kernel_reference` marks the device rows 0 and the host rows 1, and `rad_plugin_reference`
|
|
* stays 0. Marking the whole library would make the reference gate refuse the device rows. On a
|
|
* machine with no card only the reference rows exist, and the gate refuses the coupling there.
|
|
*
|
|
* The ops are declared only under --draft-coupling on; the plugin never reads the flag.
|
|
*/
|
|
#include "spechub.h"
|
|
|
|
#ifdef RAD_SPECHUB_WITH_DEVICE
|
|
#include "../../libr4d/r4d_emit.h" /* only for the three globals it declares */
|
|
|
|
/* r4d_emit.h's dispatch recorder, defined here because plugins load RTLD_LOCAL and cannot
|
|
* resolve libr4d's copy. Nothing in this plugin sets the log, so the recorder stays inert. */
|
|
const void** r4d_dispatch_log = nullptr;
|
|
int r4d_dispatch_cap = 0;
|
|
int r4d_dispatch_n = 0;
|
|
#endif
|
|
|
|
namespace {
|
|
const RadPluginInfo kInfo = {
|
|
RAD_PLUGIN_KERNEL, "spechub", "0.1.0",
|
|
"Maximal coupling of speculative drafts: Q draws (MTP, DFlash2), coupled verify", "gfx1201",
|
|
};
|
|
} /* namespace */
|
|
|
|
extern "C" uint32_t rad_plugin_abi_version(void) { return RAD_ABI_VERSION; }
|
|
extern "C" const RadPluginInfo* rad_plugin_info(void) { return &kInfo; }
|
|
/* Mixed library: 0, and the per-row answer below does the classifying. */
|
|
extern "C" int rad_plugin_reference(void) { return 0; }
|
|
|
|
/* Row layout is [device 0..2, ref 0..2] with a card, [ref 0..2] without; row/op index 2 is
|
|
* dflash_couple_propose. The device rows are the production kernels; the host rows are the oracle
|
|
* rad-kbench checks them against and the only thing a card-less machine can run. */
|
|
extern "C" int rad_kernel_reference(int i) {
|
|
#ifdef RAD_SPECHUB_WITH_DEVICE
|
|
return (i >= 0 && i < RAD_SPECHUB_N_OPS) ? 0 : 1;
|
|
#else
|
|
(void)i;
|
|
return 1;
|
|
#endif
|
|
}
|
|
|
|
extern "C" int rad_kernel_schema_count(void) { return rad_spechub_schema_count(); }
|
|
extern "C" const RadOpSchema* rad_kernel_schema_at(int i) { return rad_spechub_schema_at(i); }
|
|
|
|
/* The device rows and the host references beside them, in that order. A card-less machine loads the
|
|
* same library and resolves only the reference rows. */
|
|
extern "C" int rad_kernel_count(void) {
|
|
#ifdef RAD_SPECHUB_WITH_DEVICE
|
|
return 2 * RAD_SPECHUB_N_OPS;
|
|
#else
|
|
return RAD_SPECHUB_N_OPS;
|
|
#endif
|
|
}
|
|
|
|
namespace {
|
|
RadKernelInfo ref_row(int op, RadLaunchFn launch, const char* name) {
|
|
RadKernelInfo x = rad_spechub_row(op, launch);
|
|
x.name = name;
|
|
x.domain = RAD_DOMAIN_HOST;
|
|
x.priority = 0;
|
|
return x;
|
|
}
|
|
} /* namespace */
|
|
|
|
extern "C" const RadKernelInfo* rad_kernel_at(int i) {
|
|
#ifdef RAD_SPECHUB_WITH_DEVICE
|
|
static const RadKernelInfo dev[RAD_SPECHUB_N_OPS] = {
|
|
rad_spechub_row(0, rad_mine_mtp_couple_propose_launch),
|
|
rad_spechub_row(1, rad_mine_mtp_couple_verify_launch),
|
|
rad_spechub_row(2, rad_mine_dflash_couple_launch),
|
|
};
|
|
if (i >= 0 && i < RAD_SPECHUB_N_OPS) return &dev[i];
|
|
i -= RAD_SPECHUB_N_OPS;
|
|
#endif
|
|
static const RadKernelInfo ref[RAD_SPECHUB_N_OPS] = {
|
|
ref_row(0, rad_ref_mtp_couple_propose, "ref_mtp_couple_propose"),
|
|
ref_row(1, rad_ref_mtp_couple_verify, "ref_mtp_couple_verify"),
|
|
ref_row(2, rad_ref_dflash_couple, "ref_dflash_couple_propose"),
|
|
};
|
|
if (i < 0 || i >= RAD_SPECHUB_N_OPS) return nullptr;
|
|
return &ref[i];
|
|
}
|