feat: int8 per-tensor KV cache with FlashInfer dequant bridge (SM75)

Draft
SU
4mo ago
+390-58

Summary

Symmetric int8 per-tensor KV cache for Turing (sm_75, no FP8 hardware), port of upstream PR#41505 plus a FlashInfer dequantization bridge:

  • int8 KV storage halves KV memory (128K context: ~8GB -> ~4GB per GPU)
  • Dynamic scale calibration (--calculate-kv-scales) with tensor scales (graph inputs) so CUDA-graph replay reads calibrated values (float scales get folded to 1.0 at capture)
  • FlashInfer 0.6.8 has no int8 kernel template -> forward dequantizes KV to fp16 temp buffers before feeding kernels (K/V separate scales); storage stays int8
  • Zero-value calibration skip (warmup/dummy fwd has all-zero K/V -> scale garbage); first real long prefill calibrates
  • Per-layer uncalibrated warning dedup

Benchmark (dual RTX 2080Ti, TP2, int8_per_tensor)

metricvalue
prefill 128K125.8s / 1018 tok/s
prefill 256K343.5s / 746 tok/s
quality (12*8)96
KV memoryhalved vs fp16

Notes

  • First request must be a long prompt (>=2048 tokens) to trigger calibration
  • Triton reshape_and_cache used (C++ path has no int8 branch)

Summary by cubic

Adds symmetric int8_per_tensor KV cache on SM75 with a flashinfer dequant bridge, halving KV memory vs fp16/fp8. Old: KV in fp16/fp8; New: KV stored as int8 with per‑tensor dynamic scales, dequantized to fp16 for flashinfer or handled natively by triton; flash_attn now rejects int8 to avoid FP8 misrouting.

  • Enable with --cache-dtype int8_per_tensor --calculate-kv-scales. Calibration skips CUDA graph capture and all‑zero K/V, gates on the first eager prefill whose total request length ≥2048 tokens, and updates scales all‑or‑nothing (neither scale updates until both K and V have nonzero maxima). Uses tensor _k_scale/_v_scale so CUDA‑graph replay reads calibrated values; per‑layer deduped warnings if scales remain 1.0.

  • Sets K/V range to 127 at init and re‑asserts after quant weight load to prevent fp8‑style checkpoints from overwriting int8 ranges.

  • flashinfer: dequantizes int8 KV to temporary fp16 before kernels, passes k_scale/v_scale=1.0 to avoid double scaling, and uses triton_reshape_and_cache_flash for int8 cache updates; KV storage stays int8.

  • triton: adds KV_QUANT_MODE=5 (INT8 per‑tensor), folds k_scale into softmax and applies v_scale once post‑matmul, uses platform rounding/clamp intrinsics, and skips fp8 views for int8_per_tensor.

  • Plumbing: maps int8_per_tensor to torch.int8, treats it as a quantized KV cache, adds KVQuantMode.INT8_PER_TENSOR=5, keeps calculate_kv_scales enabled for int8 on hybrid models, and limits flash_attn selection to fp8/nvfp4.

  • Rollout: Start with a ≥2048‑token first prompt to calibrate; flash_attn cannot be used with int8_per_tensor.


⚠️ 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).