RuntimeError: The current CUDA version is not compatible with the installed PyTorch build. CUDA version: 12.1, PyTorch CUDA: 11.8
ID: cuda/version-mismatch
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 12 | active | — | — | — |
| 11 | active | — | — | — |
Root Cause
CUDA 12.1 and PyTorch 2.1 version mismatches occur when pip installs the default PyTorch wheel built against CUDA 11.8. Specifying the correct CUDA index URL during installation resolves the issue in the vast majority of cases.
genericWorkarounds
-
94% success Install PyTorch with the CUDA 12.1 index URL
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
-
89% success Use conda with the pytorch-cuda=12.1 package
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
-
75% success Build PyTorch from source with CUDA 12.1 support
export TORCH_CUDA_ARCH_LIST='8.0;9.0' && export CUDA_HOME=/usr/local/cuda-12.1 && pip install torch --no-binary torch
Dead Ends
Common approaches that don't work:
-
Reinstalling torch without specifying CUDA version (pip install torch --force-reinstall)
95% fail
The default PyPI torch wheel is built against CUDA 11.8 (or the CPU-only variant). Without specifying the CUDA-specific index URL, pip will reinstall the same incompatible wheel, leaving the version mismatch unchanged.
-
Using plain pip install torch (without --index-url)
97% fail
The default PyPI index serves wheels built against CUDA 11.8 or CPU-only builds. The CUDA 12.1-compatible wheels are only available from PyTorch's own download index at https://download.pytorch.org/whl/cu121. Without this index URL, pip cannot find the correct wheel.
-
Downgrading the NVIDIA driver to match an older CUDA toolkit
78% fail
NVIDIA drivers are forward-compatible: a driver for CUDA 12.x supports CUDA 11.x runtimes. Downgrading the driver to target CUDA 11.8 may break other software, and the correct solution is to install the matching PyTorch wheel — not to change the driver.