To leverage the Apple M3 GPU (with Metal Performance Shaders) on your Mac, you need to ensure your Python packages are compatible with ARM64 (Apple Silicon) and MPS (Metal) support. Here's how to configure your requirements.txt and install the correct versions for Python 3.12.9 and Apple M3:
✅ Updated requirements.txt for Apple M3 (ARM64)
# PyTorch with Metal (MPS) support (for Apple Silicon)
torch==2.4.1
torchvision==0.19.1
# Hugging Face Ecosystem
transformers==4.41.2
datasets==2.20.0
accelerate==0.31.0
evaluate==0.4.2
# Utilities and Metrics
seqeval==1.2.2
Pillow==10.3.0
tensorboard==2.17.0
# PDF processing
pdf2image==1.17.0
🔧 Installation Instructions for Apple M3
1. Install PyTorch with MPS Support
Apple Silicon (M1/M2/M3) uses Metal instead of CUDA. PyTorch 2.4.1 and later versions include MPS support. Install via pip:
pip install torch==2.4.1 torchvision==0.19.1
Note: If you encounter issues, ensure you're using the latest version of macOS (Sonoma 14.0+), as older macOS versions may lack full MPS support.
2. Verify MPS Support
After installation, verify that PyTorch is using the GPU:
import torch
print(torch.backends.mps.is_available()) # Should return True
print(torch.cuda.is_available()) # Should return False (no CUDA on M3)
3. Install Poppler (System Dependency for pdf2image)
pdf2image relies on Poppler, which must be installed via Homebrew:
brew install poppler
Add Poppler to your PATH if necessary:
export PATH="/opt/homebrew/opt/poppler/bin:$PATH"
4. Install Remaining Dependencies
Once PyTorch is installed, proceed with the rest:
pip install -r requirements.txt
🚨 Known Limitations and Workarounds
-
PyTorch MPS Support:
- Some operations (e.g.,
torch.nn.functional.dropout) may have bugs or performance issues on M3. Use torch.device("mps") for GPU acceleration.
- For models requiring CUDA (e.g., some Hugging Face models), consider using Rosetta 2 (for x86 compatibility) or switching to a Linux VM (via WSL2 or Docker).
-
torchvision Compatibility:
- Ensure
torchvision matches your PyTorch version (e.g., torch==2.4.1 + torchvision==0.19.1).
-
pdf2image and Poppler:
🧪 Test Your Setup
Run a simple test to confirm everything works:
import torch
import pdf2image
# Test PyTorch MPS
device = torch.device("mps")
x = torch.rand(3, 3).to(device)
print("PyTorch is using MPS:", torch.cuda.is_available())
# Test pdf2image
images = pdf2image.convert_from_path("example.pdf")
print("PDF converted to", len(images), "images")
📝 Notes
Let me know if you need help with specific models or workflows! 🚀