CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment

We Are Going To Discuss About CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment. So lets Start this Python Article.

CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment

  1. How to solve CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment

    Your installation is perfectly fine for CUDA and nvidia driver but the issue is in your PyTorch and CUDA Version you need at least CUDA 10.2 for latest version of torch that supports python 3.9
    If you are using conda simply create a new environment , conda takes care of cuda toolkit also pip and conda dont do well together:
    pip uninstall uninstall torch torchaudio torchvision
    Create your new conda env
    conda create --name yourenv python=3.9 conda activate yourenv
    For CUDA 11.1 :
    conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
    For CUDA 10.2 :
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch -c conda-forge
    If you are using pip and not anaconda environment
    Please refer to Pytorch Installation Docs / Requirements
    The latest version of Torch natively supports CUDA 10.2 and 11.1 only
    try installing CUDA 10.2 or 11.1
    try upgrading your pip and reinstalling torch :
    Uninstall currently installed Torch version by using
    pip uninstall torch torchaudio torchvision
    Upgrade pip:
    pip3 install --upgrade pip
    Install PyTorch:
    pip install torch torchvision torchaudio //cuda 10.2 pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html //cuda 11.1

  2. CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment

    Your installation is perfectly fine for CUDA and nvidia driver but the issue is in your PyTorch and CUDA Version you need at least CUDA 10.2 for latest version of torch that supports python 3.9
    If you are using conda simply create a new environment , conda takes care of cuda toolkit also pip and conda dont do well together:
    pip uninstall uninstall torch torchaudio torchvision
    Create your new conda env
    conda create --name yourenv python=3.9 conda activate yourenv
    For CUDA 11.1 :
    conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
    For CUDA 10.2 :
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch -c conda-forge
    If you are using pip and not anaconda environment
    Please refer to Pytorch Installation Docs / Requirements
    The latest version of Torch natively supports CUDA 10.2 and 11.1 only
    try installing CUDA 10.2 or 11.1
    try upgrading your pip and reinstalling torch :
    Uninstall currently installed Torch version by using
    pip uninstall torch torchaudio torchvision
    Upgrade pip:
    pip3 install --upgrade pip
    Install PyTorch:
    pip install torch torchvision torchaudio //cuda 10.2 pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html //cuda 11.1

Solution 1

Your installation is perfectly fine for CUDA and nvidia driver but the issue is in your PyTorch and CUDA Version you need at least CUDA 10.2 for latest version of torch that supports python 3.9

If you are using conda simply create a new environment , conda takes care of cuda toolkit also pip and conda dont do well together:

pip uninstall uninstall torch torchaudio torchvision

Create your new conda env

conda create --name yourenv python=3.9
conda activate yourenv

For CUDA 11.1 :

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

For CUDA 10.2 :

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch -c conda-forge

If you are using pip and not anaconda environment

Please refer to Pytorch Installation Docs / Requirements

The latest version of Torch natively supports CUDA 10.2 and 11.1 only

try installing CUDA 10.2 or 11.1

try upgrading your pip and reinstalling torch :

Uninstall currently installed Torch version by using

pip uninstall torch torchaudio torchvision

Upgrade pip:

pip3 install --upgrade pip

Install PyTorch:

pip install torch torchvision torchaudio  //cuda 10.2
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html //cuda 11.1

Original Author Utkarsh Chandra Srivastava Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment