Fast 4-bit KV-Cache Decoding on Hopper GPUs: Why Existing Kernels Are Slow and How to Fix Them
Organizations: Northeastern University
Abstract
A 4-bit KV cache reads about half the bytes of FP8, but Hopper GPUs have no FP4 hardware and little instruction-issue capacity per byte of memory bandwidth, so 4-bit values must be decoded in software. On H200, vLLM's NVFP4 KV path (FlashInfer's decode) reaches 10-20% of memory bandwidth and is up to 1.7x slower than FP8. NVBit instruction counts show two causes: the kernels behind vLLM's 4-bit paths (FlashInfer NVFP4, Triton UltraQuant) execute 2-6x Hopper's issue budget per byte and serialize loading, decoding and matrix multiplies. Our Hopper-native decode kernel overlaps a TMA producer warp with two compute warpgroups, lays the cache out at write time so decoded values feed the tensor cores from registers, and swaps the matrix operands so small query groups need no padding. On H200 it reaches 67-75% of peak bandwidth at batch 32-128 and at all 11 shapes is 1.12-1.49x faster than the faster of XQA and FlashAttention-4's proposed native FP8. Inside vLLM, with an accuracy recipe (K mean removal and rotation, 4 BF16 sink tokens, BF16 layer 0), it decodes 1.12-1.64x faster per step on Llama-3.1-8B than vLLM's FlashInfer FP8 path at batch 8 and above (1.04-1.24x over FlashAttention-4's FP8), is level at batch 1, and holds 1.63x as many tokens. On one H200 under a reasoning-like request stream, the highest rate at which 99% of requests meet the latency targets is 1.23-1.32x FP8's on Llama-3.1-8B and 1.67-2.20x on Qwen2.5-72B, as the cache becomes the limit; prefill-heavy streams are worse (7% slower prefill). On five 7B-32B models, repeated runs show no significant accuracy difference from BF16 KV. In Qwen2-family models, whose reasoning variants collapse under FP8 KV, layer 0's key mean is almost entirely the key-projection bias identified by prior work, seen through RoPE and computable from the weights alone; keeping that layer in BF16 restores FP8 KV and, with K mean removal, 4-bit KV.
Figures & tables
| Format | Element | Scale | Bytes per row |
|---|---|---|---|
| BF16 | 16-bit float | none | 256 |
| FP8 (E4M3) | 8-bit float | per tensor | 128 |
| INT4 (per token, asymmetric) | 4-bit integer | FP16 scale and zero point per row | 68 |
| NVFP4 | E2M1 | E4M3 per 16 values, plus a per-tensor FP32 scale | 72 |
| MXFP4 / UltraQuant | E2M1 | E8M0 (power of two) per 32 values | 68 |
| Kernel | Instructions per value | Bandwidth used | Implied issue utilization | Main problem |
|---|---|---|---|---|
| Our first Triton NVFP4 kernel | 11.7 | 17% | 52% | both |
| FlashInfer NVFP4 | 8.3 | 19% | 40% | both |
| vLLM UltraQuant (Triton, as shipped) | 22.5 | 8% | 50% | both |
| BitDecoding INT4 (Hopper branch) | 3.6 without spin-waits | 25% | about 24% | waiting |
| FlashInfer FP8 (ms) | FlashInfer NVFP4 | Ours INT4 | Ours NVFP4 | Ours MXFP4 | |
|---|---|---|---|---|---|
| K | 0.033 | 0.83 | 1.54 | 1.43 | 1.46 |
| K | 0.116 | 0.62 | 1.95 | 1.81 | 1.83 |
| K | 0.400 | 0.59 | 2.48 | 2.14 | 2.14 |
| K | 0.395 | 0.59 | 2.44 | 2.11 | 2.11 |
| K | 1.557 | 0.59 | 2.72 | 2.31 | 2.26 |
| K | 1.542 | 0.59 | 2.70 | 2.29 | 2.27 |
| FA2 FP8 (ms) | XQA FP8 (ms) | XQA bandwidth | Ours NVFP4 (ms) | Ours vs XQA | |
|---|---|---|---|---|---|
| K | 0.033 | 0.027 | 26% | 0.022 | 1.24 |
| K | 0.070 | 0.069 | 40% | 0.042 | 1.66 |
| K | 0.119 | 0.121 | 46% | 0.063 | 1.93 |
| K | 0.118 | 0.125 | 45% | 0.061 | 2.05 |
| K | 0.399 | 0.343 | 65% | 0.187 | 1.83 |
| K | 0.402 | 0.342 | 66% | 0.187 | 1.83 |
| Ours NVFP4 (ms) | XQA FP8 (ms) | FA4 FP8 (ms) | Best FP8 / ours | |
|---|---|---|---|---|
| 0.0214 | 0.0275 | 0.0240 | 1.12 | |
| 0.0412 | 0.0708 | 0.0528 | 1.28 | |
| 0.0623 | 0.1253 | 0.0839 | 1.35 | |
| 0.0606 | 0.1239 | 0.0824 | 1.36 | |
| 0.1877 | 0.3469 | 0.2589 | 1.38 | |
| 0.1882 | 0.3435 | 0.2589 | 1.38 |
| Variant | K | K | K | K |
| Full NVFP4 kernel (ms) | 0.042 | 0.188 | 0.188 | 0.675 |
| No E2M1 reconstruction | 0.98 | 0.87 | 0.87 | 0.87 |
| No matrix multiplies | 0.97 | 0.92 | 0.92 | 0.94 |
| Interleaved decoding (ILP) | 1.08 | 1.10 | 1.11 | 1.18 |
| MXFP4 | 0.98 | 1.01 | 0.99 | 1.01 |
| INT4 | 0.93 | 0.87 | 0.87 | 0.85 |
| context | FP8 (ms) | vLLM NVFP4 (ms) | Ours (ms) | vLLM NVFP4 | Ours |
|---|---|---|---|---|---|
| K | 4.97 | 5.52 | 4.92 | 0.90 | 1.01 |
| K | 5.57 | 6.42 | 5.31 | 0.87 | 1.05 |
| K | 7.50 | 10.43 | 6.69 | 0.72 | 1.12 |
| K | 10.25 | 15.69 | 8.06 | 0.65 | 1.27 |
| K | 12.66 | 26.36 | 10.94 | 0.48 | 1.16 |
| K | 20.42 | 47.80 | 16.43 | 0.43 | 1.24 |
| Workload | Rate | FP8: SLO share | KV | Ours: SLO share | KV | Notes |
| Reasoning-like | 0.75 | 1.00 | 32% | 1.00 | 16% | mean TPOT 13.3 vs 10.3 ms |
| (1K in, 8K out) | 1.0 | 1.00 | 59% | 1.00 | 29% | mean TPOT 19.5 vs 14.3 ms |
| 1.25 | 1.00, 1.00 | 93–97% | 1.00, 1.00 | 46% | mean TPOT 28.2 vs 20.6 ms | |
| 1.35 | 0.89, 0.94 | 100% | 0.82, 1.00, 0.86 | 55–59% | FP8: 628, 656 preemptions | |
| 0.88, 0.94 | 100% | 1.00, 1.00 | 58–61% | 4 API; FP8: 683, 651 | ||
| 1.4 | 0.82 [0.80, 0.85] | 100% | 1.00 | 62% | FP8: 750 preemptions |
| KV tokens | Highest sustainable rate (req/s) | Per step | ||||
|---|---|---|---|---|---|---|
| Model | FP8 | Ours | FP8 | Ours | Ratio | |
| Llama-3.1-8B | 1.78M | 2.90M | [1.25, 1.3) | [1.6, 1.65) † | 1.23–1.32 | 1.12–1.64 |
| Qwen3-32B | 0.50M | 0.82M | [0.25, 0.275) † | [0.4, 0.45) † | 1.45–1.80 | 1.05–1.18 |
| Qwen2.5-72B (FP8 w.) | 0.337M | 0.543M | [0.125, 0.15) † | [0.25, 0.275) † | 1.67–2.20 | 1.04–1.18 |
| Speed-up vs FP8 | MATH-500 (%) | ppl | Llama | ||||||
|---|---|---|---|---|---|---|---|---|---|
| KV cache | Bytes | Qwen2.5 | R1-Llama | Phi-4 | Qwen2.5 | Llama | KL | ||
| BF16 | 256 | 0.63–0.86 ∗ | 0.96–0.97 | 71.2 | 67.7 | 75.3 | – | – | – |
| FP8 (FlashInfer XQA) | 128 | 1.00 | 1.00 | 1.6 | 67.0 | 76.0 | 36.8 | +0.94% | 0.0037 |
| 4-bit, one scale/tensor | 64 | – | – | – | – | – | – | – | 0.297 |
| vLLM NVFP4 | 72 | 0.43–0.72 | 0.87–0.90 | 0.0 | 68.4 | 74.9 | 246 | +2.62% | 0.0282 |
| layer 0 in BF16 | 72 | – | – | 65.9 | – | – | +78% | +2.56% | 0.0262 |
| Step | Llama-3.1-8B | Qwen2.5-7B-I | Qwen3-8B-Base | |
|---|---|---|---|---|
| (a) | 4-bit FP4, one scale per tensor | 0.297 | 10.1 | 3.00 |
| (b) | NVFP4: an E4M3 scale per 16 values | 0.0269 | 5.90 | 0.0291 |
| (c) | + Hadamard rotation of K [ 2 ] | 0.0187 | 6.95 | 0.281 |
| (d) | + 4 BF16 sink tokens [ 56 , 29 ] | 0.0168 | 7.05 | 0.249 |
| (e) | + K mean removal [ 61 , 45 ] | 0.0111 | 0.0167 | 0.0125 |
| (f) | + layer 0 in BF16 | 0.0103 | 0.0147 | 0.0097 |
| Model | NVFP4, K rotated | NVFP4, K mean-removed + rotated | FP8 |
|---|---|---|---|
| Llama-3.1-8B | KL 0.0165 (+0.097) | KL 0.0115 (+0.065) | +0.015 |
| Mistral-7B-v0.3 | KL 0.0071 (+0.030) | KL 0.0060 (+0.025) | +0.007 |
| Qwen3-8B-Base | KL 0.210 (+1.38) | KL 0.0114 (+0.041) | +0.015 |
| Model | Test | Runs | BF16 | Ours | Ours BF16 [95% CI] ( ) |
|---|---|---|---|---|---|
| Qwen2.5-7B-Instruct | MATH-500 | 5 | 71.2 | 72.0 | +0.8 [ 1.6, +3.3] (0.49) |
| DeepSeek-R1-Distill-Qwen-7B | MATH-500 | 5 | 70.8 | 71.2 | +0.4 [ 2.0, +3.1] (0.71) |
| DeepSeek-R1-Distill-Llama-8B | MATH-500 | 3 | 67.7 | 67.7 | +0.07 [ 3.1, +3.3] (1.0) |
| Phi-4 | MATH-500 | 3 | 75.3 | 74.1 | 1.2 [ 3.5, +1.1] (0.33) |
| Qwen3-32B, thinking on | MATH-500, first 200, 16K tokens | 3 | 90.0 | 90.3 | +0.3 [ 2.7, +3.2] (0.89) |
| Qwen3-32B, thinking off | MATH-500 | 1 | 78.6 | 79.2 | +0.6 [ 1.6, +2.8] ∗ (–) |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
| Where | Finding | Status |
|---|---|---|
| Issue #67176 [ 50 ] | UltraQuant’s scale constant is fit for a continuous scale but applied with a power-of-two snap. The UltraQuant paper names 0.195 the power-of-two-optimal value but measured it 4.4 points less accurate in one run (its Table 5) [ 7 ] ; we find that 0.20 cuts KL by 40–56% offline and the perplexity increase over BF16 by 66–79% inside vLLM (Llama-3.1-8B, Mistral-7B-v0.3, Qwen3-8B-Base), at the same bytes | Opened by us; we posted two fixes (a constant of 0.20, or the better of two power-of-two exponents per group) with unit tests and perplexity on three models, and asked the maintainers to choose |
| Issue #41343 [ 36 ] , PR #63081 [ 48 ] | FP8 KV silently breaks Qwen2-family reasoning models at layer 0; skipping layer 0 restores accuracy, but crashes FlashAttention-3 for some models (#65821 [ 42 ] ; proposed fix in open PR #65891 [ 43 ] ) | We posted text-model data in #41343 (an existing issue about Qwen-VL with fp8_e5m2 ) and #63081; the #63081 author added a note on the crash to its docs |
| PR #46461 [ 13 ] PR #67789 [ 6 ] | TurboQuant and UltraQuant skip cached KV when a request with cached context shares a step with a longer new prompt, giving wrong answers with no error; #46461 fixed only TurboQuant | We reported that UltraQuant has the same bug, with a reproducer; #67789 fixes both and shows that default chunked prefill also triggers it; we confirmed on H200 that it fixes UltraQuant end to end (0/4 4/4 correct on both triggers); its author added our results to the PR description, and we offered a follow-up regression test for the prefix-cache trigger |
| RFC #61698 [ 32 ] , PR #69042 [ 49 ] | A prompt-logprob check, of the kind the RFC proposes for numerics PRs, catches the layer-0 FP8 failure but not the cached-KV bug above, which shows only when a cached prefix shares a step with a longer new prompt; a targeted request of that shape catches it | We posted H200 measurements in #61698; #69042, a logprob drift eval for that RFC, cites them, leaves cache-reading paths out of its scope and proposes such a request as a follow-up test, which we offered to write |
GPU Kernel Optimization
GPU kernel optimization improves the speed and memory efficiency of computations by tailoring code to GPU hardware and workloads.
See all 243 papers