Why do short windows help at long contexts? A mechanistic perspective

Counterintuitively, shorter sliding windows lead to better long-context performance in hybrids of sliding window and full attention. We try to understand this phenomenon mechanistically, by looking at where heads, responsible for a crucial long-context modeling ability (i.e. in-context recall), emerge during pretraining.

Introduction

Figure 1. Longer sliding windows hurt long-context performance RULER measures accuracy averaged over the three S-NIAH synthetic tasks at 4K sequence length. Recall measures how well the model retrieves information from natural-language documents. Perplexity measures language modeling performance at 4K contexts on FineWeb-Edu. For more details, see Evaluation details in the Appendix.. Each red dot is a hybrid that interleaves sliding window attention (SWA) with full attention, where each is trained with a different SWA window size. This SWA-full interleaving is common in recent open-source models such as Muse Glimmer, Inkling, MAI and OLMo 3.

Recently released open-source models interleave sliding window attention (SWA) with full attention. Pretraining these hybrid models involves many design choices. Here, we focus on one that can shape long-context performance of these hybrid models: the window size of the SWA layers.

Surprisingly, shorter windows improve long-context performance (Figure 1). This is counterintuitive: why would short windows help in long context modeling?

In this blog, we try to understand why from a mechanistic perspective, by looking inside what the hybrid model has learnt after pretraining.

This phenomenon has been observed in prior work It is also a piece of community folklore often discussed on X :), but the explanation has largely been that full attention layers “get lazy” 😴 when sliding windows are long . We try to pinpoint what this “laziness” could mean.

Let’s unpack what’s happening.

What are the hybrids learning?

We look inside attention-only hybrid models to understand why what they learn differs with long versus short sliding windows. Following recent models , we pretrain hybrid models that combine SWA layers (with RoPE) and full attention layers (with NoPE) in a 3:1 ratio. We vary the sliding window size across models. Each model has ~380M parameters and is pretrained on 10B tokens from FineWeb-Edu at a context length of 4K tokens. Note that in this setting, our SWA 4K hybrid is actually a full attention hybrid, since its window covers the entire 4K pretraining context. Further details are provided in the appendix.

After pretraining, we examine attention heads. Specifically, we look for recall heads : the attention heads responsible for in-context recallIn-context recall is the ability to retrieve information that appeared earlier in the context, such as a function defined thousands of tokens before the line of code that calls it.. In-context recall is one of the crucial abilities responsible for long-context modeling.

Where do the recall heads live?

Figure 2. Location of the top recall heads in each hybrid. Grey bands are the full-attention NoPE layers; white rows are SWA layers. Notice how the red squares move from the NoPE layers to the SWA layers as we increase window size. We identify these recall heads by removing (or zeroing out) heads one at a time and measuring how much recall drops, using techniques inspired from Bick et al. (see How do we identify recall heads? in the Appendix).

We locate recall heads in each hybrid model using a slightly modified version of the method described in Bick et al. . The appendix provides further details (see How do we identify recall heads?).

A clear pattern emerges: as the sliding window size increases, the top recall heads increasingly reside in SWA layers (Figure 2).

As further evidence that these heads are responsible for recall, we plot the drop in recall when we remove them one at a time (Figure 3). Moreover, language modeling performance barely changes when we remove recall heads (see Figure A2 in the Appendix).

Figure 3. Change in recall performance when one drops attention heads one at a time, measured on held-out samples. Recall drops the most when we remove recall heads, and remains the same when one drops random heads. This is evidence that these heads are most probably responsible for the in-context recall mechanism in the model .

The emergence of recall heads in SWA layers not only has some repercussions downstream, but importantly offers an explanation to the counterintuitive phenomenon we observed in Figure 1. We discuss this in the next section.

Repercussions of recall heads in SWA layers

  1. A recall head which is SWA can only attend to tokens within its window. This means information outside their windows becomes harder to recall (Figure 4). This helps explain the poorAt the 4K pretraining context length, our SWA 4K hybrid is effectively full attention in every layer. Thus, it can observe the entire context at 4K evaluations, but it still does poorly. This could be because RoPE struggles to generalize from short pretraining documents. See Why RoPE fails? in the Appendix for details. long-context performance of long windows in Figure 1.
Figure 4. Recall accuracy of the 4K pretrained models as the needle moves further from the query. The dashed line marks the SWA window size and the grey region marks distances beyond it. Notice how SWA 1K and 2K hybrids, whose recall heads are in SWA layers, drop sharply once the needle goes out of the window.
  1. Moreover, the same heads that learn to perform recall during pretraining tend to retain that role after post-training . That is, if recall heads emerge in SWA layers during pretraining, they tend to continue serving as recall heads after post-training, especially during the long-context extension phase that typically uses a lower learning rate and only a fraction of the steps and data used in pretraining. We see this in our hybrids too: the top recall heads after long-context extension are still the same heads that were recall heads before (Figure 5).
Figure 5. Recall accuracy in the 16K extended models after removing the top recall heads, one at a time. To determine recall heads in the 16K extended models, we additionally include S-NIAH accuracy at 8K and 16K in the average.

Figure 6 shows that the same phenomenon persists after long-context extension: shorter windows still lead to better long-context recall, consistent with the limited reach of recall heads in SWA layers.

Figure 6. Results after long-context extension from 4K to 16K Perplexity is measured at 16K context length on long books from the pg19 dataset..

Recall also still drops sharply beyond the SWA window after long-context extension (Figure 7).

Figure 7. Same as Figure 4, but for the 16K extended models. The same pattern persists after long-context extension: the SWA 128 hybrid degrades gracefully as the distance grows, while recall drops sharply beyond the SWA window whenever the recall heads are SWA.

This result further generally highlights how choices made during pretraining shape what a model can achieve during post-training.

Does this hold elsewhere?

We experiment with a different attention-only hybrid that mixes ALiBi and NoPE heads in a 1:1 ratio within every layer: half the heads in each layer use ALiBi and the other half use NoPE. This ALiBi-NoPE hybrid has been studied before under the name NAPE . We train two such models: one where the ALiBi heads use full attention, and one where they use a sliding window of size 128.

Figure 8. Location of the recall heads in the ALiBi-NoPE hybrids. With a 128 window, recall heads live in the NoPE heads (grey region). With full attention, they move to the ALiBi heads.

We observe the same phenomenon here: as we go from a 128 window to full attention, the recall heads move from the NoPE heads to the ALiBi heads (Figure 8). As before, removing these heads one at a time causes a large drop in recall, while removing random ALiBi or NoPE heads does not (Figure 9).

Figure 9. Change in recall performance in the ALiBi-NoPE hybrids when one drops attention heads one at a time. The dashed line marks the accuracy with no heads removed. Recall drops sharply when a recall head is removed (orange for NoPE, purple for ALiBi), and barely changes for random heads.

At the 4K pretraining length, the full attention ALiBi recall heads do not decay much and the model performs slightly better than the sliding window variant (Figure 10).

Figure 10. Before long-context extension: ALiBi-NoPE hybrids evaluated at the 4K pretraining length, just after pretraining. The full attention variant performs slightly better at this length.

But once the models are long-context finetuned, these same ALiBi recall heads can hurt since ALiBi fundamentally forgets old tokens. Indeed, the tables completely flip: the full attention variant, slightly ahead at 4K, now sees a sharp drop in long-context performance at 16K and falls far behind the sliding window variant (Figure 11).

Figure 11. After long-context extension: ALiBi-NoPE hybrids after long-context extension from 4K to 16K. The full attention variant collapses at 8K and 16K.

This again shows how pretraining choices can drastically change performance after post-training. Moreover, it is hard to predict this downstream performance from relatively “short-context-ish” metrics .

Discussion

Why do sliding windows learn recall first?

It is unclear and requires further research. Our hunch is that it could be due to the positional bias sliding windows have due to RoPE. It may be that these heads pick up recall faster than the full-attention NoPE heads, or that loss goes down faster when the model uses these heads for recall. Once the model enters this local minimum, it may be hard for it to recover.

This goes to show that just slapping together two components that are good at separate things need not make them take up those same rolesThe two components are the SWA layers and the full attention layers. SWA (with RoPE) should be good at language modeling, due to some recency bias from RoPE. Full attention (with NoPE) is bad at language modeling due to no recency bias required for language modeling, but great at long-context recall . when combined in a single model. Learning dynamics and optimization dictate what each component picks up.

What can be done then?

  1. One obvious thing to do is to pretrain on longer sequences, say 8K. This will force the full attention NoPE heads to pick up recall since the sliding windows probably cannot reduce loss on these long sequences. One must ensure that the underlying documents that are sequence packed to 8K are themselves long. For example, FineWeb-Edu (100B split) has only ~10% documents that are longer than 1K tokens (and only ~3% documents longer than 4K). As a result, naively increasing the pretraining sequence length to 8K should not help much in the case of FineWeb-Edu.

  2. Can we somehow change this learning dynamic of SWA heads picking up recall? One approach, explored in SWAX, is to vary the sliding window size during training. Shorter windows encourage the model to use its long-range recurrent memory for recall . A similar approach could encourage full-attention heads to take up recall in SWA-Full hybrids.

    Another possibility is to design an architecture or a training schedule (see for e.g. ) that enforces this division of roles more directly. Whether there are other ways to steer these learning dynamics remains a question for future work.

Conclusion

Decisions regarding window size are based on heuristics or extensive ablations that may become infeasible at scale . A better understanding of why short windows help long context may help us design better models and make choices like short windows less mysterious, and additionally reduce the need for expensive hyperparameter sweeps. This blog attempts to take a step in this direction.

In short, short sliding windows help by encouraging recall heads to emerge in full-attention layers. With longer windows, recall heads increasingly emerge in SWA layers, restricting their direct access to information beyond the window. Where the model learns to perform recall during pretraining therefore matters for its ability to use longer contexts later.

Limitations and Future Work

We work with relatively small models and data scale (~380M parameters trained on 10B tokens from FineWeb-Edu at a 4K context length).

In particular, large open-weight hybrids may be less susceptible to this issue where pretraining happens directly at 8K or 16K+ context lengths on curated data mixes rich in genuinely long documents (such as long books, code repositories, and academic PDFs), leaving plenty of long-range signal beyond the sliding window for full-attention layers to pick upFor example, OLMo 3 pretrains at an 8K context length on a pretraining mix which includes academic PDFs and code repositories and similarly, MAI-Base-1 pretrains at 16K on a mix spanning books, code, and academic papers . .

We’d be excited to see how these learning dynamics behave at larger scales, across different hybrid ratios, and under such long-document pretraining mixes.

Our analysis also focuses on attention-only hybrids.

Finally, there is a possibility that linear recurrent layers can be designed to deliberately handle shorter-range language modeling, encouraging full-attention NoPE layers to take up recall.

Concurrent and recent work points to a very similar picture of how layers specialize in hybrids.

SWAX observes that shorter sliding windows push SWA-recurrence hybrids to rely on their long-range memory rather than letting long-range layers “get lazy,” and Qiao et al. similarly observe “large-window laziness” where larger SWA windows delay retrieval-head formation in full-attention layers—while showing that small-window SWA with NoPE full attention improves long-context performance.

Our results support and sharpen this picture by showing that SWA heads actively take over recall when windows are long, capping it at the window size.

Shen et al. find the analogous “competing learning” dynamic in recurrence-attention hybrids, where recurrent layers learn retrieval first and suppress full attention unless frozen early in training.

Complementarily, Dawes et al. show that local layers write a recency bias into the residual stream that global NoPE layers read out as an implicit position signal. This signal is stronger with smaller windows, giving another orthogonal reason why short-window SWA pairs well with NoPE full attention.

Acknowledgements

We thank Aviv Bick, Sara Dragutinovic, Arshia Afzal, Rajesh Ranganath, Anirudh Buvanesh, Saksham Rastogi, Jinwoo Kim, Loïc Cabannes and Srini Iyer for super useful feedback on a draft of this blog.

Citation

Feel free to cite this blog with the following:

BibTeX
@misc{prakash2026shortwindows,
  title  = {Why do short windows help at long contexts? A mechanistic perspective},
  author = {Prakash, Jatin and McDermott, Luke and Sohoni, Nimit},
  year   = {2026},
  url    = {https://bicycleman15.github.io/blogs/why-short-helps-long/}
}

Appendix

Recall drops on all candidate heads

Figure 3 in the main text shows only the top recall heads. Here, we show the recall drop for every candidate head that passed the shortlisting stage (see “How do we identify recall heads?” below), including those that did not make it into the top recall heads.

Recall drop when zeroing each candidate head
Figure A1. Recall accuracy after removing each candidate head, one at a time. The dashed line marks the accuracy with no heads removed. Blue bars are SWA candidate heads and orange bars are full-attention NoPE candidate heads; lighter bars are random control heads.

The same pattern holds across all candidates: as the window size increases, the candidate heads that hurt recall when removed shift from NoPE layers (orange) to SWA layers (blue). In the SWA 128 hybrid, the heads causing the largest drops are NoPE heads. By SWA 1K and beyond, almost all of them are SWA heads. Dropping a random head barely changes recall in any model.

LM evals on the dropped heads

LM performance when dropping heads
Figure A2. Change in language modeling performance when one drops attention heads one at a time. This barely changes when one drops recall heads, meaning the identified recall heads are responsible for recalling stuff

Robustness across random seeds

To ensure that this phenomenon is not specific to a particular initialization or training order, we repeat the 4K-window hybrid experiment with three random seeds. Across all three runs, recall heads tend to predominantly emerge in SWA layers. In contrast, removing randomly selected SWA or NoPE heads leaves recall close to the no-ablation baseline.

Recall drops across three random seeds
Figure A3. Recall accuracy after removing candidate heads, one at a time, across three random seeds of the 4K hybrid. The dashed line marks accuracy with no heads removed. Dark blue and orange bars denote SWA and NoPE candidate heads. Lighter bars denote random heads.

Recall versus needle distance for all window sizes

Figures 4 and 7 in the main text show three of the five hybrids. Figure A4 shows all five, including SWA 512 and SWA 4K, which we discuss below.

Recall accuracy versus needle-query distance for all window sizes
Figure A4. Recall accuracy as the needle moves further from the query, for all five hybrids. The dashed line marks the SWA window size and the grey region marks distances beyond it. Top row: 4K pretrained models. Bottom row: 16K extended models.

Why does SWA 512 drop? The top-3 recall heads of the SWA 512 hybrid are all NoPE heads (Figure 2). However, an SWA head (L6H9) ranks fifth among its candidate heads (Figure A1), just outside the top 3. This head could be why recall drops once the needle leaves the window. Still, recall does not go to zero beyond the window, meaning the full-attention NoPE heads are still doing recall.

Why does SWA 4K drop before its window? In this case, recall drops even within the 4K window. The drop is likely because the pretraining data is short, as only ~10% of documents in FineWeb-Edu are longer than 1K tokens. The SWA 4K recall heads use RoPE, which struggles at query-needle offsets it rarely sees during training (see Why RoPE fails? below).

Why RoPE fails?

With RoPE , the attention score between a query at position $i$ and a key at position $j$ depends on the positions only through their offset $i - j$: $$a_{ij} = (R_i\, q_i)^\top (R_j\, k_j) = q_i^\top R_{j-i}\, k_j,$$ where $R_p$ is the RoPE rotation matrix for position $p$. RoPE works well for the offsets $i - j$ it sees during training, but struggles to generalize to offsets outside them .

We suspect the same thing happens in our SWA 4K hybrid, whose window covers the entire 4K pretraining context and so acts as full attention. FineWeb-Edu documents are short: in the 100B split, only ~10% of documents are longer than 1K tokens, and only ~3% are longer than 4K. So $(i, j)$ pairs from the same document with $|i - j|$ larger than 1K can only come from that ~10% of documents, and offsets close to 4K only from the ~3%. Needles far from the query therefore fall at offsets that the RoPE recall heads have barely been trained on, even though these offsets are within the window.

How do we identify recall heads?

We identify recall heads by testing how much recall deteriorates when a head is disabled. Following the ablation approach of Bick et al. , we disable one head at a time by zeroing its slice of the input to the attention output projection, leaving the rest of the model unchanged.

We adapt their procedure because models at our scale fail on the multi-key retrieval tasks used in their work. Running the full recall evaluation for all 384 heads across every task and context length would also be costly. We therefore proceed in two stages: (i) shortlist candidate heads, and then (ii) validate their contribution to recall.

(i) Selecting candidates. We select candidate attention heads using two simple teacher-forced statistics:

  1. Needle attention: the fraction of a head’s attention, measured from the positions that predict the answer tokens, that falls on the answer span in the context.

  2. Logit drop: the decrease in the gold-answer logit when that head alone is zeroed out.

We measure these statistics on 50 S-NIAH-2 samples at context lengths 512, 1K, and 4K tokens and 50 SWDE documents. A head becomes a candidate if it meets either of two criteria:

  • (a) Its needle attention, averaged over all answer tokens, is at least 0.5 on the 512-token S-NIAH-2 setting (because RULER reserves budget for the instructions and answer, the prompt itself is ~90 tokens long and the needle sits ~40 tokens before the query on average, so it falls inside the window even for the SWA 128 model).
  • (b) Its needle attention when predicting the first answer token is at least 0.3 on any one S-NIAH-2 setting (or at least 0.1 on SWDE), and its logit drop on the same samples is positive and ranks among the top 40 of the model’s 384 heads.

Note that because the 512-token setting keeps the needle within every model’s window, sliding-window heads have a fair shot at becoming candidates.

Overall, this “either or” shortlisting yields 12–16 candidates per model.

(ii) Validating candidates. We then remove (zero out) each candidate head independently, one at a time, and measure the drop in recall performance by decoding from the model. We use 50 held-out samples of each of S-NIAH-1 and S-NIAH-2 at each context length of 512, 1K, 2K, and 4K tokens, plus 50 held-out samples each of SWDE and FDA. We rank candidates by their average drop in recall and classify a candidate as a “recall head”While it is hard to say for sure what an individual head is doing , these ablation experiments at least causally attribute the head to performing recall . if dropping it reduces recall by more than 5 percentage points.

As controls, we also independently drop randomly selected sliding-window heads and randomly selected full-attention NoPE heads. Each changes recall minimally. These small effects provide supporting evidence that the identified recall heads are particularly important for recall.

For each head that we dropped, we also measure language-modeling perplexity and HellaSwag accuracy. The identified recall heads cause little degradation in either metric, despite substantially reducing recall. This provides further evidence that these heads contribute primarily to recall.

Training details

We use the L24D1024H16 configuration: 24 layers, a hidden dimension of 1024, and 16 attention heads per layer, totaling approximately 380M parameters.

We use untied input and output embeddings and the Llama-2 tokenizer, which has a 32K vocabulary. We do not use QK-norm in attention, as it has been shown to hurt long-context performance .

We pretrain on 10B tokens from FineWeb-Edu with a context length of 4K tokens and a batch size of 0.5M tokens. We use AdamW with $(\beta_1, \beta_2) = (0.9, 0.95)$, weight decay 0.1, gradient clipping at 1.0, and BF16 mixed precision, warming up the learning rate to a peak of 8e-4 over the first 1B tokens, then applying cosine decay to a final learning rate of 8e-5.

After pretraining, we perform a short long-context extension phase using 16K-token sequences from pg19. We train for 100M tokens with an increased batch size of 1M tokens, corresponding to 100 steps. We warm up the learning rate to 1e-5 over the first 20 steps and hold it constant for the remaining 80 steps.

Evaluation details

We evaluate long-context performance on RULER S-NIAH-1, S-NIAH-2, and S-NIAH-3 tasks, at 4K sequence length, using 100 samples per task. We also measure “natural language” recall performance on SWDE and FDA. Perplexity is measured on a held-out set from FineWeb-Edu at 4K sequence length.