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

块注意力:高效预填充

Block-Attention for Efficient Prefilling

Tencent(腾讯)

Dongyang Ma, Yan Wang, Lan Tian

AI总结:

针对检索增强生成(RAG)场景推理延迟高、成本大的问题,提出块注意力机制,将文档划分为块独立计算KV状态并重用已有段落的KV状态,在11个基准上性能与全注意力相当且延迟大幅降低,还可应用于游戏AI。

摘要:

我们引入块注意力(Block-attention),这是一种注意力机制,旨在解决检索增强生成(RAG)场景中推理延迟增加和成本上升的问题。传统方法通常以自回归方式对整个上下文进行编码。相反,块注意力将检索到的文档划分为离散块,除最后一个块外,每个块独立计算键值(KV)状态。在RAG场景中,通过将每个段落定义为一个块,块注意力使我们能够重用之前见过的段落的KV状态,从而显著降低推理期间的延迟和计算开销。块注意力的实现包括块分割、位置重编码和微调LLM以适应块注意力机制。在11个不同基准(包括RAG、ICL和通用领域)上的实验表明,经过块微调后,块注意力模型不仅达到与全注意力模型相当的性能,还能在块注意力和全注意力模式之间无缝切换而无性能损失。值得注意的是,块注意力将首token时间(TTFT)和浮点运算(FLOPs)大幅降低至极低水平。对于总长度为32K的输入序列,输出第一个token仅需45毫秒。与全注意力模型相比,TTFT和相应的FLOPs分别减少了98.7%和99.8%。此外,在附录A中,我们详细阐述了块注意力如何应用于游戏AI场景及其带来的巨大潜在益处。我们强烈建议游戏领域的研究人员不要忽视这一部分。

英文摘要:

We introduce Block-attention, an attention mechanism designed to address the increased inference latency and cost in Retrieval-Augmented Generation (RAG) scenarios. Traditional approaches often encode the entire context in an auto-regressive manner. Instead, Block-attention divides retrieved documents into discrete blocks, with each block independently calculating key-value (KV) states except for the final block. In RAG scenarios, by defining each passage as a block, Block-attention enables us to reuse the KV states of passages that have been seen before, thereby significantly reducing the latency and the computation overhead during inference. The implementation of Block-attention involves block segmentation, position re-encoding, and fine-tuning the LLM to adapt to the Block-attention mechanism. Experiments on 11 diverse benchmarks, including RAG, ICL, and general domains, demonstrate that after block fine-tuning, the Block-attention model not only achieves performance comparable to that of full-attention models, but can also seamlessly switch between the block and full attention modes without any performance loss. Notably, Block-attention significantly reduces the time to first token (TTFT) and floating point operations (FLOPs) to a very low level. It only takes 45 ms to output the first token for an input sequence with a total length of 32K. Compared to the full-attention models, the TTFT and corresponding FLOPs are reduced by 98.7% and 99.8%, respectively. Additionally, in Appendix A, we elaborate on how Block-attention is applied in Game AI scenario and the substantial potential benefits it entails. We strongly suggest researchers in the gaming field not to overlook this section.

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

↑