ZSMerge: Zero-Shot KV Cache Compression for Memory-Efficient Long-Context LLMs

Xin Liu, Xudong Wang, Pei Liu, Guoming Tang
3/13/2025
cs.CLcs.AI

Official code: SusCom-Lab/ZSMerge (23 stars, MIT, last commit 2025-09-24).

Abstract

The linear growth of key-value (KV) cache memory and quadratic computational in attention mechanisms complexity pose significant bottlenecks for large language models (LLMs) in long-context processing. While existing KV cache optimization methods address these challenges through token pruning or feature merging, they often incur irreversible information loss or require costly parameter retraining. To this end, we propose ZSMerge, a dynamic KV cache compression framework designed for efficient cache management, featuring three key operations: (1) fine-grained memory allocation guided by multi-dimensional token importance metrics at head-level granularity, (2) a residual merging mechanism that preserves critical context through compensated attention scoring, and (3) a zero-shot adaptation mechanism compatible with diverse LLM architectures without requiring retraining. ZSMerge significantly enhances memory efficiency and inference speed with negligible performance degradation across LLMs. When applied to LLaMA2-7B, it demonstrates a 20:1 compression ratio for key-value cache retention (reducing memory footprint to 5\% of baseline) while sustaining comparable generation quality, coupled with triple throughput gains at extreme 54k-token contexts that eliminate out-of-memory failures. The code is available at https://github.com/SusCom-Lab/ZSMerge.

View on arXivView PDF

Code Implementations(1)

SusCom-Lab/ZSMergeOfficial100%
MIT
232Shell, PythonMar 6, 20251 years agoMIT

Cite this paper

@article{liu2025zsmerge,
  title  = {ZSMerge: Zero-Shot KV Cache Compression for Memory-Efficient Long-Context LLMs},
  author = {Xin Liu and Xudong Wang and Pei Liu and Guoming Tang},
  year   = {2025},
  eprint = {2503.10714},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2503.10714v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.10714.svg)](https://codeofpaper.com/paper/2503.10714)

Discussion