Table of Contents
Fetching ...

ZipCache: Accurate and Efficient KV Cache Quantization with Salient Token Identification

Yefei He, Luoming Zhang, Weijia Wu, Jing Liu, Hong Zhou, Bohan Zhuang

TL;DR

ZipCache addresses the memory burden of KV caches in long-context LLMs by introducing a channel-separable quantization baseline, a normalized-attention-based token saliency metric, and an efficient probe-token approximation that preserves compatibility with fast attention implementations. The method achieves state-of-the-art compression ratios with minimal accuracy loss and substantial speedups across GSM8k, Line Retrieval, and HumanEval benchmarks. Key innovations include reducing quantization parameter overhead, mitigating bias from lower-triangular attention, and enabling rapid saliency estimation without full attention matrices. The practical impact is improved deployment feasibility for large models by lowering memory, latency, and compute requirements in KV-cache-based generation pipelines.

Abstract

KV cache stores key and value states from previous tokens to avoid re-computation, yet it demands substantial storage space, especially for long sequences. Adaptive KV cache compression seeks to discern the saliency of tokens, preserving vital information while aggressively compressing those of less importance. However, previous methods of this approach exhibit significant performance degradation at high compression ratios due to inaccuracies in identifying salient tokens. In this paper, we present ZipCache, an accurate and efficient KV cache quantization method for LLMs. First, we construct a strong baseline for quantizing KV cache. Through the proposed channel-separable tokenwise quantization scheme, the memory overhead of quantization parameters are substantially reduced compared to fine-grained groupwise quantization. To enhance the compression ratio, we propose normalized attention score as an effective metric for identifying salient tokens by considering the lower triangle characteristics of the attention matrix. Moreover, we develop an efficient approximation method that decouples the saliency metric from full attention scores, enabling compatibility with fast attention implementations like FlashAttention. Extensive experiments demonstrate that ZipCache achieves superior compression ratios, fast generation speed and minimal performance losses compared with previous KV cache compression methods. For instance, when evaluating Mistral-7B model on GSM8k dataset, ZipCache is capable of compressing the KV cache by $4.98\times$, with only a $0.38\%$ drop in accuracy. In terms of efficiency, ZipCache also showcases a $37.3\%$ reduction in prefill-phase latency, a $56.9\%$ reduction in decoding-phase latency, and a $19.8\%$ reduction in GPU memory usage when evaluating LLaMA3-8B model with a input length of $4096$.

ZipCache: Accurate and Efficient KV Cache Quantization with Salient Token Identification

TL;DR

ZipCache addresses the memory burden of KV caches in long-context LLMs by introducing a channel-separable quantization baseline, a normalized-attention-based token saliency metric, and an efficient probe-token approximation that preserves compatibility with fast attention implementations. The method achieves state-of-the-art compression ratios with minimal accuracy loss and substantial speedups across GSM8k, Line Retrieval, and HumanEval benchmarks. Key innovations include reducing quantization parameter overhead, mitigating bias from lower-triangular attention, and enabling rapid saliency estimation without full attention matrices. The practical impact is improved deployment feasibility for large models by lowering memory, latency, and compute requirements in KV-cache-based generation pipelines.

Abstract

KV cache stores key and value states from previous tokens to avoid re-computation, yet it demands substantial storage space, especially for long sequences. Adaptive KV cache compression seeks to discern the saliency of tokens, preserving vital information while aggressively compressing those of less importance. However, previous methods of this approach exhibit significant performance degradation at high compression ratios due to inaccuracies in identifying salient tokens. In this paper, we present ZipCache, an accurate and efficient KV cache quantization method for LLMs. First, we construct a strong baseline for quantizing KV cache. Through the proposed channel-separable tokenwise quantization scheme, the memory overhead of quantization parameters are substantially reduced compared to fine-grained groupwise quantization. To enhance the compression ratio, we propose normalized attention score as an effective metric for identifying salient tokens by considering the lower triangle characteristics of the attention matrix. Moreover, we develop an efficient approximation method that decouples the saliency metric from full attention scores, enabling compatibility with fast attention implementations like FlashAttention. Extensive experiments demonstrate that ZipCache achieves superior compression ratios, fast generation speed and minimal performance losses compared with previous KV cache compression methods. For instance, when evaluating Mistral-7B model on GSM8k dataset, ZipCache is capable of compressing the KV cache by , with only a drop in accuracy. In terms of efficiency, ZipCache also showcases a reduction in prefill-phase latency, a reduction in decoding-phase latency, and a reduction in GPU memory usage when evaluating LLaMA3-8B model with a input length of .
Paper Structure (23 sections, 12 equations, 6 figures, 5 tables, 3 algorithms)

This paper contains 23 sections, 12 equations, 6 figures, 5 tables, 3 algorithms.

Figures (6)

  • Figure 1: Accuracy and efficiency comparisons across various KV cache compression methods. Data is collected with LLaMA3-8B model on Line Retrieval dataset. Among these methods, ZipCache achieves the highest accuracy, generation speed and compression ratio. Details can be found in the supplementary material.
  • Figure 2: Visualization and different quantization granularities for key and value states. Here, we omit the batch dimension for simplicity. For keys, channel outliers emerge, yet token representations exhibit minimal differences. For values, both channel outliers and distinct token representations exist.
  • Figure 3: (a) A toy example to illustrate accumulated attention scores and normalized attention scores. Initial tokens have larger attention scores and more values to be accumulated. (b) A sample from GSM8k dataset with chain-of-thoughts (CoT) prompting. (c) The probability of each token being selected as a salient token, measured by both accumulated and normalized attention scores. Tokens correspond to the final question are identified as low saliency by accumulated attention scores.
  • Figure 4: (a): Efficient saliency metric only requires attention scores of probe tokens through standard attention, enabling fast computation for the majority of tokens through FlashAttention. (b): In standard attention, full attention scores are computed before deriving the attention output. (c): FlashAttention avoids large attention matrix memory transfers by partitioning input matrices into blocks for incremental computation.
  • Figure 5: Performance comparisons of various KV cache compression methods on Line Retrieval.
  • ...and 1 more figures