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 and 1 others

Baidu Inc.

Published October 13, 2026 · on the feed October 16, 2026 · ▲ 10 · arXiv 2610.17901

Efficiency & inferenceModel architecture Full code arXiv ↗Hugging Face ↗

The abstract

Long-context training of large language and multimodal models couples structured attention masks (document, prefix-LM, share-question, sliding-window, block-sparse) with multi-node context parallelism, making the mask a dominant bottleneck. FlashMask's column-wise sparse mask compresses them from O(n^2) to O(n) via four query-axis boundary vectors, covering broad structured patterns. Implemented for Ampere GPUs, it neither exploits FlashAttention-3's TMA/WGMMA warp-specialized pipeline on Hopper nor supports distribution. The column-wise sparse mask is indexed by key positions but stores query-axis interval boundaries. Under any multi-chunk context-parallel assignment, it reduces per-rank mask localization to a provably zero-communication clip--shift--max on the boundary vectors, compatible with the single-GPU kernel. FlashMask-3 introduces a mask-aware Hopper kernel with three-role warp specialization atop FlashAttention-3's TMA/WGMMA pipeline, plus 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 uses topology-aware hierarchical routing. On a single H100 across 12 masks at 4K--128K context, it improves achieved TFLOPs over FlashMask, FlexAttention, and MagiAttention by 45--141%, 34--71%, and 2--44%. At context-parallel degrees 4--32 with 8K sequence per device, it attains 31--75% compute-communication overlap efficiency and improves throughput over Megatron-Core CP ring, Megatron-Core CP all-gather, and MagiAttention by 1.80times--3.71times, 1.71times--2.92times, and 1.09times--1.46times. In end-to-end training of a 118B-A14B MoE at 128K on 128 H100 GPUs, it raises throughput by 7.3--11.0% over a Dual Chunk all-gather baseline, with attention forward+backward 24.5--44.9% faster.

The Brief

3:11

A short podcast summary of the paper. Written and voiced by AI.

Transcript

FlashMask-3. Efficient and Expressive Mask-Aware Distributed Attention. By Guoxia Wang and eight others, from Baidu. Published on the thirteenth of October. Its code repository is worked out: about one hundred and twenty source files, with a readme and a licence.

Long-context training of large language and multimodal models combines two things: structured attention masks, such as document, prefix-LM, share-question, sliding-window and block-sparse masks, and context parallelism spread across many nodes. Together they make the mask a dominant bottleneck. The earlier FlashMask handled the first half well. Its column-wise sparse mask compresses these structured patterns from quadratic to linear size, using four boundary vectors along the query axis. But it was implemented for Ampere GPUs. It does not use the warp-specialized TMA and WGMMA pipeline that FlashAttention-3 offers on Hopper, and it does not support distribution at all.

The key observation is about how that mask is laid out. It is indexed by key positions, yet what it stores are interval boundaries along the query axis. Because of that, under any multi-chunk context-parallel assignment, working out each rank's local piece of the mask reduces to a clip, shift and max on the boundary vectors. The authors show this provably needs zero communication, and the result stays compatible with the single-GPU kernel.

FlashMask-3 is built on that. On a single GPU, it adds a mask-aware Hopper kernel with three-role warp specialization, sitting atop the FlashAttention-3 pipeline. For distribution, it adds three pieces: the zero-communication mask localization, a sparsity-aware load balancer called HCC-IPO, and a mask-aware overlap of compute and communication that prunes communication based on the mask. Its forward all-gather uses hierarchical routing that is aware of the network topology.

On a single H100, across twelve masks and contexts from four thousand to one hundred and twenty-eight thousand tokens, achieved TFLOPs improve by forty-five to one hundred and forty-one percent over FlashMask, by thirty-four to seventy-one percent over FlexAttention, and by two to forty-four percent over MagiAttention.

In the distributed setting, with context-parallel degrees from four to thirty-two and eight thousand tokens of sequence per device, it reaches thirty-one to seventy-five percent efficiency in overlapping compute with communication. Throughput improves over the Megatron-Core ring variant by one point eight zero to three point seven one times, and over MagiAttention by one point zero nine to one point four six times.

End to end, training a mixture-of-experts model of one hundred and eighteen billion parameters at a context of one hundred and twenty-eight thousand tokens on one hundred and twenty-eight H100 GPUs, throughput rises by seven point three to eleven percent over a Dual Chunk all-gather baseline, and the attention forward and backward passes run twenty-four point five to forty-four point nine percent faster.

The whole distributed design hangs on one property of a data structure. A mask that stores query-axis intervals can be cut up for each rank without any rank talking to another, and that turns what had been the bottleneck into a small local computation.

More with an account

Listen to every day’s papers

Daily playlists, deep dives, quests for the papers, and quizzes on their key terms.

Join free
KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.