Papers › Keyformer: KV Cache Reduction through Key Tokens Selection for Efficient Generative Inference

Keyformer: KV Cache Reduction through Key Tokens Selection for Efficient Generative Inference

14 Mar 2024arXiv:2403.09054archive 2025-07-28

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

Transformers have emerged as the underpinning architecture for Large Language Models (LLMs). In generative language models, the inference process involves two primary phases: prompt processing and token generation. Token generation, which constitutes the majority of the computational workload, primarily entails vector-matrix multiplications and interactions with the Key-Value (KV) Cache. This phase is constrained by memory bandwidth due to the overhead of transferring weights and KV cache values from the memory system to the computing units. This memory bottleneck becomes particularly pronounced in applications that require long-context and extensive text generation, both of which are increasingly crucial for LLMs. This paper introduces "Keyformer", an innovative inference-time approach, to mitigate the challenges associated with KV cache size and memory bandwidth utilization. Keyformer leverages the observation that approximately 90% of the attention weight in generative inference focuses on a specific subset of tokens, referred to as "key" tokens. Keyformer retains only the key tokens in the KV cache by identifying these crucial tokens using a novel score function. This approach effectively reduces both the KV cache size and memory bandwidth usage without compromising model accuracy. We evaluate Keyformer's performance across three foundational models: GPT-J, Cerebras-GPT, and MPT, which employ various positional embedding algorithms. Our assessment encompasses a variety of tasks, with a particular emphasis on summarization and conversation tasks involving extended contexts. Keyformer's reduction of KV cache reduces inference latency by 2.1x and improves token generation throughput by 2.4x, while preserving the model's accuracy.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2403.09054")

Code

Syntology Ran 3 of 8 code samples harvested from 1 repository linked to this paper; 5 have no recorded run. Of those that ran: 3 ran with no contract checked.

By repository: official repository: 8 samples from 1 repository, 3 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

d-matrix-ai/keyformer-llm officialmentioned in paperpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

8 samples harvested; 3 ran; 0 honoured the contract we drafted; 5 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

3ran
5unverified

Licence: 0 of the 8 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from d-matrix-ai/keyformer-llm. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

create_sinusoidal_positions d-matrix-ai/keyformer-llm/models/gptj-keyformer-lib/modeling_gptj.py official repository ran fingerprinted Apache-2.0 (permissive) · c2217cd556fe5607 · report
get_embed_positions d-matrix-ai/keyformer-llm/models/gptj-keyformer-lib/modeling_gptj.py official repository ran fingerprinted Apache-2.0 (permissive) · 22d927bdb866159f · report
rotate_every_two d-matrix-ai/keyformer-llm/models/gptj-keyformer-lib/modeling_gptj.py official repository ran fingerprinted Apache-2.0 (permissive) · 2e3bec9f0c9b1973 · report
flash_attn_fn d-matrix-ai/keyformer-llm/models/mpt-keyformer-lib/attention_streaming_llm.py official repository unverified Apache-2.0 (permissive) · 69a085d27f83db2a · report
keyformer_mask d-matrix-ai/keyformer-llm/models/mpt-keyformer-lib/attention_lm_eval_harness.py official repository unverified Apache-2.0 (permissive) · 5b88d9d6199110e1 · report
load_tf_weights_in_gpt2 d-matrix-ai/keyformer-llm/models/cerebras-keyformer-lib/modeling_gpt2.py official repository unverified Apache-2.0 (permissive) · bc9fb74e483fb901 · report
scaled_multihead_dot_product_attention d-matrix-ai/keyformer-llm/models/mpt-keyformer-lib/attention_streaming_llm.py official repository unverified Apache-2.0 (permissive) · aa98cb8ec8ec9683 · report
triton_flash_attn_fn d-matrix-ai/keyformer-llm/models/mpt-keyformer-lib/attention_streaming_llm.py official repository unverified Apache-2.0 (permissive) · a27f1a3818430d86 · report

Tasks

Text Generation

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections