加载中…
加载中…
A learned KV-cache forget gate for Qwen/Qwen3-1.7B. For every token, as it is written to the cache, it gives one keep score per KV head. Tokens scored below the threshold are evicted. The base model is not modified.
KVzapModel.train_log.txt has the run.Code, training and evaluation: https://github.com/Manaslu-AI/razor. Paper: razor.pdf in that repo (arXiv version
pending).
All on 16 GB T4s, kvpress RULER string_match average.
| Benchmark | Full cache | RAZOR (evicted) | Same gate, KVzap objective | KVzip+ |
|---|---|---|---|---|
| RULER 4k (n=650, 5 seeds) | 88.9 | 86.6 ± 0.6 (76%) | 79.6 | 86.5 (76%) |
| RULER 16k (n=195) | 77.9 | 75.4 (81%) | 63.6 | 73.6 (76%) |
| MATH-500 L4-5, compressed while reasoning (n=30) | 66.7% | 73.3% (75%) |
The KVzap-objective gate has the same architecture, data and hyperparameters, trained to regress KVzip+ scores. It is our own training, not an NVIDIA checkpoint. KVzip+ needs a second pass over the context.
Limits: weak on RULER common-word extraction (cwe 57 vs 79 for KVzip+ at 4k). MATH n=30 shows no loss, not a gain. Eviction under thresholding varies by input (71-85% on RULER-4k, 5th-95th percentile).
pip install torch 'transformers>=4.56,<5.3' kvpress
git clone https://github.com/Manaslu-AI/razor && cd razor
from kvpress import KVPressTextGenerationPipeline # noqa: F401, registers the pipeline
from transformers import pipeline
from razor_kv.press import LocalGatePress
from razor_kv.ragged import RaggedCache, RaggedDMSPress, enable
pipe = pipeline("kv-press-text-generation", model="Qwen/Qwen3-1.7B", dtype="float16", device_map="cuda")
enable(pipe.model) # per-head ragged attention
press = RaggedDMSPress(LocalGatePress(path="Manalsu/razor-gate-Qwen3-1.7B"), threshold=0.0)
print(pipe(context, question="...", press=press, cache=RaggedCache())["answer"]) # evicted KV is freed, not masked
RaggedDMSPress deletes evicted entries per head and supports batch size 1. DMSPress(LocalGatePress(...)) from
kvpress makes the same decisions with masking.
@misc{rawal2026razor,
title = {RAZOR: Learning What to Forget in the KV Cache with a Description-Length Price},
author = {Rawal, Himansu},
year = {2026},
note = {Manaslu Labs. arXiv version pending},
url = {https://github.com/Manaslu-AI/razor}
}
Qwen/Qwen3-1.7B