arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2402.15220cs.LGcs.CL
收藏

ChunkAttention:具有前缀感知KV缓存和两阶段划分的高效自注意力

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

Microsoft(微软)

Lu Ye, Ze Tao, Yong Huang, Yang Li

AI总结:

ChunkAttention通过前缀树共享多租户LLM请求的KV缓存,并采用两阶段划分自注意力内核,在1024-4096长度系统提示词下实现3.2-4.8倍加速。

摘要:

自注意力是大语言模型(LLM)的重要组成部分,但对于长序列而言,它是推理延迟的重要来源。在多租户LLM服务场景中,可以利用多个LLM请求在前缀中共享系统提示词的概率来优化自注意力的计算和内存操作成本。本文介绍了ChunkAttention,一个前缀感知的自注意力模块,它能够在运行时检测多个请求之间匹配的提示词前缀,并在内存中共享其键/值张量,以提高KV缓存的内存利用率。这是通过将整体键/值张量拆分为更小的块并将其组织到辅助前缀树中实现的。因此,在基于前缀树的KV缓存之上,我们设计了一个高效的自注意力内核,其中实现了两阶段划分算法,以在存在共享系统提示词的情况下提高自注意力计算期间的数据局部性。实验表明,与最先进的实现相比,ChunkAttention可以将自注意力内核加速3.2-4.8倍,系统提示词长度范围为1024到4096。

英文摘要:

Self-attention is an essential component of large language models (LLM) but a significant source of inference latency for long sequences. In multi-tenant LLM 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.8$\times$ compared to the state-of-the-art implementation, with the length of the system prompt ranging from 1024 to 4096.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑