Skip to content
Apixo
Blog
news· 4 min read· via Towards AI

How KV Cache Compression Solves Memory Limits in Long-Context LLMs

An overview of KV cache memory bottlenecks, the six compression strategies, and deep dives into TurboQuant quantization and TriAttention eviction techniques.

How KV Cache Compression Solves Memory Limits in Long-Context LLMs

As large language models process longer prompts, multi-turn chat histories, and extensive reasoning chains, GPU memory exhaustion frequently stems from the Key-Value (KV) cache rather than model weights. For instance, running Llama-3.1–8B in 16-bit brain floating-point format (BF16) requires roughly 16 GB for weights. However, as the sequence length reaches 128,000 tokens, the KV cache alone demands an additional 16 GiB of memory—matching the weight size of the model itself—or up to 32 GiB when serving a batch of eight 32,000-token sequences.

The Six Strategies for KV Cache Reduction

To prevent servers from running out of memory, researchers categorize KV cache compression techniques into six primary architectural and algorithmic families:

  1. Architectural modifications: Changing attention design during training. Techniques like Grouped-Query Attention (GQA) reduce KV heads relative to query heads. DeepSeek-V2 uses Multi-head Latent Attention (MLA) to compress tokens into latent vectors, reducing KV cache size by 93.3% compared to DeepSeek 67B.
  2. Token eviction and selection: Pruning less important past tokens to reduce total sequence length. Algorithms like StreamingLLM retain initial "attention sinks" alongside a sliding window, while H2O (Heavy-Hitter Oracle) and SnapKV track attention frequency or query votes.
  3. Quantization: Storing each key and value using fewer bits per element without dropping tokens. Because outlier values in key channels degrade standard low-bit rounding, specialized schemes like KIVI, KVQuant, PolarQuant, and TurboQuant are used.
  4. Low-rank projection: Factorizing projection weights to compress stored head dimensions, as seen in methods like Palu.
  5. Cross-layer sharing: Merging or sharing KV caches across adjacent layers, such as in Cross-Layer Attention (CLA) or MiniCache.
  6. System-level and query-aware loading: Managing physical memory allocation efficiently. System frameworks like vLLM's PagedAttention eliminate fragmentation, while Quest dynamically loads high-attention cache pages from host memory.

Deep Dives into TurboQuant and TriAttention

Two recent algorithms demonstrate advanced approaches in quantization and eviction: TurboQuant and TriAttention.

Introduced by Zandieh, Daliri, Hadian, and Mirrokni (2025), TurboQuant is a data-oblivious vector quantization technique applied to the KV cache at inference time without requiring model fine-tuning or offline calibration data. Standard low-bit quantization fails when key vectors contain extreme numerical spikes. TurboQuant resolves this by applying a random orthogonal rotation matrix to distribute energy evenly across all dimensions, rendering coordinate values predictable. It then applies a precomputed Lloyd-Max codebook tailored to that resulting distribution. To prevent attention score distortion caused by dot-product bias, TurboQuant-prod adds a 1-bit Johnson-Lindenstrauss (QJL) sketch of the leftover residual error. In benchmarks with Llama-3.1–8B-Instruct, TurboQuant achieved a 0.997 needle-in-a-haystack recall score across context lengths from 4K to 104K tokens at 4x compression, matching full-precision baseline accuracy.

TriAttention, proposed by Mao, Lin, Huang, et al. (2026), addresses token eviction specifically for long-context reasoning models where chains of thought span tens of thousands of tokens. Traditional eviction methods evaluate recent post-Rotary Position Embedding (RoPE) attention scores. However, because post-RoPE queries continue to rotate as generation progresses, older queries become stale, restricting the usable observation window to roughly 25 tokens. TriAttention avoids modifying standard RoPE or attention computations during decoding. Instead, it periodically uses pre-RoPE query and key vector clustering to rank and prune unneeded tokens from the cache based on stable mean center directions.

What it means for developers

KV cache compression techniques directly address the operational bottlenecks of deploying long-context AI applications. Because autoregressive decoding is primarily limited by memory bandwidth—where generating each new token requires reading the entire stored cache—reducing KV cache memory footprint accelerates generation throughput while allowing larger concurrent batch sizes on a single GPU.

For engineering teams deploying open-weight models locally or managing cloud infrastructure, adopting GQA architectures, vLLM's PagedAttention, or low-bit KV quantization methods like TurboQuant provides higher hardware utilization and reduced per-token serving costs. For developers who prefer unified API access without managing underlying GPU infrastructure, cheap pay-per-token access to top AI models like Claude, GPT, Gemini, Grok, and DeepSeek is available through a single key at https://apixoai.online. Understanding these KV compression foundations helps developers evaluate trade-offs between context retention, latency, and hardware expenses across self-hosted and managed API deployments.


Source: Shrinking the KV Cache: An End-to-End Guide to KV Compression, with Deep Dives into TurboQuant and… — Towards AI. Written by the Apixo team from that report.

#ai-news#ai#llm#kvcache#turboquant#triattention#machinelearning
Try it with your own tools

One key for Claude, GPT, GLM, DeepSeek and more. Pay per token with crypto.

Get your API key

Keep reading