ChunkAttention: Autoattenzione Efficiente con Cache KV Consapevole del Prefisso e Partizione in Due Fasi
ChunkAttention: Efficient Self-Attention with Prefix-Aware KV Cache and Two-Phase Partition
February 23, 2024
Autori: Lu Ye, Ze Tao, Yong Huang, Yang Li
cs.AI
Abstract
L'auto-attenzione è un componente essenziale dei grandi modelli linguistici (LLM), ma rappresenta una fonte significativa di latenza durante l'inferenza per sequenze lunghe. Negli scenari di servizio multi-tenant per LLM, il costo computazionale e di operazioni di memoria dell'auto-attenzione può essere ottimizzato sfruttando la probabilità che più richieste LLM condividano prefissi di prompt di sistema. In questo articolo, introduciamo ChunkAttention, un modulo di auto-attenzione consapevole dei prefissi che può rilevare prefissi di prompt corrispondenti tra più richieste e condividere i loro tensori chiave/valore in memoria durante l'esecuzione, migliorando così l'utilizzo della memoria della cache KV. Questo è ottenuto suddividendo i tensori chiave/valore monolitici in blocchi più piccoli e strutturandoli in un albero dei prefissi ausiliario. Di conseguenza, sulla base della cache KV basata sull'albero dei prefissi, progettiamo un kernel di auto-attenzione efficiente, in cui è implementato un algoritmo di partizione a due fasi per migliorare la località dei dati durante il calcolo dell'auto-attenzione in presenza di prompt di sistema condivisi. Gli esperimenti dimostrano che ChunkAttention può accelerare il kernel di auto-attenzione di 3,2-4,8 volte rispetto all'implementazione all'avanguardia, con la lunghezza del prompt di sistema compresa tra 1024 e 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.