arXiv:2610.17901cs.LGOct 2026

Manuscript Offprint

arXiv:2610.17901

FlashMask-3: Efficient and Expressive Mask-Aware Distributed Attention

Guoxia Wang, Qianyue He, Siming Wu, Haoyang Xie, Qiwen Bao, Jinle Zeng, Jiabin Yang, Tian Wu, Dianhai Yu

Abstract

Long-context training of large language and multimodal models couples expressive structured attention masks (document, prefix-LM, share-question, sliding-window, block-sparse) with multi-node context parallelism, exposing the mask as a dominant bottleneck. The column-wise sparse mask of FlashMask compresses such masks from O(n2)O(n^2) to O(n)O(n) via four query-axis boundary vectors and covers a broad family of structured patterns. Implemented for Ampere GPUs, FlashMask does not exploit FlashAttention-3's TMA/WGMMA warp-specialized pipeline on Hopper GPUs, and offers no distributed support. We observe that the column-wise sparse mask is indexed by key positions but stores query-axis interval boundaries. Under any multi-chunk context-parallel assignment, this property reduces per-rank mask localization to a provably zero-communication clip-shift-max on the boundary vectors, directly compatible with the single-GPU kernel. Building on this property, FlashMask-3 introduces a mask-aware Hopper kernel with a three-role warp specialization atop the FlashAttention-3 TMA/WGMMA pipeline, together with a mask-aware distributed extension: zero-communication mask localization, a sparsity-aware load balancer (HCC-IPO), and a mask-aware compute-communication overlap with mask-driven communication pruning, whose forward all-gather additionally adopts topology-aware hierarchical routing. On a single H100 GPU across 12 structured masks at context lengths from 4K to 128K, FlashMask-3 improves achieved TFLOPs over FlashMask, FlexAttention, and MagiAttention by 45% to 141%, 34% to 71%, and 2% to 44%, respectively. Under context-parallel degrees from 4 to 32 with 8K sequence per device, it attains 31% to 75% compute-communication overlap efficiency and improves throughput over Megatron-Core CP (ring), Megatron-Core CP (all-gather) and MagiAttention by 1.80× to 3.71×, 1.71× to 2.92× and 1.09× to 1.46× respectively. In end-to-end training of a 118B-A14B MoE model at a 128K context on 128 H100 GPUs, it raises throughput by 7.3% to 11.0% over a Dual Chunk all-gather baseline, with attention forward+backward 24.5% to 44.9% faster. The source code is available at https://github.com/PaddlePaddle/FlashMask.

1 Introduction

Long-context training of large language and multimodal models increasingly relies on structured attention masks, including document masks [Dao et al., 2022], prefix-LM masks [Wang et al., 2026], share-question masks [Deng et al., 2025], sliding-window masks [Beltagy et al., 2020], and block-sparse patterns [Child et al., 2019, Yuan et al., 2025, Lu et al., 2025], to encode training-data semantics

∗^{*}Equal contribution.

†^{\dagger}Corresponding author.

40th Conference on Neural Information Processing Systems (NeurIPS 2026).

within a single packed batch. As context grows toward hundreds of thousands of tokens and training scales to multi-node context parallelism [Liu et al., 2023, Jacobs et al., 2023, Narayanan et al., 2021], masks become a first-class bottleneck: mask materialization, mask-aware kernel scheduling, and mask-induced load imbalance [Jiang et al., 2025, Tao and Huang, 2025] come to dominate step time. Programmable attention compilers [He et al., 2024] handle arbitrary masks but trail FlashAttention-3 (FA3) [Shah et al., 2024] in Hopper throughput; FA3 itself first-classes only causal, full, and varlen-document masks. The column-wise sparse representation of FlashMask [Wang et al., 2024] fills the expressiveness gap by encoding masks through four O(n)O(n) boundary vectors, covering 12+ structured patterns within an exact tiled kernel [Dao et al., 2022, Dao, 2023]. However, FlashMask was implemented on Ampere GPUs and predates FA3: it exploits neither Hopper's TMA/WGMMA warp-specialized pipeline [Shah et al., 2024] nor any form of distributed context parallelism [Liu et al., 2023, Brandon et al., 2023, Narayanan et al., 2021].

We observe a structural property that resolves the distributed gap. Because the column-wise sparse mask is indexed by key positions but stores query-axis intervals [Wang et al., 2024], per-rank mask localization under any multi-chunk CP assignment reduces to an elementwise clip-shift-max on the boundary vectors, requiring no cross-rank communication and producing a rank-local tensor directly compatible with the single-GPU kernel (Theorem 1). Building on this property, we present FlashMask-3, 3^{3} which organizes mask-awareness along two axes: (i) a mask-aware Hopper kernel with three-role warp specialization integrating column-wise sparse scanning into the FA3 TMA/WGMMA pipeline (§3.1); and (ii) a mask-aware distributed extension combining zero-communication mask localization (§3.2), a sparsity-aware hierarchical load balancer (§3.3), and a mask-aware compute-communication overlap [Chang et al., 2024, NVIDIA, 2023] with topology-aware hierarchical routing and mask-driven communication pruning (§3.4).

Our main contributions are as follows:

• Mask-aware Hopper kernel. A three-role warp specialization (KV Index Generator, KV Loader, MMA Consumer) integrates column-wise sparse mask processing into the asynchronous TMA/WGMMA pipeline at near-zero overhead, complemented by a preemptive persistent-tile scheduler that restores SM-level balance under irregular masks.

• Mask-aware distributed extension. A zero-communication clip-shift-max mask localization with provable correctness; a sparsity-aware hierarchical load balancer (HCC-IPO); and a mask-aware compute-communication overlap with mask-driven communication pruning, whose forward all-gather uses topology-aware hierarchical routing and whose backward reduce-scatter is overlapped with attention recomputation through bitmask-AMO (Atomic Memory Operations) synchronization.

• Empirical evaluation. On a single H100 GPU across 12 structured masks at context lengths from 4K to 128K, FlashMask-3 improves achieved TFLOPs over FlashMask, FlexAttention, and MagiAttention by 45% to 141%, 34% to 71%, and 2% to 44%, respectively. Under context-parallel degrees from 4 to 32 with 8K sequence per device, it attains 31% to 75% compute-communication overlap efficiency and improves throughput over Megatron-Core CP (ring), Megatron-Core CP (all-gather) and MagiAttention by 1.80× to 3.71×, 1.71× to 2.92× and 1.09× to 1.46× respectively. In end-to-end training of a 118B-A14B MoE model at a 128K context on 128 H100 GPUs (CP degree 16), our distributed extension raises the training throughput by 7.3% to 11.0% over the same system using Dual Chunk balancing and all-gather communication.