Keyformer halves KV cache by keeping only 'key' tokens, doubling token throughput with no fine-tuning

March 14, 20248 min

Overview

Decision SnapshotReady For Pilot

Keyformer is ready for production inference experiments: it runs without retraining, shows consistent multi-model gains, but requires per-model tuning of KV budget, recent-window ratio, and temperature schedule.

Citations6

Evidence Strength0.78

Confidence0.88

Risk Signals9

Trust Signals

Findings with numeric evidence: 5/5

Findings with evidence refs: 5/5

Results with explicit delta: 1/5

Reproducibility

Status: Code + data available

Open source: Partial

At A Glance

Cost impact: 80%

Production readiness: 80%

Novelty: 65%

Authors

Muhammad Adnan, Akhil Arunkumar, Gaurav Jain, Prashant J. Nair, Ilya Soloveychik, Purushotham Kamath

Links

Abstract / PDF / Code / Data

Why It Matters For Business

Keyformer cuts memory traffic and latency for long-context generation without retraining, lowering inference cost and enabling higher throughput on existing GPU servers.

Who Should Care

Summary TLDR

Keyformer is an inference-only technique that trims the KV cache by keeping a recent token window plus a small set of scored "key" tokens. It uses a Gumbel-based logit regularization and per-layer score accumulation to pick key tokens. On GPT-J, Cerebras-GPT and MPT families Keyformer reduces KV cache up to 50%, cuts KV data movement ~2.9×, lowers latency by 2.1× and raises token throughput up to 2.4× while matching or slightly exceeding baseline ROUGE scores on summarization and holding accuracy on few-shot tasks. The method requires no retraining and the code is released.

Problem Statement

Autoregressive generation stores past keys/values in a KV cache. For long contexts this cache dominates GPU memory bandwidth and latency. Existing system tricks help compute, but not the growing KV cache size; many KV-reduction methods need retraining. We need an inference-time way to shrink KV cache without hurting accuracy.

Main Contribution

A practical inference-time algorithm (Keyformer) that keeps a recent window plus scored key tokens to maintain a fixed KV cache budget without fine-tuning.

A new score function that adds Gumbel logit regularization and a temperature schedule to correct distribution shifts after token removal.

Key Findings

Attention concentrates on a small subset of tokens ("key tokens").

Numbers≈90% of attention mass on ~40% of tokens (Fig.3b)

Practical UseYou can safely retain a small fraction of past tokens (key tokens) plus a recent window to capture most attention while shrinking the KV cache.

Evidence RefFigure 3b, Section 2.3

KV cache reduction yields large runtime wins.

NumbersLatency 2.1× faster, throughput up to 2.4× (50% KV reduction)

Practical UseReducing KV cache to ~50% can double generation throughput and halve latency on A100-like GPUs; adopt when memory bandwidth and latency matter.

Evidence RefFigure 9, Table 1, Section 4.2

Results

MetricValueBaselineDeltaSplit / DatasetEvidenceEvidence Ref
Inference latency speedup2.1×Full Attention (no KV reduction)MPT-7B evaluations (various sequence lengths)Figure 9, Section 4.2Figure 9
Token generation throughputup to 2.4×Full AttentionMPT-7B (bigger batch), Table 1Table 1, Section 4.2Table 1

What To Try In 7 Days

Clone the Keyformer repo and run the provided example on an MPT/GPT-J checkpoint.

Measure tokens/sec and ROUGE on your summarization prompt with KV budgets at 50%, 70%, and full.

Set recent-window w to 20–30% and use τ schedule from 1→2; compare per-layer vs shared scoring.

Optimization Features

Token Efficiency
Increases tokens/sec up to 2.4×Reduces per-token KV transfer
Infra Optimization
Works on existing GPU stacks (A100) without model retraining
System Optimization
Reduces off-chip KV data movement ~2.9×Enables larger batch sizes under same GPU memory
Inference Optimization
KV cache reduction via key-token selectionMixed recent-window + key-token attentionGumbel-softmax logit regularization for scoringPer-layer score accumulationStatic KV cache budget to control memory

Reproducibility

Risks & Boundaries

Limitations

Quality depends on model, task, and positional encoding; tune per model.

Gumbel softmax scoring adds overhead and must be balanced against KV savings.

When Not To Use

Short-context generation where KV cache is small and savings are minimal.

Workflows that cannot modify the inference pipeline or scoring step.

Failure Modes

Mis-identifying key tokens reduces accuracy if score function or τ schedule is poorly tuned.

Performance gains shrink on compute-bound workloads where KV movement is not the bottleneck.

Core Entities

Models

GPT-J-6BCerebras-GPT-6.7BMPT-7BMPT-7B-storywriter

Metrics

ROUGE-1ROUGE-2ROUGE-Ltokens/secinference latencyKV cache data movement

Datasets

CNN/DailyMailGovReportSODAlm-eval-harness (PIQA, Winogrande, OpenBookQA, COPA)

Benchmarks

Accuracy