[Paper Review] Efficient Streaming Language Models with Attention Sinks
StreamingLLM enables LLMs trained with a finite attention window to generalize to infinite sequences by preserving a small set of initial attention sink KV pairs, achieving stable perplexity and up to 22.2x decoding speedup over sliding-window baselines across multiple models.
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.
Motivation & Objective
- Motivate efficient deployment of LLMs in streaming applications with unlimited text input.
- Diagnose why window attention fails for long texts and identify attention sink behavior.
- Propose a simple, non-finetuning framework (StreamingLLM) that generalizes finite-window models to infinite input.
- Show that pre-training with a dedicated sink token further improves streaming performance across models.
Proposed method
- Identify attention sinks as initial tokens that attract large attention scores in autoregressive LLMs.
- Demonstrate StreamingLLM by combining a small set of initial sink KV with a sliding window KV during inference.
- Describe how relative positional encodings (RoPE/ALiBi) are handled in the rolling KV cache.
- Propose two pre-training variants: vanilla attention, zero sink, and a learnable sink token to stabilize streaming.
- Evaluate across Llama-2, MPT, Falcon, and Pythia including 4M token long-text tests and StreamEval.

Experimental results
Research questions
- RQ1Can LLMs trained with a finite attention window accurately model texts much longer than the pre-training window without fine-tuning?
- RQ2What is the cause of poor performance in window attention for long sequences, and can attention sinks explain and mitigate it?
- RQ3Does introducing a dedicated attention sink token during pre-training improve streaming deployment without harming overall performance?
- RQ4To what extent can StreamingLLM deliver speedups and stable perplexity across multiple model families for ultra-long texts?
Key findings
- Window attention collapses once initial tokens are evicted, causing high perplexity.
- Initial tokens act as attention sinks, attracting disproportionate attention in deeper layers across several models.
- StreamingLLM maintains stable perplexity and matches sliding-window-with-recompute baselines on long texts up to 20K+ tokens and up to 4 million tokens.
- Using four initial sink tokens suffices to stabilize streaming; one or two sinks are insufficient.
- Pre-training with a learnable sink token yields stable streaming perplexity with only the sink token, and preserves performance on standard NLP benchmarks.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.