perf: int8 decode via Triton kernel (FlashInfer prefill + Triton decode hybrid)

SU
4mo ago
+459-59

Summary

int8 decode was 5.7 tok/s: whole-pool dequantization (343K tokens x 16 layers ≈ 17GB memory traffic per step) before every FlashInfer decode call. This routes decode through the Triton unified_attention kernel (native INT8_PER_TENSOR, processes only requested blocks) while keeping FlashInfer prefill (dequant path, 1400+ tok/s).

Depends on #106 (int8 KV) — uses its dequant infra.

A/B benchmark (before/after, dual RTX 2080Ti, TP2)

contextbefore (FlashInfer whole-pool dequant)after (Triton decode)
decode 1K5.7 tok/s42.2 tok/s
decode 8K5.737.0
decode 16K5.732.4
decode 32K5.725.8
decode 128K5.711.9
decode 256K5.77.0
prefill 8K15801575 tok/s (no regression)
prefill 32K14071411
128K prefill126.1s/1016125.8s/1018

Quality: 12*8 = 96, car-wash trap, 4K material — all pass.

Implementation

  • Decode-only batches skip whole-pool dequant (saves ~17GB/step)
  • 3D segmented softmax (seq_threshold_3D, 16 softmax segments) fixes 2D serial degradation on long contexts (32K: 3.4 -> 25.8 tok/s)
  • Speculative/multi-token decode (num_decode_tokens != num_decodes) and CUDA-graph padding rows fall back to FlashInfer with dequant (safe path)

Summary by cubic

Speeds up INT8 decode by routing it through Triton unified_attention and reading native int8_per_tensor KV, eliminating whole‑pool dequantization (~5.7 tok/s → ~42 tok/s at 1K) while keeping FlashInfer for prefill with no regression. Old behavior dequantized the entire KV pool each step; new behavior processes only requested blocks and dequants only for prefill or fallback.

  • Triton decode for int8_per_tensor: adds KVQuantMode.INT8_PER_TENSOR; folds k_scale into softmax scale and applies v_scale post‑accumulation; enables 3D segmented softmax; decodes from raw INT8 cache; triton_reshape_and_cache_flash quantizes with sign‑aware half‑away‑from‑zero rounding.
  • FlashInfer remains for prefill: dequantizes to fp16 with tensor scales (avoids double scaling and CUDA‑graph constant folding); flashinfer metadata now carries seq_lens and block_table for Triton decode; decode fallback dequants before calling FlashInfer.
  • Calibration (INT8 only): keep dynamic K/V scales on hybrid models; skip zero‑value warmups; guard during CUDA‑graph capture; calibrate K and V independently on the first real long prefill (>= 2048 tokens), restricted to actual prefill rows via is_prefilling; never calibrate on pure‑decode batches; warn once per layer when uncalibrated.
  • Path selection: run Triton fast path only when each request decodes 1 token with no padding (num_decode_tokens == num_decodes); speculative/multi‑token decode and CUDA‑graph padding rows fall back to FlashInfer.
  • Types/config: allow int8_per_tensor in cache_dtype; map to torch.int8 and treat as quantized KV; keep calculate_kv_scales for int8_per_tensor on hybrid models (fp8 remains disabled).

Rollout

  • Set cache_dtype=int8_per_tensor. Trigger calibration with a prompt >= 2048 tokens outside CUDA‑graph capture; warmups and pure‑decode batches defer calibration (single warning per layer).
  • No changes for non‑INT8 models or prefill throughput; speculative/multi‑token decode and padding rows continue via the FlashInfer fallback.

⚠️ Applying this PR alone (important)

This PR is one of a 4-PR series (one concern per PR, per the maintainer's review guidance). The four together form the complete feature set the SM75 serving stack depends on:

PRconcerndependency
#106int8 per-tensor KV cachefoundation
#107GDN GGUF/AWQ dual-layoutREQUIRED to serve GDN models
#108disable custom AR during profilingindependent
#109Triton decode fast pathdepends on #106

Applying only a subset leaves the tree incomplete and unsafe for the production serve environment:

  • Without #107, serving a GDN (Qwen3.5-style) model fails at engine init ( / worker exception during CUDA-graph capture). On the reference hardware this produced a systemd loop; the repeated load window escalated into a GPU Xid 154 (recovery action 0x2, Node Reboot Required). The incomplete tree is NOT a safe state.
  • Without #106, #109 has no int8 KV infrastructure to accelerate.
  • Merge order: #106 → #107 → #108 → #109 (or merge all four together).