Zenaique

Sliding window attention can't see beyond the window. Describe the trick that recovers older context.

Short answer·Medium·4.0 · 0·~3 min·Asked atGroqRobinhoodWeaviate·Relevant atMistral AI
Attempt it

Sliding window attention (used in Mistral, Longformer, etc.) restricts each token to attending only to the previous W tokens. Naively this seems to throw away anything older than W positions back. Describe the architectural property that lets information from older tokens still reach the current position, and explain how the effective receptive field scales.

Free · 2 AI evals / day
TL;DR

Layer stacking. Each layer adds W tokens of reach; after L layers the effective receptive field is roughly W * L. Mistral-7B's 4k window over 32 layers gives ~131k token reach.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture a line of telephone-game players where each player can only whisper to the four people immediately in front of them. A message from the back of the line cannot reach the front in one hop, but as the line passes the message forward four people at a time, it eventually arrives at the front. The total distance the message can travel is four people per hop times however many hops there are. Sliding-window attention works the same way: each layer is one hop, the window size is how many tokens you can reach per hop, and the depth of the transformer is how many hops the message gets.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Sliding-window attention restricts each layer to a window of W keys behind each query, but the residual stream and layer stacking together extend the effective receptive field to roughly W * L. That is the canonical answer, and Mistral 7B is the standard example: W = 4096 across 32 layers gives a theoretical receptive field of ≈ 131k tokens, despite the model's nominal 8k pretraining context.

This deep dive walks the mechanism step by step, derives the W * L scaling, runs concrete numbers for production models, explains why the theoretical bound is not the effective bound, and shows where sliding-window fits in the broader 2026 long-context design space alongside full attention, SSMs, and hybrid architectures.

Mental model: per layer W, per stack W * L. The residual stream is the highway that carries depth-hops without re-attention.

The per-layer and cross-layer reach

Sliding-window attention is a structural restriction on the attention mask: each query position can attend only to the W most recent key positions.

One-layer reach

At layer 1, position t can attend to positions in [t - W + 1, t]. Anything older than t - W + 1 is invisible at this layer.

Two-layer reach

At layer 2, position t again attends to [t - W + 1, t] in terms of layer-1 hidden states. But each of those layer-1 hidden states is itself a function of ITS window in layer 0:

  • Layer-1 position t - W + 1 saw layer-0 positions [t - 2W + 2, t - W + 1].
  • Layer-1 position t - W + 2 saw layer-0 positions [t - 2W + 3, t - W + 2].
  • ... and so on.

So when layer-2 attention at position t reads the layer-1 hidden state at position t - W + 1, it indirectly absorbs information from layer-0 positions as far back as t - 2W + 2. The effective reach at layer 2 is 2W positions.

L-layer reach

Iterating, after L layers the effective receptive field is approximately:

RFtheoreticalWL\text{RF}_{\text{theoretical}} \approx W \cdot L

for a depth-L sliding-window stack with window W.

Key insight: the per-layer window is the LOCAL constraint; depth is the LONG-RANGE mechanism. Without depth, sliding-window would be truncation; with depth, it is a multi-hop routing fabric.

Concrete numbers for Mistral 7B
The residual stream and why it makes depth-hops work
Theoretical vs effective receptive field, and the rise of hybrid architectures
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
Attention patternPer-layer costPer-layer reachEffective receptive field
Full attentionO(T^2 * d_k)T (everything)T, direct in one hop
Sliding windowO(W * T * d_k)W tokens back≈ W * L via depth-hops
SSM / MambaO(T * d_state)Recurrent, all of history compressedBounded by d_state bandwidth
Hybrid (sliding + periodic full)Mostly O(W * T) + sparse O(T^2)W per layer, plus full-attention layers≈ W * L with one-hop long edges at full-attn layers

Real products, models, and research that use this idea.

  • Mistral 7B: W = 4096, L = 32, theoretical receptive field ≈ 131k tokens despite nominal 8k pretraining context.
  • Longformer (Beltagy et al. 2020): pioneered sliding-window attention with W = 512 plus global tokens for document-level tasks.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy is the effective receptive field of a sliding-window model smaller than the theoretical W * L?
A

Each hop through depth has to repack the long-range signal into a fixed-dimension hidden state. That state already carries the local context, so distant content competes with nearby content for the same bandwidth. Empirically, sliding-window models trained on 4k contexts often degrade past 16-32k effective context length even when W * L is much larger. The information-bottleneck argument is what motivates hybrid architectures.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Assuming sliding-window models cannot see past W tokens. The per-layer window is W; the cross-layer receptive field is L * W via stacking.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • How layer stacking grows the receptive field beyond the per-layer window

  • The formula effective receptive field ≈ W * L

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium