MiniMax Sparse Attention (MSA)
github.com/minimax-ai/msa- Category
- AI Tools
- Rank
- No. 1282Tools index
Previous survey · No. 1257 ·
- Pricing
- Open Source
- Type
- TOOL
- Use case
- Models: Train & Run
- Builder
- @MiniMax_AI
- GitHub
- 441 stars
- Date
About
MSA (the fmha_sm100 package) provides dense FlashAttention and sparse top-k attention kernels for NVIDIA SM100 (Blackwell) GPUs. This Fireworks integration branch vendors a KV-outer sparse prefill backend developed by Fireworks AI and routes sparse prefill through it when GQA is at least 8, falling back to the original MiniMax MSA CuTe kernels below that, all behind an unchanged fmha_sm100 / fmha_sm100_plan Python API. The practical effect is faster prefill for MiniMax M3 inference without callers changing their code.
What it does
A Python package of attention kernels written for a single GPU generation, NVIDIA's SM100 Blackwell parts. Attention is the step where each token in a model looks back over earlier tokens. The sparse path runs in two passes: a cheap pass scores every 128-token block of the cache, a selection kernel keeps the 16 highest-scoring blocks per query, and full attention then runs over only those blocks. Dense attention and FP8 and 4-bit quantized variants ship in the same package. Kernels are compiled on your machine the first time each variant is used, not shipped as prebuilt binaries.
Why it's ranked here
The case rests on specificity. MiniMax publishes this under MIT and lists every bundled third-party piece with its license: NVIDIA CUTLASS under BSD-3-Clause, FlashInfer and TensorRT-LLM derived code under Apache-2.0. The sparse kernels are checked against a plain PyTorch reference that gathers the same blocks and runs ordinary attention, and a BF16 case passes only above a cosine similarity of 0.9999. The limits are just as concrete: one GPU family, Linux on x86, and a narrow set of supported shapes. That makes it a strong pick for teams already serving models on Blackwell hardware and irrelevant to everyone else.
What's good
The input contracts are written down and enforced. The sparse planner rejects unsupported settings up front, and the dense entry point checks that block indexes are ascending, padded only at the end, and inside each sequence's page count. Compiled kernels are cached per variant behind a file lock, so parallel processes do not rebuild the same kernel, and an environment variable moves the cache. The benchmark covers six workloads, from dense prefill to sparse decode, in FP8 and BF16, and writes tab-separated output that can be compared run to run. The README states which entry points are stable and which may change without notice.
Tradeoffs
Hardware reach is one family: the compiler flags target only SM100 and SM103, and ARM Linux is listed as untested. The first run spends 30 seconds to a few minutes compiling. Shape support is narrow: the sparse paths assume head dimension 128, the block selection kernel accepts exactly 16 blocks, and sparse prefill requires causal masking over paged caches. Loading the sparse stack adds a directory to the Python import path, which the code itself warns can shadow same-named modules. The linked branch is described as routing some prefill through a Fireworks backend, but nothing in the repository text read documents that routing, so it is unverified.
How to use it well
Built for inference engineers serving long-context models on Blackwell GPUs who are comfortable with a plan-then-run attention interface. Run the bundled smoke test first to warm the compile cache, then run the regression suites on your own shapes before trusting a configuration; tests and benchmarks all need a CUDA device. If you already call the dense kernel, the bridge layer swaps in sparse prefill without restructuring the call site. Import the sparse stack lazily, as its own notes advise, because it pulls in the full DSL toolchain. It does nothing for GPUs older than SM100, and the quantized prefill and decode paths are forward-only.
Technical notes+
python/fmha_sm100/jit.py renders per-variant CUDA from Jinja templates and builds with nvcc plus ninja, keyed on dtype, Q tile size, single warpgroup, sparse mode, page size (unpaged or 128 only; 256 is commented out), split-KV and GQA pack factor, with an impossible-combination filter; builds land in ~/.cache/minfer/fmha_sm100 (override MINFER_FMHA_CACHE_DIR) behind an fcntl lock, and flags target sm_100a and sm_103a. python/fmha_sm100/api.py keeps a module-level workspace cache sized for 16 devices and caches the SM count once per process; its input validator copies indexes to the host. python/fmha_sm100/sparse_fmha_adapter.py asserts kv_block_num in {4,8,16,32}, causal True and output_maxscore False, accepts qhead_per_kv in {1,2,4,8,16}, and hard-codes head_dim 128 for AOT kernel lookup. python/fmha_sm100/csrc/sparse_topk_select.cu rejects any topk other than 16 and clamps indexes past num_valid_pages to -1 in-kernel. python/fmha_sm100/sparse.py inserts the cute directory at the front of sys.path and documents the shadowing risk. tests/regression/test_sparse_attn.py imports the adapter under the dense names and checks cosine similarity against a PyTorch gather reference (0.9999 BF16, 0.999 FP8). benchmarks/bench_sparse_attention_ops.py hard-codes peak constants (4500 TFLOPS FP8, 8000 GB/s HBM) for its utilization column.
Observed
- License
- MIT, with SPDX MIT headers on self-authored files
- Vendored third-party code
- NVIDIA CUTLASS (BSD-3-Clause) as a git submodule; FlashInfer and TensorRT-LLM derived headers (Apache-2.0)
- Languages
- Python package with CUDA C++ kernels and CuTe-DSL Python kernels
- Python requirement
- 3.10 or newer, per pyproject.toml
- Hardware
- NVIDIA SM100 only; JIT flags target sm_100a and sm_103a
- Operating system
- Linux x86_64; aarch64 untested
- Install surface
- pip install from a recursive git clone (CUTLASS submodule required), or via the Hugging Face kernels library
- Interface
- Python library with a plan-then-run attention API; benchmark and test scripts, no CLI
- Compilation
- Kernels JIT-compiled with nvcc and ninja on first use, cached per variant
- Top-k selection kernel
- Accepts topk of 16 only, per sparse_topk_select.cu
- Tests
- Smoke, integration and regression suites in the tree; all require a CUDA device
Read from README.md, pyproject.toml, LICENSE, python/fmha_sm100/api.py, python/fmha_sm100/sparse.py, python/fmha_sm100/sparse_fmha_adapter.py, python/fmha_sm100/jit.py, python/fmha_sm100/csrc/sparse_topk_select.cu, python/fmha_sm100/cute/README.md, benchmarks/bench_sparse_attention_ops.py, tests/regression/test_sparse_attn.py.
Similar tools
Tags
Tech Stack
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.