ChatPaper.aiChatPaper

ChunkAttention: Efficiënte Self-Attention met Prefix-Aware KV Cache en Twee-Fase Partitionering

ChunkAttention: Efficient Self-Attention with Prefix-Aware KV Cache and Two-Phase Partition

February 23, 2024
Auteurs: Lu Ye, Ze Tao, Yong Huang, Yang Li
cs.AI

Samenvatting

Self-attention is een essentieel onderdeel van grote taalmodellen (LLM's), maar een belangrijke bron van inferentielatentie voor lange sequenties. In multi-tenant LLM-serving scenario's kunnen de reken- en geheugenoperatiekosten van self-attention worden geoptimaliseerd door gebruik te maken van de waarschijnlijkheid dat meerdere LLM-verzoeken gedeelde systeemprompts in prefixen hebben. In dit artikel introduceren we ChunkAttention, een prefix-bewuste self-attention module die overeenkomende promptprefixen over meerdere verzoeken kan detecteren en hun key/value-tensors in het geheugen tijdens runtime kan delen om het geheugengebruik van de KV-cache te verbeteren. Dit wordt bereikt door monolithische key/value-tensors op te splitsen in kleinere chunks en deze te structureren in de aanvullende prefixboom. Vervolgens ontwerpen we, bovenop de prefixboom-gebaseerde KV-cache, een efficiënte self-attention kernel, waarbij een tweefasen partitie-algoritme wordt geïmplementeerd om de datalokaliteit tijdens de self-attention berekening te verbeteren in aanwezigheid van gedeelde systeemprompts. Experimenten tonen aan dat ChunkAttention de self-attention kernel met 3,2-4,8 keer kan versnellen in vergelijking met de state-of-the-art implementatie, met een lengte van het systeemprompt variërend van 1024 tot 4096.
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.
PDF226December 15, 2024