Summary (Overview)
- Zyphra Hierarchical Attention (ZHA) is a novel sparse attention method that uses a hierarchical, tree-structured indexer to achieve asymptotically subquadratic attention scaling, overcoming the quadratic bottleneck of standard attention while maintaining query-dependent sparsity.
- ZHA constructs a tree of recursively compressed key summaries over the KV cache; queries traverse this tree top-down, selecting a sparse subset of keys via adaptive top-p routing at each level.
- The method can be applied to existing pretrained models (up to 35B parameters) with only a 1-billion-token KL distillation phase, freezing the base model and learning only a small set of reference queries.
- ZHA maintains performance on long-context retrieval (RULER, LongBench v2), mathematical reasoning (AIME), and agentic coding (SWE-bench) tasks, while attending to only 1–6% of the KV cache.
- A detailed roofline performance model predicts ZHA becomes faster than dense attention at ~48K tokens and faster than MiniMax Sparse Attention (MSA) at ~0.48M tokens, with potential speedups of 373–417× over dense attention at tokens.
Introduction and Theoretical Foundation
The Quadratic Bottleneck of Attention
Standard attention computes an all-to-all mapping between sequence elements, where each query compares against every key in the sequence. This leads to quadratic computational cost in prefill and linear memory bandwidth costs during decode (re-reading the KV cache per token). These costs prohibit extremely long context windows despite their demonstrated benefits for reasoning and retrieval tasks.
Limitations of Existing Approaches
| Method Family | Approach | Limitation |
|---|---|---|
| State-space models / sliding-window | Fixed-size state | State saturates at long contexts, degrading performance |
| Hybrid methods | Interleave fixed-state mixers with full attention | Few full-attention layers still dominate at long contexts |
| Sequence compression (CSA, NSA, HNet) | Online compression of multiple tokens | Constant-factor speedups, brittle in practice |
| KV cache eviction | Offline eviction of low-value tokens | Impossible to know token utility ahead of time |
| Sparse attention (DSA, MSA) | Query-dependent top-K selection | Indexer itself scales quadratically (60–90% of time at ~1M tokens) |
| Chunk-sparse (PISA, HiP) | Multi-level chunking | Log-linear complexity but retrieval degradation at long contexts |
Key Insight: Natural Sparsity of Attention
The authors demonstrate that attention's effective state size grows sublinearly with sequence length. They operationalize this via the top-p set: the smallest subset of keys whose attention probabilities sum to at least . Attention can be decomposed as:
where is the top-p subset and contains the remaining KV pairs.
Empirical finding: The top-p set size grows as a sublinear power law in context length (exponent depending on ), suggesting hierarchical, scale-invariant structure in attention representations.
Why Hierarchical Search?
The authors show that while individual queries are sparse, the union of top-p sets across future queries covers the entire cache:
where is the top-p subset for query at position . As grows, , meaning the full KV cache must be retained. This motivates a query-dependent retrieval mechanism that identifies relevant keys without scanning all of them—hence the need for a hierarchical tree indexer.
Methodology
Tree Construction
ZHA recursively creates key summaries that compress contiguous chunks of keys. For a chunk with chunk size , the log unnormalized attention mass (Log-Sum-Exp, LSE) for query is:
The first-order Taylor approximation at reference query gives a tangent , where:
The chunk's LSE for a future query is approximated by over reference queries. Higher-level nodes (spanning original keys) are constructed recursively from their children's summaries.
Training
The only learnable parameters are the reference queries. Training uses a KL-divergence loss matching predicted chunk probabilities to true attention distributions at every tree level:
where is the target chunk probability and is the predicted probability from the router's approximate log attention mass. Training requires only 1 billion tokens with the backbone frozen.
Routing
At each level, ZHA selects the top-p nodes—the smallest prefix of nodes (ordered by score) whose cumulative estimated attention mass reaches fraction :
Selected nodes' children are passed to the next level, and the process repeats until leaf chunks. The final token indices are:
with standard attention computed over this sparse subset: .
Empirical Validation / Results
Reasoning and Retrieval Performance
ZHA was evaluated on Qwen3.6-35B-A3B (converted with both deep C4-L6 and wide C256-L1 geometries, R16 reference queries, ):
| Benchmark | Dense | ZHA Deep (C4-L6) | ZHA Wide (C256-L1) | MSA |
|---|---|---|---|---|
| AIME 2026 | ~baseline | ~baseline | ~baseline | ~baseline |
| MMLU-Pro | ~baseline | ~baseline | ~baseline | ~baseline |
| GPQA Diamond | ~baseline | ~baseline | ~baseline | ~baseline |
| RULER-13 | 96.0% | 93.3% | ~96% | Significantly lower |
| LongBench v2 | ~baseline | 12.7 pts higher than MSA | ~baseline | Lower |
Key findings:
- Both ZHA geometries perform within noise of dense on reasoning and coding tasks.
- The deep router attends to only 1–6% of the KV cache with just a 3% RULER drop.
- ZHA outperforms MSA on long-context retrieval despite MSA being trained on 40× more tokens.
Robustness to Geometry
- Depth at fixed compression (): Deeper geometries sustain better retrieval at higher sparsity levels, demonstrating depth itself is not the limiting factor.
- Reference count R: Increasing improves sparsity-performance tradeoff.
- Predictive model: A simple 4-parameter model predicts RULER accuracy from :
This model achieves RMSE of 1.44 percentage points in leave-one-length-out cross-validation.
Variable Sparsity Across Tasks
ZHA's top-p routing adapts sparsity to the task:
- RULER (narrow lookup): 0.44% of chunks retained
- SWE-bench (agentic coding): 5.0% of chunks retained
- Fiction books (diffuse): 7.4% of chunks retained
Latency Scaling
The roofline model predicts per-token decode latency:
with each kernel following a three-term roofline model (compute, memory bandwidth, worker waves):
Key predictions (R1, C8, ):
- Faster than dense attention: ~48K tokens (L1)
- Faster than MSA: ~0.48M tokens (L2)
- At tokens: 373–417× speedup over dense, 52–58× over MSA (L5)
Per-level selection counts follow power laws with exponents , which are modeled cumulatively from the top down:
Theoretical and Practical Implications
Theoretical Significance
-
Subquadratic scaling with query-dependent sparsity: ZHA satisfies both requirements for an effective attention replacement—query-dependent retrieval AND sublinear active state growth—while retaining the full KV cache.
-
Power-law structure of attention: The finding that top-p set size grows as a sublinear power law suggests natural language has scale-invariant, self-similar structure that hierarchical indexers can exploit.
-
Depth robustness: ZHA is the first hierarchical attention variant to demonstrate convincing scaling to depths > 1 while maintaining parity with dense attention on challenging tasks.
-
Positional encoding dependence: The sublinear power-law structure depends on positional encoding (partial RoPE works well; NoPE shows larger retrieval losses), suggesting architectural interactions worth further study.
Practical Implications
-
Cheap adaptation: ZHA can be applied to existing pretrained models with only 1B tokens of KL distillation and negligible parameter overhead (reference queries only), without finetuning the base model.
-
Extreme context scaling potential: The performance model suggests ZHA could extend effective context windows to hundreds of millions or billions of tokens, where it dramatically outperforms both dense attention and sparse attention baselines.
-
Adaptive sparsity: Top-p routing automatically adjusts retrieval budget based on task demands—narrow for targeted lookups, broad for diffuse aggregation—impossible with fixed top-K methods.
Conclusion
ZHA introduces a principled approach to subquadratic attention via hierarchical tree-structured indexing. Key takeaways:
- Sublinear state growth matches the natural compressibility of attention representations, validated by power-law top-p scaling.
- Cheap conversion of existing models (1B tokens, frozen backbone) with maintained performance on reasoning, coding, and retrieval.
- Robust to geometry, including deep trees up to 6 levels, with predictable accuracy-sparsity tradeoffs.
Future Directions
- Empirical validation at ultra-long contexts: The primary limitation is lack of validation beyond 256K contexts; the authors plan to scale to frontier open-source models at 1M+ tokens.
- Dynamic chunk boundaries: Learning chunk boundaries instead of fixed contiguous chunks.
- Recency bias in tree structure: Allocating more detail near the current token.
- Compressed value summaries: Allowing pruned subtrees to contribute coarse attention outputs.
- Dynamic top-p scaling with depth: The critical challenge is scaling per-level to track the decrease in predictive information: fixing causes (state asymptotes to constant), while rescaling to causes (returns to quadratic). The optimal scaling depends on the intrinsic statistical structure of ultra-long context data, which remains an open question.
Related papers
- Honesty Is a Race: Predicting When Verifiable-Reward RL Teaches a Model to Bluff
A GRPO reinforcement step teaches honesty only when holding rate times reward exceeds bluff payoff plus cross-class coupling, else it teaches models to bluff.
- Agent Self-Improvement with Frozen Weights: The Added Value and Limits of Failure Traces
Trace-based lessons improved decision accuracy by 4.0 points over matched search, but search alone captured 60% of the gain, with no improvement on conversations or held-out tasks.
- Not All Loops Cost the Same: Phase-Dependent Depth for Serving Looped Transformers
LoopDuet shows that asymmetric loop depths for prefilling versus decoding—with prefilling shallower—boost throughput by up to 19% and quality by 6.04 EM points without retraining.