Documents the full drafter Step 1 landing (b1-b6 + serve wiring, opt-in VETTA_SPEC=1), the WMMA flash batch-dependence root cause + per-M dispatch fix (prefill perf preserved, measured 1.74x), the lossless gate (200 tokens EXACT) and serve reference parity (16 tokens EXACT), the n_draft sweep (optimum 2, hypothesis 5 disproved), measured ~1.16x speedup (acceptance-limited), and next steps (acceptance bisection / tree drafter / DMA streaming). Verification totals: CPU -D warnings clean, Lean 0 sorryAx, hip 45/45, ld GPU 65/65, gw GPU 22/22.
115 lines
5.7 KiB
Markdown
115 lines
5.7 KiB
Markdown
# DSpark drafter — Step 1 completato (2026-12-02)
|
|
|
|
Stato: **Step 1 del drafter speculativo MTP è completo, verificato e cablato in
|
|
serve (opt-in `VETTA_SPEC=1`)**. HEAD `ba51499` (pushed origin/main).
|
|
|
|
Riferimento piano: `review/2026-12-02-piano-vram-piatta-e-guida-drafter.md`.
|
|
Ground truth: `strata-safetensors/engine/src/inkling2/` (`ink_dspark.cuh`,
|
|
`ink_cpu_backend.cpp`, `ink_serve.h`).
|
|
|
|
## Catena verificata (brick per brick)
|
|
|
|
| Brick | Contenuto | Commit |
|
|
|---|---|---|
|
|
| b1 | Lean `spec_lossless` + `kept_rejected_disjoint` (0 sorryAx) | `afce5cb` |
|
|
| b2 | loader `mtp.safetensors` + `layout_check` (54 tensori BF16) | `3a9533a` |
|
|
| b3a | kernel `mix_taps` + `rmsnorm_rope` (RoPE f64 interno) | `7e74db7` |
|
|
| b3b | `dspark_context` (pesi proj BF16, parity 3e-6) | `0cbec2d` |
|
|
| b3c | tap capture nel trunk `[5,23,41,48]` (logits bit-identici) | `b6ed89b` |
|
|
| b4a | `block_attn` + `swiglu` | `1b10258` |
|
|
| b4b | `markov_gru` + `corr_combine` | `142580e` |
|
|
| b4c | `split3` + `dspark_draft` block-8 (ids exact vs oracle) | `f9cde49` |
|
|
| b5a | `spec_accept_greedy` (indexing fedele a ink_serve.h) | `3812845` |
|
|
| b5b-1 | kernel `hist_snaps` (snapshot shortconv per-prefisso) | `ca12801` |
|
|
| b5b-2/3 | `LayerState` snaps + `rollback_spec` + `DsparkContext` + `spec_round` | `7b617bc` |
|
|
| b6 | gate lossless: 200 token EXACT vs plain batched greedy | `7b617bc` |
|
|
| flash fix | dispatch per-M (WMMA prefill / scalare decode+verify) | `11404c4` |
|
|
| b5b-4 | wiring serve opt-in + EMA + parity reference exact | `df537bf` |
|
|
| tuning | n_draft optimum misurato = 2 + override `VETTA_SPEC_ND` | `ba51499` |
|
|
|
|
## Bug di correttezza trovato e risolto: flash WMMA batch-dipendente
|
|
|
|
La divergenza iniziale del gate (token 46) **non** era nel runner: il flash FA2
|
|
WMMA (`k_flash_swa_gqa_prefill_wmma`) su un query-tile a posizioni miste fa
|
|
dipendere l'output di una query dai vicini di batch di ~1 ulp. Causa confermata
|
|
sperimentalmente: una chiave KV extra reale (oltre `pos` della query ma entro
|
|
`q_max_pos` del tile), sebbene mascherata (P=0), filtra ~1 ulp nella PV WMMA.
|
|
Azzerando K13/V13 nel test, M=2 == M=1 exact.
|
|
|
|
Quel drift da 1 ulp, roundato bf16 nell'hist shortconv, accumula finché un
|
|
near-tie greedy si ribalta. Il gate greedy-vs-reference del **prefill** tollera
|
|
~1 ulp (infatti passava con WMMA); la **speculazione** richiede exact tra decode
|
|
(M=1) e verify (M=nd+1).
|
|
|
|
**Fix (preserva la perf misurata)**: dispatch del flash per M.
|
|
- `M >= 16` (chunk prefill): WMMA flash → win misurato preservato.
|
|
- `M < 16` (decode B=1 + verify spec M<=8): flash scalare f16 per-query
|
|
deterministico → verify e decode concordano bit-a-bit.
|
|
- `VETTA_FLASH_WMMA=1` forza WMMA (test), `VETTA_NO_FLASH_WMMA=1` forza scalare.
|
|
|
|
Misura prefill 1024 tok chunk 256: **WMMA 5.786 ms/tok vs scalare 10.047 ms/tok
|
|
(1.74x)** → nessuna regressione prefill. (Il precedente default scalare globale
|
|
`6e854a9` regrediva ~2x; superato da `11404c4`.)
|
|
|
|
Nota: il kernel WMMA resta batch-dipendente per tile misti (opt-in/test); il
|
|
guard `alpha=1.0` quando `nm==row_max` è un miglioramento minore ma non elimina
|
|
il leak PV. Fix radicale del kernel WMMA = lavoro futuro se si vuole WMMA anche
|
|
sul decode.
|
|
|
|
## Rollback speculativo (provato + verificato)
|
|
|
|
- **KV ring**: troncamento di lunghezza, nessun restore dati
|
|
(`kept_rejected_disjoint`: slot kept vs rejected disgiunti con R >= window+chunk).
|
|
- **ShortConv hist**: shift-register `[3]` per pass → snapshot per-prefisso
|
|
(`k_shortconv4_hist_snaps`, `snaps[t] == update_hist` sul prefisso t, exact) e
|
|
`rollback_spec` ripristina `hist <- snaps[accepted]`.
|
|
- Diagnostic lockstep: 200 round hist+KV **exact** vs plain batched.
|
|
|
|
## Misure reali (gfx1150, capital prompt "The capital of France is", GEN 96)
|
|
|
|
Sweep n_draft (decode tok/s):
|
|
|
|
| n_draft | 1 | **2** | 3 | 4 | 5 | 7 |
|
|
|---|---|---|---|---|---|---|
|
|
| decode tok/s | 5.25 | **6.09** | 5.78 | 5.54 | 4.58 | 5.15 |
|
|
| acceptance | 57% | 50% | 35% | 28% | 26% | 19% |
|
|
|
|
**Optimum = n_draft 2.** Ipotesi "fissare a 5" smentita dalla misura: a
|
|
~30-50% acceptance un verify batch più grande spreca compute su draft rifiutati.
|
|
EMA ritarata: parte da 2, escala solo ad acceptance molto alta (>=0.75→4,
|
|
>=0.9→7). Run adattivo: nd=2, decode **6.10 tok/s**, ON **4.59** vs OFF **3.97**
|
|
tok/s totale richiesta → **~1.16x**. Gain modesto ma reale, misurato, nessun
|
|
overclaim.
|
|
|
|
Parity: `serve_gen_spec_multi_token_parity` → il path spec emette i **16 token
|
|
reference EXACT** (batched decode == M=1 == reference). `spec_lossless_gate` →
|
|
**200 token EXACT** vs plain batched greedy su trunk+mtp reali.
|
|
|
|
## Stato serve
|
|
|
|
- Spec **opt-in** `VETTA_SPEC=1`: carica i pesi drafter resident iff
|
|
`mtp.safetensors` passa `layout_check`; prefill cattura taps + commit ctx rings;
|
|
decode `spec_round` con EMA. Solo greedy puro senza penalties. EOS/stop/length
|
|
gestiti per token emesso. Prefix save invariato.
|
|
- Decode default M=1 **invariato** (spec off).
|
|
- Server **fermo** (per i test GPU). Riavvio con `VETTA_SPEC=1` per chattare col
|
|
drafter attivo.
|
|
|
|
## Verifica totale
|
|
|
|
CPU `-D warnings` pulito · Lean 0 sorryAx · hip **45/45** · ld GPU **65/65** ·
|
|
gw GPU **22/22**.
|
|
|
|
## Prossimi passi (domani)
|
|
|
|
1. **Bisect acceptance drafter** (raccomandato): 50% sul primo draft è sotto le
|
|
attese per un head MTP addestrato → possibile disallineamento ctx ring o
|
|
anchor. Confrontare i draft vetta vs reference (`dspark_draft` call site) su
|
|
testo reale; se acceptance sale a ~70-80%, nd=3-4 diventerebbero vantaggiosi
|
|
e lo speedup crescerebbe davvero.
|
|
2. **Step 2 tree drafter** (opzionale): albero invece del block-8 lineare.
|
|
3. **DMA layer streaming** (la "parte difficile" del piano): io_uring + slab ring
|
|
DMA per flat-VRAM a contesti lunghi / modelli >80 GiB. Cuore architetturale
|
|
microkernel.
|
|
|
|
Leva vera per lo speedup spec = **acceptance**, non n_draft più alto. |