SnapKV:LLM 在生成前就知道你在寻找什么
SnapKV: LLM Knows What You are Looking for Before Generation
AI总结:
本文提出无需微调的SnapKV,利用提示末尾观察窗口识别各注意力头的重要KV位置并自动压缩缓存,在16K输入下实现3.6倍生成加速和8.2倍内存效率提升,并保持长序列任务性能。
摘要:
大语言模型(LLM)在处理长上下文方面取得了显著进展,而键值(KV)缓存在提升其性能方面发挥着关键作用。然而,随着输入长度增加,KV缓存的增长给内存和时间效率带来了挑战。为解决这一问题,本文提出 SnapKV,这是一种新颖且无需微调的方法,可高效减小KV缓存大小,同时在实际应用中保持相当的性能。我们发现,模型中的每个注意力头在生成过程中会持续关注特定的提示注意力特征;同时,这种稳定模式可以从位于提示末尾的“观察”窗口中获得。基于这一洞见,SnapKV通过为每个注意力头选择成簇的重要KV位置,自动压缩KV缓存。该方法显著降低了处理长输入序列时不断增长的计算开销和内存占用。具体而言,在处理16K token输入时,与基线相比,SnapKV实现了稳定的解码速度,生成速度提升3.6倍,内存效率提高8.2倍。同时,它在16个长序列数据集上保持了与基线模型相当的性能。此外,只需对HuggingFace实现进行少量修改,SnapKV即可在单张A100-80GB GPU上处理多达380K个上下文token,并在Needle-in-a-Haystack测试中仅表现出可忽略的准确率下降。进一步的综合研究表明了SnapKV在实际应用中的潜力。
英文摘要:
Large Language Models (LLMs) have made remarkable progress in processing extensive contexts, with the Key-Value (KV) cache playing a vital role in enhancing their performance. However, the growth of the KV cache in response to increasing input length poses challenges to memory and time efficiency. To address this problem, this paper introduces SnapKV, an innovative and fine-tuning-free approach that efficiently minimizes KV cache size while still delivering comparable performance in real-world applications. We discover that each attention head in the model consistently focuses on specific prompt attention features during generation. Meanwhile, this robust pattern can be obtained from an 'observation' window located at the end of the prompts. Drawing on this insight, SnapKV automatically compresses KV caches by selecting clustered important KV positions for each attention head. Our approach significantly reduces the growing computational overhead and memory footprint when processing long input sequences. Specifically, SnapKV achieves a consistent decoding speed with a 3.6x increase in generation speed and an 8.2x enhancement in memory efficiency compared to the baseline when processing inputs of 16K tokens. At the same time, it maintains comparable performance to the baseline models across 16 long sequence datasets. Moreover, SnapKV can process up to 380K context tokens on a single A100-80GB GPU using HuggingFace implementation with minor changes, exhibiting only a negligible accuracy drop in the Needle-in-a-Haystack test. Further comprehensive studies suggest SnapKV's potential for practical applications.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。