Skip to main content
QUICK REVIEW

[论文解读] Efficient Streaming Language Models with Attention Sinks

Ruiz Williams, Jorge Leonardo, NaNZeta LLC|arXiv (Cornell University)|Sep 29, 2023
Topic ModelingComputer Science被引用 30
一句话总结

StreamingLLM 使在有限注意力窗口上训练的 LLMs 能够通过保留一小组初始注意力汇聚 KV 对来对无限序列进行泛化,达到稳定的困惑度并在多个模型中相较滑动窗口基线实现高达 22.2x 的解码加速。

ABSTRACT

Deploying Large Language Models (LLMs) in streaming applications such as multi-round dialogue, where long interactions are expected, is urgently needed but poses two major challenges. Firstly, during the decoding stage, caching previous tokens' Key and Value states (KV) consumes extensive memory. Secondly, popular LLMs cannot generalize to longer texts than the training sequence length. Window attention, where only the most recent KVs are cached, is a natural approach -- but we show that it fails when the text length surpasses the cache size. We observe an interesting phenomenon, namely attention sink, that keeping the KV of initial tokens will largely recover the performance of window attention. In this paper, we first demonstrate that the emergence of attention sink is due to the strong attention scores towards initial tokens as a "sink" even if they are not semantically important. Based on the above analysis, we introduce StreamingLLM, an efficient framework that enables LLMs trained with a finite length attention window to generalize to infinite sequence lengths without any fine-tuning. We show that StreamingLLM can enable Llama-2, MPT, Falcon, and Pythia to perform stable and efficient language modeling with up to 4 million tokens and more. In addition, we discover that adding a placeholder token as a dedicated attention sink during pre-training can further improve streaming deployment. In streaming settings, StreamingLLM outperforms the sliding window recomputation baseline by up to 22.2x speedup. Code and datasets are provided at https://github.com/mit-han-lab/streaming-llm.

研究动机与目标

  • 促进在流式应用中高效部署具有无限文本输入的 LLM 的研究与应用。
  • 诊断为何窗口注意力在处理长文本时会失败,并识别注意力汇聚行为。
  • 提出一个简单的、非微调的框架(StreamingLLM),将有限窗口模型推广到无限输入。
  • 展示在预训练阶段引入专用汇聚标记可进一步提升跨模型的流式处理性能。

提出的方法

  • 将注意力汇聚识别为自回归 LLM 中吸引大量注意力分数的初始标记。
  • 在推理阶段通过将少量初始汇聚 KV 与滑动窗口 KV 结合来实现 StreamingLLM 的演示。
  • 描述在滚动 KV 缓存中如何处理相对位置编码(RoPE/ALiBi)。
  • 提出两种预训练变体:普通注意力、零汇聚,以及一个可学习的汇聚标记以稳定流式处理。
  • 在 Llama-2、MPT、Falcon 和 Pythia 上进行评估,包括 4M 标记长文本测试和 StreamEval。
Figure 1: Illustration of StreamingLLM vs . existing methods. The language model, pre-trained on texts of length $L$ , predicts the $T$ th token ( $T\gg L$ ). (a) Dense Attention has $O(T^{2})$ time complexity and an increasing cache size. Its performance decreases when the text length exceeds the p
Figure 1: Illustration of StreamingLLM vs . existing methods. The language model, pre-trained on texts of length $L$ , predicts the $T$ th token ( $T\gg L$ ). (a) Dense Attention has $O(T^{2})$ time complexity and an increasing cache size. Its performance decreases when the text length exceeds the p

实验结果

研究问题

  • RQ1在经过有限注意力窗口训练的 LLM 是否能够在无微调的情况下准确建模远超预训练窗口长度的文本?
  • RQ2为何在长序列上窗口注意力表现较差,注意力汇聚是否能够解释并缓解这一问题?
  • RQ3在预训练阶段引入专用的注意力汇聚标记是否能在不损害整体性能的前提下提升流式部署?
  • RQ4StreamingLLM 在多模型家族中对超长文本能在多大程度上实现加速和稳定困惑度?

主要发现

  • 一旦初始标记被移出,窗口注意力会崩溃,导致困惑度飙升。
  • 初始标记充当注意力汇聚,在多种模型的更深层中吸引不成比例的注意力。
  • StreamingLLM 在长文本(最高 20K+ 标记)和高达 4 百万标记的情况下,保持稳定困惑度并达到滑动窗口+重新计算基线的表现。
  • 使用四个初始汇聚标记即可使流式处理稳定;一个或两个标记不足以实现稳定。
  • 带可学习汇聚标记的预训练在仅有汇聚标记的情况下仍能实现稳定的流式困惑度,并保持在标准 NLP 基准上的性能。
Figure 2: Visualization of the average attention logits in Llama-2-7B over 256 sentences, each with a length of 16. Observations include: (1) The attention maps in the first two layers (layers 0 and 1) exhibit the "local" pattern, with recent tokens receiving more attention. (2) Beyond the bottom tw
Figure 2: Visualization of the average attention logits in Llama-2-7B over 256 sentences, each with a length of 16. Observations include: (1) The attention maps in the first two layers (layers 0 and 1) exhibit the "local" pattern, with recent tokens receiving more attention. (2) Beyond the bottom tw

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。