[Bug]: Fill-in DSpark underallocates KV lookahead and can overwrite target KV (synthetic CUDA repro)
Bug
For DSpark checkpoints with sample_from_anchor=false, the drafter uses N+1 query positions (bonus token + N draft tokens), but VllmConfig.num_lookahead_tokens reserves only N.
With 137 prompt tokens, 7 draft tokens and 16-token KV blocks, the scheduler allocates 144 slots (positions 0–143), while the drafter also writes position 144. That lookup can read a stale block ID from the unused table tail and overwrite another request's target KV cache. This was observed during generation, causing repetitive malformed output.
Reproduction
The regression is covered by test_dspark_lookahead_covers_query_window in #59105. It checks that the full draft query window fits the reserved blocks; no model weights or prompts are needed.
Run in a vLLM test environment:
python -m pytest --noconftest tests/v1/spec_decode/test_dflash_lookahead.py -k dspark_lookahead_covers_query_window -q- Test-only commit
58eff92e7: 1 failed. - Fix commit
a26af2d9d: 1 passed.
The test covers both anchor modes and the default, N=1/7, block sizes 16/32, and prompt lengths spanning two blocks. It checks allocation bounds; the actual KV overwrite was confirmed separately by GPU instrumentation.
Standalone synthetic CUDA reproducer exercises the actual draft slot-preparation kernel without model weights or user prompts. It fails before the fix and passes after it; instructions and expected output are included in the gist.
Environment and validation
Observed on vLLM 0.30.1rc1.dev284+gbeef814e1, PyTorch 2.13.0+cu130, Python 3.11.14, one H200, google/gemma-4-31B-it + RedHatAI/gemma-4-31B-it-speculator.dspark. BF16, FlashAttention 4, V2 runner, eager, synchronous scheduling, prefix caching off, no LoRA.
Before the fix, the workload reproducibly failed on batch 9. After the fix, three cold starts × 20 batches × 16 requests completed without the observed corruption. The originally failing batch had no invalid draft writes or target-KV mutations.
Proposed fixes
- #59105: minimal two-file fix and regression test; reserve N+1 slots for fill-in DSpark while preserving anchor-sampling and DFlash behavior.
- #48909: a broader four-file alternative for the same mismatch, also introducing a shared query-width property and updating the older runner's max-length guard.
AI assistance: Codex.
Source: vllm-project/vllm