Frontier Foundry

Efficient Attention

The Workshop · Model Architectures

Attention variants that scale better with length (sparse, linear, latent).

Also called: linear attention, sparse attention, sliding window attention, multi-head latent attention, MLA, flashattention, flash attention, hybrid attention, deepseek sparse attention. In the glossary.

How it works, as a machineThe Long Chamber · queries

Follow one query from a question at the millionth token to an answer that found its block, in a council chamber whose gallery seats a million keys.

  1. Open the key blocks
  2. Score the blocks
  3. Pick the top blocks
  4. Look at picked blocks
  5. Fold into the state
Play Efficient Attention

Efficient Attention in plain words

Efficient attention is a family of changes that make a transformer cheaper on long inputs. Standard attention compares every token with every other one, so its cost grows with the square of the length. These variants look only at nearby, selected or summarised tokens, trading some precision for reach.

An analogy

A town meeting that has outgrown its hall. Letting every resident talk with every other takes forever once there are ten thousand. So each street sends a delegate, or people speak only to their neighbours, and the meeting ends before midnight with some detail lost.

How Efficient Attention connects

7 typed relations in the knowledge graph

Builds on

  • KV Cache: The drawers are the key-value cache: what each token leaves behind for the ones after it.
  • Long Context: Picking blocks is how a model reaches a million tokens without reading them all.
  • State Space Models: The fixed-size state tank is the same idea as a recurrent state: constant memory, finite recall.

Built on by

  • State Space Models: The attention layer cache is the hybrid fix: a few full-attention layers among efficient ones.
  • Transformers & Attention: The fixes for attention cost (grouped heads, sparse blocks, tiling) are their own concept.
  • Video Generation: Sparse attention is one way to cut the cost of attention over tens of thousands of video tokens.

Makes possible

  • Long Context: Cheaper attention lets the window grow without the cost growing with its square.

Often in the same sources

Transformers & Attention, Long Context, KV Cache, Quantization, Mixture of Experts, On-Device & Local Models

See Efficient Attention in the knowledge graph

What the sources say

3 parts · 12 sources · updated 2026-11-27

Efficient attention is a family of changes that keep a transformer from comparing every new token with every earlier one. Sparse variants score blocks of the cache and attend only to the best few; linear and sliding-window variants fold or drop the rest; hybrids keep a few exact layers. The sources show big speedups at a million tokens, and a recurring risk: far-back facts are lost.

What looking at everything costs

Standard attention keeps keys and values for every earlier token and compares each new query with all of them. At a million tokens this cost, and the cache that backs it, is what every variant tries to cut.

  1. The key-block drawers hold every earlier token's keys and values; the new query has to face them all.
1,000,000 tokens
Context window of one open model built with block-sparse attention, as its builder reported it Olive Song
890 bytes per token
Global key-value cache per token of one 1M-context model after cross-layer reuse and 4-bit caching, about a quarter of its predecessor Hugging Face
~10% of V3.2
Size of one 1M-token key-value cache in a hybrid-attention model, relative to its predecessor, as summarised in a newsletter recap AINews
  • Under full attention every new token costs more than the one before it, and its keys and values must stay in memory for good. Hugging Face
  • Agent workflows, repository-scale code work and persistent memory need attention over hundreds of thousands to millions of tokens, which the quadratic cost of softmax attention makes untenable at deployment scale. Hugging Face
  • A one-million-token window is meant to let a model take in whole code bases. Olive Song

Scoring and picking blocks

Sparse attention does not read the whole cache. A light pass scores blocks of keys against the query, a selector keeps the top few, and exact attention runs only on those.

  1. The block index desk scores each key block against the query with a light attention pass.
  2. The block selector rack keeps a few blocks for each key-value group, a different set for each group.
  3. The block-sparse attention bench runs exact attention over only the blocks that were picked.
28.4x less
Per-token attention compute at 1M context for a block-sparse model on par with grouped-query attention, in a 109B-parameter model; reported by the method authors Hugging Face
14.2x prefill, 7.6x decoding
Wall-clock speedups of the same method with its co-designed kernel on H800 GPUs; reported by the authors Hugging Face
9x prefill, 15x decode
Speedups versus full attention as the speaker gave them in the talk; the paper above gives different figures, so the comparator is unclear Olive Song
72.4x
Faster attention-layer prefill than full attention on H200 at 10M tokens for an indexer added to a pretrained model; reported in a newsletter recap of the authors' post AINews
  • The index branch runs a lightweight attention with four query heads and one key head, trained with a KL loss to match the main branch's attention scores; the main branch attends only to what it picks. Olive Song
  • A light index branch scores key-value blocks and picks a top-k set for each grouped-query group on its own; the main branch then runs exact block-sparse attention over those blocks only. Hugging Face
  • If all index heads were merged into one selection, every key-value head would attend to the same tokens and the diversity of grouped-query attention would be lost, so the selection is kept separate per head. Olive Song

Folding the rest, anchoring some layers

Linear attention folds the past into a fixed-size state, so each step costs the same, but far-back details can be lost. Hybrids keep a few full-attention layers as anchors for exact retrieval, at a cost in speed.

  1. The linear state tank folds every earlier token into a fixed-size state, so each step costs the same.
  2. The full-attention anchor rack keeps exact attention in a few layers, so a far-back needle can still be fetched.
2 to 10 times
How much higher sliding-window attention with sinks scored than post-trained linear attention on needle-in-a-haystack and BABILong long-context tasks; reported by the paper authors Hugging Face
67.2% -> 9.4%
Needle-in-a-haystack recall at 256K tokens for one 9B hybrid linear-attention model before and after chain-of-thought fine-tuning; reported by the paper authors Hugging Face
3:1
Linear-to-full layer mix of one hybrid open model as a newsletter recap described it: 34 linear layers and 11 latent or sparse attention layers AINews
1:7 Full:SWA
Ratio of full-attention to sliding-window layers in one model, as a newsletter recap quoted its builder AINews
  • Linear attention reaches sub-quadratic cost by keeping memory in fixed-size states; merging old states with a fixed policy cannot follow which tokens matter and can irreversibly obscure critical ones, so error builds up over long sequences. Hugging Face
  • Recurrent linear-attention designs differ in how they decay memory and control what is erased and written; this is where they differ in expressivity. Hugging Face
  • A hybrid keeps a subset of full-attention layers and swaps the rest for linear attention, and how well a converted model works depends on which layers stay full. Hugging Face

When it breaksThe needle folded away. Teams retrofit trained models to linear attention to escape the quadratic cost. On needle-in-a-haystack and BABILong tests, a simple sliding window with sinks scored 2 to 10 times higher, with no retraining at all; multi-state linear methods that merge old states can irreversibly blur the tokens that mattered. Hugging Face

Open questionIs a plain sliding window the better cheap choice, or are linear-attention layers where models should go?

  • Sliding-window attention with sinks needs no retraining, is fast and low in memory, and beats post-trained linear attention on long-context recall, so switch to it. Hugging Face
  • Open frontier models are converging on linear attention built in from the start, usually as one layer type in a hybrid. AINews

Sources

12 in all

More in Model Architectures

The Workshop: the whole area
  • Transformers & AttentionThe attention-based architecture behind nearly all modern LLMs.
  • Mixture of ExpertsModels where a router sends each token to a few specialist sub-networks.
  • State Space ModelsRecurrent-style architectures (Mamba, RWKV) with constant memory per token.
  • Diffusion Language ModelsText models that refine a whole draft in parallel steps instead of writing left to right.
  • Small Language ModelsCompact models that are cheap to run and good enough for many tasks.
  • Looped TransformersTransformers that run a block of weight-shared layers several times per token, adding depth (more reasoning per token) without adding parameters; shipped in Inkling 2 Mini and GLM-5.4 in Nov 2026.
  • Decision Models (System One)Small 'System One' models that only decide, classify, route or score with typed outputs instead of writing text; cheap, fast building blocks inside agent systems (Jev, OpenAI Decisions API).