Sequence length vs context window, what is the practical distinction and which one drives KV cache size?
Context window is the model's fixed upper limit; sequence length is what the current request actually uses. KV cache scales with live sequence length, not the window.
Think of a parking garage that can hold 200 cars. That capacity is the context window: a fixed structural number that does not change. The sequence length is how many cars are parked right now. If only five cars are inside, you only pay for those five spots of upkeep, not for all 200. KV cache memory behaves the same way. The model architecture pre-declares the maximum it could ever store, but the GPU only allocates pages for the tokens you actually feed it. A small chat turn on a giant-context model is cheap. The total context window is only a ceiling, not a daily rent.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define both terms, show the KV cache memory formula, illustrate with a concrete 200k-context model serving a 500-token request, then close on why paged attention allocates on demand and what GQA and sliding window do to the slope in T.
Real products, models, and research that use this idea.
- Claude Opus 4.7 ships a 1M-token context window, but a typical chat turn is under 2k tokens, so most KV caches are tiny.
- GPT-5.5 advertises 400k input tokens; pricing tiers reflect realized input length, not the ceiling.
- Llama 4 Maverick supports 1M-context inference on H200 with FP8 KV cache, where serving cost scales with realized T.
- vLLM and SGLang both allocate KV cache pages on demand at decode time, freeing them at sequence completion.
- Gemini 3.1 Pro's 2M-context tier is priced per-token so long-document use cases pay only for tokens actually loaded.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does grouped-query attention change the dependence of KV cache on sequence length?
QWhy does decode cost scale with full sequence length rather than just the new token?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming a 200k-context model always allocates 200k tokens of KV cache. The cache grows with the live request, not with the architectural cap.
The night-before-the-interview bullets. Scan these on the way to the call.
Same topic, related formats. Practice these next.