-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add Apple M-series (MPS) device support to Python scripts #977
Copy link
Copy link
Open
Description
Summary
Most standalone Python scripts (.py) only detect CUDA or fall back to CPU, ignoring Apple Silicon's MPS backend. This means users with M1/M2/M3/M4 Macs always fall back to CPU, missing significant GPU acceleration.
Problem
~29 Python files use this pattern:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")This should be updated to also detect MPS:
if torch.cuda.is_available():
device = torch.device("cuda")
elif torch.backends.mps.is_available():
device = torch.device("mps")
else:
device = torch.device("cpu")Additional considerations
pin_memory=Truein DataLoaders should be conditional on CUDA availabilitytorch.compileshould be guarded (limited MPS support)- DDP scripts are inherently CUDA-only and should be left as-is
Scope
- All standalone
.pytraining/inference scripts in ch04-ch07, appendix, and pkg/tests - Excludes DDP-specific scripts (appendix-A DDP scripts, ch05/10 multi-GPU)
- Excludes notebooks (many already have MPS support)
🤖 Generated with Claude Code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels