Pytorch Mac GPU 训练与测评

配置好GPU后-Pytorch Mac GPU 训练与测评

https://zhuanlan.zhihu.com/p/517699916

Pytorch Apple Silicon GPU 训练与测评 | Yunfeng's Simple Blog (vra.github.io)
(66条消息) pytorch之多GPU使用——#CUDA_VISIBLE_DEVICES使用 #torch.nn.DataParallel() #报错解决_夏普通的博客-CSDN博客

1. 
# windows GPU 用法 
# if torch.cuda.is_available():
#     if args.cuda:
#         torch.set_default_tensor_type('torch.cuda.FloatTensor')
#     if not args.cuda:
#         print("WARNING: It looks like you have a CUDA device, but aren't " +
#               "using CUDA.\nRun with --cuda for optimal training speed.")
#         torch.set_default_tensor_type('torch.FloatTensor')
# else:
#     torch.set_default_tensor_type('torch.FloatTensor')

# MAC GPU 用法
# Check that MPS is available
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.")

else:
    mps_device = torch.device("mps")

    # Create a Tensor directly on the mps device
    x = torch.ones(5, device=mps_device)
    # Or
    x = torch.ones(5, device="mps")

    # Any operation happens on the GPU
    y = x * 2

    # Move your model to mps just like any other device
    model = YourFavoriteNet()
    model.to(mps_device)

    # Now every call runs on the GPU
    pred = model(x)

2.
# windows GPU 用法 
device = torch.device('cuda') 
model = model.to(device)
# MAC GPU 用法
device = torch.device('mps')
model = model.to(device)

3. 
# windows GPU 用法
input = Variable(input, volatile=True).cuda()
# MAC GPU 用法
device = torch.device('mps')
input = Variable(input, volatile=True).to(device) 
4.
os.environ["CUDA_VISIBLE_DEVICES"] =....注释掉

Metal Overview - Apple Developer

你可能感兴趣的:(深度学习)