[Python] torch.cuda.device_count() return 0 when torch.cuda.is_available() return True in...

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    I got an error in jupyternotebook said that RuntimeError: Attempting to deserialize object on CUDA device 0 but torch.cuda.device_count() is 0. Please use torch.load with map_location to map your storages to an existing device.

    This is the result I got in jupyter notebook

    torch.cuda.is_available() # True
    torch.cuda.device_count() # 0
    sys.executable # '/home/quiet98k/anaconda3/envs/lol/bin/python'
    os.environ["CUDA_VISIBLE_DEVICES"] # -1


    This is what I got in python terminal

    Python 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import torch
    >>> import sys
    >>> torch.cuda.is_available()
    True
    >>> torch.cuda.device_count()
    1
    >>> torch.cuda.get_device_name(0)
    'NVIDIA GeForce RTX 3070'
    >>> sys.executable
    '/home/quiet98k/anaconda3/envs/lol/bin/python'


    I'm sure that cuda is available in my wsl

    └─[$] <git:(main*)> nvidia-smi
    Mon May 19 05:06:00 2025
    +-----------------------------------------------------------------------------------------+
    | NVIDIA-SMI 550.144.03 Driver Version: 572.83 CUDA Version: 12.8 |
    |-----------------------------------------+------------------------+----------------------+
    | 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 RTX 3070 On | 00000000:01:00.0 On | N/A |
    | 53% 33C P5 31W / 280W | 2371MiB / 8192MiB | 34% Default |
    | | | N/A |
    +-----------------------------------------+------------------------+----------------------+

    +-----------------------------------------------------------------------------------------+
    | Processes: |
    | GPU GI CI PID Type Process name GPU Memory |
    | ID ID Usage |
    |=========================================================================================|
    | 0 N/A N/A 5838 C /python3.10 N/A |
    +-----------------------------------------------------------------------------------------+


    I tried to reinstall pytorch and even the entire python environment, but the problem remains. What is wrong here?????

    Continue reading...

Compartilhe esta Página