文章目录 1 查看当前的device 2 cpu设备可以使用“cpu:0”来指定 3 gpu设备可以使用“cuda:0”来指定 4 查询CPU和GPU设备数量 5 从CPU设备上转换到GPU设备 5.1 torch.Tensor方法默认使用CPU设备 5.2 使用to方法将cpu的Tensor转换到GPU设备上 5.3 使用.cuda方法将cpu的Tensor转换到GPU设备上 1 查看当前的device 输入情况: import torch print("Default Device : {}".format(torch.Tensor([4, 5, 6]).device)) 输出情况: Default Device : cpu 2 cpu设备可以使用“cpu:0”来指定 输入情况 device = torch.Tensor([1, 2, 3], device="cpu:0")