FlashMask-3:高效且富有表现力的掩码感知分布式注意力

·

研究论文 · 2026/10/16

FlashMask-3 针对长上下文训练中结构化注意力掩码与多节点上下文并行导致的瓶颈,提出了一种面向 Hopper 架构的掩码感知内核,在 FlashAttention-3 的 TMA/WGMMA 流水线上实现三角色 warp 特化,并扩展为分布式方案:零通信掩码定位、稀疏感知负载均衡器 HCC-IPO、以及掩码驱动的通信剪枝与计算-通信重叠(前向 all-gather 采用拓扑感知分层路由)。在单张 H100 上,4K 至 128K 上下文、12 种掩码下,其 TFLOPs 较 FlashMask、FlexAttention 和 MagiAttention 分别提升 45–141%、34–71% 和 2–44%。在上下文并行度 4–32、每设备序列长 8K 时,计算-通信重叠效率达 31–75%,吞吐量较 Megatron-Core CP ring、Megatron-Core CP all-gather 和 MagiAttention 分别提升 1.80–3.71 倍、1.71–2.92 倍和 1.09–1.46 倍。在 128 张 H100 上对 118B-A14B MoE 进行 128K 端到端训练,吞吐量较 Dual Chunk all-gather 基线提升 7.3–11.0%,注意力前向+反向快 24.5–44.9%。

该工作显著提升了长上下文训练中注意力掩码的计算效率与分布式扩展性,在多种掩码和并行配置下均取得大幅性能提升,并成功应用于百亿级 MoE 模型的端到端训练。

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.

阅读原文

参与讨论