gitwtfhub

wtf is streaming-llm?

mit-han-lab/streaming-llm — explained in plain English

Analysis updated 2026-06-24

7,227PythonAudience · researcherComplexity · 4/5Setup · hard

TL;DR

StreamingLLM lets AI language models run indefinitely in long chat sessions without crashing or forgetting, by keeping only the first few anchor tokens and the most recent messages in memory.

Mindmap

mindmap
  root((StreamingLLM))
    Core idea
      Attention sink tokens
      Keep first and recent
      Discard middle tokens
    Benefits
      Infinite chat sessions
      No memory reset
      22x faster than sliding
    Supported models
      Llama-2
      Falcon
      MPT and Pythia
    Integrations
      HuggingFace
      NVIDIA TensorRT
      Intel extension

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Build a chat assistant that runs non-stop for hours without resetting context or crashing.

REASON 2

Integrate efficient streaming inference into Llama-2, Falcon, or MPT models via HuggingFace.

REASON 3

Research how attention sink tokens enable infinite-length generation without full-context recomputation.

What's in the stack?

PythonPyTorchHuggingFace Transformers

How it stacks up

mit-han-lab/streaming-llmkennethreitz/recordsjrnl-org/jrnl
Stars7,2277,2237,233
LanguagePythonPythonPython
Setup difficultyhardeasyeasy
Complexity4/52/51/5
Audienceresearcherdatawriter

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · hard Time to first run · 1h+

Requires GPU hardware and compatible HuggingFace model weights for Llama-2, Falcon, or MPT.

Wtf does this do

StreamingLLM is a research project from MIT Han Lab that addresses a practical limitation of AI language models in long-running applications. Language models like Llama-2 and similar systems are trained to handle text only up to a certain length, called a context window. In a long back-and-forth chat session, the conversation can grow beyond that limit, at which point the model either needs to restart and forget what was said earlier, or spend significant compute time reprocessing the recent history. Both options are costly. The key observation behind this project is called an attention sink. When a language model processes text, it assigns attention scores to tokens to decide which parts of the text to focus on. The researchers found that early tokens in a sequence receive very high attention scores regardless of how important they actually are, acting as a kind of anchor. Removing those early tokens causes the model's quality to drop noticeably, even if they contain little useful content. StreamingLLM works by keeping two things in memory: the most recent tokens the model has seen, and the initial anchor tokens that serve as attention sinks. Everything in the middle gets discarded. This allows the model to keep running indefinitely without resetting its memory, and without the cost of recomputing past states. According to the paper, this approach achieves up to 22 times the speed of an alternative method called sliding window recomputation. It is important to understand what this does not do. The model's context window does not grow. The model cannot see or reason about the tokens that were discarded from the middle of a long conversation. Feeding an entire book into StreamingLLM and asking for a summary would only produce a summary of the final pages, because the model can only work with what is currently in its window. The project is designed for continuous dialogue and assistant-style applications where the model needs to keep running without crashing, not for tasks requiring full-document comprehension. StreamingLLM has been integrated into HuggingFace Transformers, NVIDIA TensorRT-LLM, and Intel's extension for Transformers. It supports Llama-2, MPT, Falcon, and Pythia. The paper was accepted at ICLR 2024.

Yoink these prompts

Prompt 1
Using StreamingLLM with a HuggingFace Llama-2 model, show me how to set up an infinite chat loop that never hits a context-length error.
Prompt 2
Explain the attention sink concept in StreamingLLM and show me how to configure the number of sink tokens and the recent token window size.
Prompt 3
I want to compare StreamingLLM against sliding-window recomputation on a long dialogue. Write a benchmark script that measures throughput for both.
Prompt 4
How do I apply StreamingLLM to a Falcon model? Show me the minimal code changes needed to enable streaming inference.

Frequently asked questions

wtf is streaming-llm?

StreamingLLM lets AI language models run indefinitely in long chat sessions without crashing or forgetting, by keeping only the first few anchor tokens and the most recent messages in memory.

What language is streaming-llm written in?

Mainly Python. The stack also includes Python, PyTorch, HuggingFace Transformers.

How hard is streaming-llm to set up?

Setup difficulty is rated hard, with roughly 1h+ to a first successful run.

Who is streaming-llm for?

Mainly researcher.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.