KV Cache Quantization: Extending Context Windows on Limited VRAM

`llama.cpp` optimizes the Key-Value (KV) cache, which stores attention results and grows linearly with context length, by allowing its separate quantization. This technique, using flags like `--cache-type-k q8_0 --cache-type-v q8_0`, can halve the KV cache's memory footprint, enabling significantly longer conversation contexts on hardware with limited VRAM.

The top 3

  1. Top 3 KV Cache Quantization Methods for LLMs: Leading techniques include 8-bit, 4-bit (like NVIDIA's NVFP4 or MXFP4), and even 2-bit schemes. Methods often involve affine/uniform quantization, mixed-precision, and specialized per-channel or pre-RoPE key quantization to balance memory savings with accuracy. [1, 2, 7, 15, 16]
  2. KV Cache Quantization: Maximum VRAM Savings & Context Boost: Quantization can reduce KV cache memory by 2x (FP8) to 4x (INT4) compared to FP16, and even up to 8x for ultra-low bits (1-4 bits). This allows for significantly longer context windows, such as processing up to 128k tokens on an 80GB A100 GPU or even 1 million tokens for LLaMA-7B with KVQuant. [1, 2, 3, 7, 8, 9, 11, 12, 16]

Sources

Open the full topic