7

I'm trying to use my GPU to run the YOLOR model, and I keep getting the error:

Traceback (most recent call last):
  File "D:\yolor\detect.py", line 198, in <module>
    detect()
  File "D:\yolor\detect.py", line 41, in detect
    device = select_device(opt.device)
  File "D:\yolor\utils\torch_utils.py", line 47, in select_device
    assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device  # check availablity
AssertionError: CUDA unavailable, invalid device 0 requested

When I try to check if CUDA is available with the following:

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

I get False, which explains the problem. I tried running the command

py -m pip install torch1.9.0+cu111 torchvision0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

I get the error: ERROR: Invalid requirement: 'torch1.9.0+cu111'

Running nvcc --version, I get:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:41:42_Pacific_Daylight_Time_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

Thus, I'm not really sure what the issue is, or how to fix it.

EDIT: As @Ivan pointed out, I added the == sign, but still get False when checking if CUDA is available.

1
  • Have you checked if your current NVidia driver supports CUDA 11.3? Also this question is pretty old already. Have you figured it out? Commented Jan 12, 2022 at 8:12

6 Answers 6

6

Ok after 1 week of pain I have founded this solution

1- After download NVIDIA Driver:

  • Go to your window and search for "NVIDIA Control Panel"
  • Then at the bottom left there should be "System Information"
  • Then look for "CUDA Cores"
  • Mine is 384 (year my laptop is antique) (NVIDIA GeForce GT 750M)
  • For CUDA Cores: 384 (corresponds to CUDA Toolkit 9.0)
  • For CUDA Cores: 387 (corresponds to CUDA Toolkit 9.1)
  • For other CUDA Cores you will need to do some more research yourself because I'm honestly don't know where to find this (if you are curious about where I found the one above, its on the second comments "https://github.com/pytorch/pytorch/issues/4546"

2- (Optional) Download Anaconda

  • This is the system I use, the choice is your
  • If you are using Anaconda and have been installing and uninstall to fix this problem. I recommend you to clean uninstall the environment since in my case my file got crash because of repeated install and un-install
  • Here is the link to show you how to do it "https://www.youtube.com/watch?v=dcvdOuvWI-Q&t=107s"

3- After install the right CUDA toolkit for your system

  • Go to "https://pytorch.org"
  • Put in your system details and install the right PyTorch for your system
  • (Optional) if you use Tensorflow as well, go here and install the right version for your CUDA

4- After all of that, in your Anaconda environment (or any environment you are using), type:

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

if return True then good job

if not: good luck on your coming week

hope it help and good luck on your journey with yolor (I'm learning it too)

Sign up to request clarification or add additional context in comments.

Comments

2

You forgot to put the == signs between the packages and the version number. According to the PyTorch installation page:

py -m pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

8 Comments

Hey @Ivan, thank you! I feel like an idiot. I just ran the command, and when executing print(torch.cuda.is_available()), I still get false. Any idea why?
Could you run nvidia-smi in the command line and look at the CUDA version?
Yes, I get version 11.4. For some reason, when I ran the same program in a conda environment, I get print(torch.cuda.is_available()) as True, and it works fine. Any ideas? :(
ok, which environment is the one failing with torch.cuda.is_available(), your regular Python cmd line, right? You might be running a different Python/Torch/etc... all together. Could you look at pip list and tell me if you get the correct version for PyTorch (1.9.0+cu111)?
When I run it, I get torch 1.9.0+cu111 torchaudio 0.9.0 torchvision 0.10.0+cu111
|
1

pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

Comments

0

If you are working with VSCode dev containers maybe you forgot to add the GPU to the container.

This can be fixed adding to .devcontainer/devcontainer.json

"runArgs": ["--gpus", "all"]

Comments

0

Uninstall torch, torchvision, and torchaudio (if already installed). For CUDA 12.1:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

Comments

-1

Just do this solution, I am here using TensorFlow 2.5.0, change it to what is suitable for you...

!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/libcudnn8_8.1.0.77-1+cuda11.2_amd64.deb
!dpkg -i libcudnn8_8.1.0.77-1+cuda11.2_amd64.deb
!ls -l /usr/lib/x86_64-linux-gnu/libcudnn.so.*
!pip install --upgrade tensorflow==2.5.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.