SandAI-org/MagiAttention
A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Data Training
What it does
MagiAttention is a distributed attention mechanism — a way to split the "attention" computation (the part of a neural network that lets tokens in a sequence look at each other) across multiple GPUs. This is often called context-parallel (CP).
It's built for two hard cases:
- Ultra-long contexts: inputs with very many tokens (e.g., long videos, long documents).
- Heterogeneous masks: different parts of the input need different attention patterns (e.g., some tokens can only look backward, others can look both ways).
The project claims linear scalability — meaning if you double the number of GPUs, you roughly halve the time per step, up to a point.
Why it matters
Standard attention implementations struggle when the input is very long or when the mask pattern is irregular. MagiAttention provides a flexible kernel (the low-level GPU code that does the math) that can express many mask types compactly, plus a distributed strategy that keeps all GPUs busy and avoids redundant communication.
Key design ideas (from the README)
Flexible Flash Attention Kernel (FFA): A custom attention kernel that can handle diverse mask patterns while performing comparably to Flash-Attention 3 on Hopper GPUs. It also has early support for Blackwell GPUs via a forked Flash-Attention 4.
Computation Load Balancing: A "dispatch solver" that splits the work into fine-grained chunks and assigns them to GPUs so each one does roughly the same amount of computation.
Zero-Redundant Communication: Instead of the common ring-style pattern where data passes from GPU to GPU, they use two custom primitives (GroupCast and GroupReduce) that avoid sending the same data twice, for both forward and backward passes.
Adaptive Multi-Stage Overlap: A scheduling strategy that overlaps computation and communication to hide latency, with manual or automatic tuning.
Who it's for
- Researchers and engineers training large models with very long inputs (e.g., autoregressive video generation with Magi-1).
- People using mainstream frameworks: Megatron-LM, PyTorch FSDP, HuggingFace Transformers.
Current status
- Latest release: v1.1.1 (May 2026)
- License: Apache 2.0
- Paper: arXiv:2505.13211
- Documentation: available at the project site
- Extensions: includes a drop-in FlashAttention integration with attention sink support
What's new in recent releases
- v1.1.1: Distributed
rollAPI for MTP support, uneven shard handling, FFA_FA4 extended to Ampere GPUs, multi-arch CUDA builds,fa4_func_with_sinkextension. - v1.1.0: Early Blackwell support via FFA_FA4 backend, native group collective kernels for intra/inter-node communication based on DeepEP, benchmark results on H100 and B200.
- v1.0.5: Learnable attention sink support, native group collective kernels for intranode communication.
Caveats
- The README does not provide installation steps or code examples directly — it links to external documentation.
- Performance claims ("SOTA", "near-linear scalability") are from the project's own benchmarks; the README links to those benchmark results rather than showing them inline.
- The project is under active development; some features are marked as experimental.
Related
- Project
- Project
- Project
- Dispatch
- Project