arXiv(opens in a new tab)cs.LGSep 2026Cited by 3 papers on PaperVantage

Manuscript Offprint

arXiv:2609.31093

Block Sparse Attention with Log-Linear Complexity

Bohao Tang, Zhen Qin, Yuqi Pan, Zheng Li, Pengfei Liu

Abstract

Scaling language models to long contexts is limited by the quadratic cost of self-attention. Block sparse attention offers an efficient alternative, but selecting the retained blocks remains a bottleneck. Conventional block selection requires scoring all query–block pairs and therefore remains quadratic in sequence length. To address this issue, we propose PISA, a block-sparse attention mechanism that employs a pyramid Top-K selection strategy. The main idea is to gradually narrow down the candidates across different levels, making it more efficient to find the most relevant keys. Specifically, we construct a coarse-to-fine hierarchy of keys and perform selection from the coarsest level. At each level, LogSumExp scoring is applied to a bounded candidate set to select candidates for the next finer level, continuing until the finest level is reached. Through pooling, we construct O(log⁡N)O(\log N) levels of keys, yielding an overall complexity of O(Nlog⁡N)O(N \log N), where N denotes the sequence length. We develop hardware-aware Triton kernels for both training and inference, fusing hierarchical routing and LogSumExp scoring without materializing the query–key score matrix. We further evaluate our method on language modeling tasks. Compared with the baseline, our method achieves comparable performance on benchmarks such as commonsense reasoning while delivering better results on retrieval tasks.

Date: September 28, 2026

Correspondence: tangbohao@sjtu.edu.cn, qinzhen.0109@bytedance.com, pengfei@sjtu.edu.cn

1 Introduction

Scaling language models to longer contexts has become increasingly important, but the computational complexity of full self-attention grows quadratically with sequence length, making it prohibitively expensive for long sequences [32]. Sparse attention reduces this cost by restricting each query to a subset of keys [5, 8, 37]. Block-sparse attention groups keys and values into contiguous blocks of size C, allowing the sparse computation to use efficient tiled kernels [12, 20, 36]. Block-sparse attention generally consists of two stages: Top-K block selection and attention computation over the selected blocks. Once the Top-K blocks are selected, attention is computed using the original keys and values within these blocks. Since each query attends to at most KC keys, the second stage scales linearly with sequence length.

However, conventional Top-K block selection computes a relevance score between each query and every key block, and then selects the K highest-scoring blocks. For a sequence of length N with a block size of C, there are approximately N/C candidate key blocks. Since each query must scan all candidate key blocks, the selection stage still incurs a total complexity of O(N2/C)O(N^2/C) over the entire sequence. Therefore, although attention computation over the selected blocks scales linearly with sequence length, the Top-K block-selection stage remains a major computational bottleneck in long-context modeling.

To address this bottleneck, we propose PISA (Pyramid Sparse Attention), a block-sparse attention method based on hierarchical Top-K block selection. PISA first constructs a multilevel representation of key blocks through pooling. The finest level consists of fixed-size key blocks, while each coarser level is formed by aggregating adjacent representations from the level below. As the hierarchy becomes coarser, each block covers a larger portion of the sequence and the number of candidate blocks decreases, resulting in a coarse-to-fine pyramid of key representations.

Selection starts at the coarsest level of the hierarchy. At each level, PISA computes LogSumExp (LSE) scores over a bounded set of candidate blocks and retains the Top-K candidates. Each selected block is then expanded into its finer-grained sub-blocks at the next level, while the unselected blocks are discarded. This coarse-to-fine process continues until the finest level is reached. In this way, each query only evaluates a small number of promising blocks at each level, avoiding an exhaustive comparison with all fine-grained blocks.

The pooled key hierarchy contains O(log⁡N)O(\log N) levels. With fixed Top-K budget, branching factor, and leaf-block size, each query evaluates a bounded number of candidate blocks at every level, resulting in a per-query routing complexity of O(log⁡N)O(\log N). Routing all queries in a sequence of length NN therefore yields an overall block-selection complexity of O(Nlog⁡N)O(N\log N).

To execute this process efficiently on modern hardware, we develop hardware-aware Triton kernels for both training and inference [31]. Our implementation fuses multiple levels of hierarchical routing and LSE scoring into a single kernel, allowing intermediate candidates to be directly expanded and filtered at the next level without repeatedly reading and writing intermediate results across routing levels. The kernel maintains only a bounded candidate set at the current level and does not materialize or store a dense query-key score matrix, thereby reducing memory traffic and intermediate-tensor overhead for long sequences.

We evaluate our method on language modeling tasks. Compared with the conventional block-sparse attention baseline BSA, our method achieves comparable performance on commonsense reasoning benchmarks while delivering better results on retrieval tasks. These results indicate that coarse-to-fine candidate search reduces selection complexity while preserving blocks relevant to downstream modeling. Top-K selection benchmarks with sequence lengths of up to 256K tokens further show that hierarchical routing is more efficient than conventional single-level selection for long sequences.

References (42)