
Before understanding the problem, you need to understand what attention does.
In a language model, when processing a sequence of words (tokens), the model needs to decide:
"Which other words in this sentence are relevant to understanding THIS word?"
Example:
"The cat sat on the mat because it was tired"
When processing "it", the model needs to attend to "cat" to understand what "it" refers to.
For every token, the model computes a relationship score with every other token:
Token 1 → checks relationship with Token 1, 2, 3, 4... N
Token 2 → checks relationship with Token 1, 2, 3, 4... N
Token 3 → checks relationship with Token 1, 2, 3, 4... N
...
Token N → checks relationship with Token 1, 2, 3, 4... N
The article states attention has quadratic computational complexity, written as O(N²)
| Sequence Length (N) | Computations (N²) |
|---|---|
| 10 tokens | 100 |
| 100 tokens | 10,000 |
| 1,000 tokens | 1,000,000 |
| 10,000 tokens | 100,000,000 |
Double the sequence length → QUADRUPLE the computation
Modern LLMs process thousands to millions of tokens. This means:
Dense Attention (current standard):
Every token attends to EVERY other token
T1 T2 T3 T4 T5
T1 [✓] [✓] [✓] [✓] [✓]
T2 [✓] [✓] [✓] [✓] [✓]
T3 [✓] [✓] [✓] [✓] [✓]
T4 [✓] [✓] [✓] [✓] [✓]
T5 [✓] [✓] [✓] [✓] [✓]
All 25 cells computed = N² = 5² = 25
Not all token relationships are equally important. Most attention scores are near zero anyway.
Sparse Attention: Only compute attention for the important token pairs, skip the rest.
Sparse Attention Example:
T1 T2 T3 T4 T5
T1 [✓] [✓] [ ] [ ] [ ]
T2 [ ] [✓] [✓] [ ] [ ]
T3 [ ] [ ] [✓] [✓] [ ]
T4 [ ] [ ] [ ] [✓] [✓]
T5 [✓] [ ] [ ] [ ] [✓]
Only 10 cells computed instead of 25 → 60% reduction
1. Static Sparse Patterns (predetermined, fixed)
2. Dynamic Sparse Patterns (computed at runtime)
Static: Pattern is fixed regardless of input
[✓][ ][✓][ ][✓] ← always the same
Dynamic: Pattern changes based on input content
Input A: [✓][✓][ ][ ][ ]
Input B: [ ][ ][ ][✓][✓]
Even though the concept is simple, implementing it efficiently is very difficult:
Challenge 1: Combining Patterns Real models often need multiple patterns simultaneously:
Pattern A (sliding window) + Pattern B (global tokens) + Pattern C (dynamic) = ???
Combining these manually requires complex engineering.
Challenge 2: KV Cache Management
During token generation, models store Key (K) and Value (V) matrices to avoid recomputing them:
Generating token by token:
Step 1: Generate "The" → Store K,V for "The"
Step 2: Generate "cat" → Store K,V for "The", "cat"
Step 3: Generate "sat" → Store K,V for "The", "cat", "sat"
...
With sparse attention, you don't need to cache everything — only the tokens you'll actually attend to. But figuring out the minimum cache size needed is complex.
Challenge 3: Hardware Optimization
SAS = Sparse Attention Synthesizer
It is a system that automatically generates efficient sparse attention code, so developers don't have to write it manually.
Component 1: Primitives
Think of primitives as LEGO blocks for attention patterns
Primitive A: "Attend to sliding window of size 3"
Primitive B: "Attend to first token always"
Primitive C: "Attend to top-K dynamic tokens"
Component 2: Logic Operators & Declarative Functions
Users can combine primitives using simple logic:
Final Pattern = Primitive A OR Primitive B OR Primitive C
(Like combining LEGO blocks to build something complex)
This is declarative — you describe what you want, not how to implement it.
Component 3: Geometric-Based Pattern Analyzer
SAS automatically:
User defines pattern → SAS analyzes geometry → SAS calculates minimum cache →
SAS generates optimized code
Component 4: Multi-Backend Support
Same SAS definition → Nvidia GPU optimized code
→ AWS Trainium optimized code
1. Context Encoding (Prefill)
2. Token Generation (Decode)
| Operation | Speedup |
|---|---|
| Context Encoding | 1.10–1.22× faster |
| Token Generation | 2.68–2.80× faster |
Token generation sees much larger gains because KV cache optimization has the biggest impact here (you're repeatedly accessing cached values)
| Operation | Speedup |
|---|---|
| Context Encoding | 1.41–6.49× faster |
| Token Generation | 1.39–10.87× faster |
Up to 10.87× faster token generation — meaning tasks that took ~11 minutes could take ~1 minute
1.0× = no improvement (same speed)
2.0× = twice as fast
10.87× = nearly 11 times faster
PROBLEM:
Dense Attention → O(N²) complexity → Too slow for long sequences
PARTIAL SOLUTION:
Sparse Attention → Only compute important pairs → Faster, less memory
NEW PROBLEM:
Sparse Attention is hard to implement correctly and efficiently
SAS SOLUTION:
1. Provide primitives (building blocks)
2. Let users compose patterns declaratively
3. Automatically analyze patterns geometrically
4. Auto-generate optimized KV cache management
5. Compile to multiple hardware backends
6. Result: 1.1× to 10.87× speedup
Test yourself with these questions:
| Term | Simple Definition |
|---|---|
| Attention | Mechanism for tokens to relate to each other |
| Quadratic Complexity O(N²) | Computation grows as square of sequence length |
| Sparse Attention | Only compute attention for important token pairs |
| Static Pattern | Fixed attention pattern, same for all inputs |
| Dynamic Pattern | Input-dependent attention pattern |
| KV Cache | Stored Key-Value matrices to speed up generation |
| Primitives | Basic building blocks for attention patterns |
| Declarative | Describe what you want, not how to do it |
| Synthesizer | System that automatically generates code |
| Context Encoding | Processing the full input prompt |
| Token Generation | Producing output tokens one at a time |