#59054·vllm

[Bug]: Triton attention: spec-decode verify batches (q_len>1) forced onto the 2D kernel — 7-20x per-call attention slowdown at long context

Author: kaka86mmCreated Sep 28, 2026Updated Sep 28, 2026

Describe the bug

In vllm/v1/attention/ops/triton_unified_attention.py (and the DiffKV variant triton_unified_attention_diffkv.py), the 3D/2D launch decision includes max_seqlen_q > 1 in the 2D-forcing condition:

python
use_3d = not (
    ...
    or max_seqlen_q > 1
    or num_seqs > seq_threshold_3D
    ...
)

Every speculative-decode verify batch (q_len = k+1 > 1) therefore runs the 2D varlen kernel. For a single-stream verify batch the 2D grid is (total_num_q_blocks, num_kv_heads) — e.g. (1, 4) = 4 CTAs on a 70-SM GPU, each CTA sequentially walking the entire KV history.

Kernel-level measurements

MiMo-V2.6-Flash global-attention shape (64 Q heads / 4 KV heads / QK 192 / V 128, block 128, one sequence, CUDA events, 30 iters, CMP 170HX / sm80):

q_len stock kernel (ms/call) 3D spec-verify path (ms/call) speedup KV len
1 0.27 0.28 1.0x (no regression) 67K
2 5.08 0.26 19.6x 67K
3 3.99 0.58 6.8x 67K
4 3.98 0.56 7.1x 67K
2 1.15 0.16 7.4x 19K
3 1.14 0.18 6.4x 19K
4 1.14 0.18 6.4x 19K

Notes:

  • q=1 is bit-identical between versions — pure decode is unaffected.
  • Stock q=2 is slower than stock q=4 (5.08 vs 3.98 ms) — an artifact of the 2D tile path that further underlines the pathology.
  • With the 3D path, a verify call costs ~2x a decode call (the q query positions share one KV read) — close to the theoretical optimum, versus 15-19x on stock.

Serving-level effect

4x CMP 170HX (sm80, PP=4), MiMo-V2.6-Flash-RL official fp8 checkpoint, MTP k=2, steady-state decode (unique-content prompts, thinking off, warmup dropped):

  • 67K context: 16.5 tok/s (stock) vs 33.7 tok/s (3D verify) — 2x
  • Without speculative decoding the same rig decodes 67K context at 56.1 tok/s, i.e. the kernel bug turns speculative decoding into a net loss at long context on Triton-backend hardware.
  • The cliff starts around 5K context (42.5 tok/s with spec vs ~63 without).

Fix

Allow small q_len batches onto the 3D split-KV path with BLOCK_M = q_len x GQA group so the segment axis supplies the parallelism. A complete, tested, MIT-licensed implementation exists in the MiaAI-Lab DGX-Spark recipe (drop-in on the sm80 backport fork, env-gated via VLLM_DIFFKV_SPEC_3D_MAX_Q / _BLOCK_M / _NUM_WARPS / _TILE):

https://github.com/MiaAI-Lab/DeepSeek-v4.1-Flash-DGX-Sparks/blob/main/recipe/patches/triton_unified_attention_diffkv.py

Happy to port this to mainline as a PR if the approach sounds acceptable.

Impact scope

Any user on the Triton attention backend — the default/preferred path for pre-Hopper GPUs and for DiffKV-head models — running speculative decoding with non-trivial context lengths pays this per verify step. We found no prior report of it; the win is largest exactly where the Triton path is the only option.

Environment: vLLM v0.13-lineage backport fork for sm80 (the affected code is present on current main per triton_unified_attention.py around the use_3d decision), 4x CMP 170HX, CUDA 13.0, torch 2.13.