PyTorch library for Mamba selective state space models (Mamba, Mamba-2, Mamba-3), with hardware-aware kernels and pretrained checkpoints
open sourceApache-2.0free
Mamba (the mamba-ssm package) is the reference PyTorch implementation of the Mamba state space model architecture by Albert Gu and Tri Dao: a subquadratic alternative to Transformers for sequence modeling, with a hardware-aware selective-scan design in the spirit of FlashAttention. It provides the selective SSM layer, the Mamba, Mamba-2 and Mamba-3 blocks, a full language model with generation scripts, and pretrained checkpoints from 130M to 2.8B parameters on Hugging Face. It builds on PyTorch. Not to be confused with the Mamba package manager.
Problems it solves
- train a sequence model that scales linearly with length instead of a Transformer
- try a state space model architecture in my PyTorch research code
- run long-context language modeling without quadratic attention cost
Features
- selective state space (SSM) layer with a fused CUDA scan
- Mamba, Mamba-2 and Mamba-3 blocks
- full language model and generation scripts
- pretrained Mamba and Mamba-2 checkpoints up to 2.8B parameters
- NVIDIA CUDA and AMD ROCm support
Limitations
- Runs on Linux with PyTorch; the fast selective-scan kernels need an NVIDIA GPU with CUDA 11.6+ (or an AMD GPU with ROCm) and are compiled or downloaded only when you opt in.1
- The pretrained checkpoints are research models trained on the Pile (up to 2.8B parameters), not instruction-tuned assistants.1
Alternatives
The same job
These do what Mamba does.
- RWKV An attention-free RNN language model architecture that trains like a transformer, with its reference code