Exercises — Context window and sequence length
This page is a self-testing ladder. Each rung is harder than the last:
- L1 Recognition — can you spot / recall the right idea?
- L2 Application — plug numbers into one rule.
- L3 Analysis — combine rules, reason about why.
- L4 Synthesis — design / trade off across several ideas.
- L5 Mastery — the kind of question an engineer actually gets paid to answer.
Every problem hides its worked solution inside a collapsible [!recall]- callout — forecast your answer first, then open it. After each level there is a [!mistake] callout for the exact trap most people fall into at that level.
Prerequisites you may want open: the parent topic, plus Tokenization, Self-Attention, Positional Encoding, Transformer Architecture, Truncation and Chunking, and KV Cache.
Level 1 — Recognition
L1.1
A model card says: "Context length: 8192." You send it a 500-token question (and it has not generated anything yet). What is ? What is ? Is the request valid?
Recall Solution
- (the tokens currently in the window — here just your input, since nothing is generated yet).
- (the fixed trained ceiling).
- Valid, because : . ✅
What we did: matched each number to its symbol. The card number is always the ceiling ; the current window occupancy is .
L1.2
True or false: "If my text fits inside the context window, the model uses every token equally well."
Recall Solution
False. Fitting only guarantees the tokens are visible. The "lost in the middle" effect means tokens at the start and end are attended to far better than tokens buried in the middle. Fitting ≠ attending well.
L1.3
Which quantity is your per-request choice, and which is fixed by the model: sequence length or context window?
Recall Solution
- Sequence length — under your control (you decide how long the prompt is, and how many tokens you ask the model to generate).
- Context window — fixed by the trained weights/architecture; you cannot raise it by asking.
Level 2 — Application
L2.1
An essay is 6000 words. Using tokens/word, estimate . If , does it fit?
Recall Solution
Why multiply by 1.3? subword tokenizers cut rare/long words into several tokens, so tokens outnumber words. Since , it does not fit — you must truncate or chunk.
L2.2
Model A has ; Model B has . By what factor does B's window exceed A's, and by what factor does its attention compute exceed A's?
Recall Solution
Window factor: . Attention compute , so: Why squared? every token attends to every token ⇒ pairs. A window is the attention work.
L2.3
A chat model has . Your system prompt + user message = 6000 tokens. How many tokens remain for the model's reply?
Recall Solution
Why subtract? the window holds prompt + generated output together — they draw from one shared budget, and as generation proceeds climbs from 6000 toward the ceiling. Ask for a 3000-token reply and it gets cut off at 2192.
Level 3 — Analysis
L3.1
Explain in one line each why attention compute is but attention memory (the stored weights) is only .
Recall Solution
- Compute : there are query–key pairs, and each pair's score is a dot product of two -dimensional vectors, costing multiply-adds. Multiply: .
- Memory : once computed, each pair collapses to one scalar weight. Storing scalars is , with no . (Q/K/V tensors add a separate .) Key idea: the lives inside the dot product (compute), not in the stored result (memory).
L3.2
Two setups cost the same attention compute. Setup X: , . Setup Y: , . Find for Y so that matches X.
Recall Solution
Set the products equal: What this shows: halving cuts by , so must grow to keep the same compute. Sequence length dominates because it enters squared; width enters only linearly.
L3.3
The parent note warns older models "degrade sharply" beyond position . Using Positional Encoding, explain the mechanism — what specifically is missing at position ?
Recall Solution
Classic learned/sinusoidal position tables are precomputed for positions . At position (index in 1-based counting) there is literally no entry / an untrained region in that table.
- Without a position signal, Self-Attention cannot tell order apart ("dog bites man" = "man bites dog").
- So the model must either wrap, extrapolate, or output garbage — hence the sharp cliff. Modern fix: RoPE / ALiBi / interpolation let positions extend smoothly, but quality is only guaranteed inside the trained window.
Level 4 — Synthesis
L4.1
You must fit a document of 30,000 tokens through a model with , reserving 2000 tokens in each call for a fixed instruction + output. Design a chunking plan: how many tokens of document per chunk, and how many chunks minimum?
Recall Solution
Step 1 — usable room per call. Overhead is 2000, so document room per chunk: Step 2 — number of chunks. Divide and round up (a partial chunk still needs its own call): Why round up? chunks cover only ; the leftover tokens need a 5th call.
The figure below shows all 5 calls stacked. In each row the plum block is the fixed 2000-token overhead (instruction + reserved output), the teal block is the document tokens carried in that call (6192 for calls 1–4, and only 5232 for call 5), and the dotted region is the unused room up to the orange ceiling . Reading down the teal blocks, confirms the whole document is covered.

L4.2
For that same plan, compare total attention compute of the 5-chunk approach (each chunk runs at its own length) vs a hypothetical single model that could swallow all 30,000 tokens at once. Assume same ; use as the compute proxy.
Recall Solution
Single giant call: , compute proxy . Chunked: four full chunks at plus one at : Ratio: . Interpretation: chunking is ~5× cheaper in attention here — because the law punishes one huge sequence far more than several medium ones. The trade-off: chunks lose cross-chunk attention, so the model can't relate token 1 to token 29,000.
Level 5 — Mastery
L5.1
A production API charges by total tokens processed and separately warns that attention compute scales as . You have a fixed 100,000-token corpus to answer questions over. Argue quantitatively why "just use one huge 128k-context model per query" can be worse than retrieval + a small window — and identify the one place where the big window wins.
Recall Solution
Setup. Say the small approach retrieves only the ~ relevant tokens; the big approach feeds all . Attention-compute proxy (): The big window is 625× more attention compute for the same question — and pays for it every query, forever. Where the big window wins: when the answer requires global reasoning across the whole corpus (e.g. "summarize contradictions between page 3 and page 290"). Retrieval that pulls only 4000 tokens may never co-locate the two facts that must be compared, so it can be wrong at any price. Big context buys cross-document attention that chunking/retrieval structurally cannot. The trade: cost () vs completeness (global attention). Neither is free.
L5.2
Derive the general rule: for a fixed overhead tokens per call and window , the minimum number of calls to cover a document of tokens is Then explain what happens as , and verify with .
Recall Solution
Derivation. Each call has tokens of usable room for the document (the rest is overhead). To cover tokens you need enough calls so that (calls) (room) : The ceiling appears because a fraction of a call still costs a whole call. Degenerate limit : the denominator , so — if overhead eats the whole window there is no room left for the document; the task is impossible. (And makes room negative → undefined, meaning the instruction alone already overflows.) Verify: . ✅ Matches L4.1.
Wrap-up recall
Recall One-line answers to the whole ladder
- L1: = tokens currently in the window (prompt + generated so far); = fixed trained max; .
- L2: 7800 tokens (no fit); compute; 2192 output tokens.
- L3: compute (dot products), memory (scalars); ; missing position table entry.
- L4: 6192 doc-tokens/chunk, 5 chunks; chunking ~5× cheaper but loses cross-chunk attention.
- L5: big window compute but wins on global reasoning; .