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

Manuscript Offprint

arXiv:2609.08450

Sample-Guided Exact Top-K Selection for Long-Context Sparse Attention

Siran Liu, Yang Xue, Theo Tang, Changxu Shao, Qian Cheng, Haimeng Ren, Donghua Jiang, Haipeng Ming, Lehua Ding, Zhonghan Lin, Shengying Wei, Wei Liu, Kai Liu, Jianchen Zhu

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

Abstract

Sparse attention bounds downstream attention work by retaining a fixed-size subset of indexed tokens, but its standalone exact Top-K stage must still process materialized score rows whose length grows with context. Production radix selectors discover their first actionable boundary only after a complete-row pass, forcing another row-scale traversal before exact refinement. We observe that locating a compact upper tail requires substantially less resolution than identifying the exact rank boundary, and that fixed-stride partial views of the current row remain calibrated to the corresponding complete-row rank across ragged lengths. We present HPC-Ops Top-K, a sample-guided exact selector for ragged sparse-attention score rows. A fixed-stride view proposes a row-local coarse boundary; the mandatory complete-row pass certifies its sufficiency, forms the admitted candidate set, and initializes exact FP32 refinement over the unresolved frontier. A nested secondary boundary and exact recovery handle underfilled proposals before any output is committed, so sampling controls common-path work but never correctness. The GPU implementation fuses complete-row certification and candidate formation, and combines persistent, KV-split, and direct-exact execution behind graph-capturable ragged-row dispatch. We evaluate HPC-Ops Top-K on indexer scores from Hy4-Preview. It outperforms the fastest verified external exact baseline by 1.29–1.75× across 20 operator configurations, with a 1.55× geometric-mean speedup. It further achieves 1.36× and 1.48× speedups on two framework-derived sparse-attention traces. The implementation is available in HPC-Ops, Tencent's open-source high-performance operator library for LLM inference, at https://github.com/Tencent/hpc-ops.

1 Introduction

Long-context inference increases both KV-cache traffic and the cost of determining which tokens each query should attend to. Sparse attention bounds the subsequent attention work by retaining a fixed-size subset of the indexed context. In indexer-based designs such as DeepSeek Sparse Attention (DeepSeek-AI, 2025), an indexer materializes an FP32 relevance-score row for each query, exact Top-K identifies the selected positions, and the main attention accesses only the corresponding keys and values. Fixing KK bounds the downstream attention work, but it does not bound selection: every score row must still be examined over its full valid length. At hundreds of thousands of indexed tokens and many ragged rows per invocation, exact Top-K can therefore remain on the critical path even after the surrounding kernels have been optimized.

The central cost is not the unavoidable inspection of an unsorted row, but when an exact selector obtains a boundary that can reduce the active set. Production radix selection first streams the complete row into a digit histogram; only the completed histogram reveals the bucket containing rank KK. Scores encountered before

*Correspondence to: Wei Liu.

  • 1 -

the histogram completes cannot be classified on their first encounter, so candidate formation requires another row-scale traversal before exact refinement. Other exact GPU selectors maintain ordered state, partition or reduce the row, or predict boundaries from prior invocations (Shanbhag et al., 2018; Zhang et al., 2023; Li et al., 2024; Xie et al., 2025; Gaihre et al., 2021; Cheng et al., 2026). These mechanisms trade row traffic for ordered work, resident state, data-dependent intermediate sets, or reusable history. Closing this gap requires a current-row boundary before the complete-row pass, together with exact semantics, regular GPU execution, ragged-row support, CUDA-Graph capture, and score traffic close to one complete-row scan.

Our key insight is that early reduction does not require the resolution of exact selection. Two findings support this separation. First, a large boundary error can leave only a compact upper tail: distinguishing the value at rank KK from its immediate neighbor can demand an extremely precise cutoff, whereas substantially coarser boundaries still leave compact upper tails across the captured score rows. Second, fixed-stride views track global upper-tail quantiles across ragged lengths without relying on prior invocations. Finite-population order statistics explain this position-agnostic baseline, while the endpoint structure observed in sparse-attention scores further reduces the estimation error. Together, these findings make the current row itself a low-cost source of an early boundary while leaving the unavoidable complete-row pass authoritative for exactness.

We use this separation to build HPC-Ops Top-K, a three-phase sample-guided exact selector. Phase 1 reads a fixed-stride view and proposes a row-local coarse boundary. Phase 2 applies that boundary during the mandatory complete-row traversal, certifies the sufficiency of the admitted candidate set, persists the admitted candidates, and constructs the leading histogram for exact refinement on their first encounter. If the proposal underfills, a nested secondary boundary and, when necessary, exact coarse recovery establish a sufficient candidate set before any output is committed. Phase 3 performs exact FP32 radix refinement only over the compact certified frontier, committing resolved digit groups and carrying only the unresolved boundary frontier forward. Sampling therefore controls common-path work but never determines the returned indices. With sampling stride ss, the proposal reads approximately L/sL/s scores before the required complete-row traversal, rather than introducing another row-scale boundary-localization pass.

The GPU implementation realizes the sampled pipeline within a shape-dependent portfolio of exact kernels. The fused complete-row pass uses vectorized score reads while performing boundary classification, candidate collection, and construction of the leading exact histogram in one traversal. Subsequent refinement carries forward only the unresolved frontier rather than revisiting resolved scores. Persistent kernels keep each row and its compact state under one CTA, KV-split kernels expose parallelism across a few long rows, and direct-exact kernels cover complementary shapes for which sampling does not amortize. These paths share graph-stable ragged-row dispatch and the same exact FP32 refinement contract.

We evaluate HPC-Ops Top-K on indexer scores from Hy4-Preview (Tencent Hy Team, 2026) against verified exact Top-KK implementations from vLLM, TensorRT-LLM, SGLang, FlashInfer, and PyTorch (Kwon et al., 2023; NVIDIA Corporation, 2026b; Zheng et al., 2024; Ye et al., 2025; Paszke et al., 2019). HPC-Ops Top-K is fastest in all 20 evaluated operator configurations, outperforming the fastest external baseline by 1.29−1.75×1.29-1.75\times with a 1.55×1.55\times geometric-mean speedup. On two framework-derived sparse-attention traces, it achieves 1.36×1.36\times and 1.48×1.48\times speedups. The implementation is released as part of HPC-Ops, Tencent's open-source high-performance operator library for LLM inference, at https://github.com/Tencent/hpc-ops.

Our contributions are:

  • Workload insight. We identify and analyze the separation between locating a compact upper tail and resolving its exact rank boundary, and show that fixed-stride views of the current row can locate a useful coarse boundary across ragged lengths.

  • Sample-guided exact selection. We develop a three-phase proposal–certification–refinement algorithm in which sampling reduces common-path work while complete-row certification, bounded recovery, and exact FP32 refinement preserve exact Top-KK semantics.

  • GPU realization and validation. We realize the design through fused complete-row processing and a graph-stable dispatcher over persistent, KV-split, and direct-exact kernels, bringing the principal sampled path close to the one-scan traffic floor. We validate the resulting operator at both operator and framework levels and release it as part of the open-source HPC-Ops library.

  • 2 -

References (30)