Sliding window attention is a historical technique at Mistral. It is documented in exactly one Mistral paper, the Mistral 7B paper (September 2023), with a 4,096-token window. One other model used a variant: Ministral 8B, in October 2024, whose official announcement describes a special interleaved sliding-window attention pattern for faster, more memory-efficient inference.
No model in the current line-up is documented as using this technique. The configuration files shipped with the weights of Mistral Large 3, Mistral Small 4, Mistral Medium 3.5 and Ministral 3 declare no sliding window at all. Mistral 7B itself had already dropped it by version v0.3, in May 2024.
This page is still worth reading: it explains an important architectural idea, one that other labs have reused, and it sheds light on Mistral's technical history. But read it in the past tense. If you come across a claim like "Mistral Large 3 uses sliding window attention," it rests on no official source.
Sliding Window Attention: How Mistral 7B Read Giant Documents Without Blowing Up Memory
The problem is fundamental. A classic transformer, to generate each new token, looks at ALL previous tokens. If you give it a 100-page document, it consults all 100 pages for every word it generates. In memory: the cache grows without limit. In speed: it gets slower and slower as the text gets longer.
In 2023 Mistral proposed an elegant solution: instead of looking at the entire context at each layer, you only look at a local window of a few thousand tokens. That's Sliding Window Attention (SWA). Faster, more memory-efficient, and thanks to a clever mechanism, the model still "sees" far.
Everything described on this page (the 4,096-token window, the circular buffer, the chunked pre-fill) comes from the Mistral 7B paper. It is the only document in which Mistral spells out this mechanism.
Mistral 7BThe Problem of Endlessly Growing Context
In a standard transformer, the token at position 10,000 can "see" all tokens from 1 to 9,999. The required memory (the KV cache) grows proportionally to the sequence length.
The memory explosion. For a model the size of Mistral 7B with no optimization at all, the KV cache for a 32,000-token sequence runs into tens of gigabytes, and it quadruples if you quadruple the length. That's GPU memory no longer available for anything else. The order of magnitude is enough to see the problem: the cache quickly becomes bulkier than the model itself.
Quadratic complexity. The attention computation is O(n^2): doubling the sequence length quadruples the computation time. For long sequences, this quickly becomes the main bottleneck.
During inference (token-by-token generation), the KV cache stores the keys and values of already-generated tokens to avoid recomputing them for each new token. It's an essential speed optimization. Without the cache, each new token would require reprocessing the entire sequence from the beginning. The problem: this cache grows with each generated token.
The Principle: Only Looking at a Local Window
With SWA, each attention layer only consults the last W tokens instead of the entire sequence. W is the window size.
For Mistral 7B, W = 4096. This means that in each layer, a token at position t can only "see" tokens from positions max(1, t-W+1) to t. It's like reading text through a sliding window: you only see the last 4,096 tokens, but the window moves with you.
The Immediate Gains
Constant memory. The KV cache now has a fixed size of W tokens per layer, regardless of the total sequence length. For Mistral 7B, the paper reports an eightfold reduction in cache memory on a 32,000-token sequence, with no loss of quality. Whether you generate 100 tokens or 100,000, memory stays the same.
Reduced computation. Attention is only computed over W tokens instead of t tokens, bringing complexity from O(n^2) down to O(n x W). For long sequences, that's a considerable gain.
The Trick: Propagation Through Layers
The obvious question: if each layer only sees W = 4,096 tokens, how does the model capture dependencies over 32K tokens?
The answer is ingenious and relies on stacking layers. Imagine a game of telephone that actually works:
- Layer 1: the token at position t sees tokens [t-W+1, t]. Range: W tokens.
- Layer 2: the token at position t sees the Layer 1 representations of tokens [t-W+1, t]. But these representations already contain information from tokens [t-2W+2, t] (because Layer 1 had itself looked backward). Effective range: 2W tokens.
- Layer L: information can theoretically come from tokens [t-L x W+L, t].
For Mistral 7B: L = 32 layers, W = 4096, so the theoretical range is 32 x 4096 = 131,072 tokens. That's well above the official 32K token context window. Information "percolates" from layer to layer, like waves propagating.
The theoretical range (L x W) is a maximum, not a guarantee. In practice, information dilutes as it crosses layers, like a message in a game of telephone. Very long-distance dependencies are weaker than nearby ones. However, experiments show the model effectively captures dependencies over distances well beyond W. SWA doesn't cut off information, it gradually attenuates it.
The Rolling Buffer KV Cache: An Elegant Implementation
The concrete implementation of SWA in Mistral uses a circular buffer (rolling buffer) for the KV cache. It's a simple but effective engineering trick.
How It Works
The cache is a fixed-size array of W. When a new token is generated at position t, its key and value are stored at index t mod W in the buffer. When the buffer is full, new entries overwrite the oldest ones, exactly like an airplane's black box recorder.
With W = 4 (simplified for illustration):
| Token position | Buffer index (t mod 4) |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 0 (overwrites position 0) |
| 5 | 1 (overwrites position 1) |
Why It's Clever
Strictly constant memory. Regardless of sequence length (100 or 100,000 tokens), the cache occupies exactly W x d_model x 2 (keys + values) x number of layers. Not a byte more.
No dynamic allocation. The buffer is pre-allocated at startup. No malloc during inference, no memory fragmentation, no surprise latency from the garbage collector.
Predictable memory access. The buffer access patterns are regular and localized, which optimizes CPU/GPU cache usage. Hardware loves predictable memory accesses.
Chunk Pre-fill: Handling Long Prompts
When a user sends a long prompt (several thousand tokens), the model must first "read" it entirely before starting to generate. This is the pre-fill phase.
The mechanism: instead of processing the entire prompt in a single operation (which would require a massive attention matrix of size prompt x prompt), the prompt is split into chunks of size W. Each chunk is processed sequentially, and only the cache of the last W tokens is kept in memory.
This chunking reduces the peak memory needed for pre-fill and maintains consistency with SWA logic. It's transparent to the user: the result is identical.
SWA isn't the only approach for reducing attention complexity. Others exist: linear attention (Performer, Linear Transformer), local + global attention (Longformer, BigBird), and FlashAttention (which is a hardware optimization rather than an algorithmic one). SWA stands out for its implementation simplicity and practical effectiveness. No complex theoretical trade-off: you just look at a window, and the layers do the rest.
Which Mistral Models Actually Use SWA?
That's the question that matters, and the answer is shorter than what you usually read. The table below relies solely on Mistral's papers, its official announcements, and the configuration files published with the weights.
| Model | Sliding window | Max context |
|---|---|---|
| Mistral 7B v0.1 (Sept. 2023) | 4,096 | 32K |
| Mistral 7B v0.3 (May 2024) | none | 32K |
| Mixtral 8x7B | none | 32K |
| Mixtral 8x22B | none | 64K |
| Mistral NeMo | none | 128K |
| Ministral 8B (Oct. 2024) | 32,768, alternating with full-attention layers | 32K served |
| Ministral 3 (Dec. 2025) | none | 256K |
| Mistral Large 3 (Dec. 2025) | none | 256K |
| Mistral Small 4 (March 2026) | none | 256K |
| Mistral Medium 3.5 (April 2026) | none | 256K |
Two surprises in that table.
Mixtral never used SWA. This is a very widespread confusion, including in serious technical articles: because Mixtral 8x7B is built on the Mistral 7B building blocks, people assume it inherited the sliding window. Its published configuration says otherwise. Mixtral was trained with a 32,000-token context using full attention.
Mistral 7B itself abandoned SWA. As of version v0.3, the sliding window disappears from the configuration. So the technique had a short life, even on the model that made it famous.
How do Mistral Large 3, Mistral Small 4 or Mistral Medium 3.5 hold 256,000 tokens of context? Mistral has not published it. No architecture paper, no technical post.
What can be observed in the files shipped with the weights: these models extend their reach through position scaling (the technique known as YaRN, which "stretches" the positional encoding of a model trained on shorter sequences), and Mistral Large 3 additionally declares a low-rank projection on keys and values, that is, a form of cache compression. But those are configuration parameters, not a description signed off by Mistral. Stay cautious: you regularly read that "Mistral Large 3 combines sliding window attention with KV cache compression." The first half of that sentence is contradicted by the official files, and the second half is confirmed by no Mistral text.
SWA + GQA Synergy: Multiplicative Savings
The combination of SWA with Grouped-Query Attention (GQA) multiplies memory savings.
GQA reduces the number of K/V heads. Instead of having 32 K/V heads (one per attention head), you have 8 that are shared across attention heads. Cache size is divided by 4.
SWA limits cache length to W tokens instead of the total sequence length.
The combined effect is multiplicative. For Mistral 7B with 8 K/V heads (GQA 4:1) and W = 4096 (SWA), the KV cache is about 32 times smaller than with standard Multi-Head Attention over the full context. That's what made inference on consumer hardware possible.
Note that GQA, by contrast, was not abandoned: it is in fact the optimization that survived. Mistral Medium 3.5 declares 96 attention heads for only 8 key/value heads, a far more aggressive form of sharing than on Mistral 7B. The sliding window is gone; head sharing stayed.
SWA implies information loss for tokens beyond the window in a given layer. For tasks that require recalling a precise detail mentioned 10,000 tokens ago (a number, a name, a date), it is less reliable than full attention.
And that is exactly what today's models are asked to do: find a clause in a 200-page contract, an identifier in a log file. The fact that Mistral has removed the sliding window from all its models since mid-2024 is consistent with that trade-off, but this is a reading of the facts, not an explanation given by Mistral, which has never commented on the change.
Sliding Window Attention nicely illustrates Mistral's philosophy in 2023: an elegant technical innovation, simple in principle, that delivered major practical gains (constant memory, fast inference) without excessive implementation complexity. It let a 7-billion-parameter model run where nobody expected it to. That the idea was later set aside takes nothing away from it: it remains one of the most widely reused efficient-attention mechanisms in the industry, and a good example of how a hardware constraint turns into an architectural choice.