Source-linked AI summary
Long-Context Attention Benchmark: From Kernel Efficiency to Distributed Context Parallelism
Tao Bu, Qiangang Wang, Bowen Zeng, Hanwen Sun, Yunpeng Huang, Chun Cao, Jingwei Xu
TL;DR
Long-context attention has quadratic costs, and systematic comparisons of kernels and distributed strategies remain limited. This paper presents a unified benchmark spanning attention kernels, context-parallel mechanisms, mask patterns, and distributed scales. It exposes method-specific trade-offs and constraints, including sparse-kernel specialization gains and backward-pass bottlenecks.
Problem
Long-context attention has quadratic computation and memory costs, while evaluations of kernels and framework-specific context-parallel methods remain incomplete and difficult to compare systematically.
Source: §1 · pp. 1–2Method
The paper builds a unified benchmark with standardized interfaces for representative dense and sparse kernels and distributed attention mechanisms, evaluated across mask patterns and context lengths.
Source: §1 · p. 2Results
The benchmark exposes method-specific trade-offs; block-sparse performance improves through specialization, while backward computation remains a major bottleneck.
Source: §3.2 · p. 8, §5 · p. 10Takeaways & Limitations
The benchmark provides objective references for comparing approaches and guiding future research and development in ultra-long-context training.
Source: §5 · p. 10Ring All-Gather experimental results are omitted because of resource constraints.
Source: §3.3 · p. 8
Abstract
from arXiv · showhide
Transformer-based large language models (LLMs) have achieved remarkable success, yet their standard attention mechanism incurs quadratic computation and memory costs with respect to sequence length, posing a major bottleneck for long-context training. Prior work tackles this challenge along two directions: (1) kernel-level optimizations, which accelerate dense and sparse attention operators; and (2) module-level strategies, often referred to as distributed attention or context parallel training, which scale attention across multiple devices. However, systematic evaluation still remains limited: operator-level comparisons are often incomplete, while context parallel strategies are typically framework-specific, with unclear performance analysis across contexts. To address these gaps, we propose a unified benchmark that integrates representative attention kernels and context parallel mechanisms with a modular and extensible interface for evaluation. The benchmark evaluates methods along two critical dimensions: (1) attention mask patterns, which strongly affect efficiency, scalability, and usability, and (2) sequence length and distributed scale, which determine performance under extreme long-context training. Through comprehensive experiments on the cluster of up to 96 GPUs, our benchmark enables reproducible comparisons, highlights method-specific trade-offs, and provides practical guidance for designing and deploying attention mechanisms in long-context LLM training.
1 INTRODUCTION
Long-context attention is costly at extreme sequence lengths, while systematic comparisons of kernels and distributed attention remain limited. The paper introduces a unified benchmark to compare these approaches across mask patterns, context lengths, and distributed scales.
1 INTRODUCTION
- Conventional attention’s quadratic computation and memory costs make it a bottleneck as sequence length grows, while long-context performance at distributed scales remains insufficiently understood.Existing evaluations are incomplete across operators, and context-parallel methods are often framework-specific, limiting reusability and systematic comparison.Source: §1 · pp. 1–2
- The benchmark standardizes evaluation of representative attention kernels and context-parallel mechanisms, including dense and sparse kernels and optimized distributed implementations.It uses a unified data-preparation interface and analyzes up to 14 mask patterns and contexts reaching 512K on 96 GPUs.Source: §1 · p. 2
- The paper analyzes attention efficiency and scalability across dense long-context scenarios to identify factors that can guide ultra-long-context training and development.Its stated contributions combine unified benchmarking, modular components, and in-depth analysis.Source: §1 · p. 2
2 LONGCA-BENCH
LongCA-bench provides a standardized, extensible platform for comparing single-device attention kernels and distributed context-parallel mechanisms. Its evaluation spans mask patterns, data scales, kernel types, and distributed designs.
2 LONGCA-BENCH
- LongCA-bench combines standardized data preparation, input representation for 7 dense and 5 sparse kernels, and an optimized framework incorporating 5 distributed attention mechanisms.These components support comparisons of operator-level efficiency and distributed scalability.Source: §2 · p. 2
2.1 DATA PREPARATION
- The data-preparation interface combines diverse mask patterns with variable-length sequence sampling to reflect long-context training conditions.It is designed to avoid using downstream datasets directly as benchmark inputs.Source: §2.1 · p. 2
2.1.1 INPUT MASK PATTERNS
- LongCA-bench categorizes 14 mask patterns into 12 static masks (6 regular and 6 heterogeneous) and 2 dynamic masks, distinguished by whether masks are predetermined before training or generated adaptively during training.Source: §2.1.1 · p. 3
2.1.2 INPUT DATA SAMPLING
- Dense sampling uses Pile for sequences up to 8K, ProLong64K up to 64K, and ProLong512K up to 512K; sparse workloads use randomized masks at sparsities 0.2, 0.5, and 0.8.Sparse evaluation covers 32K–128K sequences, MHA and GQA, and uniform block sizes of 64×64 and 128×128.Source: §2.1.2 · p. 4
2.2 ATTENTION KERNEL
- The benchmark adapts kernel-specific inputs to a unified representation and includes dense kernels such as FlashAttention, cuDNN, FlexAttention, and FlashMask, alongside five block-sparse kernels.Sparse kernels include dedicated implementations optimized for uniform blocks and general-purpose implementations supporting arbitrary block structures; only a limited subset supports backward computation.Source: §2.2 · pp. 4–5
2.3 DISTRIBUTED ATTENTION MECHANISM
- Five distributed mechanisms are reproduced under a standardized setup; they use All-to-All, ring point-to-point, ring All-Gather, or hybrid designs, with current support limited to FULL, CAUSAL, and document masks.The framework adds load balancing, buffering, and communication-computation overlap, while Ulysses scalability is constrained by attention-head count and ring approaches can incur lower efficiency and numerical error accumulation.Source: §2.3 · pp. 5–6
3 EVALUATION
The evaluation compares dense and sparse kernels and distributed context-parallel attention across mask patterns, sequence lengths, and device scales. Results show configuration-specific performance, support, and scalability trade-offs.
3 EVALUATION
- The benchmark measures single-GPU kernel throughput and memory, and multi-GPU context-parallel performance on H100s across varied lengths and scales.Dense-kernel tests include 12 static masks at 1K–48K; context-parallel tests scale from 8 to 96 GPUs and 64K–512K total context.Source: §3 · p. 6, §3.1 · p. 6, §3.3 · p. 8
3.1 DENSE ATTENTION KERNEL PERFORMANCE
- Dense naive attention and Torch SDPA become impractical for long contexts because quadratic complexity causes severe efficiency degradation and memory overhead.FlashMask’s column-wise representation is optimized for heterogeneous masks but cannot cover every scenario, making it less general than FlexAttention.Source: §3.1 · pp. 6–7
- On H100, FA3 achieves the best performance for regular masks, while cuDNN imposes stricter pattern constraints and kernel choice depends on target hardware.The 8K GQA comparison also reports that FA and cuDNN fused kernels do not support heterogeneous masks.Source: §3.1 · pp. 6–7, Figure 3 · p. 7
3.2 SPARSE ATTENTION KERNEL PERFORMANCE
- Sparse-kernel support remains uneven: FA2 sparse lacks block size 64, FlashInfer lacks backward computation, and VSA lacks block size 128 and GQA support.FlashInfer also risks OOM at longer sequences and smaller blocks because of metadata storage.Source: §3.2 · p. 7
- VSA leads Triton VSA and FlashInfer in panels (a,b), while FlashInfer leads FA2 sparse in panels (c,d); specialization improves block-sparse performance.Across kernels, forward throughput exceeds backward throughput; GQA has better GPU memory efficiency than MHA despite minimal performance differences.Source: §3.2 · pp. 7–8, Figure 4 · p. 8
3.3 CONTEXT PARALLEL ATTENTION PERFORMANCE
- Ulysses exposes AllToAll communication and scales only up to the attention-head count; Ring P2P is optimal for FULL masks but fluctuates on DOCUMENT masks.DOCUMENT padding varies with scale and sampling, causing per-GPU computation variation.Source: §3.3 · p. 9
- The hybrid context-parallel design reduces per-group AllToAll volume, while LoongTrain’s extra synchronization erases its forward speedups overall.The comparison is for FULL DOCUMENT; the figure reports forward TFLOPs.Source: Figure 5 · p. 8, §3.3 · p. 9
4 RELATED WORK
Related work addresses attention efficiency through kernel-level methods and distributed context parallelism. The paper frames open challenges in ultra-long context training across both directions.
Long context language modeling
- Long-context modeling supports extended-input tasks including retrieval, reasoning, summarization, in-context learning, and multimodal understanding.Reported context windows have expanded from thousands of tokens to millions.Source: §4 · p. 9
Attention kernels
- Attention kernels reduce attention’s O(n^2) context-length cost through hardware-efficient techniques such as tiling, fusion, and low-bit quantization.Sparse kernels exploit attention-map sparsity; other approaches reduce KV-cache memory through weight sharing or low-rank decomposition.Source: §4 · p. 9
Parallelism for distributed training
- Context parallelism partitions data by sequence, but still faces challenges in computation–communication overlap, load balancing, scalability, and usability.Near-linear scalability remains difficult, and many designs remain underexplored.Source: §4 · p. 9
5 CONCLUSION
The conclusion presents a fair, unified benchmark spanning single-device kernels and large-scale distributed context-parallel methods. It aims to clarify performance trade-offs and constraints and guide future work.
5 CONCLUSION
- The benchmark spans single-device kernels through large-scale distributed context-parallel methods to compare approaches fairly and expose their trade-offs and constraints.The authors state that selecting or developing suitable methods for ultra-long context training is challenging and resource-intensive.Source: §5 · p. 10
A.1 DETAILS OF DENSE DATA SAMPLING
The dense-data analysis examines public pretraining datasets for short- and long-context sampling. It describes dataset composition, context-extension data sources, and how length statistics are estimated.
Dataset coverage
- The dataset analysis covers publicly available, widely used pretraining corpora, with short- and long-context distributions presented side by side in Figure 6.The listed sources include Pile, ProLong64K, ProLong512K, Upsampled SlimPajama, OpenWebText, and C4.Source: §A.1 · p. 18, Figure 6 · p. 20
Short-context datasets
- Pile and SlimPajama are analyzed for short-context modeling; the benchmark samples Pile sequences up to 8k tokens rather than fully sampling SlimPajama.Pile is an 825 GB corpus with 22 subsets; SlimPajama contains 627B tokens and is derived from RedPajama through normalization, cleaning, deduplication, and document interleaving.Source: §A.1 · p. 18
Long-context datasets
- For context extension, the benchmark collects Upsampled SlimPajama, ProLong64K, and ProLong512K statistics for datasets used to extend context to 64K and 512K tokens.The described long-context data-mixing approach oversamples long sequences while preserving domain diversity and mixing high-quality long- and short-context sources (Fu et al., 2024; Gao et al., 2024b).Source: §A.1 · p. 18
Length statistics
- Length statistics split English samples on spaces as an approximate proxy for tokenized length, and show long-text tokens reaching up to 60% without necessarily dominating length distributions.The authors note that datasets are generally expressed by token counts rather than sample counts.Source: §A.1 · p. 18
A.2 DETAILS OF SPARSE DATA SAMPLING
Sparse-data sampling constructs block masks by partitioning the attention map, scoring blocks, and selecting top-ranked key blocks for each query block. Experiments use three representative sparsity ratios.
Block Partitioning
- The attention map is partitioned into query- and key-block grids, with uniform masks using equal block sizes and variable masks allowing different sizes.The grid dimensions follow the lengths of the query- and key-block lists.Source: §A.2 · p. 21
Score Calculation
- Block scores represent importance, and masks may vary by attention head or KV-head group; experiments use random scores to isolate final block-sparse attention computation.MHA can use a unique score matrix per head, while GQA shares masks within a group.Source: §A.2 · p. 21
Top-k Selection
- For each query block, top-k key blocks are selected, with sparsity ratios of 0.2, 0.5, and 0.8 used to test kernel performance across sparsity levels.The sparsity ratio is directly convertible to top-k and is described as essentially equivalent.Source: §A.2 · p. 21
A.3 DETAILS OF SPARSE ATTENTION KERNELS
The sparse-kernel comparison covers implementations with different design targets, hardware support, and training capabilities; several implementations have important limitations for LLM training.
VSA
- VSA selects top-k key blocks per query block, then uses a Hopper-customized ThunderKittens kernel for fine-grained sparse attention (Zhang et al., 2025d; Spector et al., 2024).Its coarse stage uses token rearrangement from STA (Zhang et al., 2025c), cube partitioning, and mean-pooling on QK scores.Source: §A.3 · p. 21
- VSA’s fine-grained stage accounts for over 80% of latency at contexts of 32K or more, motivating the benchmark’s focus on that kernel.Source: §A.3 · p. 21
VSA variants
- Triton VSA targets cross-hardware compatibility but loses performance; both VSA implementations target video models and lack GQA support.Source: §A.3 · p. 21
FA2 Sparse
- FA2 Sparse modifies FlashAttention-2 to traverse designated KV blocks, but lacks backward-pass support and Hopper optimization (Dao, 2023).Source: §A.3 · p. 21
FlexAttention
- FlexAttention supports block-mask sparsity, but its representation can compile into a full O(S^2) mask with significant memory overhead (Dong et al., 2024).Source: §A.3 · p. 21
FlashInfer
- FlashInfer converts block-sparse inputs to paged attention with page size 1, supporting arbitrary block sizes but not backward passes (Ye et al., 2025).Source: §A.3 · p. 21
A.4 DETAILS OF DENSE KERNEL PERFORMANCE
Dense-kernel performance was measured using repeated runs, with sampling procedures differing for single-sequence and multisequence masks.
Measurement procedure
- Single-sequence FULL/CAUSAL and SLIDING WINDOW masks use two runs, each with five warm-ups and 20 kernel-computation steps.Source: §A.4 · p. 22
- Multisequence DOCUMENT and SHARE QUESTION masks use 30 independently sampled runs, each with five warm-ups and 20 computation steps.Source: §A.4 · p. 22
Reported metrics
- Reported FLOPS and peak memory are medians; results reflect these settings, and occasional large deviations in individual runs are considered normal.Source: §A.4 · p. 22
A.4.1 PERFORMANCE METRIC: FLOPS
The FLOPS comparisons cover standard and structured attention masks, showing that kernel performance varies with sequence length and mask context.
FULL and CAUSAL
- For FULL and CAUSAL, SDPA and Flex approximate unfused baselines; throughput generally rises with sequence length, stabilizes around 16K, and FA3 gains on H100.Source: §A.4.1 · p. 22, Figure 8 · p. 24
FULL/CAUSAL DOCUMENT
- FULL/CAUSAL DOCUMENT packs variable-length sequences to reduce padding, but many small fragments can make computation unstable.Source: §A.4.1 · p. 22, Figure 9 · p. 26
SLIDING WINDOW
- The sliding-window experiments fix window size at 1024, while the authors recommend evaluating other window sizes too.Source: §A.4.1 · p. 22, Figure 10 · p. 28
Heterogeneous masks
- Across heterogeneous masks, Flex and FlashMask show performance gains that vary by context.Source: §A.4.1 · p. 22
PREFIX LM
- PREFIX LM and PREFIX LM DOCUMENT randomly generate a prefix per run and report medians; prefixes let prefix-trained models use context for long-text and multi-turn dialogue tasks (Raffel et al., 2020).Source: §A.4.1 · p. 22, Figure 11 · p. 30
SHARE QUESTION and CAUSAL BLOCKWISE
- SHARE QUESTION lets all queries share keys from the first document; CAUSAL BLOCKWISE lets keys share queries from the last document, supporting reward-model and demonstration–test settings (Ouyang et al., 2022; Bertsch et al., 2024).Source: §A.4.1 · p. 22, Figure 12 · p. 32
GLOBAL SLIDING
- GLOBAL SLIDING combines global and windowed attention, with sampled global-window sizes; increased sparsity lowers Flex and FlashMask performance.Source: §A.4.1 · p. 23, Figure 13 · p. 33
BLOCK CAUSAL DOCUMENT
- BLOCK CAUSAL DOCUMENT raises DOCUMENT computation to the block level and uses a fixed block size of 1024 in these experiments.Source: §A.4.1 · p. 25, Figure 14 · p. 34
A.4.2 PERFORMANCE METRIC: PEAK MEMORY USAGE
This part examines peak memory usage across sequence lengths, including separate forward and backward measurements for global-sliding MHA with static heterogeneous masks.
A.4.2 PERFORMANCE METRIC: PEAK MEMORY USAGE
- Around 16K in forward and 8K in backward, Naive Attention and SDPA reach their reported sequence-length limits; peak memory rises with longer contexts.The plots are truncated at certain points and annotate corresponding values.Source: §A.4.2 · p. 35, Figure 16 · p. 41
- With model parameters fixed, activation growth drives peak memory approximately quadratically as sequence length increases.The standard attention module's activation memory is computed as 11bshd + 5bhs2 + 2bshd; gradient checkpointing and offloading are not considered.Source: §A.4.2 · p. 35
- Under the same mask, kernels show similar forward-pass peak memory but noticeable differences in the backward pass.Peak-memory growth across kernels aligns with the expected trend as sequence length increases.Source: §A.4.2 · p. 35
- Tensor and data parallelism are insufficient to alleviate activation-driven peak memory, whereas context parallelism balances work across the sequence dimension and can address it.Source: §A.4.2 · p. 35
- The forward peak-memory plot covers global-sliding MHA at sequence lengths from 1k to 48k.It appears within Figure 17, which is captioned as peak memory of static heterogeneous masks.Source: §A.4.2 · p. 46, Figure 17 · p. 47
- The backward peak-memory plot covers global-sliding MHA at sequence lengths from 1k to 48k.It appears within Figure 17, which is captioned as peak memory of static heterogeneous masks.Source: §A.4.2 · p. 46, Figure 17 · p. 47
A.5 DETAILS OF SPARSE KERNEL PERFORMANCE
Sparse-kernel performance and memory use vary with block size and implementation, while context-parallel results depend on communication overlap and workload pattern. Hybrid USP and LoongTrain designs improve stability in document scenarios, with different forward- and backward-pass trade-offs.
A.5.1 PERFORMANCE METRIC: FLOPS
- VSA remains stable across sparsity ratios for 64-block MHA, while its performance falls as context length increases, especially in backward computation.FlashInfer is also stable across sparsity ratios but can run out of memory at higher sparsity ratios because of metadata overhead.Source: §A.5.1 · p. 48, Figure 18 · p. 49
- For 128-block MHA, FlashInfer TFLOPS increase about 2x versus 64-block size and OOM issues decrease; FA2 Sparse averages about 300+ FLOPS.FlexAttention performs poorly at 64-block size but is comparable to FA2 Sparse at 128-block size and supports backward computation at similar performance; sparse-kernel baselines are partial because of unsupported configurations.Source: §A.5.1 · p. 48, §A.5 · p. 48, Table 4 · p. 50
A.5.2 PERFORMANCE METRIC: PEAK MEMORY USAGE
- FlexAttention's mask creation consumes most of its GPU memory, whereas runtime memory use is not high; its O(S^2) block-mask representation contributes severe overhead.The evaluation is limited to TFLOPS at 4 heads and 16K context length because dynamic block-sparse mask generation is difficult through compilation.Source: §A.5.2 · p. 49, Table 8 · p. 52
- For 64-block MHA, VSA and Triton VSA have similar memory use with almost no sparsity-ratio correlation, while FlashInfer memory grows with sparsity ratio.In GQA, FlashInfer uses less memory than in MHA, and FA2 Sparse uses less than FlashInfer; the passage also reports lower FlashInfer memory at 128 versus 64 block size in MHA.Source: §A.5.2 · p. 48, Figure 19 · p. 51, Table 6 · p. 51
A.6 DETAILS OF CONTEXT PARALLEL ATTENTION PERFORMANCE
- LoongTrain's DoubleRing design uses inter-window prefetching for superior forward performance to USP, but extra backward communication and synchronization leave it overall comparable to USP.Ring P2P communication volume cannot be adjusted, and the slowest inter-node link can underutilize overall bandwidth.Source: §A.6 · pp. 53–54
- Hybrid USP and LoongTrain improve performance in FULL and CAUSAL scenarios and stability in document scenarios, where performance declines with reduced computation.The document-scenario stability mitigates limitations of Ulysses-only or Ring P2P-only designs.Source: §A.6 · p. 53, Figure 20 · p. 54, Figure 21 · p. 55
- In FULL, Ring P2P efficiency remains essentially constant as distributed scale grows when communication overlaps computation; in CAUSAL, reduced per-stage computation can leave communication exposed.At 8 nodes, reported CAUSAL forward degradation is attributed mainly to machine instability, where one underperforming GPU can stall the ring.Source: §A.6 · p. 53, Figure 20 · p. 54, Figure 21 · p. 55
- Variable-length DOCUMENT workloads fluctuate because padding changes per-GPU computation while communication stays constant, and sampling changes computational sparsity.The passage reports similar Ring P2P trends for CAUSAL DOCUMENT and FULL DOCUMENT; the hybrid designs show improved stability in these settings.Source: §A.6 · p. 53, Figure 22 · p. 55
Related papers
This paper cites
- Attention Is All You Need2017
- BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding2018
- Language Models are Few-Shot Learners2020
- Training language models to follow instructions with human feedback2022
- GPT-4 Technical Report2023
- DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning2025