SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.23416 · NeurIPS · 2025

KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction

Sangdoo Yun, Jang-Hyun Kim, Hyun Song, Jae Lee, Jinuk Kim, Sangwoo Kwon

arXiv · PDF · Open in the Atlas

Code that ran

9 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 5 failures of our instrument; 3 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, measured 2026-11-24; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2505.23416.json · badge: /api/ran/2505.23416.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
snu-mllab/kvzip canonical (classifier label)
classifier basis not recorded on the link
4 ran · 3 no recorded run
zefan-cai/kvcache-factory canonical (classifier label)
classifier basis: classifier_2025
4 ran · 0 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
FunctionStatusWhere it lives
repeat_kv Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from Time-MoE/Time-MoE
pointer only · get_code("3c76e52815c5401d")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

build_chat Ran
ran; our contract draft was wrong, not the code
zefan-cai/kvcache-factory/run_longbench.py
code served (permissive licence) · get_code("3ddd62fbad41e698")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

ARGS = {
    "prompt": "What is the meaning of life?"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
build_chat_llama3 Ran
ran; our contract draft was wrong, not the code
zefan-cai/kvcache-factory/run_longbench.py
code served (permissive licence) · get_code("a06d17c88eb31b3d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function takes a single parameter 'prompt' which is a string
# It formats the prompt with Llama3 chat template markers and returns it
# No complex objects needed - just a simple string

ARGS = {
    "prompt": "Hello, how are you today?"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
chunk_fn Ran
ran on a synthesized input
snu-mllab/kvzip/model/wrapper.py
code served (permissive licence) · get_code("612ed3463f489b86")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small tensor with shape (batch_size=2, sequence_length=10)
# The function accesses ctx_ids.shape[1], so we need a 2D tensor
ctx_ids = torch.randint(0, 100, (2, 10))

# chunk_size parameter - use a value that will trigger chunking
chunk_size = 3

ARGS = {
    "ctx_ids": ctx_ids,
    "chunk_size": chunk_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_model_id Ran
ran on a synthesized input
snu-mllab/kvzip/model/load.py
code served (permissive licence) · get_code("d0b3eff8cf9ed489")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

ARGS = {
    'name': 'llama3.1-8b'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
key_pruner_query_driven Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zefan-cai/kvcache-factory/pyramidkv/pyramidkv_utils.py
code served (permissive licence) · get_code("3597e5670a759378")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# kv_states: shape (batch, num_heads, seqlen, head_dim)
# q_states: shape (batch, num_heads, seqlen, head_dim)
# recent_size: int, default 128
# ratio: float, default 0.3

batch_size = 2
num_heads = 3
seqlen = 160
head_dim = 4

kv_states = torch.randn(batch_size, num_heads, seqlen, head_dim)
q_states = torch.randn(batch_size, num_heads, seqlen, head_dim)
recent_size = 128
ratio = 0.3

ARGS = {
    "kv_states": kv_states,
    "q_states": q_states,
    "recent_size": recent_size,
    "ratio": ratio,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_quant_model Ran
ran on a synthesized input
snu-mllab/kvzip/model/load.py
code served (permissive licence) · get_code("f23bd99d186e42f1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from unittest.mock import Mock, MagicMock, patch

torch.manual_seed(0)

# Create a mock quantized model class
class MockLlamaForCausalLMW8A8(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    @classmethod
    def from_quantized(cls, quant_model_id: str):
        """Mock method that returns an instance"""
        return cls()
    
    @classmethod
    def get_tokenizer(cls):
        """Mock method that returns a tokenizer"""
        tokenizer = Mock()
        tokenizer.encode = Mock(return_value=[1, 2, 3])
        tokenizer.decode = Mock(return_value="test output")
        return tokenizer

# Create mock monkeypatch functions
def mock_replace_attn():
    pass

def mock_replace_quantized_wrapper():
    pass

# Patch the imports and functions before defining ARGS
# We'll use sys.modules to inject our mocks
import sys
from types import ModuleType

# Create mock modules
mock_quant_model = ModuleType('model.quant_model.w8a8kv4_llama')
mock_quant_model.LlamaForCausalLM = MockLlamaForCausalLMW8A8

mock_monkeypatch = ModuleType('model.quant_model.monkeypatch')
mock_monkeypatch.replace_attn = mock_replace_attn
mock_monkeypatch.replace_quantized_wrapper = mock_replace_quantized_wrapper

mock_model_pkg = ModuleType('model.quant_model')
mock_model_pkg.w8a8kv4_llama = mock_quant_model
mock_model_pkg.monkeypatch = mock_monkeypatch

mock_model = ModuleType('model')
mock_model.quant_model = mock_model_pkg

sys.modules['model'] = mock_model
sys.modules['model.quant_model'] = mock_model_pkg
sys.modules['model.quant_model.w8a8kv4_llama'] = mock_quant_model
sys.modules['model.quant_model.monkeypatch'] = mock_monkeypatch

# Now define ARGS with the quant_model_id parameter
ARGS = {
    'quant_model_id': 'meta-llama/Llama-2-7b-hf'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
model, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
maybe_repeat_kv_before_cache Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zefan-cai/kvcache-factory/pyramidkv/pyramidkv_utils.py
code served (permissive licence) · get_code("6211e835b472f7ad")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned tuple, ndim 5, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a minimal config class with kv_cache_granularity attribute
class MinimalConfig:
    def __init__(self, kv_cache_granularity='query_head'):
        self.kv_cache_granularity = kv_cache_granularity

# Create test tensors
# Shape: (batch, num_key_value_heads, seqlen, head_dim)
batch = 2
num_key_value_heads = 3
seqlen = 4
head_dim = 5

key_states = torch.randn(batch, num_key_value_heads, seqlen, head_dim)
value_states = torch.randn(batch, num_key_value_heads, seqlen, head_dim)

# num_key_value_groups is the repetition factor
num_key_value_groups = 2

# Create config with default 'query_head' granularity
config = MinimalConfig(kv_cache_granularity='query_head')

ARGS = {
    'config': config,
    'key_states': key_states,
    'value_states': value_states,
    'num_key_value_groups': num_key_value_groups
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 5, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
template Ran
ran on a synthesized input
snu-mllab/kvzip/model/template.py
code served (permissive licence) · get_code("f0111855fc4c12e0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

ARGS = {
    "model_name": "llama-2-7b",
    "task": "gsm8k"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_cuda_bare_metal_version Not yet run
unverified (harvested, no recorded run)
snu-mllab/kvzip/csrc/build.py
code served (permissive licence) · get_code("956f62d22920f5cf")
How it ran

no invocation recorded.

load_head_score Not yet run
unverified (harvested, no recorded run)
snu-mllab/kvzip/model/wrapper.py
code served (permissive licence) · get_code("9c573adab3602fd1")
How it ran

no invocation recorded.

load_model Not yet run
unverified (harvested, no recorded run)
snu-mllab/kvzip/model/load.py
code served (permissive licence) · get_code("9c76a69893a315be")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 6 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 1 the same month, 5 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
repeat_kv 243 other papers
181 dated earlier, 10 the same month, 46 later, 4 same year, order not determinable, 2 undated · 22 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2305.17888 (2023-05)
LLM-QAT: Data-Free Quantization Aware Training for Large Language Models
and 240 more not named here
build_chat 3 other papers
1 dated earlier, 1 later, 1 same year, order not determinable
2410.19258 (2024-10)
Not All Heads Matter: A Head-Level KV Cache Compression Method with Integrated Retrieval and Reasoning
2025.findings-emnlp.429 (2025 (year only))
More Tokens, Lower Precision: Towards the Optimal Token-Precision Trade-off in KV Cache Compression
2506.08373 (2025-06)
Draft-based Approximate Inference for LLMs
get_cuda_bare_metal_version 2 other papers
2 dated earlier
2312.00752 (2023-12)
Mamba: Linear-Time Sequence Modeling with Selective State Spaces
2410.19258 (2024-10)
Not All Heads Matter: A Head-Level KV Cache Compression Method with Integrated Retrieval and Reasoning
key_pruner_query_driven 2 other papers
1 dated earlier, 1 later
2406.02069 (2024-06)
PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funneling
2506.08373 (2025-06)
Draft-based Approximate Inference for LLMs
maybe_repeat_kv_before_cache 2 other papers
1 dated earlier, 1 later
2406.02069 (2024-06)
PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funneling
2506.08373 (2025-06)
Draft-based Approximate Inference for LLMs
build_chat_llama3 1 other paper
1 later
2506.08373 (2025-06)
Draft-based Approximate Inference for LLMs

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Transformer-based large language models (LLMs) cache context as key-value (KV) pairs during inference. As context length grows, KV cache sizes expand, leading to substantial memory overhead and increased attention latency. This paper introduces KVzip, a query-agnostic KV cache eviction method enabling effective reuse of compressed KV caches across diverse queries. KVzip quantifies the importance of a KV pair using the underlying LLM to reconstruct original contexts from cached KV pairs, subsequently evicting pairs with lower importance. Extensive empirical evaluations demonstrate that KVzip reduces KV cache size by 3 4× and FlashAttention decoding latency by approximately 2×, with negligible performance loss in question-answering, retrieval, reasoning, and code comprehension tasks. Evaluations include various models such as LLaMA3.1, Qwen2.5, and Gemma3, with context lengths reaching up to 170K tokens. KVzip significantly outperforms existing query-aware KV eviction methods, which suffer from performance degradation even at a 90% cache budget ratio under multi-query scenarios.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2505.23416")
get_code_for_paper("2505.23416")
have("2505.23416")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2505.23416.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2505.23416.svg)](https://syntology.ai/paper/2505.23416)

Connect an agent — have() is free.