Highlights

Contents

Part II
02

Choosing fewer connections

Most possible comparisons may be unnecessary for a task. Sparse patterns remove them deliberately. Explain the paths they retain, the information they can lose, and whether the kernel actually skips their work.

THE ARCHITECTURE INVESTIGATIONCost + future tokens01Sparse connections02Compressed history03Latent memory04Compare KV designs05Speculative decoding06Controlled experiment07Interpret + decide08

#Section 4Sparse attention

A code file refers to a variable declared far earlier. If the declaration lies outside a local-only decoder’s window, the final layer cannot inspect it directly. The connection pattern is part of what the model can learn.

Dense vs sparse attention and reducing attended positions

Sparse attention restricts each query to a subset of positions. A binary attention mask lists the allowed query-key pairs. Dense causal attention allows every nonfuture position; a sparse causal pattern allows fewer and still forbids the future.

CAUSAL CONNECTION PATTERNS: THE QUERY IS THE ROWdense36 allowed pairswindow 321 allowed pairswindow + globals27 allowed pairsall patterns prohibit attending to future positions
Figure 6.5Computed illustrative masks for eight tokens compare dense causal attention, a window including three positions, and that window plus fixed global positions. Each orange cell is an allowed connection, not a measured attention weight.

Complexity reduction and information trade-offs

If each of TT queries reads at most ww keys, arithmetic scales as O(Tw) instead of O(T²), but only if the kernel actually skips disallowed pairs. Computing dense scores and then zeroing entries is still dense work, and a dense Boolean mask still costs quadratic memory.

Absent edges cannot carry a direct comparison at that layer. Deeper layers or global paths may recover indirect communication, which is not the same as full attention. Child and colleagues' Sparse Transformer explored structured sparsity for long sequences. Sparse Transformer paper.

For eight tokens, dense causal attention has 36 pairs. A width-4 causal window has 1 + 2 + 3 + 4 + 4 + 4 + 4 + 4 = 26, a structural saving of 10 pairs, not evidence that any GPU kernel is faster.

#Section 5Local attention

In prose, a pronoun usually depends on a nearby noun. Restricting attention to a neighborhood keeps that structure while skipping distant comparisons.

Fixed local neighborhoods and nearby-token attention

Local attention restricts each position to a neighborhood: a symmetric radius in a bidirectional encoder, a past-only span in a causal decoder. Fixed blocks do not overlap; sliding neighborhoods move with each query.

A causal window holding the current token and three predecessors lets position 7 read positions 4 to 7. Position 1 sees only 0 and 1 because nothing comes earlier. These boundaries matter when counting cost or writing masks.

Reduced cost

For T≥wT\ge w, a causal window of width ww including the current position has

Nlocal=w(w+1)2+(T−w)w.N_{\mathrm{local}}=\frac{w(w+1)}{2}+(T-w)w.

For a fixed window, each query compares with only a bounded neighborhood. Near the sequence start it sees fewer positions; a window covering the sequence reduces to full causal attention.

Fixed blocks can strand two adjacent tokens on either side of a boundary. A sliding window avoids that but still drops distant edges. Pick the pattern from the paths the task needs and the kernels you have.

#Section 6Sliding-window attention

The sequence keeps growing, but each query reads only the most recent span. Layers that need only that span can keep a rolling cache instead of all past keys and values.

Window size and restricted context

Sliding-window attention uses a neighborhood defined relative to each query. Our window size ww includes the current position, so width 4 means three prior positions plus the current one. Some implementations count only past tokens, so translate their values before comparing.

Receptive-field growth across layers

A receptive field is the set of input positions that can influence a representation. With LL layers of causal width-ww attention, the maximum span is 1 + L(w-1), clipped at the sequence start. That is a set of possible paths, not lossless storage along them.

A LOCAL EDGE CAN CARRY INDIRECT INFORMATION ACROSS LAYERSlayer 00123456789layer 10123456789layer 20123456789layer 30123456789with w = 4, each layer can extend reach by at most 3
Figure 6.6Computed reach for a width-4 causal window expands by at most three positions per layer. The drawing shows reachability, not attention strength or successful retrieval.

Memory savings and long-range limitations

A rolling cache saves memory only if the runtime evicts old states and no full-attention layer still needs them.

Mistral 7B (2023) used sliding-window attention with a rolling cache. Mistral 7B paper.

#Section 7Global and strided attention

A distant header names the document's subject. Local edges alone need many layers to carry it to every paragraph; a few long-range links shorten the path.

Global tokens take part in connections beyond the local neighborhood. In a causal decoder they still obey the past-only rule: later queries can read a prefix token, but that token cannot summarize what comes after it in the same pass.

Longformer combined local attention with task-selected global positions in a bidirectional encoder. Copying its global behavior into causal generation unchanged would leak the future. Longformer paper.

Strided patterns and combining local/global information

Strided attention connects positions at periodic intervals. One rule reads keys in the same residue class modulo stride ss; another lets every query read indices that are multiples of ss. They connect different pairs, so document which one a mask implements.

Count the union of local and global positions, avoiding duplicates. Global positions must remain hidden from earlier queries in a causal model.

A fixed number gg of globals gives O(T(w+g)) pairs. A stride exposing about T/s distant keys per query gives O(Tw + T²/s), still quadratic at fixed stride. "Strided" does not mean linear.

#Section 8Hybrid attention

Most layers can use local windows while a few read the full prefix. Recent-token work stays bounded, and long-range access survives at chosen depths.

Local layers, full-attention layers, and periodic global attention

Hybrid attention mixes patterns within one model, for example three local layers then one full layer, repeated. Periodic global attention here means a full causal layer at a set depth, not a bidirectional global token.

ALTERNATE LOCAL WORK WITH EXPLICIT FULL-CONTEXT ACCESSL1localL2localL3localL4fullL5localL6localL7localL8full6 local layers + 2 full layersillustrative Finch-24 schedule; quality needs retraining and evaluation
Figure 6.7An illustrative eight-layer Finch schedule has full attention at layers 4 and 8, with six local layers. It is a proposed variant and carries no measured quality claim.

Efficiency vs context access

A hybrid retains full history in its full layers and rolling history in local layers. Its memory depends on the whole schedule, not the cheapest layer.

THREE SCHEDULES, SAME FINCH SHAPES: CACHE BYTES AND ALLOWED PAIRSKV payload, MiBcausal pairs per headall full3267,125,248hybrid 2 + 69.522,876,928all local28,127,488batch 2, length 4,096, window 256, 8 layers; computed payloads, not measured latencythe two full layers carry most of the cost
Figure 6.8Computed cache payload and causal pair counts for all-full, hybrid, and all-local schedules under the same Finch shapes. The two full layers account for 8 of the hybrid's 9.5 MiB.

These counts predict arithmetic and payload, not wall time or quality. A dense fallback for local masks erases the saving, and the full layers only help if training teaches the model to use them. Compare against an all-full baseline at the same budget and test dependencies at several distances.