For those who couldn't install using conda
like me use pip
as following:-
Requirement:
- Any Macbook with apple silicon chip
- macOS version 12.3+
Installation:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Update:
No need of nightly version. Pytorch version 1.12 now supports GPU acceleration in apple silicon. Simply install using following command:-
pip3 install torch torchvision torchaudio
You may follow other instructions for using pytorch in apple silicon and getting your benchmark.
Usage:
Make sure you use mps
as your device as following:
device = torch.device('mps')
# Send you tensor to GPU
my_tensor = my_tensor.to(device)
Benchmarking (on M1 Max, 10-core CPU, 24-core GPU):
- Without using GPU
import torch
device = torch.device('cpu')
x = torch.rand((10000, 10000), dtype=torch.float32)
y = torch.rand((10000, 10000), dtype=torch.float32)
x = x.to(device)
y = y.to(device)
%%timeit
x * y
17.9 ms ± 390 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
- Using GPU (5x faster)
import torch
device = torch.device('mps')
x = torch.rand((10000, 10000), dtype=torch.float32)
y = torch.rand((10000, 10000), dtype=torch.float32)
x = x.to(device)
y = y.to(device)
%%timeit
x * y
3.43 ms ± 57.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)