pytorch在Mac上实现像cuda一样的加速
1. 参考:https://developer.apple.com/metal/pytorch/Mac M芯片或者AMD的GPU
2. 具体实现:
2.1 Requirements
macOS 12.3 or later
Python 3.7 or later
Xcode command-line tools:
xcode-select --install
2.2 准备anaconda或者miniconda或者自带的pip3
conda安装:
conda install pytorch torchvision torchaudio -c pytorch-nightly
pip安装:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
3. 应用检验:
import torch
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
x = torch.ones(1, device=mps_device)
print (x)
else:
print ("MPS device not found.")
# if not torch.backends.mps.is_available():
# if not torch.backends.mps.is_built():
# print("MPS not available because the current PyTorch install was not "
# "built with MPS enabled.")
# else:
# print("MPS not available because the current MacOS version is not 12.3+ "
# "and/or you do not have an MPS-enabled device on this machine.")
# mps_device = torch.device("mps")
# x = torch.ones(5, device=mps_device)
# # 或者 x = torch.ones(5, device="mps")
# y = x * 2
# model = YourFavoriteNet()
# model.to(mps_device)
# pred = model(x)

浙公网安备 33010602011771号