Home Knowledge Base 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?

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.

local-global attentionllm architecture

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.