RuntimeError: 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.
Did anyone meet this problem? Please help ! !
Hi, I've met this problem before, so I'm here to help. But before we get started, there are some pre-checklists to finish:
- Run "nvcc -V" in a terminal to see the CUDA version installed on your computer or server;
- Run python3 -c "import torch; print(torch.version)" in a terminal or VScode to check the PyTorch version and its compatible CUDA version. For example, in my server, it will return with "2.0.1+cu118" meaning PyTorch 2.0.1 and CUDATOOLKIT 11.8 are installed.
After running the pre-checklists above, a normal outcome should be match; while in your case, a mismatch is expected. However, you might refer to https://stackoverflow.com/questions/76285777/cuda-and-pytorch-versions-mismatch-in-conda to see if it works; if it doesn't work, consider uninstalling the CUDA version you are using and installing a lower version (11.7) to match your PyTorch requirement manually.
Uninstall the previous version of the Pytorch pip uninstall torch torchvision torchaudio -y and reinstall to match the 12.1 version pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 make sure your env is accepting the code python -c "import torch; print(torch.version)" as PyTorch version: 2.5.1+cu121