cuda version_incompatibility ai_generated true

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

Also available as: JSON · Markdown
92%Fix Rate
88%Confidence
38Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.

generic

Workarounds

  1. 94% success Install PyTorch with the CUDA 12.1 index URL
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

    Sources: https://pytorch.org/get-started/locally/

  2. 89% success Use conda with the pytorch-cuda=12.1 package
    conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

    Sources: https://pytorch.org/get-started/locally/

  3. 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

    Sources: https://github.com/pytorch/pytorch#from-source

Dead Ends

Common approaches that don't work:

  1. 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.

  2. 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.

  3. 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.

Error Chain

Leads to:
Preceded by:
Frequently confused with: