Skip to main content

Mamba SSM - State Space Models optimized for Apple Silicon

Project description

Mamba SSM for macOS Apple Silicon

Mamba 1 and Mamba 2 State Space Models for Apple Silicon

Apple Silicon Python PyTorch PyPI License

Training and inference of Mamba 1 & 2 on Apple Silicon with MPS acceleration. Works without CUDA/Triton. Supports CLI, Python API, and interactive demos.

Installation

pip install mamba-ssm-macos

Or install from source:

git clone https://github.com/purohit10saurabh/mamba-ssm-macos.git
cd mamba-ssm-macos
uv sync                                     # or: pip install -r requirements.txt

Quick Start

python -m scripts.download_models mamba1    # Mamba 1 (493MB)
python -m scripts.download_models mamba2    # Mamba 2 (493MB)

make run-mamba1                             # Quick Mamba 1 demo
make run-mamba2                             # Quick Mamba 2 demo

Prerequisites: macOS 12.3+ with Apple Silicon, Python 3.10+, 8GB+ RAM recommended.

Usage

Text Generation

python -m scripts.run_models mamba1 --prompt "The future of AI" --max-length 50
python -m scripts.run_models mamba2 --prompt "The future of AI" --max-length 30
python -m scripts.run_models mamba1 --prompt "Once upon a time" --temperature 0.8
python -m examples.02_text_generation --interactive

Examples

python -m examples.01_core_modules     # Core modules usage
python -m examples.02_text_generation  # Text generation demo
python -m examples.03_training         # Training example

Makefile Commands

make download-models   # Download both models
make run-mamba1        # Quick Mamba 1 demo
make run-mamba2        # Quick Mamba 2 demo
make test-quick        # Fast integration test
make test              # Full test suite

Training

See examples/03_training.py for a full example. Snippet:

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()

Repository Structure

mamba-ssm-macos/
├── mamba_ssm/              # Core library (models, modules, ops, utils)
├── scripts/                # download_models.py, run_models.py
├── tests/                  # unit/, integration/, run_unit_tests.py
├── examples/               # 01_core_modules, 02_text_generation, 03_training
├── Makefile
└── pyproject.toml

Troubleshooting

"Model files not found" — Run make download-models or python -m scripts.download_models mamba1|mamba2.

"MPS not available" — Check with python -c "import torch; print(torch.backends.mps.is_available())". Falls back to CPU automatically.

Import errors — Use module syntax: python -m examples.02_text_generation.

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

Contributing

Contributions are welcome — bug fixes, performance improvements, docs, and new features. Open an issue or submit a PR.

git clone https://github.com/purohit10saurabh/mamba-ssm-macos.git
cd mamba-ssm-macos
uv sync --extra dev
make test

License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mamba_ssm_macos-1.0.1.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mamba_ssm_macos-1.0.1-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file mamba_ssm_macos-1.0.1.tar.gz.

File metadata

  • Download URL: mamba_ssm_macos-1.0.1.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mamba_ssm_macos-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f84eadfea95647ba69eed361a744df41a98cb84c69bdf6e1708cc3f21615be7b
MD5 3795aa373fb4d196e071efbcc5eebccd
BLAKE2b-256 8c9f875be208fe3079e2d5f5d56e3051b61f08d66799640acfc305c14e4905e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mamba_ssm_macos-1.0.1.tar.gz:

Publisher: publish.yml on purohit10saurabh/mamba-ssm-macos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mamba_ssm_macos-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mamba_ssm_macos-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81e3d9fd52e2e3f2db6ec613d048e9696b572a17c27eb27a67e61547ba01e22d
MD5 253beb54c2edfe97373d2ba3dbf760a5
BLAKE2b-256 fd92a8d33605c4ebfc0370dce773c85ecadbab3ca5916c9a04d3be2a7046de42

See more details on using hashes here.

Provenance

The following attestation bundles were made for mamba_ssm_macos-1.0.1-py3-none-any.whl:

Publisher: publish.yml on purohit10saurabh/mamba-ssm-macos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page