KV Cache Quantization: Halving Memory for Context
Llama.cpp significantly optimizes memory by quantizing the Key-Value (KV) cache, which stores previous token representations. This technique, using precisions like q8_0, can cut KV cache memory usage by up to 50% during generation, crucial for supporting longer context windows on devices with limited RAM.
The top 3
- KV Cache Quantization: Memory Savings by Bit-Depth: 8-bit KV cache quantization (`q8_0`) halves memory with negligible quality loss, while 4-bit (`q4_0`) quarters it but may introduce noticeable precision loss, especially for long reasoning chains.
- KV Cache Quantization: Extending Context Windows on Consumer Hardware: 8-bit KV cache quantization can effectively double the achievable context length on consumer GPUs, allowing 32K context on hardware that previously supported 16K, while advanced 3-bit methods like TurboQuant can enable 128K+ context.
- Asymmetric KV Cache Quantization: Optimizing Quality-Memory Balance: Quantizing Key and Value caches separately, such as using 3-bit for Keys and 2-bit for Values, can yield significantly better quality than symmetric quantization, as Key cache errors propagate more broadly through the model.
Sources
Open the full topic