貌似mac支持了pytorch的显卡调用功能,通过以下函数进行启用
import torch
def setup_device(force_cpu=False):
if force_cpu:
return torch.device("cpu")
if torch.cuda.is_available():
return torch.device("cuda:0")
if torch.backends.mps.is_built():
return torch.device("mps:0")
return torch.device("cpu")
device = setup_device()
[文章导入自 http://qzq-go.notion.site/14649a7b4e75803587dbf8d24c438d85 访问原文获取高清图片]