Manuscript Offprint

arXiv:2610.42147

Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention

Ales Kubicek, Andrea Caciolai, Liangzu Peng, Sukrit Sumant, Benjamin Hoover, Fraser Greenlee, Ruairidh M. Battleday, Radim Urban, Torsten Hoefler, James C. R. Whittington

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Agentic workflows are increasingly shifting towards long-horizon tasks, such as open-ended scientific work, where models benefit from long context windows. However, at ultra-long context (above 1M tokens), full attention is prohibitively expensive. A promising approach is sparse attention, in which a dedicated indexer selects a subset of keys for the attention. Yet current methods of indexing either still have quadratic cost in context size or lose accuracy at ultra-long context scale. We address this with Latent Sparse Attention (LSA), an efficient attention method that maintains accuracy at ultra-long context. In LSA, keys are hierarchically clustered in a learned latent space, and queries score the hierarchy of clusters instead of scoring every key, making prefill, decode and training faster at long context. We propose two variants, Distilled-LSA (D-LSA), which can be applied to pre-trained models via distillation, and Native-LSA (N-LSA), which is trained natively on the next-token loss alone. On GLM-5.3-FLASH (QWEN-3.8-27B) at 10M tokens, D-LSA speeds up one attention layer by 22.7×22.7\times (72.4×72.4\times) in prefill and 4.6×4.6\times (42.5×42.5\times) in decode over its original sparse attention (full attention), while keeping similar accuracy across a variety of tasks. N-LSA matches the accuracy of full attention with a training speedup of 1.6×1.6\times per layer at 128k tokens. LSA offers practical and efficient attention for models to benefit from ultra-long context.

1 INTRODUCTION

Large language models have moved from answering single requests to agentic workflows in long-horizon tasks, such as software engineering and open-ended scientific research (Jimenez et al., 2024; Lu et al., 2026). These tasks keep growing in length (Kwa et al., 2025), and models with longer context windows tend to score higher on them (Zhu et al., 2026). In line with this trend, recent models extend their context windows to 1M tokens and beyond (Gemini Team, 2024; MiniMax, 2025; DeepSeek-AI, 2026a; Qwen Team, 2026a).

At this context size, attention dominates the cost, as its work grows with context (Vaswani et al., 2017; Dao et al., 2022). An established technique to reduce such costs is sparse attention (Hoefler et al., 2021), in which each query attends to only a subset of the keys, chosen by a fixed pattern (Child et al., 2019; Beltagy et al., 2020; Zaheer et al., 2020), by their content (Kitaev et al., 2020; Roy et al., 2021), or by a dedicated indexer (Yuan et al., 2025; DeepSeek-AI, 2025). Recent frontier models are increasingly adopting sparse

Figure

Figure 1. D-LSA and N-LSA overview. Top: one attention layer. The keys are pooled and clustered into buckets. A query (●) scores the bucket centroids (▲) and attends only to the selected long-range keys (plus sink and window). Bottom: accuracy and performance (P: prefill, D: decode, T: training) for both D-LSA and N-LSA. D-LSA is shown with flat search. Its subquadratic variant, D-LSA (Tree), follows a similar trend (Figure 5).

*Core contributors. † Senior author. ¹Prefrontal AI, London, United Kingdom ²ETH Zurich, Zurich, Switzerland. Correspondence to: Ales Kubicek ales@prefrontal.ai, James C.R. Whittington james@prefrontal.ai.

Preprint.

attention, in which keys are selected using a dedicated indexer (DeepSeek-AI, 2025; Qwen Team, 2026a).

However, current indexers still score every preceding key, or block of keys, for each query. This remains expensive (quadratic in prefill, linear in decode), and becomes a bottleneck at long context (Zan et al., 2026; Xu et al., 2026). For example, at 10M tokens, 98% of the prefill time of a sparse attention layer is spent on indexing (Figure 2). The cost of sparse attention at ultra-long context is therefore dominated by the cost of finding the keys.

To address this, we introduce Latent Sparse Attention (LSA), which clusters keys in a learned latent space and lets each query search the clusters instead of scoring every key. This can be done using only one level of clustering (Flat), or with a hierarchy of clusters (Tree), which makes the prefill sub-quadratic. Furthermore, we propose two trainable designs: D-LSA, which adds LSA to pre-trained models and only trains small projection matrices per layer (contribution #1), and N-LSA, which trains LSA natively with the Next-Token Prediction (NTP) loss alone (contribution #2). We evaluate state-of-the-art models (QWEN-3.8-27B and GLM-5.3-FLASH) beyond their advertised context, up to 10M tokens (contribution #3), on RULER (Hsieh et al., 2024), which is an established long-context benchmark, and PaperTrail, which we developed to test long-context scientific understanding by finding and connecting facts across unseen scientific papers (contribution #4). Finally, we integrate LSA into SGLang (Zheng et al., 2024)¹ with context parallelism, provide GPU kernels for H200 and B300, and release the code² with all training and inference details (contribution #5). Figure 1 outlines our contributions.

References (100)

Couldn't load all references. Reload the page to try again.