【问题标题】:Why can't I use my graphic card with PyTorch?为什么我的显卡不能与 PyTorch 一起使用?
【发布时间】:2021-07-03 19:27:03
【问题描述】:

我正在尝试在我的 Ubuntu 18.04 中使用带有 GPU 的 PyTorch。 GPU 是 GeForce GTX 1070。

nvidia-smi:

| NVIDIA-SMI 460.67       Driver Version: 460.67       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:0B:00.0 Off |                  N/A |
| 21%   49C    P2    60W / 180W |   4598MiB /  8119MiB |     17%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1070    Off  | 00000000:42:00.0 Off |                  N/A |
|  0%   48C    P8     7W / 180W |     20MiB /  8117MiB |      0%      Default |
|                               |                      |                  N/A |

nvcc --version:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

.bashrc 文件:

export PATH="/usr/local/cuda-10.2/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH"

我使用以下命令安装了 pytorch(来自 here):

pip install torch torchvision torchaudio

火炬版本:

PyTorch Version: 1.8.0

Python 版本:

Python 3.8.7

gcc/g++ 版本:

gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

如果我尝试获取 GPU,我会得到以下信息:

>>> import torch
>>> print(torch.cuda.is_available())
False

谁能给我建议

【问题讨论】:

  • 您的 CUDA_HOME 变量设置为什么?见:discuss.pytorch.org/t/cuda-path-not-correctly-configured/63695/…
  • 另外,这可能是一个幼稚的建议,但重新启动总是值得一试,请参阅:discuss.pytorch.org/t/…
  • 然后...最后,请确保您已下载并安装了 cuDNN:docs.nvidia.com/deeplearning/cudnn/install-guide/index.html
  • 其实,如果通过pip/conda安装的话,主机中不需要有CUDA/cuDNN。两个二进制文件里面都有两个库。你确定这个 pip install 安装在正确的 Python 中吗?
  • 顺便说一句,总是有帮助的一件事是查看实际的系统调用。 strace python -c 'import torch; print(torch.cuda.is_available())' 会告诉你 python 实际上在做什么来要求内核检查硬件;如果在尝试访问 /dev/sys 中的内容时出现权限错误之类的问题,它会显示在那里。

标签: python pytorch


【解决方案1】:

如果你看pytorch page,他们建议使用特殊命令来安装带有cuda 的torch,所以你可能想使用这个:

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

【讨论】:

  • 感谢您的回复!使用 conda 安装 Torch 解决了这个问题
猜你喜欢
  • 2011-12-25
  • 2020-10-08
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
  • 2020-08-26
相关资源
最近更新 更多