PyTorch "torchvision were compiled with different CUDA versions" in CI
torchvision checks at import time that its CUDA build matches torch's, and they differ. One was installed as a cu118 wheel and the other as cu121 (or one CPU, one CUDA), so torchvision refuses to load.
What this error means
Importing torchvision raises "RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA versions" and prints both CUDA versions.
python
RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA
versions. PyTorch has CUDA Version=11.8 and torchvision has CUDA Version=12.1.
Please reinstall the torchvision that matches your PyTorch install.Common causes
Wheels from different CUDA channels
pip pulled torch from one CUDA index (cu118) and torchvision from another (cu121), so their bundled CUDA versions disagree.
A partial upgrade left mismatched cu suffixes
Upgrading only one of the two packages, or letting the default index supply one, mixes CUDA builds.
How to fix it
Reinstall both from one CUDA channel
- Choose a single CUDA suffix (for example cu121) for the whole job.
- Install torch and torchvision together from that one index.
- Confirm import succeeds and both report the same CUDA version.
Terminal
pip install --index-url https://download.pytorch.org/whl/cu121 \
torch torchvisionInspect the installed CUDA build
Print what each package was built with so a mismatch is obvious in logs.
Terminal
python -c "import torch, torchvision; print(torch.version.cuda, torchvision.version.cuda)"How to prevent it
- Install all torch-family packages from the same CUDA index.
- Pin matching versions with identical cu suffixes in the lockfile.
- Log torch.version.cuda in CI so drift is caught early.
Related guides
PyTorch "undefined symbol" torchvision/torch ABI mismatch in CIFix torchvision/torchaudio "undefined symbol" ImportError in CI - the extension was compiled against a differ…
PyTorch installs the CPU wheel instead of the CUDA wheel in CIFix pip pulling the CPU-only torch wheel in CI when you wanted CUDA - the default PyPI index has no CUDA whee…
CUDA "no kernel image is available for execution on the device" in CIFix CUDA "no kernel image is available for execution on the device" in CI - the installed binaries were not c…