Skip to content

KV Cache and Quantization: Making Large Models Faster

Intuition: remember what you already computed

Section titled “Intuition: remember what you already computed”

LLMs generate text one token at a time. If each new token required recomputing attention over all previous tokens, it would waste enormous compute. The intuition behind KV Cache is simple: store the Key and Value vectors computed for previous tokens and reuse them directly, avoiding redundant computation.

Quantization is another cost-reduction idea: model weights are typically 32-bit floats. If reduced to 16-bit, 8-bit, or even 4-bit, memory footprint and compute drop significantly. Some precision is lost, but the trade-off is often fully acceptable in practice.

Engineering view: the memory wall and precision trade-offs

Section titled “Engineering view: the memory wall and precision trade-offs”

KV Cache is one of the main memory consumers during inference, especially in long-context scenarios. Optimization directions include:

  • PagedAttention (vLLM): Manage KV Cache in pages to reduce memory fragmentation and improve batching efficiency.
  • KV Cache compression: Reduce cache size through quantization, pruning, sliding windows, or eviction policies.
  • GQA / MQA: Share Key/Value across multiple attention heads to reduce cache volume.

Quantization techniques by category:

  • PTQ (Post-Training Quantization): GPTQ, AWQ, SmoothQuant, etc. Quantize an already-trained model without retraining.
  • QAT (Quantization-Aware Training): Simulate low precision during training; usually better results but higher cost.
  • GGML/GGUF: Community-standard 4-bit formats that let large models run on laptops.

In practice, evaluate perplexity, downstream task accuracy, and end-to-end latency after quantization—not just memory savings. Different layers have different sensitivity to precision; mixed precision or per-layer tuning often works best.

2026: ultra-low-bit quantization and local inference of trillion-parameter models

Section titled “2026: ultra-low-bit quantization and local inference of trillion-parameter models”

Two trends stand out in 2026:

  • 2-bit-class quantization becomes practical: combined with MoE architectures (activated parameters are far smaller than total parameters), trillion-parameter-class model weights quantized to 2 bits fit into high-end consumer hardware and run offline at usable speed—e.g. the community-built 2-bit MLX release of DeepSeek V4-Flash. Co-optimization between quantization formats and hardware kernels (MLX on Apple Silicon, the GGUF ecosystem, low-bit kernels in vLLM/SGLang) is the key enabler.
  • KV cache eviction becomes more content-aware: moving from position- or frequency-based eviction to adaptive eviction by value importance (e.g. value-aware stochastic eviction), shrinking cache size severalfold more at ultra-long contexts.

The corresponding trade-offs: the lower the bit-width, the more calibration-set quality and per-layer sensitivity analysis matter; MoE expert routing is more sensitive to quantization error, so a common recipe is mixed precision—high precision for routing-related parameters, low bits for expert weights.

Research view: the boundary of precision and efficiency

Section titled “Research view: the boundary of precision and efficiency”

Research questions include: what are the limits of quantization? Can 1-bit or ternary weights still preserve language ability? How can activation distribution analysis find optimal clipping thresholds and scaling factors?

Another frontier is speculative decoding: a small model rapidly generates candidate sequences, and the large model verifies and corrects them in parallel, achieving 2-3x speedup without quality loss. This is essentially a rebalancing between computation and memory.

🔬 Open Research Questions

Key questions and research directions in this area:

  1. Can KV cache memory footprint be further compressed without significant precision loss? Which approach is better: sparsification, quantization, or distillation?
  2. What is the optimal strategy for mixed-precision inference? Which layers and parameters are more suitable for low precision?
  3. Is quantization-aware training necessary? Can post-training quantization achieve the same effect?
  4. At 2-bit and lower bit-widths, how does quantization error propagate through MoE expert routing? What is the optimal mixed-precision split between routing parameters and expert weights?

References