A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Data Training
Python
946
288 commits
updated Sep 23, 2026
roll API for MTP support and uneven shard handling; (2) extend FFA_FA4 to Ampere (sm80) and support multi-arch CUDA builds; (3) add fa4_func_with_sink to magi_attn_extensions; alongside several bug fixes and dependency updates.FFA_FA4 using forked Flash-Attention 4; (2) provide full support for native group collective kernels for both intranode and internode communication based upon DeepEP; (3) update the MagiAttention Blog with comprehensive Attention Benchmark on H100 and B200, demonstrating SOTA performance and near-linear scalability.FULL, with some code cleanup and bug fixes.MagiAttention is a next‑generation distributed attention mechanism—commonly called context‑parallel (CP)—that offers kernel‑level flexibility for diverse attention‑mask patterns while delivering linear scalability across distributed training setups. It is especially well suited for workloads involving ultra-long contexts and heterogeneous masks, e.g., autoregressive video generation with Magi-1.
Additionally, it integrates easily with mainstream training frameworks such as Megatron-LM, Pytorch FSDP and HuggingFace Transformers; see QuickStart for usage.
We are committed to continually improving the performance and generality of MagiAttention for the broader research community.
Stay tuned for exciting enhancements and new features on the horizon! Any feedback or contributions are very welcome!
To achieve linear scalability in distributed attention, we implemented the following key design innovations:
AttnSlice with a tailed kernelFlex‑Flash‑Attention (FFA)—natively designed to enable compact expression of diverse mask types and make distributed mask partitioning tractable, with performance comparable to Flash-Attention 3 on Hopper GPUs, and preliminary support for Blackwell via a forked Flash-Attention 4.If you are interested in the detailed methodology and implementation, please check our blog for more information.
We provide comprehensive documentation here for MagiAttention, including installation instructions, API references, usage examples, tuning guides, technical blogs, performance benchmarks, etc.
Please refer to our Installation documentation for detailed instructions on how to install MagiAttention from source.
Please refer to our QuickStart documentation on how to get started with MagiAttention, with simple code snippets for basic usage and examples for integrating with popular training frameworks like Megatron-LM, Pytorch FSDP and HuggingFace Transformers.
We provide additional magi_attn_extensions to offer supplementary utilities based on magi_attention, such as FlashAttention with Attention Sink.
Please refer to our Future Work documentation for upcoming features and improvements.
We present representative distributed-level benchmarks below for the most commonly used varlen causal mask on both H100 and B200 GPUs, highlighting MagiAttention’s performance and scalability versus other leading CP strategies.
For detailed performance benchmarks of MagiAttention on various hardware setups and (distributed) attention scenarios, please refer to our Benchmark blog.
We welcome and value any contributions and collaborations. Please check out CONTRIBUTING.md for how to get involved.
To collect your valuable feedback and stay updated with the latest news, releases, and discussions about MagiAttention, join our official WeChat group by scanning the QR code below:
If you find MagiAttention useful in your research, please cite:
@misc{magiattention2025,
title={MagiAttention: A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Mask Training},
author={Zewei, Tao and Yunpeng, Huang},
year={2025},
howpublished={\url{https://github.com/SandAI-org/MagiAttention/}},
}
We would like to thank everyone who contributed to the development of MagiAttention.
NOTE: Affiliations and emails listed might be as of the time of their (initial) contribution and outdated. Please refer to their GitHub accounts for the most up-to-date information.
Actively developing and maintaining the codebase.
| Member | Affiliations | GitHub Account | |
|---|---|---|---|
| Zewei Tao | SandAI | zeweitao@sand.ai | littsk |
| Yunpeng Huang | SandAI | yunpenghuang@sand.ai | Strivin0311 |
| Jin Li | SandAI, Tsinghua University | 2609835176@qq.com | lijinnn |
| Hao Chen | SandAI, Xiamen University | haoc80996@gmail.com | cherhh |
| Zhiyao Cen | SandAI, Tsinghua University | 2523403608@qq.com | cennn |
| Bowen Zeng | Zhejiang University | zbw.cs@zju.edu.cn | KevinZeng08 |
| Yufeng Yang | Minimax | 793626853@qq.com | demonatic |
We are deeply grateful for their valuable contributions during the initial research and bootstrapping phases of MagiAttention.
| Member | Affiliations | GitHub Account | |
|---|---|---|---|
| Qiangang Wang | Nanjing University | 522024330081@smail.nju.edu.cn | WT1W |
| Tao Bu | Nanjing University | 502024330002@smail.nju.edu.cn | Big-TRex |
| Hanwen Sun | Peking University | sunhanwen@stu.pku.edu.cn | hanwen-sun |
| WenYang Fang | Nanjing University | fwy@smail.nju.edu.cn | kagami4243 |
| Siyuang Yan | Nanjing University | siyuanyan@smail.nju.edu.cn | FibonaccciYan |
| Zixu Jiang | Nanjing University | 522023330040@smail.nju.edu.cn | 191220042 |
| Dingkun Xu | Nanjing University | 211220090@smail.nju.edu.cn | PureDimension |
| Mingyu Liang | Nanjing University | mingyuliang518@gmail.com | gaomusiki |
| Jingwei Xu | Nanjing University | jingweix@nju.edu.cn | paragonlight |
We sincerely thank the NVIDIA DevTech team—especially Jerry Chen cjerry@nvidia.com, Jiayu Sun jiayus@nvidia.com, and Jemiry Guo jemiryg@nvidia.com—for their continuous technical support.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Python
78.8%
C++
13.6%
Cuda
6.5%
A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Data Training
Python
946
288 commits
updated Sep 23, 2026
roll API for MTP support and uneven shard handling; (2) extend FFA_FA4 to Ampere (sm80) and support multi-arch CUDA builds; (3) add fa4_func_with_sink to magi_attn_extensions; alongside several bug fixes and dependency updates.FFA_FA4 using forked Flash-Attention 4; (2) provide full support for native group collective kernels for both intranode and internode communication based upon DeepEP; (3) update the MagiAttention Blog with comprehensive Attention Benchmark on H100 and B200, demonstrating SOTA performance and near-linear scalability.FULL, with some code cleanup and bug fixes.MagiAttention is a next‑generation distributed attention mechanism—commonly called context‑parallel (CP)—that offers kernel‑level flexibility for diverse attention‑mask patterns while delivering linear scalability across distributed training setups. It is especially well suited for workloads involving ultra-long contexts and heterogeneous masks, e.g., autoregressive video generation with Magi-1.
Additionally, it integrates easily with mainstream training frameworks such as Megatron-LM, Pytorch FSDP and HuggingFace Transformers; see QuickStart for usage.
We are committed to continually improving the performance and generality of MagiAttention for the broader research community.
Stay tuned for exciting enhancements and new features on the horizon! Any feedback or contributions are very welcome!
To achieve linear scalability in distributed attention, we implemented the following key design innovations:
AttnSlice with a tailed kernelFlex‑Flash‑Attention (FFA)—natively designed to enable compact expression of diverse mask types and make distributed mask partitioning tractable, with performance comparable to Flash-Attention 3 on Hopper GPUs, and preliminary support for Blackwell via a forked Flash-Attention 4.If you are interested in the detailed methodology and implementation, please check our blog for more information.
We provide comprehensive documentation here for MagiAttention, including installation instructions, API references, usage examples, tuning guides, technical blogs, performance benchmarks, etc.
Please refer to our Installation documentation for detailed instructions on how to install MagiAttention from source.
Please refer to our QuickStart documentation on how to get started with MagiAttention, with simple code snippets for basic usage and examples for integrating with popular training frameworks like Megatron-LM, Pytorch FSDP and HuggingFace Transformers.
We provide additional magi_attn_extensions to offer supplementary utilities based on magi_attention, such as FlashAttention with Attention Sink.
Please refer to our Future Work documentation for upcoming features and improvements.
We present representative distributed-level benchmarks below for the most commonly used varlen causal mask on both H100 and B200 GPUs, highlighting MagiAttention’s performance and scalability versus other leading CP strategies.
For detailed performance benchmarks of MagiAttention on various hardware setups and (distributed) attention scenarios, please refer to our Benchmark blog.
We welcome and value any contributions and collaborations. Please check out CONTRIBUTING.md for how to get involved.
To collect your valuable feedback and stay updated with the latest news, releases, and discussions about MagiAttention, join our official WeChat group by scanning the QR code below:
If you find MagiAttention useful in your research, please cite:
@misc{magiattention2025,
title={MagiAttention: A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Mask Training},
author={Zewei, Tao and Yunpeng, Huang},
year={2025},
howpublished={\url{https://github.com/SandAI-org/MagiAttention/}},
}
We would like to thank everyone who contributed to the development of MagiAttention.
NOTE: Affiliations and emails listed might be as of the time of their (initial) contribution and outdated. Please refer to their GitHub accounts for the most up-to-date information.
Actively developing and maintaining the codebase.
| Member | Affiliations | GitHub Account | |
|---|---|---|---|
| Zewei Tao | SandAI | zeweitao@sand.ai | littsk |
| Yunpeng Huang | SandAI | yunpenghuang@sand.ai | Strivin0311 |
| Jin Li | SandAI, Tsinghua University | 2609835176@qq.com | lijinnn |
| Hao Chen | SandAI, Xiamen University | haoc80996@gmail.com | cherhh |
| Zhiyao Cen | SandAI, Tsinghua University | 2523403608@qq.com | cennn |
| Bowen Zeng | Zhejiang University | zbw.cs@zju.edu.cn | KevinZeng08 |
| Yufeng Yang | Minimax | 793626853@qq.com | demonatic |
We are deeply grateful for their valuable contributions during the initial research and bootstrapping phases of MagiAttention.
| Member | Affiliations | GitHub Account | |
|---|---|---|---|
| Qiangang Wang | Nanjing University | 522024330081@smail.nju.edu.cn | WT1W |
| Tao Bu | Nanjing University | 502024330002@smail.nju.edu.cn | Big-TRex |
| Hanwen Sun | Peking University | sunhanwen@stu.pku.edu.cn | hanwen-sun |
| WenYang Fang | Nanjing University | fwy@smail.nju.edu.cn | kagami4243 |
| Siyuang Yan | Nanjing University | siyuanyan@smail.nju.edu.cn | FibonaccciYan |
| Zixu Jiang | Nanjing University | 522023330040@smail.nju.edu.cn | 191220042 |
| Dingkun Xu | Nanjing University | 211220090@smail.nju.edu.cn | PureDimension |
| Mingyu Liang | Nanjing University | mingyuliang518@gmail.com | gaomusiki |
| Jingwei Xu | Nanjing University | jingweix@nju.edu.cn | paragonlight |
We sincerely thank the NVIDIA DevTech team—especially Jerry Chen cjerry@nvidia.com, Jiayu Sun jiayus@nvidia.com, and Jemiry Guo jemiryg@nvidia.com—for their continuous technical support.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Python
78.8%
C++
13.6%
Cuda
6.5%