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=True in DataLoaders should be conditional on CUDA availability
torch.compile should be guarded (limited MPS support)
- DDP scripts are inherently CUDA-only and should be left as-is
Scope
- All standalone
.py training/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
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:
This should be updated to also detect MPS:
Additional considerations
pin_memory=Truein DataLoaders should be conditional on CUDA availabilitytorch.compileshould be guarded (limited MPS support)Scope
.pytraining/inference scripts in ch04-ch07, appendix, and pkg/tests🤖 Generated with Claude Code