How to install pytorch when cuda=12.0?

I’m working on ubuntu server, got this when I want to install through pip:

RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda))
    RuntimeError:
    The detected CUDA version (12.0) mismatches the version that was used to compile
    PyTorch (11.8). Please make sure to use the same CUDA versions.
    
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

From this my cuda =12.0 while pytorch=11.8 ,it’s becuz I didn’t find pytorch 12.0 in https://pytorch.org/get-started/locally/ when installing.

So I should reinstall pytorch 12.0 now, how to do that?

here’s some info I can provide:

nvidia-smi output:

VVIDIA-SMI 525.105.17  Driver Version: 515.105.17  CUDA version 12.0

nvcc -V output:

Cuda comilation tools, release 12,0 V12.0.76
Build cuda_12.0.r12.0/compiler.31968024_0

I want to install pytorch in anaconda environment with python=3.10

How can I do? Thanks!!!

Btw I installed cuda in my personal directory, like this
in ~/.bashrc (of course my own )

# cuda
export PATH="/mydirectoyr/cuda-12.0/bin:$PATH"
export :D_LBRARY_PATH="/mydirectory/cuda/cuda-12.0/lib64:/mydirectory/cuda/cuda-12.0/mylib/lib64:$LD_LIBRARY_PATH"

Should I choose downgrade cuda ? :thinking:

This error message is most likely raised if you try to build a custom CUDA extension in an environment where the locally installed CUDA toolkit and the CUDA toolkit used to build PyTorch differ in the major version. In this case try to install any PyTorch binary with CUDA 12 and try to rebuild your extension.

CUDA 12.1 build works perfectly with CUDA 12.0 due to backward compatibility as far as I know.

Try force-reinstall

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

I wouldn’t recommend installing such an old binary since all of our CUDA 12.x builds will work on CUDA 12 drivers. As previously explained the error message seems to be raised by an attempt to build a custom extension from source.