dflash2: lossless coupled acceptance at T > 0 (--draft-coupling on)

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>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-27 18:37:28 +01:00
1 parent 72a58d0c0c
commit cb0abe9ac7
18 files changed
+1330 -115

No files matched your search

+22 -4
View File
@@ -2692,11 +2692,13 @@ resolutions of one op. The one exception is `sample_chain` (below).
| `sample_logprobs` | `M`(range) `n_vocab` `k` `vocab_off`/opt | `logits`, `params` → `stats` |
| `mtp_couple_propose` | `M`(range) `n_vocab` `round` `max_rounds` | `idx`:inout, `val`, `seq_ids`, `draw` → `state`:inout |
| `mtp_couple_verify` | `M`(range) `n_cand` `n_vocab` | `cand_idx`, `cand_val`, `params`, `state` → `token`:inout |
| `dflash_couple_propose` | `M`(range) `steps` `top_k` `rank` `n_vocab` `anchor_stride` `max_rounds` `q_temp`:f64/opt | `cand`, `unary`, `hp`?, `anchor`, `pred`w, `succ`w, `seq_ids`, `draw`, `tokens`:inout → `state`:inout |
`mtp_couple_propose` and `mtp_couple_verify` are the linear-MTP coupling (`--draft-coupling on`),
and nothing else in the engine knows about coupling. Turning coupling on requires the
linear serial draft chain: a block drafter (`RAD_DRAFT_BLOCK`) or no drafter at all is refused at
bringup, because neither has a per-round draw to couple. The `spechub` plugin ships both rows and
`mtp_couple_propose`, `dflash_couple_propose` and `mtp_couple_verify` are the speculative coupling
(`--draft-coupling on`), and nothing else in the engine knows about coupling. Turning coupling on
requires a linear chain of drafts: a serial head's rounds, or a block drafter whose architecture
declares the coupled walk (DFlash2); no drafter, or a block drafter without the walk, is refused at
bringup, because neither has a per-round draw to couple. The `spechub` plugin ships every row and
their host oracle in one library and marks them per row, so the device rows count as production
kernels while the oracle stays reference; on a machine with no card only the oracle is left, and
the gate refuses the coupling there. A `RADIANCE_KERNELS` list is exclusive:
@@ -2714,6 +2716,22 @@ that seed and position keeps the ordinary token. `P` is FP64-normalised where `s
FP32/24-bit, so a coupled row realizes the ideal filtered target law and is **not** seed-identical
to the ordinary pick.
`dflash_couple_propose` is DFlash2's block walk sampled (abi/rad_spechub.h,
`rad_dflash_couple_step`). It runs right after `dflash_select` over the same lattice, one workgroup a
sequence. At position `l` every candidate scores `dflash_select`'s
`unary + Σ_r pred[pid][r]·hp[l][r]·succ[cand][r]`, with `pid` the anchor at `l = 0` and the walk's
own previous token after it; `Q_l` is the FP64 softmax of `score / q_temp` over the best eight
in-vocabulary candidates, `x_l ~ Q_l` at the draw's `(seed, base, KEY_DRAFT + l + 1)`, and `x_l` is
both the proposal (into `tokens`) and position `l + 1`'s predecessor. Position `l` writes the state
row of round `l + 1`, so the engine binds and the sampler verifies it exactly as an MTP round. A
greedy request's row (draw mode 0) keeps `dflash_select`'s tokens (`status = 0`); a draw staged for
another card, or a position whose eight cannot form a `Q`, takes the walk's argmax (`status = -1`)
and the ordinary verify. `Q_l` depends on the committed text and on `x_0 .. x_{l-1}`, never on the
verify, and is stored exactly, which is all the coupling needs to be lossless; `q_temp` (the
architecture's, `RADIANCE_DFLASH_Q_TEMP` on Qwen3.5/3.8) moves acceptance only. Each edge is eight
partial `fmaf` chains over contiguous slices of the rank, added in order, so the device kernel and
the host oracle agree bit for bit.
`sample_temp` divides a row's logits by its `temp` and leaves a row whose `temp` is 0 or less, or
exactly 1, as it is. The sampler relies on that: a step none of whose chain rows has another
temperature does not issue the stage.