Trainable Dynamic Mask Sparse Attention
Not on the map. Why?
Abstract (arXiv)
The increasing demand for long-context modeling in large language models (LLMs) is bottlenecked by the quadratic complexity of the standard self-attention mechanism. The community has proposed sparse attention to mitigate this issue. However, position-aware sparse attention methods rely on static sparse structures that lack adaptability to diverse query contexts, while content-aware sparse attention methods depend on heuristic key-value selection, hindering full differentiability. We introduce a trainable dynamic mask sparse attention mechanism, a method that merges the advantages of both position-aware and content-aware approaches. Dynamic Mask Attention (DMA) achieves this through three key innovations: First, it leverages value vector representations to generate content-aware dynamic masks, enabling the model to adaptively identify and attend to critical information. Second, it computes position-aware sparse weights in a hardware-friendly manner, efficiently skipping unnecessary computational regions. Finally, we demonstrate that the introduced dynamic mask and sparse weights do not obstruct gradients, supporting end-to-end training. We have validated the performance of DMA through comprehensive experiments. A large body of experimental evidence shows that DMA consistently holds a Pareto advantage over state-of-the-art sparse attention baselines in tasks including scaling laws, multi-query associative recall, standard benchmarks, and needle in a haystack tests, while also delivering up to a 10x overall speedup. These results highlight its ability to effectively balance model efficiency with long-context modeling capabilities. Our computational kernel code is now open-source at https://github.com/SmallDoges/flash-dmattn to encourage further research and application by the community.
Key facts. Cited by 6 papers in the map (data through 14 Oct 2026). Builds on 44 of its 59 references that are in the map. First posted on arXiv 4 Aug 2025.
Builds on
44 of 59 references.
References · 44
- 2017Attention Is All You Needcited by 60,361
- 2020Measuring Massive Multitask Language Understandingcited by 7,963
- 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,330
- 2018Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challengecited by 4,886
- 2023Mamba: Linear-Time Sequence Modeling with Selective State Spacescited by 4,718
- 2019HellaSwag: Can a Machine Really Finish Your Sentence?cited by 4,100
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
- 2023Generative Agents: Interactive Simulacra of Human Behaviorcited by 3,568
- 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,455
- 2020Longformer: The Long-Document Transformercited by 3,413
- 2017TriviaQA: A Large Scale Distantly Supervised Challenge Dataset for Reading Comprehensioncited by 2,955
- 2019PIQA: Reasoning about Physical Commonsense in Natural Languagecited by 2,883
32 more
- 2020The Pile: An 800GB Dataset of Diverse Text for Language Modelingcited by 2,411
- 2018Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answeringcited by 2,164
- 2024Scaling LLM Test-Time Compute Optimally can be More Effective than Scaling Model Parameterscited by 1,986
- 2019Transformer-XL: Attentive Language Models Beyond a Fixed-Length Contextcited by 1,850
- 2017Decoupled Weight Decay Regularizationcited by 1,831
- 2020Big Bird: Transformers for Longer Sequencescited by 1,684
- 2019Generating Long Sequences with Sparse Transformerscited by 1,546
- 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,417
- 2024Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Dualitycited by 1,336
- 2016The LAMBADA dataset: Word prediction requiring a broad discourse contextcited by 992
- 2022In-context Learning and Induction Headscited by 964
- 2024SnapKV: LLM Knows What You are Looking for Before Generationcited by 880
- 2023H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Modelscited by 832
- 2022GPT-NeoX-20B: An Open-Source Autoregressive Language Modelcited by 713
- 2024Quest: Query-Aware Sparsity for Efficient Long-Context LLM Inferencecited by 501
- 2023Model Tells You What to Discard: Adaptive KV Cache Compression for LLMscited by 474
- 2025Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attentioncited by 407
- 2016From Softmax to Sparsemax: A Sparse Model of Attention and Multi-Label Classificationcited by 341
- 2023Effective Long-Context Scaling of Foundation Modelscited by 303
- 2015Unitary Evolution Recurrent Neural Networkscited by 294
- 2024CodeAgent: Enhancing Code Generation with Tool-Integrated Agent Systems for Real-World Repo-level Coding Challengescited by 282
- 2023Zoology: Measuring and Improving Recall in Efficient Language Modelscited by 204
- 2024InfLLM: Training-Free Long-Context Extrapolation for LLMs with an Efficient Context Memorycited by 197
- 2024Flex Attention: A Programming Model for Generating Optimized Attention Kernelscited by 185
- 2024Scaling Laws and Compute-Optimal Training Beyond Fixed Training Durationscited by 170
- 2024SeerAttention: Learning Intrinsic Sparse Attention in Your LLMscited by 124
- 2021CKConv: Continuous Kernel Convolution For Sequential Datacited by 120
- 2024MagicPIG: LSH Sampling for Efficient LLM Generationcited by 111
- 2024ClusterKV: Manipulating LLM KV Cache in Semantic Space for Recallable Compressioncited by 65
- 2024HashAttention: Semantic Sparsity for Faster Inferencecited by 24
- 2024LLM×MapReduce: Simplified Long-Sequence Processing using Large Language Modelscited by 17
- 2025DAM: Dynamic Attention Mask for Long-Context Large Language Model Inference Accelerationcited by 4
Built on by
Citing papers per year: 2025: 2; 2026: 4.
6 papers.
- 2025NOSA: Native and Offloadable Sparse Attentioncited by 4
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Evictioncited by 3
- 2026VMonarch: Efficient Video Diffusion Transformers with Structured Attentioncited by 3
- 2026Elastic Threshold Attention: Learned Contextual Sparsity for Long-Context Decodingcited by 1
- 2026HierEdit: Region-Aware Hierarchical Diffusion for Efficient High-Resolution Editingcited by 0
- 2026A Self-Pruning Transformer: Extreme KV-Cache Compression with Universal Attentioncited by 0
- 2026A Self-Pruning Transformer: Extreme KV-Cache Compression with Universal Attention6 Oct 2026
- 2026Elastic Threshold Attention: Learned Contextual Sparsity for Long-Context Decoding16 Sep 2026
- 2026HierEdit: Region-Aware Hierarchical Diffusion for Efficient High-Resolution Editing17 May 2026
- 2026VMonarch: Efficient Video Diffusion Transformers with Structured Attention29 Jan 2026
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Eviction23 Oct 2025
- 2025NOSA: Native and Offloadable Sparse Attention15 Oct 2025