Manuscript Offprint

arXiv:2610.32057

HyScale: Scaling Long-Context Training for Learned Sparse Attention

Yangsheng Deng, Xinjing Huang, Yulong Wang, Yunzhuo Liu, Jun Hu, Shuyong Tang, Junchi Zeng, Mingji Han, Ray Ying, Key Zhang, Luo Mai

Abstract

We present HyScale, a long-context training system for learned sparse attention. Learned sparse attention is a promising architecture for million-token contexts, widely adopted in production since DeepSeek-V3.2. Selection, however, grows into the training bottleneck. For each query, it scores every previous token whereas sparse attention reads only k; worse, current systems materialize a full score table and repeat selection during recomputation. Our key insight is that the output of selection is not an activation, but rather a set of indices. Building on it, HyScale introduces HyTopK and selection replay. HyTopK finds each query's exact top-k on the fly without a score table, while selection replay reuses forward-pass selection in recomputation. Together with holistic system optimizations tackling end-to-end training challenges, HyScale speeds up GLM-5.1 training on 1M-token sequences by 2.07×2.07\times over Megatron-LM on 512 H20 GPUs. It also speeds up the CSA layers of DeepSeek-V4-Flash and the QSA layers of Qwen3.8-Flash-Next by 2.01×2.01\times and 1.57×1.57\times at 1M tokens on 32 H800 GPUs.

1 Introduction

Long context has become a core capability of large language models, driving training sequence lengths from 128K to 1M tokens across long documents, code repositories, and agent trajectories. At these lengths, full attention dominates training cost: its computation grows quadratically with context length because each query attends to every previous token.

Learned sparse attention (Yuan et al., 2025; DeepSeek-AI et al., 2025) reduces this cost by splitting attention into two steps. In selection, a lightweight indexer scores every previous token for each query and keeps the top-k. In sparse attention, each query attends only to the selected tokens. Token-level designs, pioneered by DeepSeek Sparse Attention (DSA) (DeepSeek-AI et al., 2025), are widely adopted in production models such as GLM-5.1 (GLM-5-Team et al., 2026) and Hy4 preview (Tencent-Hunyuan, 2026). Block-level variants select contiguous token blocks instead, including CSA in DeepSeek-V4 (DeepSeek-AI et al., 2026), QSA in Qwen3.8-Flash-Next (Qiu et al., 2026), and MSA in MiniMax-M3 (Lai et al., 2026).

Selection, however, grows into the new training bottleneck. While sparse attention reads only k tokens per query, selection still scores every previous token. Worse, current systems amplify this cost in two ways. First, they materialize a full score table across all previous tokens, even though top-k keeps only k entries per query. Second, they repeat selection during activation recomputation (Chen et al., 2016; Korthikanti et al., 2023) by rerunning the entire layer from scratch. In Megatron-LM (Shoeybi et al., 2019), selection consequently consumes 47% of a GLM-5.1 training step at 1M tokens, excluding the pipeline wait—6.6× the time of sparse attention (Figure 1).

Both inefficiencies stem from treating the output of selection as a standard activation. Our key insight is that the output of selection is not a continuous activation, but rather a discrete set of indices. Unlike standard activations, top-k selection is non-differentiable: the backward pass requires neither the intermediate score table nor a rerun of top-k search. Specifically, sparse attention uses only the selected indices, and the indexer loss differentiates through only the k selected scores. Consequently, training can find these indices on the fly without materializing the full score table, and directly reuse them during recomputation instead of repeating selection.

Realizing this insight in end-to-end training raises three challenges. First, on-the-fly top-k selection must decide whether to retain or discard each score immediately upon computation. Existing sampling-based top-k operators (Yin et al., 2026) estimate a score threshold for inference, but break down in training: sampling is incompatible with context parallelism (CP), threshold underestimation overflows fixed buffers, and selection becomes non-deterministic. Second, existing selective recomputation policies (Korthikanti et al., 2023; PyTorch, 2026) op-erate at the granularity of whole operators, whereas the indexer loss requires only the k selected scores. Consequently, recomputation must either retain the full score table or rescore all previous tokens merely to recover k values per query. Third, once selection is accelerated, CP communication and inefficient sparse kernels become exposed. Existing systems gather indexer keys and KV states synchronously before selection—stalling selection on KV transfers it never reads—while their sparse kernels assign each thread block a single query, repeating the loads and updates of entries adjacent queries share.

To address these challenges, we present HyScale, a long-context training system for learned sparse attention. We make three contributions:

(1) HyTopK, an on-the-fly top-k selection operator via optimistic thresholding. HyTopK selects top-k entries while scoring, eliminating the score table entirely. Built on the observation that threshold-based filtering can tolerate optimistic thresholds as long as failures are rare and cheap to recover from, HyTopK delivers fast, exact, and deterministic top-k selection with full CP compatibility.

(2) Selection replay, a fine-grained recomputation policy for selection. Rather than operating at the operator level, selection replay records forward-pass selection results and replays only the k selected entries during recomputation. This fine-grained replay eliminates repeated selection with negligible memory overhead, reducing recomputation cost by orders of magnitude over existing selective policies.

(3) HyScale, a holistic training system for learned sparse attention. Built on Megatron-LM, HyScale integrates HyTopK and selection replay with end-to-end system optimizations: decoupled CP overlap hides the CP collectives of sparse attention behind selection, while locality-aware sparse kernels process two adjacent queries together so that they load and update their shared entries once. HyScale supports diverse learned sparse attention architectures, including DSA, CSA, and QSA.

Across 512 H20 GPUs, HyScale accelerates end-to-end GLM-5.1 training on 1M-token sequences by 2.07×2.07\times over Megatron-LM, with speedups scaling further as context length grows. Beyond token-level DSA, HyScale generalizes seamlessly to block-level architectures: at 1M tokens on 32 H800 GPUs, it accelerates the CSA layers of DeepSeek-V4-Flash by 2.01×2.01\times and the QSA layers of Qwen3.8-Flash-Next by 1.57×1.57\times. HyScale is deployed in production, powering large-scale LLM training at million-token contexts.

References (29)