ZigZagkv: Dynamic KV Cache Compression for Long-context Modeling based on Layer Uncertainty
Meizhi Zhong, Xikai Liu, Chen Zhang, Yikun Lei, Yan Gao, Yao Hu, Kehai Chen, Min Zhang
TL;DR
ZigZagKV tackles the memory bottleneck of KV caches in long-context LLM inference by introducing a training-free, layer-uncertainty–driven dynamic budgeting scheme. It analyzes how attention and hidden-state information loss varies across layers and models, formalizes LMBA and LMBO as per-layer minimum budgets, and allocates budgets with a bounded minimum using LMBA-derived uncertainty. The method dynamically assigns per-layer budgets and selects KV entries via cumulative attention signals, achieving memory usage around ~20% of FullKV while preserving near-lossless performance on Needle-in-a-Haystack and LongBench across Mistral and LLaMa backbones. This approach offers practical benefits for scalable long-context reasoning without additional training or heavy computation, enabling more memory-efficient inference in real-world deployments.
Abstract
Large Language models (LLMs) have become a research hotspot. To accelerate the inference of LLMs, storing computed caches in memory has become the standard technique. However, as the inference length increases, growing KV caches might lead to out-of-memory issues. Many existing methods address this issue through KV cache compression, primarily by preserving key tokens throughout all layers to reduce information loss. Most of them allocate a uniform budget size for each layer to retain. However, we observe that the minimum budget sizes needed to retain essential information vary across layers and models based on the perspectives of attention and hidden state output. Building on this observation, this paper proposes a simple yet effective KV cache compression method that leverages layer uncertainty to allocate budget size for each layer. Experimental results show that the proposed method can reduce memory usage of the KV caches to only $\sim$20\% when compared to Full KV inference while achieving nearly lossless performance.
