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.
Recently released open-source models
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
Let’s unpack what’s happening.
We look inside attention-only hybrid models to understand why what they learn differs with long versus short sliding windows.
Following recent models
After pretraining, we examine attention heads.
Specifically, we look for recall heads
We locate recall heads in each hybrid model using a slightly modified version of the method described in Bick et al.
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).
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.
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.
pg19 dataset.Recall also still drops sharply beyond the SWA window after long-context extension (Figure 7).
This result further generally highlights how choices made during pretraining shape what a model can achieve during post-training.
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 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).
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).
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).
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
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 roles
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.
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
Another possibility is to design an architecture or a training schedule (see for e.g.
Decisions regarding window size are based on heuristics or extensive ablations that may become infeasible at scale
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.
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 up
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
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.
Complementarily, Dawes et al.
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.
Feel free to cite this blog with the following:
@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/} }
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.
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.
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.
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.
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).
With RoPE
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.
We identify recall heads by testing how much recall deteriorates when a head is disabled. Following the ablation approach of Bick et al.
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:
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.
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:
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”
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.
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.
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.