What's the relationship between cuda_toolkit and pytorch

when I try to run python setup.py develop (a file in openpcdet), an error eccoured

The detected CUDA version (12.1) mismatches the version that was used to compile
PyTorch (11.7). Please make sure to use the same CUDA versions.

I think it is because my pytorch is not compatiable with my cuda,but i don’t know what to do.

My environment:

  1. wsl2–Ubuntu20.04

  2. when I run nvcc -V in my terminal
    i got

*nvcc: NVIDIA (R) Cuda compiler driver*
*Copyright (c) 2005-2023 NVIDIA Corporation*
*Built on Tue_Feb__7_19:32:13_PST_2023*
*Cuda compilation tools, release 12.1, V12.1.66*
*Build cuda_12.1.r12.1/compiler.32415258_0*

which shows my cuda version is 12.1

  1. through pytorch website I install pytorch with command
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia

i run this commands in my conda env (for learning openpcdet)

>>> print(torch.backends.cudnn.version())
>>> print(torch.__version__)
>>> print(torch.version.cuda)
>>> print(torch.backends.cudnn.version())

My questions:

  1. how can i solve this problem
  2. i could only see pytorch matches cuda11.8(lastest) in the pytorch website,
    so i want to know if there any problem if my cuda version is 12.1
  3. in the pytorch install command i saw this pytorch-cuda=11.7 is this a cuda_toolkit? when it have conflict with my cuda12.1 which is installed through
    CUDA Toolkit 12.1 Update 1 Downloads | NVIDIA Developer
  4. do i need to uninstall my CUDA and install cuda11.7 to match pytorch?

I have the same issue. I would love to know the solutions as well. Many thanks.

You can install the cuda-toolkit version that you need (11.7) in parallel to the existing version.

sudo apt-get install cuda-toolkit-11-7

Then you need to set the cuda path environment variable so that it points to the correct cuda version.

export CUDA_HOME=/usr/local/cuda-11.7/

Afterwards it should work fine.

PyTorch - GPU

From the description of pytorch-cuda on Anaconda’s repository, it seems that it is assist the conda solver to pull the correct version of pytorch when one does conda install. By having the line pytorch-cuda=11.7, it seems to pull the version of pytorch that is compiled with cuda 11.7, hence the installed pytorch would expect to have cuda 11.7 available on the system that it is being installed at.

Metapackage to select the PyTorch variant. Use conda’s pinning mechanism in your environment to control which variant you want.
-Anaconda pytorch-cuda repo description

PyTorch - CPU

The CPU-only version of pytorch has a package called pytorch::cpuonly and seems to serve the same purpose to assisting the conda solver as it does not seem to provide anything else.