HashEvict: A Pre-Attention KV Cache Eviction Strategy using Locality-Sensitive Hashing

Minghui Liu, Tahseen Rabbani, Tony O'Halloran, Ananth Sankaralingam, Mary-Anne Hartley +3 more
12/13/2024
cs.LGcs.AIcs.CL

No confident code implementation found for this paper.

Abstract

Transformer-based large language models (LLMs) use the key-value (KV) cache to significantly accelerate inference by storing the key and value embeddings of past tokens. However, this cache consumes significant GPU memory. In this work, we introduce HashEvict, an algorithm that uses locality-sensitive hashing (LSH) to compress the KV cache. HashEvict quickly locates tokens in the cache that are cosine dissimilar to the current query token. This is achieved by computing the Hamming distance between binarized Gaussian projections of the current token query and cached token keys, with a projection length much smaller than the embedding dimension. We maintain a lightweight binary structure in GPU memory to facilitate these calculations. Unlike existing compression strategies that compute attention to determine token retention, HashEvict makes these decisions pre-attention, thereby reducing computational costs. Additionally, HashEvict is dynamic - at every decoding step, the key and value of the current token replace the embeddings of a token expected to produce the lowest attention score. We demonstrate that HashEvict can compress the KV cache by 30%-70% while maintaining high performance across reasoning, multiple-choice, long-context retrieval and summarization tasks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{liu2024hashevict,
  title  = {HashEvict: A Pre-Attention KV Cache Eviction Strategy using Locality-Sensitive Hashing},
  author = {Minghui Liu and Tahseen Rabbani and Tony O'Halloran and Ananth Sankaralingam and Mary-Anne Hartley and Furong Huang and Cornelia Fermüller and Yiannis Aloimonos},
  year   = {2024},
  eprint = {2412.16187},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2412.16187v3}
}

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/2412.16187.svg)](https://codeofpaper.com/paper/2412.16187)

Discussion