For Apple M3, you'll be using Apple's Metal Performance Shaders (MPS) backend instead of CUDA. The good news is that PyTorch has excellent support for Apple Silicon GPUs!
Updated requirements.txt for Apple M3
# Core ML/DL Framework
torch==2.3.1
torchvision==0.18.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
-
Install PyTorch with MPS support:
pip install torch==2.3.1 torchvision==0.18.1
The standard PyTorch wheels from PyPI already include MPS support for macOS, so you don't need special index URLs like with CUDA.
-
Install remaining packages:
pip install -r requirements.txt
-
Install Poppler (system dependency):
brew install poppler
Using GPU on Apple M3
To use the GPU on your M3, you'll use the mps device instead of cuda:
import torch
# Check if MPS is available
if torch.backends.mps.is_available():
device = torch.device("mps")
print("MPS device found!")
else:
device = torch.device("cpu")
print("MPS device not found, using CPU")
# Use it in your code
model = model.to(device)
tensor = tensor.to(device)
For Transformers/Accelerate
When using Hugging Face libraries, you can specify the device:
from transformers import AutoModel
# Load model directly to MPS
model = AutoModel.from_pretrained("bert-base-uncased").to("mps")
# Or with Trainer
from transformers import TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
use_mps_device=True, # This enables MPS
# ... other arguments
)
With Accelerate:
from accelerate import Accelerator
accelerator = Accelerator()
# Accelerate will automatically detect and use MPS
Important Notes for Apple Silicon
-
Performance: MPS acceleration on M3 is very good, but some operations might still be faster on CPU for small models. Test both to see what works best for your use case.
-
Memory: Apple Silicon uses unified memory, so you share RAM between CPU and GPU. The M3 base model has 8GB, Pro has 18GB or 36GB, and Max has up to 128GB.
-
Compatibility: While most PyTorch operations work with MPS, some advanced operations might fall back to CPU. PyTorch will usually handle this automatically.
-
Environment Variable: You can set this to suppress MPS warnings:
export PYTORCH_ENABLE_MPS_FALLBACK=1
The versions I've provided are all tested to work well with Apple Silicon and should give you good GPU acceleration on your M3!