Reference
← All guidesSliding-window Attention
Sliding-window attention limits each token to a fixed range of nearby tokens. This reduces the number of attention pairs computed in a local layer.
Overview
How it works
In a causal local layer, a token attends only to recent positions within its window. Information from farther away can arrive indirectly through earlier layers. Some models also use full-attention layers for direct access to the whole context.
Details
Window size and cost
For N tokens and window size W, local attention computes O(NW) pairs instead of O(N²). At decoding time, a local layer can retain a rolling cache limited to its window. Full-attention layers in a hybrid model still need their own longer caches.
Details
Depth and receptive field
An earlier token’s representation can already contain information from its neighbors. Stacking local layers therefore expands the set of positions that can influence an output. A larger possible receptive field does not guarantee that every distant fact is retained.
Details
Access to distant tokens
A token outside the window is unavailable for direct attention in that layer. A wider window or a full-attention layer can restore direct access. These choices affect both compute cost and the model’s ability to use older context.
Details
Local and global layers
A hybrid stack mixes local layers with full-attention layers. Local layers reduce cost. Full-attention layers allow direct connections across the sequence. Window size, layer depth and the global-layer schedule are model design choices.
Sources