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

用于带有长系统提示的高效大型语言模型服务的RelayAttention

RelayAttention for Efficient Large Language Model Serving with Long System Prompts

City University of Hong Kong(香港城市大学);SenseTime Research(商汤科技研究院)

Lei Zhu, Xinjiang Wang, Wayne Zhang, Rynson W. H. Lau

AI总结:

本文提出RelayAttention算法,通过数学重构因果注意力,使批量请求中长系统提示的缓存状态仅需从DRAM读取一次,无需重训练即可消除内存访问冗余,显著提升了LLM服务的吞吐量和延迟性能。

摘要:

实际的LLM服务可能涉及长系统提示,它指定任务的指令、示例和知识文档,并在请求间重用。然而,长系统提示会导致吞吐量/延迟瓶颈,因为生成下一个token的成本随序列长度增加。本文旨在提高涉及长系统提示的LLM服务效率。我们的关键观察是,在现有因果注意力计算算法中,处理这些系统提示需要大量冗余的内存访问。具体而言,对于批量请求,系统提示的缓存隐藏状态(即键值对)从片外DRAM传输到片上SRAM多次,每次对应一个单独的请求。为消除这种冗余,我们提出RelayAttention,这是一种注意力算法,允许对一批输入token从DRAM仅读取这些隐藏状态一次。RelayAttention是免费午餐:它保持生成质量且无需模型重训练,因为它基于因果注意力的数学重构。我们观察到,通过与vLLM集成RelayAttention,对该生产级系统有显著性能提升。使用更长的系统提示时,改进更为深远。

英文摘要:

A practical large language model (LLM) service may involve a long system prompt, which specifies the instructions, examples, and knowledge documents of the task and is reused across requests. However, the long system prompt causes throughput/latency bottlenecks as the cost of generating the next token grows w.r.t. the sequence length. This paper aims to improve the efficiency of LLM services that involve long system prompts. Our key observation is that handling these system prompts requires heavily redundant memory accesses in existing causal attention computation algorithms. Specifically, for batched requests, the cached hidden states (\ie, key-value pairs) of system prompts are transferred from off-chip DRAM to on-chip SRAM multiple times, each corresponding to an individual request. To eliminate such a redundancy, we propose RelayAttention, an attention algorithm that allows reading these hidden states from DRAM exactly once for a batch of input tokens. RelayAttention is a free lunch: it maintains the generation quality while requiring no model retraining, as it is based on a mathematical reformulation of causal attention. We have observed significant performance improvements to a production-level system, vLLM, through integration with RelayAttention. The improvements are even more profound with longer system prompts.

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

↑