CoSA: Accelerating Long-Context Inference via Proxy-Kernel Co-Designed Sparse Attention

Yufei Xue, Lin Niu, Hong Liu, Siran Liu, Hanyong Shao, Wei Liu, Guanghua Yu, Jianchen Zhu, Jun ZhangarXiv 2026

TL;DR

CoSA introduces a training-free, proxy-kernel co-designed sparse attention mechanism that accelerates long-context LLM inference by up to 4.93×. By replacing traditional binary masks with a computation-order mask, it prioritizes processing key blocks first, allowing the system to safely and aggressively skip redundant calculations during the prefilling stage with negligible accuracy loss.

What Problem Does This Paper Address?

As Large Language Models (LLMs) handle increasingly massive context windows (e.g., 128K tokens or more), the standard self-attention mechanism becomes a massive bottleneck. Because its computational cost scales quadratically ($O(N^2)$) with sequence length, processing long inputs leads to agonizingly slow Time-to-First-Token (TTFT) latencies.

To fix this, researchers use "sparse attention" to skip unimportant block interactions. Current methods generally fall into two camps, both with major drawbacks:

  1. Mask-driven methods: Use a cheap "proxy" algorithm to predict a binary mask of which blocks to keep. Under tight compute budgets, these proxies inevitably drop critical blocks, tanking model accuracy.
  2. In-kernel skipping methods: Decide whether to skip blocks on the fly using exact hardware statistics. While accurate, they still require calculating full query-key (QK) multiplications first, leaving a lot of potential speedup on the table. They also suffer from a "bucket effect"—if even a single row in a block demands computation, the entire block must be processed.

CoSA addresses this disconnect by co-designing the proxy and the execution kernel so they work in harmony rather than in isolation.

Methods

CoSA splits the sparse attention process into a two-stage pipeline connected by a novel computation-order mask ($M_{KAP}$):

Figure 4: Overview of CoSA. MKAP: the KAP mask serves as a bridge between the co-designed proxy and kernel. Left: KAP estimates a per-block score together with the HRM flag. They are merged into the computation-order mask MKAP, which places HRM blocks first. Right: OSK consumes MKAP through KV page remapping, yielding three per-block patterns: ➀ mask-skipped, ➁in-kernel skipped, and ➂computed.
  • Stage 1: Kernel-Aware Proxy (KAP): Instead of generating a rigid binary mask, the KAP downsamples the queries and keys to cheaply estimate block importance. Crucially, it identifies "Have RowMax" (HRM) blocks—blocks that contain the maximum logit values for a given query row. It then outputs an ordered mask that prioritizes visiting these HRM blocks first.
  • Stage 2: Ordered-Skipping Kernel (OSK): The OSK consumes this ordered mask via lightweight page-table remapping. Because online softmax computation is order-invariant (the final math is the same regardless of the order blocks are processed), the kernel can safely visit the HRM blocks first.

By front-loading the highest-value blocks, the kernel's running maximum rises rapidly. As a result, subsequent blocks can be aggressively and safely skipped using exact in-kernel logits, effectively bypassing the conservative "bucket effect" that plagues traditional backends.

Datasets

The authors evaluated CoSA across two primary long-context benchmarks using Qwen3-8B and Llama-3.1-8B-Instruct as backbones:

  • RULER: A synthetic benchmark testing context lengths from 4K to 128K tokens across various retrieval and aggregation tasks.
  • LongBench-v2: A real-world dataset focused on deep understanding and reasoning. It was tested in both direct answering modes (w/o Chain-of-Thought) and thinking modes (w/ Chain-of-Thought) to ensure the sparsification didn't disrupt complex reasoning chains.

Key Insights and Ideas

  • Exploiting Order Invariance: The core "aha moment" is realizing that FlashAttention's online softmax doesn't care about the sequence in which blocks are processed. Reordering block execution is entirely correctness-preserving.
  • The Power of Front-Loading: In-kernel skipping is usually conservative because it tests blocks against a low running maximum. By using the proxy to intentionally process the most dominant blocks first, the running maximum approaches the true global maximum almost immediately. This makes subsequent skipping decisions incredibly sharp and effective.
  • Bridging the Software-Hardware Gap: Traditional sparse attention treats the algorithm (proxy) and execution (kernel) as separate layers. CoSA proves that passing richer metadata (an ordered sequence rather than a binary yes/no) allows the hardware backend to optimize execution dynamically.

Key Results

CoSA consistently outperforms mainstream sparse attention baselines (like MInference, FlexPrefill, and XAttention) in both speed and fidelity:

  • Speedups: At a 128K context length, CoSA achieves a 4.93× attention speedup and a 2.53× end-to-end prefilling speedup (TTFT) compared to full attention.
  • Efficiency vs. Accuracy: On the RULER benchmark, CoSA maintains near-dense accuracy while operating on a heavily reduced compute budget (averaging around 22% of full attention compute).
Figure 5: Attention (left) and time-to-first-token (TTFT) (right) speedups over the Full Attention baseline across context lengths ranging from 4K to 128K.

Limitations and Future Work

Currently, CoSA's optimization is strictly focused on the prefilling stage of inference, where the quadratic cost of attention is most heavily concentrated. It leaves the decoding stage dense. As future work, the authors plan to extend the proxy-kernel co-design principles to the decoding stage, which will require adapting to different query shapes and distinct memory traffic patterns.

Summary updated

BibTeX
@misc{xue2026cosa,
  author = {Yufei Xue and Lin Niu and Hong Liu and Siran Liu and Hanyong Shao and Wei Liu and Guanghua Yu and Jianchen Zhu and Jun Zhang},
  title = {{CoSA: Accelerating Long-Context Inference via Proxy-Kernel Co-Designed Sparse Attention}},
  year = {2026},
  eprint = {2607.25291},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.25291},
}
Figure