Compress LLM KV cache up to 10× with per-token, outlier-aware quantization and little accuracy loss

March 7, 20247 min

Overview

Production Readiness

0.7

Novelty Score

0.45

Cost Impact Score

0.8

Citation Count

3

Authors

Shichen Dong, Wen Cheng, Jiayu Qin, Wei Wang

Links

Abstract / PDF

Why It Matters For Business

QAQ can cut the GPU memory used by KV caches by ~8–10×, enabling longer-context features or reducing GPU requirements and cost with little accuracy loss.

Summary TLDR

QAQ is a post-training quantization method for the Key-Value (KV) cache used during LLM autoregressive inference. It (1) assigns different quantization strategies to keys and values, (2) keeps rare outlier entries in full precision, and (3) uses an attention-window heuristic to avoid irreversible mistakes. On LLaMA-2 (7B/13B) and three zero-shot tasks, QAQ compresses the KV cache near 8–10× with negligible accuracy loss and ~1.6–1.8× better lossless compression than prior cache-only methods. Code is available.

Problem Statement

The KV cache (stored keys and values from past tokens) grows linearly with context length and quickly dominates GPU memory for long-context LLM inference. Prior eviction heuristics can remove needed tokens. The problem: shrink KV cache memory via quantization while keeping attention outputs (and thus generation quality) intact.

Main Contribution

QAQ: a post-training, per-token quantization formula that assigns bits separately for key and value caches based on predicted impact on attention outputs.

Mixed-precision outlier handling: keep the top/ bottom α% of KV entries at full precision and quantize the rest, reducing quantization error.

Attention-window: use the max of recent attention scores to predict future importance and avoid irreversible aggressive quantization.

Empirical results on LLaMA-2 (7B/13B) showing near 8–10× KV cache compression with small accuracy loss and improved lossless compression vs prior KV-cache methods.

Key Findings

Key vectors are more sensitive to quantization than value vectors; uniform 2-bit quantization harms keys far more than values.

NumbersLLaMA-2-7B experiment: 2-bit value quantization retains high accuracy; 2-bit key quantization causes large accuracy drop

QAQ compresses the KV cache up to about 10× with minimal accuracy loss on evaluated tasks.

NumbersClaimed up to 10×; typical lossless compression ≈7.4–9.0× on LLaMA-2 tasks

QAQ improves lossless compression over prior KV-cache SOTA by ~1.6–1.8× on evaluated models/tasks.

Numbers1.6–1.8× improvement vs SOTA KV-cache methods

Handling outliers matters: not treating outliers causes substantial accuracy drops; isolating 1% outliers keeps accuracy higher with small compression cost.

NumbersAblation: not handling outliers causes 12%–26% accuracy drop; treating 1% outliers adds ≈4% compression overhead

Using an attention window to predict future importance reduces wrong irreversible quantizations and raises performance.

NumbersAblation: attention-window yields ≈2%–4% accuracy improvement vs no window

Results

Accuracy

ValueLLaMA-2-7B: HellaSwag 7.48×, PIQA 7.48×, MathQA 6.04×

Baselineuncompressed (1×)

Accuracy

ValueLLaMA-2-13B: HellaSwag 8.39×, PIQA 9.02×, MathQA 6.06×

Baselineuncompressed (1×)

Max claimed compression with negligible loss

ValueUp to 10×

Outlier handling effect

ValueNot handling outliers causes 12%–26% accuracy drop; handling 1% outliers adds ~4% compression cost

BaselineQAQ with outlier handling

Attention window effect

ValueAttention window improves accuracy by ~2%–4%

Baselinewindow size =1 (no history)

Who Should Care

What To Try In 7 Days

Run the authors' repo on a LLaMA-2-7B model and reproduce memory vs accuracy plots on one dataset.

Try α=1% outliers and attention window n=5; measure memory, latency, and accuracy trade-offs.

Integrate QAQ into your inference pipeline where KV cache size limits context length and measure real-world speed/transfer costs.

Optimization Features

Token Efficiency

  • Per-token bit assignment based on predicted σ bounds
  • Quantize low-importance tokens to fewer bits

System Optimization

  • Reduces GPU memory footprint for KV cache
  • Relies on CPU-GPU transfers when adjusting quantization

Inference Optimization

  • Per-token adaptive bit allocation
  • Mixed-precision: keep outliers at full precision
  • Attention-window to predict future importance
  • Re-quantization between CPU and GPU when needed

Reproducibility

Code Available

Open Source Status

  • partial

Risks & Boundaries

Limitations

  • Relies on the persistence-of-importance assumption; abrupt attention changes still need re-quantization.
  • Evaluation limited to LLaMA-2 (7B/13B) and three zero-shot tasks; generality to other models/tasks untested.
  • Requires CPU↔GPU transfers when changing per-token quantization, adding latency and system complexity.
  • Hyperparameters (outlier ratio α, attention-window size) require tuning per model and workload.

When Not To Use

  • On ultra-low-latency systems where CPU–GPU transfers are prohibitively expensive.
  • When the model uses multi-query attention variants that already reduce KV cache size significantly.
  • If you cannot store unquantized KV tokens on CPU for re-quantization (memory/policy constraints).

Failure Modes

  • Underestimating future attention for a token leads to irreversible quantization and degraded output.
  • Misclassifying outliers (too many or too few) either wastes memory or causes accuracy drops.
  • Frequent re-quantization can increase latency and negate memory savings in practice.

Core Entities

Models

  • LLaMA 2-7B
  • LLaMA 2-13B

Metrics

  • compression ratio (KV cache size)
  • Accuracy

Datasets

  • HellaSwag
  • PIQA
  • MathQA

Context Entities

Models

  • OPT-6B
  • OPT-13B
  • OPT-30B