AI GLOSSARY · AI CONCEPTS

Sparse attention

Markdown version

Definition

Sparse attention uses fewer direct token-pair connections than dense attention, aiming to reduce computation and memory. Patterns can be fixed or data-dependent; some tokens may still have global attention. Costs and quality depend on the design and workload.

Also called: sparse attention transformer, sparse attention mechanism, sparse transformer, sparse self-attention, sparse attention LLM.

In plain language

Reading a long report, you do not compare every sentence with every other sentence. You look at nearby sentences and a few key ones, such as the title and summary. Sparse attention gives a language model the same shortcut. Unmasked dense attention compares all token pairs within a layer; causal masks exclude future positions. Sparse patterns omit direct connections, but their selection may be fixed or data-dependent, and information can still travel indirectly across layers. A vendor may not disclose a hosted model’s pattern. Compute and memory effects depend on the chosen design and workload.

Technical definition

The Sparse Transformers paper (arXiv 1904.10509) notes that standard Transformers need time and memory that grow quadratically with sequence length, and introduces sparse factorizations of the attention matrix that reduce this to O(n sqrt(n)). The Longformer paper (arXiv 2004.05150) combines local windowed attention with task-motivated global attention, so the cost scales linearly with sequence length, and describes it as a drop-in replacement for standard self-attention. The Hugging Face documentation for Longformer describes global_attention_mask, where 0 means local attention and 1 means global attention, for tokens that attend to all other tokens and that all other tokens attend to. This differs from attention_mask, where 0 masks padding and 1 marks unmasked tokens. Reformer uses locality-sensitive hashing, an example of content-dependent selection rather than a universally fixed pattern.

Worked examples in this catalogue

Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.

  1. Guide · Illustrative, not executed

    What Is an LLM? The Facts Agent Users Need

    What you see
    The current guide contrasts the original Transformer decoder's autoregressive generation with BERT's masked pretraining, and distinguishes runtime context from learned parameters.
    Why it exercises the concept
    Sparse attention is one design aimed at making long inputs cheaper inside the model. The guide covers the limit you meet from outside the model. It does not say which attention pattern any model uses.
  2. Skill by Skill Almanac · Illustrative, not executed

    context-window-packer 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill chooses which files fit one prompt's token budget and records what was kept, shrunk or dropped, and why.
    Why it exercises the concept
    A contrast case. Sparse attention changes which token pairs a model compares inside one input. The packer decides what goes into the input at all, which is a choice you control whatever the architecture.
  3. Skill by Skill Almanac · Illustrative, not executed

    llm-cost-estimator 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill turns a usage profile and your own price table into a monthly LLM cost range.
    Why it exercises the concept
    Input length affects cost, and attention design is one reason long inputs are costly to serve. The skill uses the prices you supply and does not model attention. Prices are a service policy, not a property of sparse attention.

How it shows up when you use agents

Sparse attention is an internal model choice, not something a coding-product name establishes. Longer retained inputs can require more work, but latency and charges depend on the implementation, cache, workload and provider or plan; architecture alone does not set the bill. The context window is finite. Research on sparse patterns exists because the standard attention mechanism in a Transformer has time and memory costs that grow quadratically with sequence length, as the Sparse Transformers paper states.

Where it can appear: in open model code you run yourself, such as the Longformer classes in Hugging Face Transformers, where global_attention_mask marks local versus global attention, separately from the padding attention_mask. For a hosted model, the vendor may not say which pattern it uses, so check its documentation instead of assuming.

What goes wrong when it is misunderstood: people read "sparse" as "the model ignores most of your text" and trim prompts blindly, or they assume a larger window means the model uses every token equally. A window size and an attention pattern are separate facts.

Next action: treat context as a budget. Decide what a task needs, put that in first, and use a packing step like the one in the catalogue. Test on your own long inputs instead of relying on a design name.

Common confusions

  • Sparse attention versus a longer context window. A window is how much input a model accepts. Sparse attention is one way to make longer inputs cheaper to compute. A model can have one without the other.
  • Sparse attention versus Flash Attention. Both concern attention cost, but they are different ideas. See the Flash Attention entry; this entry makes no claim about how they compare.
  • Local versus global attention. In Longformer, local attention is a sliding window and global attention is used for chosen tokens that attend to all others and are attended by all others.
  • Sparse attention versus mixture of experts. Sparse attention changes which tokens attend to which. Mixture of experts is a different design that activates parts of a network. Do not use the word "sparse" alone to tell them apart.
  • Myth. Sparse means worse. The Longformer abstract reports results on long-document tasks, and this entry makes no general quality claim in either direction.

Terms that mention Sparse attention

1 terms mention this one

More in AI concepts

Next steps

  1. What Is an LLM? The Facts Agent Users Need The long-form guide.
  2. context-window-packer A skill that exercises it.
  3. Context window Related term.
  4. Transformer Related term.
  5. All glossary terms A to Z and by family.

Sources

Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.

Review record

Last verified

Drafted by Claude (original draft); OpenAI Codex (bounded factual repairs); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .

Change log (4)
  • : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
  • : First version.
  • : Bounded source repairs: Scoped dense/causal and fixed/data-dependent per-layer connections; named global_attention_mask versus padding mask; updated guide and conditional workload/billing claims. Pending independent re-review.
  • : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.