Run CUDA-hardcoded PyTorch repos on Apple Silicon (MPS) with zero source edits.
Project description
mpsify
Run CUDA-hardcoded PyTorch repos on Apple Silicon (MPS) — with zero source edits.
You inherit someone's training script. It's full of .cuda(), device='cuda',
torch.cuda.amp, map_location='cuda'. PyTorch-MPS could run the actual math
fine on your Mac — but the code dies before it gets the chance. mpsify patches
torch at import time so all of that transparently retargets to MPS.
pip install mpsify
Usage
Point it at any script — no edits to their code:
python -m mpsify train.py --epochs 10 --lr 1e-3
# or, after install, the console script:
mpsify train.py --epochs 10 --lr 1e-3
Or drop one line at the top of your entry file:
import mpsify # patches torch on import
The wrapper (python -m mpsify) is preferred: it sets
PYTORCH_ENABLE_MPS_FALLBACK=1 before torch loads, which the import form
can't always guarantee.
What it does
| CUDA thing | Retargeted to |
|---|---|
torch.cuda.is_available() |
True |
.cuda(), .to('cuda'), device='cuda' |
mps |
torch.device('cuda') |
mps |
torch.load(map_location='cuda') |
mps |
DataLoader(pin_memory=True) |
pin_memory=False (no pinned memory on MPS) |
torch.cuda.amp autocast / GradScaler |
no-op, fp32 (see knobs) |
nn.DataParallel |
identity (single device) |
nccl backend |
gloo |
Ops with no Metal kernel fall back to CPU automatically. mpsify catches those
fallbacks, warns once per op live, and prints a summary at exit — so you can
see exactly which ops are your latency hot spots.
Libraries with no Metal backend at all (bitsandbytes, apex, deepspeed,
flash_attn, triton) are detected and reported loudly instead of crashing
cryptically.
Diagnosing slow ops
python -m mpsify --profile train.py
Runs a dispatch-level profiler that counts calls and times ops. This adds per-op overhead — use it for a diagnostic pass, not production.
Knobs
| Env var | Effect |
|---|---|
MPSIFY_AMP=1 |
Re-enable AMP/autocast (default off = fp32, correct but slower). AMP on MPS is where correctness gets dicey. |
MPSIFY_QUIET=1 |
Suppress live fallback warnings; keep the exit summary. |
Scope
Handles pure-PyTorch repos (torchvision / timm models — ResNet, EfficientNet,
ViT, etc.). It does not translate custom .cu/Triton kernels or make
CUDA-only libraries (flash-attention, DeepSpeed, apex) actually work — those are
detected and reported, not fixed.
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 mpsify-0.1.0.tar.gz.
File metadata
- Download URL: mpsify-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ef493054e50207974c98e63d241b0609651d51f424455d5ab4d18b3874e4dfb
|
|
| MD5 |
155d140aabe36823c09eca3ee715cfaa
|
|
| BLAKE2b-256 |
e53044d074d3bc261e1047eb00c9a8174e5ba4dc5b059b3207e00284f7db0f40
|
File details
Details for the file mpsify-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mpsify-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
562951ca70a7b2ad5c6498f9c501436c44978722830bb0d29966d0ffbd956f61
|
|
| MD5 |
1071af5e3378b3e579c6ac1693948ad7
|
|
| BLAKE2b-256 |
eff713cb973ed13ec80fb37f23411919e9207062bb106dbc7f502fe8a8723ad8
|