Patch mamba2_torch on Apple Silicon to bypass Triton imports.
Project description
mamba2-triton-guard
A tiny helper tool that patches an installed mamba2_torch so it can be imported on Apple Silicon (M1/M2/M3) even when Triton isn't available.
This is useful when:
- you're experimenting with Mamba 2 models on macOS,
- you only want to run on CPU/MPS,
- the library you installed assumes Triton is present and crashes at import time.
Note
This tool does not provide Triton kernels and does not make Triton work on macOS. It only makes the Python package importable by guarding or stubbing Triton-related imports.
Installation
Install from your local checkout or from a package index:
pip install mamba2-triton-guard
Or, from a local source tree:
pip install -e .
(Use whatever virtual environment workflow you prefer.)
Usage
-
Make sure
mamba2_torchis installed in the same environment:pip install mamba2-torch # example; use the actual source you have
-
Run the guard:
mamba2-triton-guard
This will:
- locate the installed
mamba2_torch - find its
ops/modules - wrap Triton imports in a
try/exceptwith a lightweight dummy Triton
- locate the installed
-
Test the import:
python -c "from mamba2_torch import Mamba2Config; print('ok')"
If that works, you can run your own script that imports and uses mamba2_torch.
How it works
-
The tool discovers the installed
mamba2_torchwithout importing it, so it doesn't trigger the failingimport triton. -
It scans the
ops/directory for files that directly import Triton. -
For each such file, it:
-
removes the raw
import tritonlines -
prepends a guarded block like:
try: import triton import triton.language as tl HAS_TRITON = True except ImportError: HAS_TRITON = False # define a tiny dummy Triton that accepts decorators ...
-
-
It also makes version checks conditional on
HAS_TRITON.
This keeps the module importable on platforms where Triton is not present.
Limitations
- This is a workaround for packages that aggressively import Triton at import time.
- It does not enable Triton kernels on macOS.
- If the upstream package changes its layout (different module names, no
ops/, etc.), you may need to update this tool. - Always run it inside the environment that actually holds
mamba2_torch.
CLI
usage: mamba2-triton-guard [-h] [-q]
Patch mamba2_torch to run on Apple Silicon without Triton.
options:
-h, --help show help and exit
-q, --quiet suppress per-file output
Development
-
Clone the repository.
-
Create and activate a virtual environment.
-
Install in editable mode:
pip install -e .
-
Run the CLI against an environment that has
mamba2_torchinstalled.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mamba2_triton_guard-0.1.0.tar.gz.
File metadata
- Download URL: mamba2_triton_guard-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
456f8103456c1eb79664e7d47df1688c49e808233bdc757c2f54fd7986bf6cd5
|
|
| MD5 |
a7e468bee8dcd3da0ffd8195a0742838
|
|
| BLAKE2b-256 |
3a267227ebdb2f3ac5d9d0868fc7f2d37e114aa965b140773a865ebdf36cba2e
|
File details
Details for the file mamba2_triton_guard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mamba2_triton_guard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
488d4033ee6600232ab11661c2f1c976ed44ae66cfe6961d6d6f0fac19c8d93c
|
|
| MD5 |
6903a83878af586de0ecf1960fd49425
|
|
| BLAKE2b-256 |
1cc087b4bb633d446c62e59cdc1bce5cbb0d635eb1679ea42b94a9fc0b432443
|