版本:pytorch 1.0
指定GPU显卡
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
设定全局的tensor 初始化为 tensor.cuda()
if torch.cuda.is_available():
torch.set_default_tensor_type('torch.cuda.FloatTensor')
将CPU转为GPU的tensor
# self.model = TextCNNNet(self.kwargs).cuda()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")