Mamba SSM for macOS Apple Silicon
Mamba 1 and Mamba 2 State Space Models for Apple Silicon
Training and inference of Mamba 1 & 2 on Apple Silicon with MPS acceleration. Works without CUDA/Triton.
Installation
pip install mamba-ssm-macos
Prerequisites: macOS 12.3+ with Apple Silicon, Python 3.10+, 8GB+ RAM recommended.
Quickstart
import torch
from transformers import AutoTokenizer
from mamba_ssm import MambaLMHeadModel, generate_text_with_model, get_device
device = get_device()
model_name = "state-spaces/mamba-130m" # or "state-spaces/mamba2-130m"
model = MambaLMHeadModel.from_pretrained(model_name, device=device)
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
text = generate_text_with_model(model, tokenizer, "Once upon a time", device, max_length=50, temperature=0.8)
print(text)
The model is downloaded from Hugging Face Hub on first run and cached under ~/.cache/huggingface/.
Training
import torch
from torch import nn
from mamba_ssm.modules.mamba2 import Mamba2
model = nn.Sequential(nn.Embedding(1000, 128), *[Mamba2(d_model=128, d_state=64, d_conv=4, expand=2, headdim=64, ngroups=1, chunk_size=256, device='mps') for _ in range(2)], nn.LayerNorm(128), nn.Linear(128, 1000, bias=False)).to('mps')
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4)
criterion = nn.CrossEntropyLoss()
for input_ids, labels in dataloader:
optimizer.zero_grad()
logits = model(input_ids)
loss = criterion(logits.view(-1, logits.size(-1)), labels.view(-1))
loss.backward()
optimizer.step()
See examples/03_training.py for a complete training example.
Examples
Clone the repo to run examples:
git clone https://github.com/purohit10saurabh/mamba-ssm-macos.git
cd mamba-ssm-macos
uv sync
python -m examples.01_core_modules # Core modules usage
python -m examples.02_text_generation --interactive # Text generation
python -m examples.03_training # Training
Troubleshooting
"MPS not available" — Check with python -c "import torch; print(torch.backends.mps.is_available())". The library falls back to CPU automatically.
Slow first run — Initial from_pretrained downloads ~500MB of weights from Hugging Face Hub. Subsequent runs use the local cache.
Development
git clone https://github.com/purohit10saurabh/mamba-ssm-macos.git
cd mamba-ssm-macos
uv sync --extra dev
make test
Available make targets: test, test-unit, test-integration, test-quick, format, format-check, clean. See the Makefile for details.
Citation
Also available via GitHub's "Cite this repository" button (CITATION.cff).
@software{purohit2026mamba_ssm_macos,
title={Mamba SSM for macOS Apple Silicon},
author={Purohit, Saurabh},
year={2026},
url={https://github.com/purohit10saurabh/mamba-ssm-macos}
}
Original Mamba papers
@article{gu2023mamba,
title={Mamba: Linear-Time Sequence Modeling with Selective State Spaces},
author={Gu, Albert and Dao, Tri},
journal={arXiv preprint arXiv:2312.00752},
year={2023}
}
@article{dao2024transformers,
title={Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality},
author={Dao, Tri and Gu, Albert},
journal={arXiv preprint arXiv:2405.21060},
year={2024}
}
References
- state-spaces/mamba — Original implementation
- state-spaces/mamba1-130m — Mamba 1 130M pre-trained model
- state-spaces/mamba2-130m — Mamba 2 130M pre-trained model
Contributing
Feel free to open an issue or submit a PR. See Development for the local setup.
License
Apache 2.0 — see LICENSE.
Metadata
Release files for mamba-ssm-macos 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mamba_ssm_macos-1.0.2.tar.gz | 30.3 kB | With provenance | Details for mamba_ssm_macos-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mamba_ssm_macos-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for mamba_ssm_macos-1.0.2-py3-none-any.whl |
Total release size: 63.7 kB
Release files / mamba_ssm_macos-1.0.2.tar.gz
| Download URL | mamba_ssm_macos-1.0.2.tar.gz |
|---|---|
| Size | 30.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a49f7676a651b3f3ba384f0a68319840abd8f52293194410028065e044798acc
|
|
BLAKE2b-256 checksum How to use checksums |
be2e2cd4ab4c31e2f3b9f409e6f8d8b2db407acd6903c1f5f3a383ec62f1da4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logRelease files / mamba_ssm_macos-1.0.2-py3-none-any.whl
| Download URL | mamba_ssm_macos-1.0.2-py3-none-any.whl |
|---|---|
| Size | 33.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8deec4f5f5d239e5fa93b6f821b2b2df2776668c01456f0bbe2bd3cd661167d
|
|
BLAKE2b-256 checksum How to use checksums |
9cfad9e51f826d12d4bc05fc0a4486354b5667b8fa4299b207636760926e641c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logSecurity for mamba-ssm-macos 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mamba_ssm_macos-1.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.