Views
No views yet
KVPressTextGenerationPipeline, which is automatically registered as a transformers pipeline with the name kv-press-text-generation when kvpress is imported:1import requests
2from transformers import pipeline
3from kvpress import KVzapPress, DMSPress
4
5model = "Qwen/Qwen3-8B"
6pipe = pipeline("kv-press-text-generation", model=model, device_map="auto", dtype="auto")
7press = DMSPress(KVzapPress(model_type="mlp"), threshold=-4)
8
9# Prefilling compression only, thinking disabled
10press.decoding = False
11context = requests.get("https://arxiv.org/abs/2601.07891").text
12question = "\n What is this article about in 2 sentences ?"
13answer = pipe(context, question=question, press=press)["answer"]
14print(f"Compression ratio: {press.compression_ratio:.2%}\nAnswer: {answer}")
15
16# Prefilling and decoding compression, thinking enabled
17press.decoding = True
18prompt = "What is the best hardware to run LLMs and why ?"
19answer = pipe(prompt, press=press, enable_thinking=True, max_new_tokens=2000)["answer"]
20print(f"Compression ratio: {press.compression_ratio:.2%}\nAnswer: {answer}")1@article{jegou2025kvzap,
2 title={KVzap: Fast, Adaptive, and Faithful KV Cache Pruning},
3 author={Jegou, Simon and Jeblick, Maximilian},
4 journal={arXiv preprint arXiv:2601.07891},
5 year={2025},
6 url={https://arxiv.org/abs/2601.07891}
7}