KV cache quantization stores the attention keys and values used by an LLM at lower precision. It can free memory for longer context or more concurrent requests. To estimate what you gain, budget the compressed payload, any full-precision residual window, and quantization metadata separately. Then measure the whole serving process under the workload you intend to run.
In the worked example below, one 32,768-token request needs 4 GiB of BF16 cache. A hypothetical INT4 layout uses about 1.14 GiB after charging for its residual window and group metadata. That is a cache-only estimate. Weights, workspaces, and allocator overhead still need GPU memory.
When KV cache quantization helps
The cache holds the keys and values from previous tokens so autoregressive generation can reuse them. For a model with conventional full attention, a longer live sequence stores more K and V entries. Concurrent requests grow that total when they own separate cache blocks. Grouped-query attention reduces the number of KV heads relative to the number of query heads. Use the KV head count in your estimate.
Weight quantization and KV cache quantization act on different parts of the memory budget. Weight precision governs model parameters. Cache precision governs these per-request attention states. A four-bit weight file therefore tells you little about cache precision. Check the resolved runtime settings even if the model loads with enough memory to serve a short prompt.
The most promising starting point is a workload where long sequences or concurrent requests already put pressure on the KV pool. With short context and low concurrency, the savings may arrive too late to matter. A quantized cache can also add conversion work. The attention kernel and how it reads the cache determine whether decode latency improves or worsens.
Calculate KV cache quantization savings
For ordinary full-attention layers with the same K and V dimensions, start with this per-request count.
values per token =
2 × cache-bearing layers × KV heads × head dimension
full-precision bytes =
values per token × retained tokens × bytes per value
mixed-cache bytes =
values per token × (
residual tokens × full-precision bytes per value
+ compressed tokens × quantized bits per value / 8
) + metadata bytes
Use the number of retained prompt and generated tokens. When requests differ in length, add their individual cache sizes. For paged engines, account for block rounding and sharing separately. Sliding-window layers, latent attention, and layouts that quantize keys and values differently need a calculation that reflects the tensors the engine actually stores.
Worked example with group overhead
Take 32 layers, 8 KV heads, a head dimension of 128, and a single request retaining 32,768 tokens. The model stores 65,536 K and V values per token. BF16 costs 2 bytes per value. For the illustrative INT4 layout, keep the latest 128 tokens in BF16 and budget one 4-byte metadata record per 64 compressed values. That record stands for the scale and zero-point together. Actual backends may use other group sizes, encodings, scale layouts, or padding.
| Layout | Payload | Metadata | Total |
|---|---|---|---|
| BF16 | 4,096 MiB | 0 | 4,096 MiB |
| FP8 | 2,048 MiB | Varies | Varies |
| INT4 + BF16 | 1,036 MiB | 127.5 MiB | 1,163.5 MiB |
The INT4 payload breaks down into 16 MiB for the 128-token BF16 residual and 1,020 MiB for the 32,640 compressed tokens. The metadata calculation is 32,640 × 65,536 ÷ 64 × 4 bytes, or 127.5 MiB. Four independent requests of this length would occupy 4,654 MiB in this example. The figures are arithmetic estimates, with 1 MiB equal to 1,048,576 bytes. They exclude page padding, shared prefixes, and temporary buffers.
INT4's nominal payload ratio is four to one against BF16. After the assumed residual and metadata, the actual ratio in this model is about 3.52 to one. A shorter request spends a larger share of its cache at full precision if the same residual applies. For example, with only 256 retained tokens, this layout estimates 20.5 MiB of cache against 32 MiB for BF16.
Start with the KV cache calculator for the baseline. Carry that figure into your context and VRAM budget, then add the format overhead for your chosen runtime. On engines that preallocate the KV pool, a startup memory reading can look similar after changing precision. Compare the number of usable cache tokens or blocks and the concurrency your service can sustain at its latency target.
Check which format your runtime actually uses
- vLLM FP8. The vLLM 0.15.0 documentation describes FP8 cache scales and calibration paths. Check the documentation for your installed version and confirm the GPU, dtype, attention backend, and scale source. Format support and the preferred calibration path can differ by backend.
- Hugging Face Transformers. The Transformers implementation write-up explains group quantization and residual storage for its low-bit cache. Use the cache guide alongside the documentation for your installed release to confirm the backend, bit widths, and configuration options. The worked example above assumes one layout and should be replaced with your runtime's actual accounting.
- KIVI. The original KIVI paper motivates per-channel grouping for keys and per-token grouping for values. It provides evidence for a particular method. Its evaluation results apply to the models and workloads the authors tested. FP8 and INT4 also refer to different formats. Treat each runtime and cache configuration as a separate candidate in your rollout test.
Test quality and serving capacity before rollout
- Fix the baseline. Record the checkpoint, weight dtype, runtime version, GPU, attention backend, and sampling settings. Use the same prompts and maximum output budget in both arms. Record the exact cache dtype and scales or group settings actually in use.
- Test the context lengths where the savings matter. Include short requests, typical production lengths, and requests near your operating limit. Put exact identifiers or instructions at different positions in long prompts. For code, run the generated output through the same tests. For structured output, check parseability and required fields.
- Look at failures by workload. A good aggregate score can hide regressions on document retrieval, tool calls, or long code edits. Define an acceptance threshold for each important group and compare against the same full-precision baseline. Use representative prompts, avoiding calibration data overlap where applicable.
- Measure serving behavior separately. At fixed concurrency, compare peak GPU usage, time to first token, decode latency, and throughput. Then increase concurrency at the same latency target and look for admission failures, preemption, or cache thrashing. Compare equivalent warmup and traffic conditions.
- Choose the least aggressive format that meets the capacity target. Keep the baseline settings available for rollback. If the cache no longer limits capacity, examine weights, workspace requirements, or how the runtime reserves memory before reducing precision further. Use the weight quantization guide when weights dominate the budget.
KV cache quantization is most useful when cache capacity is keeping a serving workload from meeting its context or concurrency target. Size the cache from actual KV heads and retained tokens, include residual and metadata costs, and let the quality and latency checks determine whether the extra capacity is usable.
