perf: int8 decode via Triton kernel (FlashInfer prefill + Triton decode hybrid)
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)
| context | before (FlashInfer whole-pool dequant) | after (Triton decode) |
|---|---|---|
| decode 1K | 5.7 tok/s | 42.2 tok/s |
| decode 8K | 5.7 | 37.0 |
| decode 16K | 5.7 | 32.4 |
| decode 32K | 5.7 | 25.8 |
| decode 128K | 5.7 | 11.9 |
| decode 256K | 5.7 | 7.0 |
| prefill 8K | 1580 | 1575 tok/s (no regression) |
| prefill 32K | 1407 | 1411 |
| 128K prefill | 126.1s/1016 | 125.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: addsKVQuantMode.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_flashquantizes 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);
flashinfermetadata now carriesseq_lensandblock_tablefor 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_tensorincache_dtype; map totorch.int8and treat as quantized KV; keepcalculate_kv_scalesforint8_per_tensoron 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:
| 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).