Loading the interactive visualization…

04 · Reference notes

← All visual guides

Sliding-Window Attention Explained

Sliding-window attention limits each token to a local context window, reducing attention cost while stacked or occasional global layers preserve longer-range information.

01 · Definition

What is Sliding Window Attention?

It is a structured sparse-attention pattern: rather than compare every token with every earlier token, each layer gives a token a fixed local neighborhood to read.

02 · Mechanism

Why use a local window

Full attention grows quadratically with context length because every token can compare with every other token. A fixed window makes each token attend to only a bounded number of neighbors, so the attention work grows much more gently with sequence length.

03 · Mechanism

How information travels farther

A single local layer cannot connect distant tokens directly. But stacking local layers expands the receptive field: information can pass from one neighborhood to the next. Some architectures also add global or full-attention layers to reconnect the entire context at selected depths.

04 · Mechanism

What the window changes

The model gets reliable nearby context at every layer and gives up immediate access to arbitrary far-away tokens. Window size, layer depth, and the placement of global layers determine the balance between cost and long-range recall.

05 · Mechanism

When sliding windows help

They are useful when local syntax, recent instructions, or nearby evidence carry most of the signal. They reduce compute and cache pressure for long documents, while architectural choices preserve enough long-range communication for the task.

Source · Original paper