LLM Library
Running and Using LLMsAnimated
Context Windows and Long Context
How much text the model can consider at once.
The idea
The context window is the maximum number of tokens in the prompt plus output. Longer windows need more KV-cache memory and attention compute, and models may use middle parts of a long prompt poorly.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current token sees
- other tokens see
Causal mask: a token can look at itself and earlier tokens but never the future, so the model can be trained to predict the next token.
- query token:
- 1
- sees:
- 1
1/12
Rows are the token asking (query); columns are the tokens it may look at (keys).
Step by step
- 1Count the prompt tokens
- 2Fit them within the window
- 3Pay attention cost and cache memory
- 4Trim or retrieve when it is too long
Where it is used
Long documents, codebases and conversations.
Watch out for
A bigger window is not the same as better use of it. Retrieval is often cheaper.