Hierarchical Sparse Attention Done Right: Toward Infinite Context Modeling
arXiv · HuggingFace · ▲68
Abstract (verbatim)
Scaling modern large language models (LLMs) to long contexts is limited by the quadratic computation cost, and poor length extrapolation of dense attention. Chunk-wise sparse attention offers a promising alternative, but all existing methods fall short of full attention because of their inaccurate chunk selection. We propose Hierarchical Landmark Sparse (HiLS) Attention, a chunk-wise sparse attention mechanism that learns chunk selection end-to-end under the language-modeling (LM) loss. HiLS factorizes attention hierarchically: each query performs attention independently with each retrieved chunk to extract chunk-specific information, and the resulting outputs are fused according to chunk retrieval scores. By incorporating retrieval scores into the forward attention computation, HiLS optimizes them directly with the LM loss, enabling end-to-end retrieval learning and native sparse training. Experimental results show that HiLS-Attention achieves performance comparable to, and in some cases better than, full attention at in-domain context lengths. Meanwhile, HiLS-Attention extrapolates more than 64times the training context length with 90% retrieval accuracy, far beyond full attention. Moreover, existing full-attention models can be converted to HiLS-Attention with lightweight continued pretraining, preserving in-domain performance while acquiring ultra-long-context extrapolation. Together with its sparse KV access and computation, HiLS-Attention breaks the usual efficiency-performance trade-off, enabling long-context LLMs that are both more efficient and more effective on general long-context tasks than their full-attention counterparts.
Background
Background Analysis
1. Technical Context
Modern large language models (LLMs) need to handle increasingly long text contexts, such as long-document understanding, multi-turn dialogue, or complex reasoning. However, traditional "full attention" mechanisms suffer from quadratic computational costs, making long-text processing inefficient and struggling with accurate length extrapolation (predicting beyond training lengths). "Chunk-wise sparse attention" has been proposed to reduce costs by selectively attending to relevant text chunks, but existing methods still cannot match full attention in performance.
2. Previous Limitations
The core issue with existing methods is inaccurate chunk selection. For example, simple non-parametric approaches like mean pooling fail to adequately represent chunk importance, while parametric methods, though more flexible, do not optimize their selected chunks directly with the language modeling (LM) loss. This leads to poor discrimination between relevant and irrelevant content. Additionally, these methods often require extra computational steps (e.g., hard thresholding), making them less efficient than full attention.
3. Proposed Solution
This paper introduces "Hierarchical Landmark Sparse (HiLS) Attention," which addresses these problems in two steps: first, it adds a "landmark token" to each chunk to generate more expressive chunk summaries; second, it directly links the chunk selection process to the LM’s training objective (e.g., predicting the next token), allowing the model to learn which chunks are important automatically. This approach avoids the high computational costs of full attention while improving selection accuracy through end-to-end optimization.
4. Key Difference
Unlike previous methods, HiLS-Attention’s innovation lies in treating chunk selection as learnable attention weights and using full attention’s mathematical properties (e.g., Taylor expansion approximations) to guide chunk summary design. Experiments show that this method not only performs well on standard lengths but also extends context lengths over 64 times beyond training data, far surpassing existing approaches.




