ubuntu16下安装pytorch

酆晔
2023-12-01

安装pytorch

No CUDA版本

# Python 3.5
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1.post2-cp35-cp35m-linux_x86_64.whl
pip3 install torchvision

CUDA10版本

# Python 3.5
pip3 install https://download.pytorch.org/whl/cu100/torch-1.0.1.post2-cp35-cp35m-linux_x86_64.whl
pip3 install torchvision

验证是否安装成功

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

正常情况应该输出类似如下结果:

tensor([[0.2710, 0.6443, 0.5779],
        [0.4283, 0.1401, 0.1689],
        [0.2173, 0.6645, 0.2762],
        [0.5044, 0.9063, 0.4861],
        [0.7070, 0.9941, 0.0107]])

检测GPU驱动和CUDA是否可用

import torch
if(torch.cuda.is_available()):
    print("cuda is available")
else:
    print("no cuda")

参考:https://pytorch.org/get-started/locally/

 类似资料: