EXP-039: FSM-gated scoped re-emission drafter (verbatim spans → 811 tok/s measured)
Layers a rolling-hash scoped drafter on top of MTP: when the last G generated tokens uniquely match a prompt span, draft K_scoped tokens of the continuation; otherwise MTP passes through untouched. Env-gated (VLLM_S4_SCOPED_DRAFTER=0 default). v1's misalignment (merge runs pre-bookkeeping → proposed the just-sampled token) was reproduced in a pure-python unit test, fixed via effective-tail splice, re-A/B'd on hardware: quote-shaped 365→811.5 tok/s (mean 7.44 accepted/step), mixed 101.5 no-harm, generation unchanged. Ship blockers documented: K=16 memory profiling underestimate (~5 GiB), mamba align block inflation at high K (mnbt floor), async-scheduling-off headwind on mixed work (GPU-side merge is the named next increment).
@cubic-dev-ai review
🤖 Generated with Claude Code
Summary by cubic
Adds an FSM-gated, prompt‑scoped drafter for verbatim re‑emission plus a GPU‑side merge path and a verify‑workspace VRAM reserve to prevent post‑profiling OOMs. Previously S4’s CPU merge forced async_scheduling off and K>1 could OOM after profiling; GPU merge keeps drafts on device and sizing subtracts a verify reserve, but the latest async‑on window shows scoped acceptance past position 1 collapsing to zero, so S4 remains default‑off.
- Scoped drafter: opens only when the last G generated tokens uniquely match a prompt span and reconciles against
sampled_token_ids; fail‑safe returns MTP drafts unchanged. Quote‑shaped copies measured 365→811.5 tok/s in v2 (async‑off); generation shows no regression. - Async and merge: with
VLLM_S4_SCOPED_DRAFTER=1, async stays enabled only whenVLLM_S4_GPU_MERGE=1; otherwise we fail fast if async is explicitly set and auto‑disable async in auto mode. Current v3 async‑on runs are negative (positions 2..15 zero acceptance); keep async off when evaluating S4. - GPU merge (v3): retains the CPU rolling‑hash gate; scatters gate‑open rows into a pinned staging buffer, H2D copies to a device buffer, and selects into the MTP tensor via
torch.where. Width‑normalizes MTP’s capped draft to full K; real‑tensor tests cover equivalence and buffer growth. - Verify‑workspace reserve: subtracts
(K-1) * max_num_seqs * vocab * 4 * VLLM_SPEC_VERIFY_OVERSHOOT_MULTbefore KV sizing; logs the decision before cudagraph profiling and runs GC + empty_cache to relieve upstream OOM. Controlled byVLLM_SPEC_RESERVE_VERIFY_WORKSPACE(default on). - Safety and diagnostics: fix numpy≥2 uint64 crash in
_hash_tail(pads as -1) by masking; skip prompt indexing on non‑token ids; reserve returns 0 onNone; narrow the vocab‑size guard; always log the reserve decision; toolss4_v3_window.shnow uses process‑group reaping, a pre‑boot VRAM guard, and waits for VRAM release between arms.
Rollout
- Default off. To evaluate S4:
--speculative-config '{"method":"mtp","num_speculative_tokens":16}', setVLLM_MTP_DRAFT_CAP=2,VLLM_S4_SCOPED_DRAFTER=1, and tuneVLLM_S4_K_SCOPED,VLLM_S4_G,VLLM_S4_MIN_UNIQ. Do not enableVLLM_S4_GPU_MERGEin production yet; keep async off when S4 is on. - Size for scoped K: ensure
--max-num-batched-tokensaccounts for K; keep--gpu-memory-utilizationconservative or adjustVLLM_SPEC_VERIFY_OVERSHOOT_MULT. To guarantee boot at high K, cap cudagraph capture sizes or lowermax_num_seqs.