6.1.10 · D5Scaling & Efficient Architectures

Question bank — Long-context architectures

2,412 words11 min readBack to topic

This is a question bank. Each line is a trap: a statement that sounds right, or a boundary case people skip. Cover the answer, commit to a reason (not just "true"/"false"), then reveal. If your reason differs from the answer's reason, that's the misconception caught.

Every item here builds on the ideas in the parent note and its prerequisites: Attention Mechanisms, Computational Complexity, Transformer Architecture, Recurrent Neural Networks, Kernel Methods, Retrieval-Augmented Generation, and Information Bottleneck.

Two derivations that the traps lean on — worked out once here so the reveals can just cite them.


True or false — justify

Full self-attention over tokens costs because every token compares against every other token.
True. Each of the query tokens forms a dot product with all key tokens, giving comparisons — the grid is fully filled in, so cost grows with the square of .
Sparse attention always saves training memory, no matter how it is implemented.
False. Sparsity only helps if the implementation skips the masked-out entries. Many frameworks apply a sparse mask on top of a dense matrix — the full grid is still allocated, so memory is unchanged. Real savings require a specialised kernel (block-sparse, gather/scatter) that never materialises the dropped pairs.
Longformer's sliding window alone (no global tokens) already preserves document-level understanding.
False. A pure local window of size means token can only ever see tokens within ; information from far-away tokens must hop through many intermediate layers, and shallow models lose it — that's exactly why global tokens are added.
Linear attention is called "linear" because the feature map is a linear function.
False. can be nonlinear (the random-feature above uses ); "linear" refers to the total cost scaling in sequence length, achieved by the associative re-order that summarises keys once instead of comparing them per query.
Replacing with leaves the attention output unchanged.
False. As the derivation above shows, only equals in expectation — it is an unbiased approximation with variance; the efficiency win buys cost at the price of no longer computing the exact softmax kernel (see Kernel Methods).
A State Space Model (SSM) has fixed memory cost regardless of how long the sequence is.
True. The hidden state is a fixed-dimension vector (e.g. 256 numbers); it is overwritten every step, so storing it does not grow with — unlike attention, which caches a key/value for every past token.
Because an SSM keeps a fixed-size state, it can never lose information from early tokens.
False. The opposite: a fixed-size state is an Information Bottleneck — old information must be compressed into the same 256 numbers, so distant details can be squeezed out, whereas attention keeps a separate cached vector per token.
The convolutional form of S4 and its recurrent form compute different outputs.
False. They are two views of the same linear recurrence : the kernel unrolls the recurrence into a convolution, so outputs match — the convolution is just chosen for parallel training.
Memory-augmented models achieve overall because nearest-neighbour lookup over a memory of size is roughly .
True — with a caveat. Approximate nearest-neighbour search (e.g. FAISS) is sub-linear per query, so total cost is ; this is only while and stay much smaller than (i.e. exponential-in-; see the edge case below).

Spot the error

"We use a sliding window of size to be safe, and still enjoy complexity."
Error: if the window is the whole sequence, so cost is — you've reverted to full attention. The linear win requires .
"Linear attention precomputes separately for each query, one per query."
Error: is computed once, globally, shared by all queries (see the associative re-order above). Recomputing it per query would reintroduce the scan and defeat the entire method.
"In linear attention we can drop the denominator since it's just a scaling constant."
Error: that denominator is the softmax-style normalizer ; different queries have different denominators, so dropping it removes the normalization and gives unbounded, wrongly-weighted outputs.
"The SSM matrix , so a bigger step size always means the state changes more slowly."
Error: the effect depends on the sign/magnitude of 's eigenvalues. For stable systems (), larger makes smaller, so the past decays faster — the state forgets more quickly, not more slowly.
"S4 chooses diagonal-plus-low-rank purely to reduce the number of parameters."
Error: the structure exists to make the matrix exponential and the convolution kernel fast to compute (diagonal exp + Woodbury correction); parameter count is a minor side effect, computability is the point.
"A [CLS] global token costs the same as any other token in Longformer."
Error: a global token attends to all tokens (cost ), while a regular token attends to only (cost ). That's why the budget is , with the term paying for the global tokens.
"Memory-augmented attention retrieves the top- nearest neighbours, so it always sees the single most relevant past token."
Error: it uses approximate nearest-neighbour search — for speed it may miss the exact top match; you trade a small recall error for lookup, similar to retrieval in Retrieval-Augmented Generation.

Why questions

Why does full attention hit a wall around 2k–8k tokens even though a modern GPU has plenty of raw FLOPs?
Because the bottleneck is memory, not FLOPs: the score matrix must be stored, and at large it exceeds GPU RAM long before compute becomes the limit.
Why can't we just make the window grow slowly with (say ) and call it ?
You can, but then — that's the "" sparse regime, better than but not truly linear.
Why does the associativity trick before multiplying by save so much?
Because it changes the order of a matrix product: summarising keys+values first builds the fixed-size matrix (and normalizer ); each query then multiplies by in time, so the expensive scan over happens once instead of per query — exactly the algebra in the formula callout above.
Why do SSMs offer a convolutional training form but a recurrent inference form?
Training sees the whole sequence at once, so the convolution parallelises across all positions on a GPU; inference generates tokens one at a time, so the step-by-step recurrence (carry state forward) is the natural, memory-cheap mode — the same duality that motivates Recurrent Neural Networks.
Why do memory-augmented models still keep a local sliding window instead of relying entirely on retrieved memory?
Local, recent tokens carry fine-grained syntactic dependencies that retrieval (built for coarse semantic similarity) often misses; the window guarantees nearby context is always attended to, regardless of what the memory returns.
Why is calling any sub-quadratic method "just as good as full attention" misleading?
Every method trades exactness for cost: sparse patterns drop token pairs, linear attention approximates the kernel, SSMs compress into a bottleneck. They approach full-attention quality on many tasks but can fail on tasks needing exact, arbitrary long-range pairwise lookups.

Edge cases

What happens to Longformer's cost accounting if every token is made a global token ()?
The term becomes , so complexity collapses back to — global attention is only cheap when the global set is tiny.
What is the attention cost when is smaller than the window (a short sequence)?
Each token can attend to at most tokens, so the effective window saturates at ; sparse and full attention coincide, and there is no efficiency gain — sparsity only helps once .
What does linear attention's output become if every value is identical, say ?
The numerator becomes , and dividing by the normalizer gives exactly — normalization guarantees the output is the constant, matching intuition that averaging identical values returns that value.
What happens to an SSM's state as if the largest eigenvalue of has magnitude ?
The state grows without bound (each step amplifies), so outputs blow up — this is why S4 constrains eigenvalues to keep for a stable, decaying memory.
What is the memory-lookup cost when the memory bank is empty (start of a long document)?
There is nothing to retrieve, so only the local window contributes; cost per token is just , and the model behaves like a plain sliding-window model until enough context is stored.
What if the memory bank grows with the sequence, e.g. (store every token)?
Then becomes not linear. The advertised holds only under the unstated assumption (a compressed, bounded memory); an ever-growing memory quietly reintroduces a factor.
What breaks if the feature-map dimension in linear attention is chosen as large as ?
The per-query cost then scales with , so total cost returns to — the linear guarantee holds only while is a fixed small constant, independent of sequence length.
Recall One-line summary of the whole trap set

Every efficient long-context method wins by not filling the full grid — sparse drops pairs, linear reorders sums, SSM compresses to a fixed state, memory retrieves a few neighbours — and each win comes with a specific failure mode when its "" assumption is violated.


Pictures behind the traps

Text alone hides geometry. These four figures are the visual anchors the traps refer back to.

The grid and what each method keeps. Full attention fills the whole square (every token-pair). The red cells are the only comparisons each efficient method actually computes.

Figure — Long-context architectures

Sliding window vs global tokens. A local token sees a red band around the diagonal; a global token (top row/left column, red) sees the entire sequence.

Figure — Long-context architectures

SSM: one recurrence, two shapes. The same can be unrolled left-to-right (recurrent, red arrows) or flattened into a single convolution kernel (red) applied to all inputs at once.

Figure — Long-context architectures

Memory-augmented lookup. The current query (red) attends to a small local window plus the top- neighbours pulled from a bounded memory bank — never to the whole past.

Figure — Long-context architectures