feat: int8 per-tensor KV cache with FlashInfer dequant bridge (SM75)
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)
| metric | value |
|---|---|
| prefill 128K | 125.8s / 1018 tok/s |
| prefill 256K | 343.5s / 746 tok/s |
| quality (12*8) | 96 |
| KV memory | halved 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_scaleso 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, passesk_scale/v_scale=1.0to avoid double scaling, and usestriton_reshape_and_cache_flashfor int8 cache updates; KV storage stays int8. -
triton: addsKV_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 forint8_per_tensor. -
Plumbing: maps
int8_per_tensortotorch.int8, treats it as a quantized KV cache, addsKVQuantMode.INT8_PER_TENSOR=5, keepscalculate_kv_scalesenabled for int8 on hybrid models, and limitsflash_attnselection to fp8/nvfp4. -
Rollout: Start with a ≥2048‑token first prompt to calibrate;
flash_attncannot be used withint8_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:
| PR | concern | dependency |
|---|---|---|
| #106 | int8 per-tensor KV cache | foundation |
| #107 | GDN GGUF/AWQ dual-layout | REQUIRED to serve GDN models |
| #108 | disable custom AR during profiling | independent |
| #109 | Triton decode fast path | depends 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).