步骤一:PyTorch官网安装
PyTorch官网:https://pytorch.org/
根据PyTorch官网的安装提示,选择合适版本后会生成安装语句,拷贝安装语句到Anaconda相应虚拟环境中,即可一键安装。
步骤二:检查GPU是否可用
- 进入环境:
ipython

- 导入pytorch包:
import torch
- 查看cuda是否可用:
torch.cuda.is_available()
- 查看cuda设备的数量:
torch.cuda.device_count()
- 查看当前使用的cuda编号:
torch.cuda.current_device()
- 查看GPU设备名:
torch.cuda.get_device_name()
- 查看设备容量:
torch.cuda.get_device_capability(0)
在PyCharm中检查GPU是否可用
- 代码:
import torch
def gpu_is_available():
print('\nGPU details:')
print(f' gpu_is_available : ', torch.cuda.is_available())
print(f' cuda_device_count : ', torch.cuda.device_count())
print(f' cuda_device_name : ', torch.cuda.get_device_name())
print(f' cuda_device_capability: ', torch.cuda.get_device_capability(0))
gpu_is_available()
- 效果:

PyTorch安装与GPU检测指南
本文提供了PyTorch的官网安装步骤,包括在Anaconda虚拟环境中执行安装命令。之后,详细阐述了如何使用Python交互式环境(iPython)和PyCharm检查GPU是否兼容及可用,通过torch.cuda的相关函数查询CUDA版本、设备数量、设备名和设备容量。
1万+

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



