Skip to main content
QUICK REVIEW

[논문 리뷰] Efficient Streaming Language Models with Attention Sinks

Ruiz Williams, Jorge Leonardo, NaNZeta LLC|arXiv (Cornell University)|2023. 09. 29.
Topic ModelingComputer Science인용 수 30
한 줄 요약

StreamingLLM은 finite attention window으로 학습된 LLM이 초기 주의 sink KV 쌍의 작은 세트를 보존하여 무한 시퀀스에 일반화하도록 하고, 여러 모델에서 슬라이딩 윈도우 기준선 대비 안정적인 perplexity와 최대 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의 효율적 배치를 촉진한다.
  • 창(window) 주의가 긴 텍스트에서 왜 실패하는지 진단하고 주의 sink 동작을 식별한다.
  • 유한 창 모델을 무한 입력으로 일반화하는 간단하고 비-파인튜닝 프레임워크(StreamingLLM)를 제안한다.
  • 전용 sink 토큰으로의 사전 학습이 모델 전반의 스트리밍 성능을 추가로 개선하는지 보여준다.

제안 방법

  • 자 autoregressive LLM에서 큰 주의 점수를 끌어들이는 초기 토큰으로 주의 sink를 식별한다.
  • 추론 중 작은 초기 sink KV 세트를 슬라이딩 윈도우 KV와 결합하여 StreamingLLM을 시연한다.
  • rolling KV 캐시에서 상대 위치 인코딩(RoPE/ALiBi)이 어떻게 처리되는지 설명한다.
  • 스트리밍을 안정화하기 위한 두 가지 사전 학습 변형: vanilla attention, zero sink, 그리고 학습 가능한 sink token을 제안한다.
  • 4M 토큰 길이 텍스트 테스트 및 StreamEval를 포함하여 Llama-2, MPT, Falcon, Pythia 전반에 걸쳐 평가한다.
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긴 시퀀스에서 창 주의의 성능 저하의 원인은 무엇이며, 주의 sink가 이를 설명하고 완화할 수 있는가?
  • RQ3사전 학습 중에 전용 주의 sink 토큰을 도입하면 스트리밍 배포를 개선하고 전반적 성능에 해를 끼치지 않는가?
  • RQ4StreamingLLM이 ultra-long 텍스트에 대해 여러 모델 계열에서 속도향상과 안정적인 perplexity를 어느 정도까지 제공할 수 있는가?

주요 결과

  • 초기 토큰이 제거되면 창 주의가 붕괴되어 높은 perplexity를 야기한다.
  • 초기 토큰은 주의 sink로 작용하여 여러 모델의 더 깊은 계층에서 불균형적으로 주의를 끈다.
  • StreamingLLM은 20K+ 토큰의 긴 텍스트와 최대 4백만 토큰에 대해 안정적인 perplexity를 유지하고 슬라이딩 윈도우 재계산 기준선과 일치한다.
  • 네 개의 초기 sink 토큰을 사용하는 것이 스트리밍을 안정시키기에 충분하며, 하나 또는 두 개의 sink는 insufficient하다.
  • 학습 가능한 sink 토큰으로의 사전 학습은 sink 토큰만으로도 안정적인 스트리밍 perplexity를 제공하고 표준 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

이 논문 읽기

누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.

누빈트에서 이 논문 읽기

이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.