torch.cuda.is_available() 返回 false,我还应该检查什么?

问题描述 投票:0回答:1

内容:

我在让 PyTorch 识别我的系统上的 CUDA 时遇到问题。详情如下:

系统信息:

  • 操作系统:在 WSL2 上运行的 Ubuntu 22.04.4 LTS (x86_64)
  • Python版本:3.7.16
  • PyTorch版本:1.12.0+cu113
  • GPU:采用 Max-Q 设计的 NVIDIA GeForce GTX 1650
  • Nvidia 驱动程序版本: 537.13

环境信息: python -m torch.utils.collect_env

Collecting environment information...
PyTorch version: 1.12.0+cu113
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.17

Python version: 3.7.16 (default, Jan 17 2023, 22:20:44)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.146.1-microsoft-standard-WSL2-x86_64-with-debian-bookworm-sid
Is CUDA available: False
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1650 with Max-Q Design
Nvidia driver version: 537.13
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.6
[pip3] torch==1.12.0+cu113
[pip3] torchaudio==0.12.0+cu113
[pip3] torchvision==0.13.0+cu113
[conda] numpy                     1.21.6                   pypi_0    pypi
[conda] torch                     1.12.0+cu113             pypi_0    pypi
[conda] torchaudio                0.12.0+cu113             pypi_0    pypi
[conda] torchvision               0.13.0+cu113             pypi_0    pypi

我采取的步骤:

  1. 验证 CUDA 是否安装正确:

    nvcc --version
    

    输出:

    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2021 NVIDIA Corporation
    Built on Mon_May__3_19:15:13_PDT_2021
    Cuda compilation tools, release 11.3, V11.3.109
    Build cuda_11.3.r11.3/compiler.29920130_0
    
  2. 设置环境变量:

    export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    

    echo 'export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}' >> ~/.bashrc
    echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
    
  3. 已验证的 NVIDIA 驱动程序状态:

    nvidia-smi
    

    输出:

    Sun May 19 03:03:53 2024
    +---------------------------------------------------------------------------------------+
    | NVIDIA-SMI 535.103                Driver Version: 537.13       CUDA Version: 12.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  NVIDIA GeForce GTX 1650 ...    On  | 00000000:02:00.0 Off |                  N/A |
    | N/A   50C    P0              13W /  35W |      0MiB /  4096MiB |      0%      Default |
    |                                         |                      |                  N/A |
    +-----------------------------------------+----------------------+----------------------+
    
    +---------------------------------------------------------------------------------------+
    | Processes:                                                                            |
    |  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
    |        ID   ID                                                             Usage      |
    |=======================================================================================|
    |  No running processes found                                                           |
    +---------------------------------------------------------------------------------------+
    
  4. 检查 CUDA 在 PyTorch 中是否可用:

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

    输出:

    False
    

问题:

  1. 为什么
    torch.cuda.is_available()
    会回来
    False
  2. 我应该执行哪些额外检查或步骤来解决此问题?

预先感谢您的帮助!

python pytorch cuda
1个回答
0
投票

我建议您检查此页面以了解cuda兼容性。 使用 Pytorch 时,遵循安装页面上推荐的所有依赖项非常重要,如果只跳过一件事,则无法启动 torch。

在您的情况下,驱动程序 537.13 与 CUDA 12.2 兼容。

尝试重新检查安装步骤,也许你跳过了一些东西

© www.soinside.com 2019 - 2024. All rights reserved.