@NFT_Chen: Unbelievable! Qwen 3.8 27B's attention layer has been completely broken through! With 10M ultra-long context, Prefill attention is 72.4x faster and Decode is 42.5x faster! End-to-end first-token latency cut to about 1/9! Attention, anyone with idle GPUs: hand this new method to Claude/Codex, …

X AI KOLs Timeline Papers

Summary

The paper proposes Latent Sparse Attention (LSA), which hierarchically clusters Keys in latent space so that Queries only need to score against cluster centers. This achieves a 72.4x speedup in Prefill attention and a 42.5x speedup in Decode for a single attention layer of Qwen3.8-27B under 10M ultra-long context, reduces end-to-end first-token latency to about 1/9, and keeps accuracy essentially unchanged. The method includes two variants: distillable D-LSA and natively trained N-LSA, with code and distilled weights open-sourced.

🤯 Unbelievable! Qwen 3.8 27B's attention layer has been completely broken through! With 10M ultra-long context, Prefill attention is 72.4x faster and Decode is 42.5x faster! End-to-end first-token latency cut to about 1/9! Anyone with idle GPUs, take note: hand this new method to Claude/Codex and have it port directly to Qwen 27B! "Porting" attention algorithms has already been proven feasible. What's amazing: 🔹 Under 10M-token (about 10 million) ultra-long context, traditional sparse attention spends 98% of the time "figuring out which tokens to look at" — actually computing attention isn't that expensive 🔹 The new method, Latent Sparse Attention (LSA): first cluster Keys into a hierarchical structure based on semantic similarity, then Queries only look at the cluster centers and pick the most relevant buckets to compute. It goes from "full scan" to "tree search" 🔹 Measured results (Qwen-3.8-27B): single-layer attention Prefill is 72.4x faster and Decode is 42.5x faster! End-to-end first-token latency can also be reduced to about 1/9 🔹 Accuracy barely drops, and it's even slightly better on long-context tasks like RULER 🔹 Only requires a short distillation training run for the Indexer (base model frozen), so it can be applied to existing models. The natively trained version can match full-attention accuracy and is even faster 🔹 Huge significance for GPU-scarcity folks: ultra-long context (millions of tokens) no longer requires racks of H100/H200 to run — a single card or a few cards can now afford truly long-context agents Setup steps: 1️⃣ git clone the repo, then install with uv sync (Python 3.12) 2️⃣ The official distilled weights for Qwen3.8-27B are already released (d-lsa-weights-v1 release) — just download them 3️⃣ Launch the service using their SGLang fork image, mounting the repo + weights 4️⃣ At launch, add --json-model-override-args '{"lsa": {"projections": "/maps/qwen38_27b.pt", "query_heads": "all"}}' (remember to add --disable-prefill-cuda-graph) 5️⃣ If you want to train it yourself, just run lsa distill targets → lsa distill train → export (base model frozen, only train the Indexer) The code is open-sourced and the paper is out — anyone with idle cards, rush in first? Paper: https://arxiv.org/abs/2610.42147 GitHub: https://github.com/Prefrontal-AI/latent-sparse-attention… #Qwen #LSA #LongContext #AI #GPU #LocalLLM #AttentionOptimization #Qwen38 #Alibaba
Original Article
View Cached Full Text

Cached at: 11/03/26, 12:30 PM

🤯 Mind-blowing! Qwen 3.8 27B’s attention layers have been completely blown wide open! With a 10M ultra-long context, Prefill attention is up to 72.4× faster and Decode up to 42.5× faster! End-to-end first-token latency cut to roughly 1/9! Friends with idle GPUs, take note: throw this new method at Claude/Codex and have it port it directly to Qwen 27B! Attention algorithm “porting” has already been shown to work.

The astonishing parts:

🔹 Under 10M-token (~10 million) ultra-long context, traditional sparse attention spends 98% of the time “figuring out which tokens to look at” — actually computing attention isn’t that expensive

🔹 The new method, Latent Sparse Attention (LSA): first cluster Keys into a hierarchical structure by “similar meaning,” Queries only look at the cluster centers, then pick the most relevant buckets to compute on. Going from a “full scan” to a “tree search”

🔹 Measured on Qwen-3.8-27B: single attention layer Prefill is 72.4× faster, Decode is 42.5× faster! End-to-end first-token latency can also drop to about 1/9

🔹 Accuracy barely drops — it’s even slightly better on long-context tasks like RULER

🔹 Only needs a short distillation-training of the Indexer (base model frozen), so it can be applied to existing models. The natively-trained version can match full-attention accuracy, and is faster too

🔹 Huge for the GPU-starved crowd: ultra-long context (million-scale) no longer requires stacking a full rack of H100/H200 — a single card or a handful of cards can now afford truly long-context Agents

Adaptation steps:

1️⃣ git clone the repo, then install with uv sync (Python 3.12) 2️⃣ The official Qwen3.8-27B distilled weights are already out (d-lsa-weights-v1 release) — just download them 3️⃣ Launch the service using their SGLang fork image, mounting the repo + weights 4️⃣ At launch, add --json-model-override-args '{"lsa": {"projections": "/maps/qwen38_27b.pt", "query_heads": "all"}}' (remember to add --disable-prefill-cuda-graph) 5️⃣ If you want to train it yourself: run lsa distill targets → lsa distill train → export (base frozen, only the Indexer is trained)

The code is open-sourced and the paper is out — anyone with spare cards, go hit it up first?

Paper: https://arxiv.org/abs/2610.42147 GitHub: https://github.com/Prefrontal-AI/latent-sparse-attention…

#Qwen #LSA #LongContext #AI #GPU #LocalLLM #AttentionOptimization #Qwen38 #Alibaba


1 Introduction

Source: https://arxiv.org/html/2610.42147

marginparsep has been altered. topmargin has been altered. marginparwidth has been altered. marginparpush has been altered. The page layout violates the ICML style. Please do not change the page layout, or include packages like geometry, savetrees, or fullpage, which change it for you. We’re not able to reliably undo arbitrary changes to the style. Please remove the offending package(s), or layout-changing commands and try again.

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†¹

††footnotetext: *Core contributors. †Senior author. ¹Prefrontal AI, London, United Kingdom ²ETH Zurich, Zurich, Switzerland. Correspondence to: Ales Kubicek, James C.R. Whittington. Preprint.

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× (72.4×) in prefill and 4.6× (42.5×) 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× per layer at 128k tokens. LSA offers practical and efficient attention for models to benefit from ultra-long context.

1 Introduction

Refer to caption

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).

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 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 subquadratic. 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)¹¹¹github.com/Prefrontal-AI/sglang with context parallelism, provide GPU kernels for H200 and B300, and release the code ²²²github.com/Prefrontal-AI/latent-sparse-attention with all training and inference details (contribution #5). Figure 1 outlines our contributions.

2 Sparse Attention

In full attention, every query attends to every preceding key. Prefilling a context of T tokens therefore costs \mathcal{O}(T^2), and decoding one token costs \mathcal{O}(T). In sparse attention, the work is split between an indexer and the attention. For each query, the indexer selects which keys the attention attends to³³³In this view, full attention corresponds to an indexer that returns the indices of all preceding keys. With a fixed budget of k keys, the attention then costs \mathcal{O}(Tk) to prefill and \mathcal{O}(k) per decoded token. If the indexer selects the most relevant keys, this is sufficient to stay close to the accuracy of full attention (Appendix A).

However, the indexer has a cost. Since it must score all preceding keys, it typically remains \mathcal{O}(T^2) in prefill and \mathcal{O}(T) in decode, though with reduced constant factors. This makes ultra-long context still prohibitively expensive. For example, at 10M tokens the indexer takes 98% of the prefill time of traditional sparse attention (Figure 2), and a ‘free’ indexer would make sparse attention a further 58× faster in prefill and 8.9× in decode.

Figure 2: Traditional sparse attention at ultra-long context. One global attention layer of GLM-5.3-Flash (512k to 10M tokens) on one H200, prefilling the last chunk of 32,768 queries and decoding one token. Speedup of sparse attention over full attention (blue), share of the indexer (%), and potential speedup over sparse attention if the indexer were ‘free’ (green).

2.1 Design Choices

Sparse attention methods can be categorised by their indexer designs and how they are trained.

Token Sparse Attention. For each query, a lightweight indexer (fewer heads, smaller dimension, lower precision) scores every preceding key and selects which to attend to.

Block Sparse Attention. Consecutive keys are grouped into blocks, and each query scores blocks instead of every key. All keys of the selected blocks are sent to the attention.

Semantic Sparse Attention. Keys are clustered by similarity rather than position, and each query scores one centroid per cluster. All keys of the selected clusters are sent to the attention.

For the last two categories, a query can search the groups in three ways. Flat search scores every group directly, which is \mathcal{O}(T) work per query. Fixed search adds a shallow hierarchy and refines from coarse to fine groups, which is also \mathcal{O}(T) per query. Tree search descends a deeper hierarchy and expands only the groups it keeps at each level, which is \mathcal{O}(\log T) per query.

An indexer can be training-free, distilled from a pre-trained model, or trained natively on the NTP loss alone.

2.2 Related Work

Table 1: Sparse attention methods compared. Rows are grouped by the unit the indexer scores: single keys, blocks of consecutive keys, or clusters of similar keys. Design column: compression of the sequence the indexer scans by compressing consecutive keys (C. Seq.), or clustering keys by content (C. Sem.), and its search: flat (), a fixed number of levels (), or levels efficiently growing as \log T (). Evaluation: the largest context at which accuracy (Acc.) and performance (Perf.) are reported. supported, partial support, not supported.

Table 1 provides an overview of the existing work on sparse attention, as categorised above. We focus on methods that keep the whole KV cache and select keys per query, unlike fixed sparse patterns (Child et al., 2019; Beltagy et al., 2020; Zaheer et al., 2020) and KV cache eviction techniques (Zhang et al., 2023b; Li et al., 2024; Xiao et al., 2024b).

Among distillation methods, DSA (DeepSeek-AI, 2025) and MiniMax SA (Lai et al., 2026) first distil the indexer and then continue training the full model under sparse attention. Alternatively, SeerAttention (Gao et al., 2025; Gao et al., 2026) distils a gate over pooled blocks and HashAttention (Desai et al., 2025) learns binary codes of queries and keys, both with the model frozen. As the context grows, the indexer itself becomes the bottleneck (Xu et al., 2026; Zan et al., 2026; Bai et al., 2026). To reduce its cost, CSA (DeepSeek-AI, 2026a), QSA (Qwen Team, 2026a), and GLM-5.3-Flash SA (Z.ai, 2026) compress every four keys into one before scoring them. HISA (Xu et al., 2026) and LongCat LSA (Zan et al., 2026) score blocks first and then only the keys inside the selected blocks. IndexCache (Bai et al., 2026), LongCat LSA and DeepSeek-V4.1 (DeepSeek-AI, 2026b) reuse the selection of one layer in the following layers. Each improvement divides the cost of the indexer by a constant, and its work per query therefore still grows linearly with the context.

NSA (Yuan et al., 2025) and MoBA (Lu et al., 2025) instead pre-train the model with sparse attention from scratch, such that the indexer learns from the NTP loss alone. NSA scores each block by a learned compressed key, and MoBA by the mean of its keys. InfLLM-V2 (Zhao et al., 2026) and SSA (Mao et al., 2026a) bring such block selection to existing dense models by fine-tuning. HSA (Hu et al., 2025; Leng et al., 2026; Hu et al., 2026a) and HSA-UltraLong (Hu et al., 2026b) also weight the output of each block by its score, such that the loss trains the scores directly. All of these methods still scan every block. PISA (Tang et al., 2026) replaces this scan with a tree, but evaluates accuracy only at small scale (up to 16k tokens).

At the other end, Quest (Tang et al., 2024), InfLLM (Xiao et al., 2024a) and MInference (Jiang et al., 2024) select blocks based on simple summaries of their keys without any training. HiP (Lee et al., 2025a) se

Similar Articles

@NFT_Chen: Mind-Blowing! Enhanced Qwen3.8-27B Rivals Opus 5.5, GPT-6 Astra! It's just 27B parameters, yet it undergoes specialized…

X AI KOLs Timeline

A community fine-tune of Qwen3.8-27B (Coder390-EfficientThink) is released, post-trained with SFT + RLOO + MTP on 3.9M lines of code and distilled from frontier models, boosting LiveCodeBench to 90 while cutting reasoning tokens by ~44-53%. Apache-2.0 GGUF builds run locally on 24GB GPUs via llama.cpp or SGLang with DFlash2 speculative decoding.

@servasyy_ai: https://x.com/servasyy_ai/status/2106563331976991217

X AI KOLs Timeline

This long post is a real-world test of running Qwen3.8-27B on two second-hand V100 32G GPUs. By rewriting the kernel of the inference engine NInfer, adding dual-GPU support and speculative decoding, generation speed on a 200K-token code task jumped from 36 tok/s to roughly 100 tok/s, beating the 80.9 tok/s of a single 4090 48G. The post also analyzes how VRAM bandwidth, quantization, and NVLink affect inference performance.

@karminski3: Magic! DeepSeekV4 context memory compressed to 1/10! Everyone knows DeepSeekV4 supports 1M context and is heavily optimized. To actually use 1M context, VRAM usage is only about 10GB (compared to DeepSeek-V3.2 which needs about…

X AI KOLs Following

FlashMemory-DeepSeek-V4 proposes a novel inference paradigm called Lookahead Sparse Attention (LSA), which uses a neural memory indexer to actively predict future context needs, compressing physical KV cache usage to 13.5% of full context baseline while improving average accuracy by 0.6%. This method adopts a decoupled training strategy that allows independent training of the indexer without loading the base model, significantly reducing training cost.