ChatPaper.aiChatPaper

ChunkAttention: Autoatenção Eficiente com Cache KV Consciente de Prefixo e Partição em Duas Fases

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

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

Resumo

A auto-atenção é um componente essencial dos grandes modelos de linguagem (LLMs), mas também uma fonte significativa de latência de inferência para sequências longas. Em cenários de serviço multi-inquilino de LLMs, o custo computacional e de operação de memória da auto-atenção pode ser otimizado utilizando a probabilidade de que múltiplas requisições de LLM compartilhem prompts de sistema em seus prefixos. Neste artigo, introduzimos o ChunkAttention, um módulo de auto-atenção consciente de prefixos que pode detectar prefixos de prompts correspondentes em múltiplas requisições e compartilhar seus tensores de chave/valor na memória durante a execução, melhorando a utilização da memória do cache KV. Isso é alcançado dividindo tensores monolíticos de chave/valor em blocos menores e estruturando-os em uma árvore de prefixos auxiliar. Consequentemente, sobre o cache KV baseado em árvore de prefixos, projetamos um kernel de auto-atenção eficiente, onde um algoritmo de partição em duas fases é implementado para melhorar a localidade dos dados durante o cálculo da auto-atenção na presença de prompts de sistema compartilhados. Experimentos mostram que o ChunkAttention pode acelerar o kernel de auto-atenção em 3,2 a 4,8 vezes em comparação com a implementação state-of-the-art, com o comprimento do prompt de sistema variando de 1024 a 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