KV Cache Quantization
KV cache quantization compresses the key-value cache memory used in autoregressive LLM inference, reducing memory usage and enabling longer context windows.
KV cache quantization is a technique that reduces the memory footprint of the key-value (KV) cache during autoregressive inference with transformer-based LLMs. In a transformer model, for each token generated, the model computes keys and values from the input tokens, which are stored in memory and reused for subsequent tokens to compute attention. This KV cache grows linearly with the sequence length (both input and generated tokens) and the number of layers and attention heads. For a 7B model with 40 layers, 32 attention heads, a hidden size of 4096, and a context window of 4096 tokens, the KV cache can exceed 10GB in FP16 precision. For models with 70B parameters and 128K context windows, the cache can balloon to hundreds of gigabytes, often exceeding GPU memory. KV cache quantization compresses these stored keys and values from FP16 (2 bytes per value) to lower precision, typically INT8 (1 byte) or FP8 (1 byte), and in some cases INT4 (0.5 byte). This reduction is possible because attention patterns tend to be reliable at low precision. Most inference engines like vLLM, llama.cpp, and TensorRT-LLM support selective quantization of the KV cache, often using per-channel or per-token scaling to minimize accuracy loss. For example, vLLM supports KV cache FP8 quantization on H100 GPUs, achieving up to 2x memory reduction with negligible quality degradation. Some implementations use block-wise quantization (e.g., quantizing in blocks of 128 values) to balance memory and accuracy. The primary benefit is enabling larger batches or longer context windows within the same GPU memory budget. This is critical for applications like long-document analysis, code completion with large repositories, or multi-turn chatbots that need to remember extensive conversation history.
KV cache quantization does not quantize the model weights; it only compresses the temporary key and value tensors stored for each generated token, leaving weights at their original precision.
Related terms
Concepts you'll usually encounter alongside this one.
The KV cache stores intermediate key and value tensors from previous tokens during autoregressive generation, enabling subquadratic computation by avoiding redundant re-encoding of the full context.
The context window defines the maximum number of input tokens a transformer model can process at once, determining the length of conversation history or document it can reason over.
vLLM is an open-source high-performance LLM inference engine using PagedAttention to efficiently manage KV cache memory and achieve high throughput.
Mentioned in tutorials
Hands-on guides that put this concept to work.
Squeeze a 70-billion-parameter model onto a single RTX 4090 by quantizing weights to 4 bits. Quality stays high, VRAM usage drops to 24 GB.
Scale a single model across multiple GPUs with tensor parallelism. Configure vLLM and llama.cpp, fix PCIe bottlenecks, double your VRAM.
Squeeze 10-15% more performance from your RTX card with smarter power and thermal settings. Less heat, less noise, lower power bill.
What quantization actually does to a model, why Q4_K_M is the default sweet spot, and when to deviate. A practical reference for picking quants.
See how this term affects your memory budget.
Real numbers, real chips, every workload.
Picks for builders, by use case.
Stay Ahead of the AI Curve
Get weekly AI hardware news, benchmark updates, and deals in your inbox. Founding-subscriber list, be one of the first.