ChunkAttention: プレフィックス認識KVキャッシュと二相分割による効率的なセルフアテンション
ChunkAttention: Efficient Self-Attention with Prefix-Aware KV Cache and Two-Phase Partition
February 23, 2024
著者: Lu Ye, Ze Tao, Yong Huang, Yang Li
cs.AI
要旨
Self-attentionは大規模言語モデル(LLM)の重要な構成要素であるが、長いシーケンスに対する推論レイテンシの主要な原因でもある。マルチテナントLLMサービングシナリオでは、複数のLLMリクエストがプレフィックスとして共有システムプロンプトを持つ確率を利用することで、self-attentionの計算コストとメモリ操作コストを最適化できる。本論文では、ChunkAttentionを紹介する。これはプレフィックスを認識するself-attentionモジュールであり、複数のリクエスト間で一致するプロンプトプレフィックスを検出し、実行時にそれらのキー/バリューテンソルをメモリ内で共有することで、KVキャッシュのメモリ使用効率を向上させる。これは、単一のキー/バリューテンソルを小さなチャンクに分割し、それらを補助的なプレフィックスツリーに構造化することで実現される。その結果、プレフィックスツリーベースのKVキャッシュ上で、共有システムプロンプトが存在する場合のself-attention計算中のデータ局所性を改善するために、2段階のパーティションアルゴリズムを実装した効率的なself-attentionカーネルを設計した。実験結果によると、ChunkAttentionは最先端の実装と比較して、システムプロンプトの長さが1024から4096の範囲で、self-attentionカーネルを3.2~4.8倍高速化できることが示された。
English
Self-attention is an essential component of large language models(LLMs) but a
significant source of inference latency for long sequences. In multi-tenant
LLMs serving scenarios, the compute and memory operation cost of self-attention
can be optimized by using the probability that multiple LLM requests have
shared system prompts in prefixes. In this paper, we introduce ChunkAttention,
a prefix-aware self-attention module that can detect matching prompt prefixes
across multiple requests and share their key/value tensors in memory at runtime
to improve the memory utilization of KV cache. This is achieved by breaking
monolithic key/value tensors into smaller chunks and structuring them into the
auxiliary prefix tree. Consequently, on top of the prefix-tree based KV cache,
we design an efficient self-attention kernel, where a two-phase partition
algorithm is implemented to improve the data locality during self-attention
computation in the presence of shared system prompts. Experiments show that
ChunkAttention can speed up the self-attention kernel by 3.2-4.8times
compared to the start-of-the-art implementation, with the length of the system
prompt ranging from 1024 to 4096.