Sequence length vs context window, what is the practical distinction and which one drives KV cache size?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.