Organizations: School of Advanced Interdisciplinary Sciences, University of Chinese Academy of Sciences, Beijing, China · Meituan, Beijing, China · University of Chinese Academy of Sciences, Beijing, China
While sparse attention mitigates the computational bottleneck of long-context LLM training, its distributed training process exhibits extreme heterogeneity in both 1) sequence length and 2) sparsity sensitivity, leading to a severe imbalance problem and sub-optimal model accuracy. Existing algorithms and training frameworks typically focus on single issue, failing to systematically co-optimize these two problems. Therefore, we propose SparseBalance, a novel algorithm-system co-design framework, which exploits the sparsity and sequence heterogeneity to optimize model accuracy and system efficiency jointly. First, we propose workload-aware dynamic sparsity tuning, which employs a bidirectional sparsity adjustment to eliminate stragglers and exploit inherent bubbles for free accuracy. Second, we propose a sparsity-aware batching strategy to achieve coarse-grained balance, which complements dynamic sparsity tuning. Experimental results demonstrate that SparseBalance achieves up to a 1.33× end-to-end speedup while still improving the long-context capability by 0.46% on the LongBench benchmark.
Figures & tables
Fig. 1 : Extreme heterogeneity in sequence length distributions across two real-world long-context datasets. The x-axis represents the sequence length, and the y-axis denotes its corresponding proportion within the entire dataset.
Fig. 2 : Illustration of the straggler effect caused by workload imbalance. Within PP group, a bottleneck micro-batch (e.g., Micro-batch 4) dictates the critical path and exacerbates pipeline bubbles. Furthermore, DP synchronization significantly amplifies this imbalance across the entire system.
Fig. 3 : Forward-pass latency of micro-batches over continuous training iterations. The substantial gap between the maximum ( Tmax , red solid line), mean ( Tmean , blue dashed line), and minimum ( Tmin , green dashed line) latencies reveals severe workload imbalance.
Fig. 4 : Cumulative score coverage under different attention budgets.
Fig. 5 : Overview of SparseBalance, which consists of three components: workload-aware dynamic sparsity tuning (DST), sparsity-aware batching (SAB) and latency prediction module.
Fig. 6 : Practical latency of sparse attention cannot be reliably predicted by either theoretical FLOPs or sequence length alone, motivating our profiling-based latency predictor.
Fig. 7 : Overall performance and step-by-step speedups on two clusters and two datasets. We evaluate the normalized speedup ratios (measured by average iteration time) of SparseBalance and its two main components for specific model settings (from left to right: Qwen2.5-0.5B, Qwen2.5-3B, and Qwen2.5-3B in LoRA). Results demonstrate significant efficiency improvements in SparseBalance and confirm the effectiveness of each component.
Category
Dataset
Baseline SFT
Min 0.1
Min 0.2
Mean 0.1
Mean 0.2
Single-Doc QA
NarrativeQA
22.42
23.62
22.88
22.89
22.03
Qasper
32.25
35.77
36.62
32.99
34.88
MultiFieldQA-en
42.06
42.19
41.54
42.92
42.06
Multi-Doc QA
HotpotQA
44.81
46.80
45.65
45.40
47.25
2WikiMQA
33.42
33.17
33.98
35.62
33.20
MuSiQue
24.30
26.71
25.50
26.51
25.78
TABLE I : Evaluation results on the LongBench benchmark. The best results for each dataset are highlighted in bold .
Fig. 8 : Sensitivity of end-to-end speedup with respect to the sparsity threshold p and execution anchor choice. The upper end of each bar corresponds to Min , the lower end corresponds to Max , and the horizontal line denotes Mean .
Fig. 9 : Sensitivity of end-to-end speedup to different micro-batch sizes ( mbs=1 to 4 , corresponding to global batch sizes gbs=8 to 32 ). SparseBalance consistently achieves clear speedups across all tested settings.
Config.
Imbalance ↓
Iter. (ms)
Overheads (ms)
Speedup ↑
Baseline
1.81 ×
4202.09
0.00
1.00 ×
+DST
1.73 ×
3901.57
37.14
1.08 ×
+SAB
1.41 ×
3470.73
1.81
1.21 ×
+LBB
1.58 ×
3421.98
0.00
1.23 ×
+SAB+DST
1.34 ×
3107.83
44.23
1.35 ×
+LBB+DST
1.41 ×
3272.88
39.01
1.28 ×
TABLE II : LBB denotes a length-based batching strategy. Imbalance measures the average micro-batch-level imbalance degree (lower is better). Overheads report the additional cost introduced by SparseBalance.
Fig. 10 : Training loss comparison between the MoBA baseline and SparseBalance with different dynamic tuning configurations.
Model
≤ 8K
16K
32K
64K
Baseline SFT
100.00
100.00
100.00
97.60
Min 0.1
100.00
100.00
99.93
96.33
Min 0.2
100.00
100.00
99.93
95.20
Mean 0.1
100.00
100.00
100.00
97.53
Mean 0.2
100.00
100.00
99.93
96.47
TABLE III : Average accuracy (%) of Needle-in-a-Haystack (NIAH) tasks evaluated on Qwen-2.5-3B model. Results are averaged across the niah_single_1 , niah_single_2 , and niah_single_3 evaluations for each model.
Task
Base-SFT
Min 0.1
Min 0.2
Mean 0.1
Mean 0.2
ARC-Chal.
0.4727
0.4735
0.4684
0.4744
0.4659
ARC-Easy
0.7332
0.7348
0.7277
0.7315
0.7260
BoolQ
0.7936
0.7994
0.7951
0.8003
0.8031
HellaSwag
0.7356
0.7354
0.7355
0.7349
0.7366
Lambada
0.6598
0.6583
0.6594
0.6604
0.6592
Piqa
0.7884
0.7867
0.7894
0.7911
0.7900
TABLE IV : General benchmark results on Qwen2.5-3B. Bold indicates the best performance.
Fig. 11 : Trade-off between training speedup and downstream model performance under different configurations in SparseBalance.
Large-language-models (LLMs) demonstrate enormous utility in long-context tasks which require processing prompts that consist of tens to hundreds of thousands of tokens. However, existing LLM training libraries do not provide easy to use abstractions to optimize for long-context training, instead focusing on optimizations for models with large parameter counts through ZeRO-3/FSDP, Tensor and Pipeline parallelism. This forces users to rewrite LLM training libraries to incorporate compositions of various complex long-context optimizations, such as sequence-parallelism, to training pipelines; a process that requires in-depth expertise, reducing developer productivity. To tackle these challenges, we introduce AutoSP: the first automated solution to automatically optimize LLM training for longer-contexts. AutoSP compiles models and applies a targeted set of optimizations: automated sequence parallelism, and long-context aware activation-checkpointing, to drastically enhance LLM trainability at negligible cost to throughput. Our evaluation demonstrates AutoSP's capability on both NVIDIA and AMD hardware, increasing training contexts by upto 2.7× and 2.5× respectively over competitive hand-written baseline at negligible cost to runtime performance.
Ahan Gupta, Zhihao Wang, Neel Dani +3
SSAIL Lab, University of Illinois Urbana-Champaign Champaign, IL, USA · Anyscale San Francisco, CA, USA · Snowflake San Mateo, CA, USA
Long-context inference in large language models is bottlenecked by the quadratic cost of full attention. Existing efficient alternatives often rely either on native sparse training or on heuristic token eviction, creating an undesirable trade-off among efficiency, training cost, and accuracy. In this work, we show that full-attention LLMs are already intrinsically sparse and can be transformed into highly sparse models with only minimal adaptation. Our approach is built on three observations: (1) only a small subset of attention heads truly requires full long-context processing; (2) long-range retrieval is governed primarily by a low-dimensional subspace, allowing relevant tokens to be retrieved efficiently with a 16-dimensional indexer; and (3) the useful token budget is strongly query-dependent, making dynamic top-p selection more suitable than fixed top-k sparsification. Based on these insights, we propose RTPurbo, which retains the full KV cache only for retrieval heads and introduces a lightweight token indexer for sparse attention. By exploiting the model's intrinsic sparsity, RTPurbo achieves sparsification with only a few hundred training steps. Experiments on long-context benchmarks and reasoning tasks show that RTPurbo preserves near-lossless accuracy while delivering substantial efficiency gains, including up to a 9.36× prefill speedup at 1M context and about a 2.01× decode speedup. These results suggest that strong sparse inference can be obtained from standard full-attention training without expensive native sparse pretraining.
Long context training is crucial for extending LLM context windows. Existing schemes, such as sequence parallelism, incur substantial communication overhead. Pipeline parallelism (PP) reduces this cost, but its effectiveness hinges on partitioning granularity. Batch-level PP employing sequence packing exhibits high memory consumption in long-context scenarios, whereas token-level PP splitting sequences into slices alleviates memory overhead but may introduce performance degradation. Moreover, the skewed sequence-length distribution in real-world datasets defeats any monolithic, static choice of PP granularity. In this paper, we propose Dynamic Pipeline Parallelism (DPP), which transforms PP granularity from a static design choice into a workload-adaptive optimization space over packed, split, and hybrid chunks. DPP further introduces a new coupling between heterogeneous pipeline scheduling and gradient checkpointing. To solve this coupling, \name co-optimizes dynamic chunk scheduling with Stage-Aware Chunk-Level Adaptive Checkpointing. Comprehensive experiments demonstrate that \name achieves up to 1.69\texttimes\ speedup over FlexSP and up to 1.40\texttimes\ over MEPipe. The source code is available at https://github.com/wsjdsg/InfiniPipe-code.
Shiju Wang, Yujie Wang, Fangcheng Fu +6
Tsinghua University · Peking University · Shanghai Jiao Tong University +1