Local-Global Attention

Local-Global Attention is a hybrid sparse attention pattern that combines efficient sliding window (local) attention with a small number of global attention tokens that attend to and from every position in the sequence — achieving O(n × (w + g)) complexity instead of O(n²), where w is the local window size and g is the number of global tokens, enabling long-sequence processing while maintaining the ability to capture long-range dependencies through the global tokens that serve as information bottlenecks connecting distant parts of the sequence.

What Is Local-Global Attention?

  • Definition: An attention pattern where most tokens use local sliding window attention (attending only to nearby tokens within window w), but a designated set of "global" tokens attend to ALL positions and are attended to BY all positions — creating information highways that connect the entire sequence.
  • The Problem: Pure local attention (sliding window) is efficient but blind to long-range dependencies. A token at position 50,000 cannot directly attend to a critical fact at position 100. Information must cascade through hundreds of layers to travel that distance.
  • The Solution: Insert global attention tokens that see the entire sequence. These tokens aggregate information from the full context, and other tokens can access this global summary, restoring long-range connectivity without full O(n²) attention.

Types of Global Tokens

TypeHow SelectedExampleAdvantage
Fixed PositionPre-determined positions (CLS, first token, every k-th token)Longformer uses CLS token as globalSimple, no learning required
Task-SpecificTokens relevant to the task get global attentionQuestion tokens in QA attend globally to find answerTask-optimized information flow
LearnedModel learns which tokens should be globalTrainable global token selectionMost flexible
HierarchicalAggregate local regions into summary tokens at regular intervalsEvery 512th token is globalBalanced coverage

Complexity Analysis

PatternPer-Token ComputeTotal for n=100K
Full AttentionAttend to all n tokens10B operations
Local Only (w=512)Attend to w tokens51M operations
Local-Global (w=512, g=128)Attend to w + g tokens64M operations
Benefit156× less than full attention

Local-Global in Practice

ComponentTokensAttention PatternPurpose
Local tokens~99% of tokensAttend within window w onlyEfficient local context capture
Global tokens~1% of tokensAttend to/from ALL positionsLong-range information conduit
Local→GlobalLocal tokens attend to global tokensProvides access to global context"Read" global summaries
Global→LocalGlobal tokens attend to all local tokensCaptures full sequence information"Write" global summaries

Models Using Local-Global Attention

ModelLocal WindowGlobal TokensTotal ContextKey Design
Longformer256-512CLS + task-specific16,384+ dilated windows in upper layers
BigBird256-512Fixed set (64-128)4,096-8,192+ random attention connections
LED512-1024Encoder CLS16,384Encoder-decoder variant of Longformer
ETCConfigurableHierarchical global tokens8,192+Extended Transformer Construction

Local-Global Attention is the most practical efficient attention pattern for long documents — combining the O(n × w) efficiency of sliding window attention with strategically placed global tokens that maintain full-sequence information flow, enabling models like Longformer and BigBird to process documents of 4K-16K+ tokens on standard GPUs while preserving the ability to capture long-range dependencies that pure local attention patterns would miss.

Take local-global attention further

Ask the copilot about this term, or have our engineers assess it against your process.