Pytorch:torch,torchvision,cudatoolkit 对应的版本
https://pytorch.org/get-started/previous-versions/
下载torch以及torchvision,toolkit网址
http://download.pytorch.org/whl/torch_stable.html
下载下来的whl文件
在这个目录下
pip install xxxxxx.whl
在GPU上执行程序
a.自定义的参数需要转化为cuda支持的tensor
b.model需要转化为cuda支持的model
c.执行的结果需要和cpu的tensor计算时
tensor.cpu()把cuda的tensor转化为cpu的tensor
#定义一个device对象
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
例:将model定义在cuda上
my_linear = MyLinear().to(device)
本文介绍了如何在PyTorch中正确设置GPU环境,包括安装 torch、torchvision 和 cudatoolkit,如何将自定义参数、模型及运算结果适配CUDA,并通过device对象指定设备。重点讲解了如何将模型迁移到cuda并进行CPU与GPU间的转换操作。
3943

被折叠的 条评论
为什么被折叠?



