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>
55 lines
2.5 KiB
C++
55 lines
2.5 KiB
C++
/* mtp_couple_plan.h -- which draw the engine stages for each drafting row (serial or block).
|
|
*
|
|
* Engine::stage_couple_draws (core/engine_draft.cpp) reads the draw of every sequence on its card
|
|
* from the step plan and, for each drafting row, the plan entry naming the row's sequence on the
|
|
* row's card. Pure host bookkeeping, so it is tested without a card.
|
|
*
|
|
* `by_card` has one entry per card slot, indexed by StepEntry::card in [0, max_seqs), the range of
|
|
* the StepSlots the advance reads.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "batch.h"
|
|
#include "scheduler.h" /* Scheduler::SerialRow */
|
|
|
|
#include "rad_spechub.h"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace rad {
|
|
|
|
/* Fills `by_card[0, n_card)` from the plan and writes one draw per drafting row to `stage[0, n)`.
|
|
* RAD_OK, or RAD_E_STATE with `why` set: the plane is too small for the card slots, or a drafting
|
|
* row's card carries no plan entry naming its sequence (a stale row -- the plugin would refuse the
|
|
* staged draw, so it is refused here where the row can be named). */
|
|
template <class Row> /* Scheduler::SerialRow or Scheduler::BlockRow: a sequence and its card */
|
|
inline int mtp_couple_plan_stage(const StepPlan& plan, int n_card, const Row* rows,
|
|
int n, std::vector<RadMtpCoupleDraw>* by_card,
|
|
RadMtpCoupleDraw* stage, std::string* why) {
|
|
if (!by_card || !stage || !why) return RAD_E_INVAL;
|
|
if ((int)by_card->size() < n_card) {
|
|
*why = "the draw plane holds " + std::to_string(by_card->size()) +
|
|
" card slot(s), the step can use " + std::to_string(n_card);
|
|
return RAD_E_STATE;
|
|
}
|
|
for (int c = 0; c < n_card; ++c) (*by_card)[(size_t)c] = RadMtpCoupleDraw{};
|
|
for (const StepEntry& e : plan.e)
|
|
if (e.req && e.card >= 0 && e.card < n_card)
|
|
(*by_card)[(size_t)e.card] = { e.req->sp.seed, (uint64_t)e.req->output.size(), e.seq,
|
|
e.card, e.req->sp.greedy() ? 0u : 1u };
|
|
for (int i = 0; i < n; ++i) {
|
|
const Row& row = rows[i];
|
|
if (row.card < 0 || row.card >= n_card || (*by_card)[(size_t)row.card].seq != row.seq) {
|
|
*why = "drafting row " + std::to_string(i) + " (sequence " + std::to_string(row.seq) +
|
|
", card " + std::to_string(row.card) + ") has no plan entry on its card";
|
|
return RAD_E_STATE;
|
|
}
|
|
stage[i] = (*by_card)[(size_t)row.card];
|
|
}
|
|
return RAD_OK;
|
|
}
|
|
|
|
} // namespace rad
|