KVキャッシュ圧縮のためのシンプルで効果的なL_2ノルムベース戦略
A Simple and Effective L_2 Norm-Based Strategy for KV Cache Compression
June 17, 2024
著者: Alessio Devoto, Yu Zhao, Simone Scardapane, Pasquale Minervini
cs.AI
要旨
大規模言語モデル(LLM)の展開は、特にコンテキスト長が増加するにつれて、Key-Value(KV)キャッシュの膨大なメモリ要件によってしばしば妨げられます。既存のKVキャッシュサイズを削減するアプローチには、モデルを微調整して圧縮戦略を学習させる方法や、アテンションスコアを活用してシーケンス長を短縮する方法があります。私たちは、デコーダのみのTransformerベースのモデルにおけるアテンション分布を分析し、ほとんどの層でアテンションの割り当てパターンが一貫していることを観察しました。驚くべきことに、キャッシュされたKVペアに対するL_2ノルムとアテンションスコアの間に明確な相関関係があることがわかりました。具体的には、キー埋め込みのL_2ノルムが低い場合、デコード中に高いアテンションスコアが得られる傾向があります。この発見は、KVペアの影響が、クエリされる前にキー埋め込み自体によって決定される可能性を示唆しています。この観察に基づいて、私たちはキー埋め込みのL_2ノルムに基づいてKVキャッシュを圧縮します。実験結果は、このシンプルな戦略が、言語モデリングや針を探すタスクではKVキャッシュサイズを50%削減し、パスキー検索タスクでは90%削減できることを示しています。しかも、精度を損なうことなく実現できます。
English
The deployment of large language models (LLMs) is often hindered by the
extensive memory requirements of the Key-Value (KV) cache, especially as
context lengths increase. Existing approaches to reduce the KV cache size
involve either fine-tuning the model to learn a compression strategy or
leveraging attention scores to reduce the sequence length. We analyse the
attention distributions in decoder-only Transformers-based models and observe
that attention allocation patterns stay consistent across most layers.
Surprisingly, we find a clear correlation between the L_2 and the attention
scores over cached KV pairs, where a low L_2 of a key embedding usually leads
to a high attention score during decoding. This finding indicates that the
influence of a KV pair is potentially determined by the key embedding itself
before being queried. Based on this observation, we compress the KV cache based
on the L_2 of key embeddings. Our experimental results show that this simple
strategy can reduce the KV cache size by 50% on language modelling and
needle-in-a-haystack tasks and 90% on passkey retrieval tasks without losing
accuracy.