SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2507.06517 · ACL · 2025

SpindleKV: A Novel KV Cache Reduction Method Balancing Both Shallow and Deep Layers

Lefei Zhang, Ping Wang, Luohe Shi, Zicong Tang, Baoyuan Qi, Guoming Liu, Z. Li

arXiv · PDF · Open in the Atlas

Code that ran

7 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (6 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 1 failure of our instrument; 2 no recorded run), 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/2507.06517.json · badge: /api/ran/2507.06517.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
tyxqc/SpindleKV community
Papers with Code archive
7 ran · 2 no recorded run
FunctionStatusWhere it lives
DCT_Compressor_Manager Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("885da9876401ac0d")
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 an instance of its own class, DCT_Compressor_Manager: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
import numpy as np

torch.manual_seed(0)

# Build a minimal config structure that DCT_Compressor_Manager expects
# The config should have layer_idx -> head_idx -> parameters mapping
def generate_config(num_layers, num_heads):
    config = {}
    for layer_idx in range(num_layers):
        config[layer_idx] = {}
        for head_idx in range(num_heads):
            config[layer_idx][head_idx] = {
                'reserve_ratio': 0.5,
                'reserve_variance': None,
                'norm': 'ortho'
            }
    return config

# Create a small config (2 layers, 2 heads each instead of 32x32)
small_config = {}
for layer_idx in range(2):
    small_config[layer_idx] = {}
    for head_idx in range(2):
        small_config[layer_idx][head_idx] = {
            'reserve_ratio': 0.5,
            'reserve_variance': None,
            'norm': 'ortho'
        }

ARGS = {
    'config': small_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, torch_dct — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DCT_Compressor_Manager — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DCT_Compressor_Manager 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
DctCompressor Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("379490e311311127")
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 an instance of its own class, DctCompressor: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
import torch.nn as nn

torch.manual_seed(0)

# Create a small sample tensor for compress/decompress operations
# Shape: (seq_len=5, dim=4)
sample_tensor = torch.randn(5, 4, dtype=torch.float32)

ARGS = {
    'reserve_ratio': 0.5,
    'reserve_variance': None,
    'norm': 'ortho'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, torch_dct — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DctCompressor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DctCompressor 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
PastKey Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("4100920cbd32b463")
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 an instance of its own class, PastKey: the run constructed the object and did not call it, so no result was computed. 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)

# Construct small tensors for the PastKey constructor
# The function uses tensors' .shape[-2] attribute to get sequence length dimension
# Keep them tiny: batch_size=2, feature_dim=4, seq_len=3

compressedkey = torch.randn(2, 3, 4)  # shape: (batch=2, seq=3, features=4)
protectedkey = torch.randn(2, 5, 4)   # shape: (batch=2, seq=5, features=4)
bias = torch.randn(2, 4)               # shape: (batch=2, features=4)

ARGS = {
    "compressedkey": compressedkey,
    "protectedkey": protectedkey,
    "bias": bias,
}
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 PastKey — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PastKey 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
PastValue Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("e17033f46f8c6bad")
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 an instance of its own class, PastValue: the run constructed the object and did not call it, so no result was computed. 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 small tensors for the PastValue constructor
# compressedvalue: shape (batch=2, seq_len=3, dim=4)
compressedvalue = torch.randn(2, 3, 4)

# protectedvalue: shape (batch=2, seq_len=5, dim=4)
protectedvalue = torch.randn(2, 5, 4)

# bias: shape (dim=4,)
bias = torch.randn(4)

ARGS = {
    "compressedvalue": compressedvalue,
    "protectedvalue": protectedvalue,
    "bias": bias,
}
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 PastValue — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PastValue 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
Pool Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("7cb1afdb14211e1e")
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 an instance of its own class, Pool: the run constructed the object and did not call it, so no result was computed. 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
import numpy as np

torch.manual_seed(0)

# Build ARGS dict with all parameters for Pool.__init__
ARGS = {
    'distance_method': 'cos',
    'block_size': 500,
    'block_version': 1,
    'verbose': False,
    'compensation_method': '',
    'cpp': False,
    'top_k': 1,
    'check_zero_gap': 100000
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Pool — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Pool 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
PrePool Ran
ran on a synthesized input · constructed an object; no result was computed
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("83bda82a67b5cd7d")
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 an instance of its own class, PrePool: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
import numpy as np

torch.manual_seed(0)

def similarity_custom(tensor1, tensor2, method, dtype=torch.float):
    """Stand-in function for similarity computation"""
    batch_size = tensor1.shape[0]
    pool_size = tensor2.shape[0]
    return torch.randn(batch_size, pool_size, dtype=dtype)

ARGS = {
    'distance_method': 'cosine',
    'block_size': 500,
    'block_version': 1,
    'verbose': False,
    'compensation_method': '',
    'cpp': False,
    'top_k': 1,
    'thresholds': 4000,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PrePool — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PrePool 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
parse_thresholds Ran
ran; our contract draft was wrong, not the code
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("0a813f84fe488d52")
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 dict. 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
import numpy as np

# Analyzing the function: parse_thresholds takes a string parameter
# The string is parsed with commas separating key-value pairs
# Each pair has format: key:value where value contains segments separated by '+'
# Each segment has format: number*count (e.g., "0.5*3" means 0.5 repeated 3 times)

# Valid example string:
# "model_a:0.5*2+0.7*1,model_b:0.3*3+0.8*2"
# This would parse to:
# {
#     'model_a': (0.5, 0.5, 0.7),
#     'model_b': (0.3, 0.3, 0.3, 0.8, 0.8)
# }

ARGS = {
    'thresholds_str': 'detector:0.5*2+0.7*1,classifier:0.3*3+0.8*2'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
Compressor Not yet run
unverified (harvested, no recorded run)
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("455d8fc04c2ce866")
How it ran

no invocation recorded.

apply_rotary_pos_emb_k Not yet run
unverified (harvested, no recorded run)
tyxqc/SpindleKV/compressor/compressor.py
code served (permissive licence) · get_code("a0b1cfb815e3ea99")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 9 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.

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

Large Language Models (LLMs) have achieved impressive accomplishments in recent years. However, the increasing memory consumption of KV cache has possessed a significant challenge to the inference system. Eviction methods have revealed the inherent redundancy within the KV cache, demonstrating its potential for reduction, particularly in deeper layers. However, KV cache reduction for shallower layers has been found to be insufficient. Based on our observation that, the KV cache exhibits a high degree of similarity. Based on this observation, we proposed a novel KV cache reduction method, SpindleKV, which balances both shallow and deep layers. For deep layers, we employ an attention weight based eviction method, while for shallow layers, we apply a codebook based replacement approach which is learnt by similarity and merging policy. Moreover, SpindleKV addressed the Grouped-Query Attention (GQA) dilemma faced by other attention based eviction methods. Experiments on two common benchmarks with three different LLMs shown that SpindleKV obtained better KV cache reduction effect compared to baseline methods, while preserving similar or even better model performance.Our code is available in https://github.com/tyxqc/SpindleKV.

For agents

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

get_harvested_code_for_paper("2507.06517")
get_code_for_paper("2507.06517")
have("2507.06517")

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

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

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

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

Connect an agent — have() is free.