0

I can't get PyTorch to work.

I have cuda and NVIDIA drivers installed

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

I have installed PyTorch using the following command

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

I am testing PyTorch using the following code snippet

import torch

print(torch.__version__)

print(torch.cuda.is_available())

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()

#Additional Info when using cuda
if device.type == 'cuda':
    print(torch.cuda.get_device_name(0))
    print('Memory Usage:')
    print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
    print('Cached:   ', round(torch.cuda.memory_reserved(0)/1024**3,1), 'GB')

Which tells me PyTorch can't access CUDA

    1.13.1
    /home/vn/miniconda3/lib/python3.10/site-packages/torch/cuda/__init__.py:88: UserWarning: CUDA initialization: Unexpected error from cudaGetDeviceCount(). 
Did you run some cuda functions before calling NumCudaDevices() that might have already set an error? 
Error 803: system has unsupported display driver / cuda driver combination 
(Triggered internally at /opt/conda/conda-bld/pytorch_1670525541990/work/c10/cuda/CUDAFunctions.cpp:109.)
      return torch._C._cuda_getDeviceCount() > 0
    False
    Using device: cpu

In case it makes any difference I am running 6.1.15-060115-generic kernel under ubuntu 22.04

Rotkiv
  • 1,051
  • 2
  • 13
  • 33
  • 2
    "I have cuda and NVIDIA drivers installed" You've given no actual indication that you have a CUDA GPU and a properly installed driver, or what version that driver might be. Furthermore, for CUDA 11.7, you must have a "new enough" driver. Not enough information in your post to diagnose. Your `conda` command does not install a GPU driver. ***Install the latest driver for your GPU.*** – Robert Crovella Mar 09 '23 at 17:30
  • 1
    Related https://stackoverflow.com/questions/60987997/why-torch-cuda-is-available-returns-false-even-after-installing-pytorch-with – jodag Mar 09 '23 at 18:30
  • @RobertCrovella, thank you. That made me realize I assume that installed cuda == cuda available. – Rotkiv Mar 10 '23 at 05:06

1 Answers1

1

tldr - "installed cuda" doesn't mean "cuda can be used by the card."

ultimately I had to get nvidia-smi work. the easiest way to do it was by using NVIDIA drivers that came with ubuntu.

Rotkiv
  • 1,051
  • 2
  • 13
  • 33