Sliding window attention limits each token to attending to a recent window of tokens, which keeps the compute and the cache bounded no matter how long the text gets. The Mistral 7B paper uses sliding window attention to handle sequences of arbitrary length with reduced inference cost. Full attention lets every token see every earlier token, which preserves distant facts but costs more. The tradeoff is real: a windowed model can lose a fact that sits outside the window, so compare the two on long text before choosing.
What you need
- A long-document task with facts spread through the text
- Two models that differ mainly in attention type, or one model with a switchable window
- A scoring rule for the answers at each length
Step 1: Build the same task at several lengths
Take the same long document and build versions at increasing lengths, for example 4,000, 16,000 and 64,000 tokens, with questions whose answers sit at different positions, including near the start.
Step 2: Run both attention types on every length
Run the sliding-window model and the full-attention model on each length with the same prompts, and record which questions each one answers correctly.
Step 3: Find where the window starts to lose facts
Compare the scores length by length. If the sliding-window model matches full attention at short lengths but fails the early-position questions at long lengths, the window is the cause, and the fix is a larger window, a summary of the early text, or full attention.
Worked example: synthetic attention comparison at 3 lengths
The table below is a synthetic example. It shows the expected result of comparing attention types; no model was run.
| Length | Full attention score | Sliding window score |
|---|---|---|
| 4,000 tokens | 0.90 | 0.90 |
| 16,000 tokens | 0.88 | 0.85 |
| 64,000 tokens | 0.85 | 0.60 |
Expected result (UNTESTED). both match at short lengths, but the sliding window model falls behind at 64,000 tokens. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Sliding window attention keeps inference cost bounded, which is its purpose; the quality cost appears only on long inputs.
- The Mistral paper reports sliding window attention alongside grouped-query attention, so the two effects are not separable in its results.
- A cache for sliding window layers never grows larger than the window, so the memory saving is real.
- Long-context models can also suffer the lost-in-the-middle problem, so position matters as well as length.
