【pytorch】【进行中】基本配置

2019年12月07日    Author:Guofei

文章归类: 0x26_torch    文章编号: 261


版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2019/12/07/torch_setting.html

Edit

GPU

import torch

torch.cuda.is_available() # 返回 True/False 表示GPU是否可用
torch.cuda.device_count() # 可用的GPU数量

转为GPU


device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

model.to(device) # 模型
mytensor = my_tensor.to(device) # tensor

model = nn.DataParallel(model)

案例

model = Model(input_size, output_size)
if torch.cuda.device_count() > 1:
  print("Let's use", torch.cuda.device_count(), "GPUs!")
  # dim = 0 [30, xxx] -> [10, ...], [10, ...], [10, ...] on 3 GPUs
  model = nn.DataParallel(model)

model.to(device)

您的支持将鼓励我继续创作!
WeChatQR AliPayQR qr_wechat