【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

windows系统下安装pytorch0.4.0,在linux系统下安装时只需要将命令中的”win_amd64″换成”linux_x86_64”即可。(大部分如此,具体的还要看你系统,不过方法都是一样的)

Python3.6+pip安装cpu版本

pip install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl

Python3.6+pip安装gpu版本 目前 gpu 版本支持 cuda8.0 , cuda9.0cuda9.1 ,请选择对应的版本下载安装,不要同时执行下面三个命令

pip install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip install http://download.pytorch.org/whl/cu91/torch-0.4.0-cp36-cp36m-win_amd64.whl

1.查看pytorch是否存在以及pytorch的版本

import torch
print(torch.__version__)

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

2.查看cuda是否可用

print(torch.cuda.is_available())

3.查看cuda版本

print(torch.version.cuda)

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

4.查看当前工作的GPU

print(torch.cuda.current_device())

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

5.查看gpu的数目

print(torch.cuda.device_count())

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

6.设置工作GPU

print(torch.cuda.current_device())
torch.cuda.set_device(1)
print(torch.cuda.current_device())

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

也有的方法说下述方式也可以实现切换GPU但需要将这句话写在”import torch”之前。

os.environ[“CUDA_VISIBLE_DEVICES”] = ‘0’

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

7.查看gpu名字,设备索引默认从0开始:

print(torch.cuda.get_device_name(0))
print(torch.cuda.get_device_name(1))

【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

Original: https://blog.csdn.net/m0_58810879/article/details/122147996
Author: neu_eddata_yjzhang
Title: 【PYTORCH】Pytorch0.4.0安装教程与GPU配置大合集(含测试代码)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/709228/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球