Torch not compiled with cuda enabled windows

I'm trying to do neural style swapping, and for some reason, I keep getting the following errors. AssertionError: Torch not compiled with CUDA enabled File "c:appsMiniconda3libsite-pac...

I had the same problem but still I cannot find a solution to my problem

I installed everything in my anaconda environment with:

conda install -c conda-forge -c pytorch python=3.7 pytorch torchvision cudatoolkit=10.1 opencv numpy pillow

Now I noticed that I installed the following packages (among others)

  python             conda-forge/linux-64::python-3.7.12-hb7a2778_100_cpython
  python_abi         conda-forge/linux-64::python_abi-3.7-2_cp37m
  pytorch            conda-forge/linux-64::pytorch-1.10.0-cpu_py37hf3cc979_0
  pytorch-cpu        conda-forge/linux-64::pytorch-cpu-1.10.0-cpu_py37h718b53a_0
  qt                 conda-forge/linux-64::qt-5.12.9-hda022c4_4

Which means that the versions of pytorch installed are CPU only. Correct?

How can I install now a version of pytorch which is CUDA enabled?

Output details

Command:

conda install -c conda-forge -c pytorch python=3.7 pytorch torchvision cudatoolkit=10.1 opencv numpy pillow

Result:

Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.10.1
  latest version: 4.10.3

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /home/fabrizioschiano/anaconda3/envs/deeplabv3finetuning

  added / updated specs:
    - cudatoolkit=10.1
    - numpy
    - opencv
    - pillow
    - python=3.7
    - pytorch
    - torchvision


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    hdf5-1.12.1                |nompi_h2750804_102         3.5 MB  conda-forge
    libpq-13.5                 |       hd57d9b9_0         2.8 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         6.3 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge
  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-1_llvm
  alsa-lib           conda-forge/linux-64::alsa-lib-1.2.3-h516909a_0
  bzip2              conda-forge/linux-64::bzip2-1.0.8-h7f98852_4
  c-ares             conda-forge/linux-64::c-ares-1.18.1-h7f98852_0
  ca-certificates    conda-forge/linux-64::ca-certificates-2021.10.8-ha878542_0
  cairo              conda-forge/linux-64::cairo-1.16.0-h6cf1ce9_1008
  cffi               conda-forge/linux-64::cffi-1.15.0-py37h036bc23_0
  cudatoolkit        conda-forge/linux-64::cudatoolkit-10.1.243-h036e899_9
  dbus               conda-forge/linux-64::dbus-1.13.6-h48d8840_2
  expat              conda-forge/linux-64::expat-2.4.1-h9c3ff4c_0
  ffmpeg             conda-forge/linux-64::ffmpeg-4.3.2-hca11adc_1
  fontconfig         conda-forge/linux-64::fontconfig-2.13.1-hba837de_1005
  freeglut           conda-forge/linux-64::freeglut-3.2.1-h9c3ff4c_2
  freetype           conda-forge/linux-64::freetype-2.10.4-h0708190_1
  future             conda-forge/linux-64::future-0.18.2-py37h89c1867_4
  gettext            conda-forge/linux-64::gettext-0.19.8.1-h73d1719_1008
  glib               conda-forge/linux-64::glib-2.70.1-h780b84a_0
  glib-tools         conda-forge/linux-64::glib-tools-2.70.1-h780b84a_0
  gmp                conda-forge/linux-64::gmp-6.2.1-h58526e2_0
  gnutls             conda-forge/linux-64::gnutls-3.6.13-h85f3911_1
  graphite2          conda-forge/linux-64::graphite2-1.3.13-h58526e2_1001
  gst-plugins-base   conda-forge/linux-64::gst-plugins-base-1.18.5-hf529b03_2
  gstreamer          conda-forge/linux-64::gstreamer-1.18.5-h9f60fe5_2
  harfbuzz           conda-forge/linux-64::harfbuzz-3.1.1-h83ec7ef_0
  hdf5               conda-forge/linux-64::hdf5-1.12.1-nompi_h2750804_102
  icu                conda-forge/linux-64::icu-68.2-h9c3ff4c_0
  jasper             conda-forge/linux-64::jasper-2.0.33-ha77e612_0
  jbig               conda-forge/linux-64::jbig-2.1-h7f98852_2003
  jpeg               conda-forge/linux-64::jpeg-9d-h36c2ea0_0
  krb5               conda-forge/linux-64::krb5-1.19.2-hcc1bbae_3
  lame               conda-forge/linux-64::lame-3.100-h7f98852_1001
  lcms2              conda-forge/linux-64::lcms2-2.12-hddcbb42_0
  ld_impl_linux-64   conda-forge/linux-64::ld_impl_linux-64-2.36.1-hea4e1c9_2
  lerc               conda-forge/linux-64::lerc-3.0-h9c3ff4c_0
  libblas            conda-forge/linux-64::libblas-3.9.0-12_linux64_mkl
  libcblas           conda-forge/linux-64::libcblas-3.9.0-12_linux64_mkl
  libclang           conda-forge/linux-64::libclang-11.1.0-default_ha53f305_1
  libcurl            conda-forge/linux-64::libcurl-7.80.0-h2574ce0_0
  libdeflate         conda-forge/linux-64::libdeflate-1.8-h7f98852_0
  libedit            conda-forge/linux-64::libedit-3.1.20191231-he28a2e2_2
  libev              conda-forge/linux-64::libev-4.33-h516909a_1
  libevent           conda-forge/linux-64::libevent-2.1.10-h9b69904_4
  libffi             conda-forge/linux-64::libffi-3.4.2-h7f98852_5
  libgcc-ng          conda-forge/linux-64::libgcc-ng-11.2.0-h1d223b6_11
  libgfortran-ng     conda-forge/linux-64::libgfortran-ng-11.2.0-h69a702a_11
  libgfortran5       conda-forge/linux-64::libgfortran5-11.2.0-h5c6108e_11
  libglib            conda-forge/linux-64::libglib-2.70.1-h174f98d_0
  libglu             conda-forge/linux-64::libglu-9.0.0-he1b5a44_1001
  libiconv           conda-forge/linux-64::libiconv-1.16-h516909a_0
  liblapack          conda-forge/linux-64::liblapack-3.9.0-12_linux64_mkl
  liblapacke         conda-forge/linux-64::liblapacke-3.9.0-12_linux64_mkl
  libllvm11          conda-forge/linux-64::libllvm11-11.1.0-hf817b99_2
  libnghttp2         conda-forge/linux-64::libnghttp2-1.43.0-h812cca2_1
  libnsl             conda-forge/linux-64::libnsl-2.0.0-h7f98852_0
  libogg             conda-forge/linux-64::libogg-1.3.4-h7f98852_1
  libopencv          conda-forge/linux-64::libopencv-4.5.3-py37hbfc4018_5
  libopus            conda-forge/linux-64::libopus-1.3.1-h7f98852_1
  libpng             conda-forge/linux-64::libpng-1.6.37-h21135ba_2
  libpq              conda-forge/linux-64::libpq-13.5-hd57d9b9_0
  libprotobuf        conda-forge/linux-64::libprotobuf-3.18.1-h780b84a_0
  libssh2            conda-forge/linux-64::libssh2-1.10.0-ha56f1ee_2
  libstdcxx-ng       conda-forge/linux-64::libstdcxx-ng-11.2.0-he4da1e4_11
  libtiff            conda-forge/linux-64::libtiff-4.3.0-h6f004c6_2
  libuuid            conda-forge/linux-64::libuuid-2.32.1-h7f98852_1000
  libvorbis          conda-forge/linux-64::libvorbis-1.3.7-h9c3ff4c_0
  libwebp-base       conda-forge/linux-64::libwebp-base-1.2.1-h7f98852_0
  libxcb             conda-forge/linux-64::libxcb-1.13-h7f98852_1004
  libxkbcommon       conda-forge/linux-64::libxkbcommon-1.0.3-he3ba5ed_0
  libxml2            conda-forge/linux-64::libxml2-2.9.12-h72842e0_0
  libzlib            conda-forge/linux-64::libzlib-1.2.11-h36c2ea0_1013
  llvm-openmp        conda-forge/linux-64::llvm-openmp-12.0.1-h4bd325d_1
  lz4-c              conda-forge/linux-64::lz4-c-1.9.3-h9c3ff4c_1
  mkl                conda-forge/linux-64::mkl-2021.4.0-h8d4b97c_729
  mysql-common       conda-forge/linux-64::mysql-common-8.0.27-ha770c72_1
  mysql-libs         conda-forge/linux-64::mysql-libs-8.0.27-hfa10184_1
  ncurses            conda-forge/linux-64::ncurses-6.2-h58526e2_4
  nettle             conda-forge/linux-64::nettle-3.6-he412f7d_0
  ninja              conda-forge/linux-64::ninja-1.10.2-h4bd325d_1
  nspr               conda-forge/linux-64::nspr-4.32-h9c3ff4c_1
  nss                conda-forge/linux-64::nss-3.72-hb5efdd6_0
  numpy              conda-forge/linux-64::numpy-1.21.4-py37h31617e3_0
  olefile            conda-forge/noarch::olefile-0.46-pyh9f0ad1d_1
  opencv             conda-forge/linux-64::opencv-4.5.3-py37h89c1867_5
  openh264           conda-forge/linux-64::openh264-2.1.1-h780b84a_0
  openjpeg           conda-forge/linux-64::openjpeg-2.4.0-hb52868f_1
  openssl            conda-forge/linux-64::openssl-1.1.1l-h7f98852_0
  pcre               conda-forge/linux-64::pcre-8.45-h9c3ff4c_0
  pillow             conda-forge/linux-64::pillow-8.4.0-py37h0f21c89_0
  pip                conda-forge/noarch::pip-21.3.1-pyhd8ed1ab_0
  pixman             conda-forge/linux-64::pixman-0.40.0-h36c2ea0_0
  pthread-stubs      conda-forge/linux-64::pthread-stubs-0.4-h36c2ea0_1001
  py-opencv          conda-forge/linux-64::py-opencv-4.5.3-py37h6531663_5
  pycparser          conda-forge/noarch::pycparser-2.21-pyhd8ed1ab_0
  python             conda-forge/linux-64::python-3.7.12-hb7a2778_100_cpython
  python_abi         conda-forge/linux-64::python_abi-3.7-2_cp37m
  pytorch            conda-forge/linux-64::pytorch-1.10.0-cpu_py37hf3cc979_0
  pytorch-cpu        conda-forge/linux-64::pytorch-cpu-1.10.0-cpu_py37h718b53a_0
  qt                 conda-forge/linux-64::qt-5.12.9-hda022c4_4
  readline           conda-forge/linux-64::readline-8.1-h46c0cb4_0
  setuptools         conda-forge/linux-64::setuptools-59.2.0-py37h89c1867_0
  sleef              conda-forge/linux-64::sleef-3.5.1-h9b69904_2
  sqlite             conda-forge/linux-64::sqlite-3.36.0-h9cd32fc_2
  tbb                conda-forge/linux-64::tbb-2021.4.0-h4bd325d_1
  tk                 conda-forge/linux-64::tk-8.6.11-h27826a3_1
  torchvision        conda-forge/linux-64::torchvision-0.10.1-py37h9e046cd_0_cpu
  typing_extensions  conda-forge/noarch::typing_extensions-4.0.0-pyha770c72_0
  wheel              conda-forge/noarch::wheel-0.37.0-pyhd8ed1ab_1
  x264               conda-forge/linux-64::x264-1!161.3030-h7f98852_1
  xorg-fixesproto    conda-forge/linux-64::xorg-fixesproto-5.0-h7f98852_1002
  xorg-inputproto    conda-forge/linux-64::xorg-inputproto-2.3.2-h7f98852_1002
  xorg-kbproto       conda-forge/linux-64::xorg-kbproto-1.0.7-h7f98852_1002
  xorg-libice        conda-forge/linux-64::xorg-libice-1.0.10-h7f98852_0
  xorg-libsm         conda-forge/linux-64::xorg-libsm-1.2.3-hd9c2040_1000
  xorg-libx11        conda-forge/linux-64::xorg-libx11-1.7.2-h7f98852_0
  xorg-libxau        conda-forge/linux-64::xorg-libxau-1.0.9-h7f98852_0
  xorg-libxdmcp      conda-forge/linux-64::xorg-libxdmcp-1.1.3-h7f98852_0
  xorg-libxext       conda-forge/linux-64::xorg-libxext-1.3.4-h7f98852_1
  xorg-libxfixes     conda-forge/linux-64::xorg-libxfixes-5.0.3-h7f98852_1004
  xorg-libxi         conda-forge/linux-64::xorg-libxi-1.7.10-h7f98852_0
  xorg-libxrender    conda-forge/linux-64::xorg-libxrender-0.9.10-h7f98852_1003
  xorg-renderproto   conda-forge/linux-64::xorg-renderproto-0.11.1-h7f98852_1002
  xorg-xextproto     conda-forge/linux-64::xorg-xextproto-7.3.0-h7f98852_1002
  xorg-xproto        conda-forge/linux-64::xorg-xproto-7.0.31-h7f98852_1007
  xz                 conda-forge/linux-64::xz-5.2.5-h516909a_1
  zlib               conda-forge/linux-64::zlib-1.2.11-h36c2ea0_1013
  zstd               conda-forge/linux-64::zstd-1.5.0-ha95c52a_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
hdf5-1.12.1          | 3.5 MB    | ################################################################################################################################################## | 100% 
libpq-13.5           | 2.8 MB    | ################################################################################################################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: | By downloading and using the CUDA Toolkit conda packages, you accept the terms and conditions of the CUDA End User License Agreement (EULA): https://docs.nvidia.com/cuda/eula/index.html

done

Details of my system

I am on Ubuntu 20.04

The command:

gives the following output

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

The command:

gives the following output

Tue Nov 23 17:44:11 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.82.00    Driver Version: 470.82.00    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0  On |                  N/A |
| N/A   54C    P0    25W /  N/A |    833MiB /  7973MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1082      G   /usr/lib/xorg/Xorg                102MiB |
|    0   N/A  N/A      1693      G   /usr/lib/xorg/Xorg                405MiB |
|    0   N/A  N/A      1823      G   /usr/bin/gnome-shell              130MiB |
|    0   N/A  N/A      2306      G   ...AAAAAAAAA= --shared-files      139MiB |
|    0   N/A  N/A      4719      G   .../debug.log --shared-files        2MiB |
|    0   N/A  N/A     13922      G   ...AAAAAAAAA= --shared-files       37MiB |
+-----------------------------------------------------------------------------+

you dont have to install it via anaconda, you could install cuda from their website. after install ends open a new terminal and check your cuda version with:

>>> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:52:33_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

my is V11.5

then go here and select your os and preferred package manager(pip or anaconda), and the cuda version you installed, and copy the generated install command, I got:

pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

notice that for me I had python 3.10 installed but my project run over 3.9 so either use virtual environment or run pip of your wanted base interpreter explicitly (for example C:SoftwarePythonPython39python.exe -m pip install .....)
else you will be stuck with Could not find a version that satisfies the requirement torch errors

then open python console and check for cuda availability

>>> import torch
>>> torch.cuda.is_available()
True

AssertionError: torch not compiled with Cuda enabled error occurs because of using cuda GPU enable syntax over normal PyTorch (CPU only ). There are multiple scenarios where you can get this error. Sometimes CUDA enablement is clear and visible. This is easy to fix by making it false or removing the same. But in some scenarios, It is indirectly calling Cuda which is explicitly not visible. Hence There we need to understand the internal working of such parameter or function which is causing the issue. Anyways in this article, we will go throw the most common reasons.

Solution 1: Switching from CUDA to normal version  –

Usually while compiling any neural network in PyTorch, we can pass cuda enable. If we simply remove the same it will remove the error. Refer to the below example, If you are using a similar syntax pattern then remove Cuda while compiling the neural network.

from torch import nn
net = nn.Sequential(
    nn.Linear(18*18, 80),
    nn.ReLU(),
    nn.Linear(80, 80),
    nn.ReLU(),
    nn.Linear(80, 10),
    nn.LogSoftmax()
).cuda()

The correct way is –

assertionerror torch not compiled with cuda enabled solution

assertionerror torch not compiled with cuda enabled solution

Solution 2: Installing cuda supported Pytorch –

See the bottom line is that if you are facing such an incompatibility issue either you adjust your code according to available libraries in the system. Or we install the compatible libraries in our system to get rid of the same error.

You may any package managers to install cuda supported pytorch. Use any of the below commands –

conda –

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

pip –

pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

Solution 3:  set pin_memory=False –

This is one of the same categories where CUDA is not visible directly. But Internally if it is True then it copies the tensors into CUDA space for processing. To Avoid the same we have to make it False. Once more thing, By Default it is True. Hence we have to explicitly make it False while using the get_iterator function in DataLoader class.

torch not compiled with cuda enabled ( Similar Error )-

There are so many error which has similar solution but because of the specification added it looks bit different. Hence to avoid the confusion , Here are some variations:

  1. Platform specification : This error has generic solution with most of the platform like win10, mac, linux etc.
  2. Addition Module : Some time we get this error in intermediate module like detectron2 etc. But the solution will be generic in all the cases.

Benefits of CUDA with Torch –

CUDA is parallel processing framework which provide application interface to deal with graphic card utility of the system. In complex operation like deep learning model training where we have to run operations like backpropagation we need multiprocessing. GPU provide great support for multiprocessing for that we need CUDA (NVIDA ). PyTorch or Tensorflow or any other deep learning  framework required GPU handling for high performance. Although it works fine with CPU in case of small dataset , less epochs etc. But Typically the dataset for any state of art algorithm is usually large in volume. Hence we need CUDA with PyTorch ( Python binding of Torch).

Thanks

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

We respect your privacy and take protecting it seriously

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Table of Contents
Hide
  1. Why this error occurs?
  2. Code Example

    1. Solutions
    2. Related Posts

In this article we will see the code solutions for Pytorch assertionerror torch not compiled with cuda enabled.

Why this error occurs?

Cuda is a toolkit which allows GPU to take charge of applications and increase the performance. In order to work with it, it’s essential to have Cuda supported Nvidia GPU installed in your system. Also Pytorch should also support GPU acceleration.

This assertionerror occurs when we try to use cuda on Pytorch version which is for CPU only. So, you have two options to resolve this error –

  1. Use Pytorch version which is compatible to Cuda. Download right stable version from here.
  2. Disable Cuda from your code. This could turn out to be tricky as you might not be using Cuda directly but some of the library in your project may. So, you need to troubleshoot that.

Error Code – Let’s first reproduce the error –

1. cuda passed as function parameter

import torch

my_tensor = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.float32, device="cuda")
print(my_tensor)

The above code will throw error – assertionerror: torch not compiled with cuda enabled. Here is the complete output –

Traceback (most recent call last):
  File "C:/Users/aka/project/test.py", line 3, in <module>
    my_tensor = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.float32, device="cuda")
  File "C:Usersakaanaconda3envsdeeplearninglibsite-packagestorchcuda__init__.py", line 166, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

This is because we set the flag device="cuda". If we change it to cpu like device="cpu" then the error will disappear.


2. Dependency using pytorch function with cuda enabled

There are many pytorch functions which copy data to Cuda memory for faster performance. They are generally disabled by default but some dependency of your project could be using those functions and enabling them. So, you need to look into that dependency and disable from there.

For example, torch.utils.data.DataLoader class has parameter pin_memory which, according to pytorch documentation says –

pin_memory (bool, optional) – If True, the data loader will copy Tensors into device/CUDA pinned memory before returning them. 

If a function using this class and setting pin_memory=true, then we will get torch not compiled with cuda enabled error.


Solutions

1. Check Pytorch version

First of all check if you have installed the right version. Pytorch is available with or without Cuda.

PyTorch versions with and without CUDA

2. Check if Cuda is available in installed Pytorch

Use this code to check if cuda is available in your installed Pytorch –

print(torch.cuda.is_available())

3. Create new project environment

Due to a lot of troubleshooting and error handling to resolve bugs, we break our project environment. Try creating a new environment if it solves your Cuda error.

4. Using .cuda() function

Some pytorch functions could be run on GPU by passing them through .cuda(). For example, neural network sequential() function could be run on cuda. So, append or remove it according to your use case –

model = nn.Sequential(OrderedDict([
          ('conv1', nn.Conv2d(1,20,5)),
          ('relu1', nn.ReLU()),
          ('conv2', nn.Conv2d(20,64,5)),
          ('relu2', nn.ReLU())
        ])).cuda()

5. Provide correct device parameter

If a function expects a device parameter then you may provide cuda or cpu according to your use case –

import torch

my_tensor = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.float32, device="cpu")

print(my_tensor)

This is Akash Mittal, an overall computer scientist. He is in software development from more than 10 years and worked on technologies like ReactJS, React Native, Php, JS, Golang, Java, Android etc. Being a die hard animal lover is the only trait, he is proud of.

Related Tags
  • Error,
  • python error,
  • python-short

I figured out this is a popular question, but still I couldn’t find a solution for that.

I’m trying to run a simple repo Here which uses PyTorch. Although I just upgraded my Pytorch to the latest CUDA version from pytorch.org (1.2.0), it still throws the same error. I’m on Windows 10 and use conda with python 3.7.

    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

How to fix the problem?

Here is my conda list:

# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py37_0    anaconda
_pytorch_select           1.1.0                       cpu    anaconda
_tflow_select             2.3.0                       mkl    anaconda
absl-py                   0.7.1                    pypi_0    pypi
alabaster                 0.7.12                   py37_0    anaconda
anaconda                  2019.07                  py37_0    anaconda
anaconda-client           1.7.2                    py37_0    anaconda
anaconda-navigator        1.9.7                    py37_0    anaconda
anaconda-project          0.8.3                      py_0    anaconda
argparse                  1.4.0                    pypi_0    pypi
asn1crypto                0.24.0                   py37_0    anaconda
astor                     0.8.0                    pypi_0    pypi
astroid                   2.2.5                    py37_0    anaconda
astropy                   3.2.1            py37he774522_0    anaconda
atomicwrites              1.3.0                    py37_1    anaconda
attrs                     19.1.0                   py37_1    anaconda
babel                     2.7.0                      py_0    anaconda
backcall                  0.1.0                    py37_0    anaconda
backports                 1.0                        py_2    anaconda
backports-csv             1.0.7                    pypi_0    pypi
backports-functools-lru-cache 1.5                      pypi_0    pypi
backports.functools_lru_cache 1.5                        py_2    anaconda
backports.os              0.1.1                    py37_0    anaconda
backports.shutil_get_terminal_size 1.0.0                    py37_2    anaconda
backports.tempfile        1.0                        py_1    anaconda
backports.weakref         1.0.post1                  py_1    anaconda
beautifulsoup4            4.7.1                    py37_1    anaconda
bitarray                  0.9.3            py37he774522_0    anaconda
bkcharts                  0.2                      py37_0    anaconda
blas                      1.0                         mkl    anaconda
bleach                    3.1.0                    py37_0    anaconda
blosc                     1.16.3               h7bd577a_0    anaconda
bokeh                     1.2.0                    py37_0    anaconda
boto                      2.49.0                   py37_0    anaconda
bottleneck                1.2.1            py37h452e1ab_1    anaconda
bzip2                     1.0.8                he774522_0    anaconda
ca-certificates           2019.5.15                     0    anaconda
certifi                   2019.6.16                py37_0    anaconda
cffi                      1.12.3           py37h7a1dbc1_0    anaconda
chainer                   6.2.0                    pypi_0    pypi
chardet                   3.0.4                    py37_1    anaconda
cheroot                   6.5.5                    pypi_0    pypi
cherrypy                  18.1.2                   pypi_0    pypi
click                     7.0                      py37_0    anaconda
cloudpickle               1.2.1                      py_0    anaconda
clyent                    1.2.2                    py37_1    anaconda
colorama                  0.4.1                    py37_0    anaconda
comtypes                  1.1.7                    py37_0    anaconda
conda                     4.7.11                   py37_0    anaconda
conda-build               3.18.9                   py37_3    anaconda
conda-env                 2.6.0                         1    anaconda
conda-package-handling    1.3.11                   py37_0    anaconda
conda-verify              3.4.2                      py_1    anaconda
console_shortcut          0.1.1                         3    anaconda
constants                 0.6.0                    pypi_0    pypi
contextlib2               0.5.5                    py37_0    anaconda
cpuonly                   1.0                           0    pytorch
cryptography              2.7              py37h7a1dbc1_0    anaconda
cudatoolkit               10.0.130                      0    anaconda
curl                      7.65.2               h2a8f88b_0    anaconda
cycler                    0.10.0                   py37_0    anaconda
cython                    0.29.12          py37ha925a31_0    anaconda
cytoolz                   0.10.0           py37he774522_0    anaconda
dask                      2.1.0                      py_0    anaconda
dask-core                 2.1.0                      py_0    anaconda
decorator                 4.4.0                    py37_1    anaconda
defusedxml                0.6.0                      py_0    anaconda
distributed               2.1.0                      py_0    anaconda
docutils                  0.14                     py37_0    anaconda
entrypoints               0.3                      py37_0    anaconda
et_xmlfile                1.0.1                    py37_0    anaconda
ez-setup                  0.9                      pypi_0    pypi
fastcache                 1.1.0            py37he774522_0    anaconda
fasttext                  0.9.1                    pypi_0    pypi
feedparser                5.2.1                    pypi_0    pypi
ffmpeg                    4.1.3                h6538335_0    conda-forge
filelock                  3.0.12                     py_0    anaconda
first                     2.0.2                    pypi_0    pypi
flask                     1.1.1                      py_0    anaconda
freetype                  2.9.1                ha9979f8_1    anaconda
future                    0.17.1                   py37_0    anaconda
gast                      0.2.2                    py37_0    anaconda
get                       2019.4.13                pypi_0    pypi
get_terminal_size         1.0.0                h38e98db_0    anaconda
gevent                    1.4.0            py37he774522_0    anaconda
glob2                     0.7                        py_0    anaconda
google-pasta              0.1.7                    pypi_0    pypi
graphviz                  2.38.0                        4    anaconda
greenlet                  0.4.15           py37hfa6e2cd_0    anaconda
grpcio                    1.22.0                   pypi_0    pypi
h5py                      2.9.0            py37h5e291fa_0    anaconda
hdf5                      1.10.4               h7ebc959_0    anaconda
heapdict                  1.0.0                    py37_2    anaconda
html5lib                  1.0.1                    py37_0    anaconda
http-client               0.1.22                   pypi_0    pypi
hypothesis                4.34.0                   pypi_0    pypi
icc_rt                    2019.0.0             h0cc432a_1    anaconda
icu                       58.2                 ha66f8fd_1    anaconda
idna                      2.8                      py37_0    anaconda
imageio                   2.4.1                    pypi_0    pypi
imageio-ffmpeg            0.3.0                    pypi_0    pypi
imagesize                 1.1.0                    py37_0    anaconda
importlib_metadata        0.17                     py37_1    anaconda
imutils                   0.5.2                    pypi_0    pypi
intel-openmp              2019.0                   pypi_0    pypi
ipykernel                 5.1.1            py37h39e3cac_0    anaconda
ipython                   7.6.1            py37h39e3cac_0    anaconda
ipython_genutils          0.2.0                    py37_0    anaconda
ipywidgets                7.5.0                      py_0    anaconda
isort                     4.3.21                   py37_0    anaconda
itsdangerous              1.1.0                    py37_0    anaconda
jaraco-functools          2.0                      pypi_0    pypi
jdcal                     1.4.1                      py_0    anaconda
jedi                      0.13.3                   py37_0    anaconda
jinja2                    2.10.1                   py37_0    anaconda
joblib                    0.13.2                   py37_0    anaconda
jpeg                      9b                   hb83a4c4_2    anaconda
json5                     0.8.4                      py_0    anaconda
jsonschema                3.0.1                    py37_0    anaconda
jupyter                   1.0.0                    py37_7    anaconda
jupyter_client            5.3.1                      py_0    anaconda
jupyter_console           6.0.0                    py37_0    anaconda
jupyter_core              4.5.0                      py_0    anaconda
jupyterlab                1.0.2            py37hf63ae98_0    anaconda
jupyterlab_server         1.0.0                      py_0    anaconda
keras                     2.2.4                         0    anaconda
keras-applications        1.0.8                      py_0    anaconda
keras-base                2.2.4                    py37_0    anaconda
keras-preprocessing       1.1.0                      py_1    anaconda
keyring                   18.0.0                   py37_0    anaconda
kiwisolver                1.1.0            py37ha925a31_0    anaconda
krb5                      1.16.1               hc04afaa_7
lazy-object-proxy         1.4.1            py37he774522_0    anaconda
libarchive                3.3.3                h0643e63_5    anaconda
libcurl                   7.65.2               h2a8f88b_0    anaconda
libiconv                  1.15                 h1df5818_7    anaconda
liblief                   0.9.0                ha925a31_2    anaconda
libmklml                  2019.0.5                      0    anaconda
libpng                    1.6.37               h2a8f88b_0    anaconda
libprotobuf               3.8.0                h7bd577a_0    anaconda
libsodium                 1.0.16               h9d3ae62_0    anaconda
libssh2                   1.8.2                h7a1dbc1_0    anaconda
libtiff                   4.0.10               hb898794_2    anaconda
libxml2                   2.9.9                h464c3ec_0    anaconda
libxslt                   1.1.33               h579f668_0    anaconda
llvmlite                  0.29.0           py37ha925a31_0    anaconda
locket                    0.2.0                    py37_1    anaconda
lxml                      4.3.4            py37h1350720_0    anaconda
lz4-c                     1.8.1.2              h2fa13f4_0    anaconda
lzo                       2.10                 h6df0209_2    anaconda
m2w64-gcc-libgfortran     5.3.0                         6
m2w64-gcc-libs            5.3.0                         7
m2w64-gcc-libs-core       5.3.0                         7
m2w64-gmp                 6.1.0                         2
m2w64-libwinpthread-git   5.0.0.4634.697f757               2
make-dataset              1.0                      pypi_0    pypi
markdown                  3.1.1                    py37_0    anaconda
markupsafe                1.1.1            py37he774522_0    anaconda
matplotlib                3.1.0            py37hc8f65d3_0    anaconda
mccabe                    0.6.1                    py37_1    anaconda
menuinst                  1.4.16           py37he774522_0    anaconda
mistune                   0.8.4            py37he774522_0    anaconda
mkl                       2019.0                   pypi_0    pypi
mkl-service               2.0.2            py37he774522_0    anaconda
mkl_fft                   1.0.12           py37h14836fe_0    anaconda
mkl_random                1.0.2            py37h343c172_0    anaconda
mock                      3.0.5                    py37_0    anaconda
more-itertools            7.0.0                    py37_0    anaconda
moviepy                   1.0.0                    pypi_0    pypi
mpmath                    1.1.0                    py37_0    anaconda
msgpack-python            0.6.1            py37h74a9793_1    anaconda
msys2-conda-epoch         20160418                      1
multipledispatch          0.6.0                    py37_0    anaconda
mysqlclient               1.4.2.post1              pypi_0    pypi
navigator-updater         0.2.1                    py37_0    anaconda
nbconvert                 5.5.0                      py_0    anaconda
nbformat                  4.4.0                    py37_0    anaconda
networkx                  2.3                        py_0    anaconda
ninja                     1.9.0            py37h74a9793_0    anaconda
nltk                      3.4.4                    py37_0    anaconda
nose                      1.3.7                    py37_2    anaconda
notebook                  6.0.0                    py37_0    anaconda
numba                     0.44.1           py37hf9181ef_0    anaconda
numexpr                   2.6.9            py37hdce8814_0    anaconda
numpy                     1.16.4                   pypi_0    pypi
numpy-base                1.16.4           py37hc3f5095_0    anaconda
numpydoc                  0.9.1                      py_0    anaconda
olefile                   0.46                     py37_0    anaconda
opencv-contrib-python     4.1.0.25                 pypi_0    pypi
opencv-python             4.1.0.25                 pypi_0    pypi
openpyxl                  2.6.2                      py_0    anaconda
openssl                   1.1.1c               he774522_1    anaconda
packaging                 19.0                     py37_0    anaconda
pandas                    0.24.2           py37ha925a31_0    anaconda
pandoc                    2.2.3.2                       0    anaconda
pandocfilters             1.4.2                    py37_1    anaconda
parso                     0.5.0                      py_0    anaconda
partd                     1.0.0                      py_0    anaconda
path.py                   12.0.1                     py_0    anaconda
pathlib2                  2.3.4                    py37_0    anaconda
patsy                     0.5.1                    py37_0    anaconda
pattern                   3.6                      pypi_0    pypi
pdfminer-six              20181108                 pypi_0    pypi
pep8                      1.7.1                    py37_0    anaconda
pickleshare               0.7.5                    py37_0    anaconda
pillow                    6.1.0            py37hdc69c19_0    anaconda
pip                       19.1.1                   py37_0    anaconda
pkginfo                   1.5.0.1                  py37_0    anaconda
pluggy                    0.12.0                     py_0    anaconda
ply                       3.11                     py37_0    anaconda
portend                   2.5                      pypi_0    pypi
post                      2019.4.13                pypi_0    pypi
powershell_shortcut       0.0.1                         2    anaconda
proglog                   0.1.9                    pypi_0    pypi
prometheus_client         0.7.1                      py_0    anaconda
prompt_toolkit            2.0.9                    py37_0    anaconda
protobuf                  3.7.1                    pypi_0    pypi
psutil                    5.6.3            py37he774522_0    anaconda
public                    2019.4.13                pypi_0    pypi
py                        1.8.0                    py37_0    anaconda
py-lief                   0.9.0            py37ha925a31_2    anaconda
pybind11                  2.3.0                    pypi_0    pypi
pycodestyle               2.5.0                    py37_0    anaconda
pycosat                   0.6.3            py37hfa6e2cd_0    anaconda
pycparser                 2.19                     py37_0    anaconda
pycrypto                  2.6.1            py37hfa6e2cd_9    anaconda
pycryptodome              3.8.2                    pypi_0    pypi
pycurl                    7.43.0.3         py37h7a1dbc1_0    anaconda
pydot                     1.4.1                    pypi_0    pypi
pyflakes                  2.1.1                    py37_0    anaconda
pygments                  2.4.2                      py_0    anaconda
pylint                    2.3.1                    py37_0    anaconda
pyodbc                    4.0.26           py37ha925a31_0    anaconda
pyopenssl                 19.0.0                   py37_0    anaconda
pyparsing                 2.4.0                      py_0    anaconda
pyqt                      5.9.2            py37h6538335_2    anaconda
pyreadline                2.1                      py37_1    anaconda
pyrsistent                0.14.11          py37he774522_0    anaconda
pysocks                   1.7.0                    py37_0    anaconda
pytables                  3.5.2            py37h1da0976_1    anaconda
pytest                    5.0.1                    py37_0    anaconda
pytest-arraydiff          0.3              py37h39e3cac_0    anaconda
pytest-astropy            0.5.0                    py37_0    anaconda
pytest-doctestplus        0.3.0                    py37_0    anaconda
pytest-openfiles          0.3.2                    py37_0    anaconda
pytest-remotedata         0.3.1                    py37_0    anaconda
python                    3.7.3                h8c8aaf0_1    anaconda
python-dateutil           2.8.0                    py37_0    anaconda
python-docx               0.8.10                   pypi_0    pypi
python-graphviz           0.11.1                   pypi_0    pypi
python-libarchive-c       2.8                     py37_11    anaconda
pytorch                   1.2.0               py3.7_cpu_1  [cpuonly]  pytorch
pytube                    9.5.1                    pypi_0    pypi
pytz                      2019.1                     py_0    anaconda
pywavelets                1.0.3            py37h8c2d366_1    anaconda
pywin32                   223              py37hfa6e2cd_1    anaconda
pywinpty                  0.5.5                 py37_1000    anaconda
pyyaml                    5.1.1            py37he774522_0    anaconda
pyzmq                     18.0.0           py37ha925a31_0    anaconda
qt                        5.9.7            vc14h73c81de_0  [vc14]  anaconda
qtawesome                 0.5.7                    py37_1    anaconda
qtconsole                 4.5.1                      py_0    anaconda
qtpy                      1.8.0                      py_0    anaconda
query-string              2019.4.13                pypi_0    pypi
request                   2019.4.13                pypi_0    pypi
requests                  2.22.0                   py37_0    anaconda
rope                      0.14.0                     py_0    anaconda
ruamel_yaml               0.15.46          py37hfa6e2cd_0    anaconda
scikit-image              0.15.0           py37ha925a31_0    anaconda
scikit-learn              0.21.2           py37h6288b17_0    anaconda
scipy                     1.3.0                    pypi_0    pypi
scipy-stack               0.0.5                    pypi_0    pypi
seaborn                   0.9.0                    py37_0    anaconda
send2trash                1.5.0                    py37_0    anaconda
setuptools                41.1.0                   pypi_0    pypi
simplegeneric             0.8.1                    py37_2    anaconda
singledispatch            3.4.0.3                  py37_0    anaconda
sip                       4.19.8           py37h6538335_0    anaconda
six                       1.12.0                   py37_0    anaconda
snappy                    1.1.7                h777316e_3    anaconda
snowballstemmer           1.9.0                      py_0    anaconda
sortedcollections         1.1.2                    py37_0    anaconda
sortedcontainers          2.1.0                    py37_0    anaconda
soupsieve                 1.8                      py37_0    anaconda
sphinx                    2.1.2                      py_0    anaconda
sphinxcontrib             1.0                      py37_1    anaconda
sphinxcontrib-applehelp   1.0.1                      py_0    anaconda
sphinxcontrib-devhelp     1.0.1                      py_0    anaconda
sphinxcontrib-htmlhelp    1.0.2                      py_0    anaconda
sphinxcontrib-jsmath      1.0.1                      py_0    anaconda
sphinxcontrib-qthelp      1.0.2                      py_0    anaconda
sphinxcontrib-serializinghtml 1.1.3                      py_0    anaconda
sphinxcontrib-websupport  1.1.2                      py_0    anaconda
spyder                    3.3.6                    py37_0    anaconda
spyder-kernels            0.5.1                    py37_0    anaconda
sqlalchemy                1.3.5            py37he774522_0    anaconda
sqlite                    3.29.0               he774522_0    anaconda
statsmodels               0.10.0           py37h8c2d366_0    anaconda
summa                     1.2.0                    pypi_0    pypi
sympy                     1.4                      py37_0    anaconda
tbb                       2019.4               h74a9793_0    anaconda
tblib                     1.4.0                      py_0    anaconda
tempora                   1.14.1                   pypi_0    pypi
tensorboard               1.14.0           py37he3c9ec2_0    anaconda
tensorboardx              1.8                      pypi_0    pypi
tensorflow                1.14.0          mkl_py37h7908ca0_0    anaconda
tensorflow-base           1.14.0          mkl_py37ha978198_0    anaconda
tensorflow-estimator      1.14.0                     py_0    anaconda
tensorflow-mkl            1.14.0               h4fcabd2_0    anaconda
termcolor                 1.1.0                    pypi_0    pypi
terminado                 0.8.2                    py37_0    anaconda
testpath                  0.4.2                    py37_0    anaconda
tk                        8.6.8                hfa6e2cd_0    anaconda
toolz                     0.10.0                     py_0    anaconda
torchvision               0.4.0                  py37_cpu  [cpuonly]  pytorch
tornado                   6.0.3            py37he774522_0    anaconda
tqdm                      4.32.1                     py_0    anaconda
traitlets                 4.3.2                    py37_0    anaconda
typing                    3.6.6                    pypi_0    pypi
typing-extensions         3.6.6                    pypi_0    pypi
unicodecsv                0.14.1                   py37_0    anaconda
urllib3                   1.24.2                   py37_0    anaconda
validators                0.13.0                   pypi_0    pypi
vc                        14.1                 h0510ff6_4    anaconda
vs2015_runtime            14.15.26706          h3a45250_4    anaconda
wcwidth                   0.1.7                    py37_0    anaconda
webencodings              0.5.1                    py37_1    anaconda
werkzeug                  0.15.4                     py_0    anaconda
wheel                     0.33.4                   py37_0    anaconda
widgetsnbextension        3.5.0                    py37_0    anaconda
win_inet_pton             1.1.0                    py37_0    anaconda
win_unicode_console       0.5                      py37_0    anaconda
wincertstore              0.2                      py37_0    anaconda
winpty                    0.4.3                         4    anaconda
wrapt                     1.11.2           py37he774522_0    anaconda
xlrd                      1.2.0                    py37_0    anaconda
xlsxwriter                1.1.8                      py_0    anaconda
xlwings                   0.15.8                   py37_0    anaconda
xlwt                      1.3.0                    py37_0    anaconda
xz                        5.2.4                h2fa13f4_4    anaconda
yaml                      0.1.7                hc54c509_2    anaconda
youtube-dl                2019.8.2                 pypi_0    pypi
zc-lockfile               1.4                      pypi_0    pypi
zeromq                    4.3.1                h33f27b4_3    anaconda
zict                      1.0.0                      py_0    anaconda
zipp                      0.5.1                      py_0    anaconda
zlib                      1.2.11               h62dcd97_3    anaconda
zstd                      1.3.7                h508b16e_0    anaconda
1) Solution

you dont have to install it via anaconda, you could install cuda from their website. after install ends open a new terminal and check your cuda version with:

>>> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:52:33_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

my is V11.5

then go here and select your os and preferred package manager(pip or anaconda), and the cuda version you installed, and copy the generated install command, I got:

pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

notice that for me I had python 3.10 installed but my project run over 3.9 so either use virtual environment or run pip of your wanted base interpreter explicitly (for example C:SoftwarePythonPython39python.exe -m pip install .....)
else you will be stuck with Could not find a version that satisfies the requirement torch errors

then open python console and check for cuda availability

>>> import torch
>>> torch.cuda.is_available()
True
2) Solution

How did you install pytorch? It sounds like you installed pytorch without CUDA support. https://pytorch.org/ has instructions for how to install pytorch with cuda support.

In this case, we have the following command:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

OR the command with latest cudatoolkit version.

3) Solution

Uninstalling the packages and reinstalling it with pip instead solved it for me.

1.conda remove pytorch torchvision torchaudio cudatoolkit

2.pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

4) Solution

try this:

conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
5) Solution

This error is happening because of incorrect device. Make sure to run this snippet before every experiment.

device = "cuda" if torch.cuda.is_available() else "cpu"
device
6) Solution

First activate your environment. Replace <name> with your environment name.

conda activate <name>

Then see cuda version in your machine. To see cuda version:

nvcc --version

Now for CUDA 10.1 use:

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch

For CUDA 10.0 use:

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.0 -c pytorch

For CUDA 9.2 use:

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2 -c pytorch
7) Solution

One more thing to note here is if you are installing PyTorch with CUDA support in an anaconda environment, Please make sure that the Python version should be 3.7-3.9.

conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge.

I was getting the same «AssertionError: Torch not compiled with CUDA enabled» with python 3.10.

Comments Section

@merv just added. Yeah idk why it says py3.7_cpu_1 for pytorch! ^_^

Maybe try forcing the CUDA version: conda install -c pytorch pytorch=1.2.0=py3.7_cuda92_cudnn7_1 or browse the files for a different compatible version.

That command will reconfigure your environment to use the specified version. So you don’t need to explicitly uninstall. Another (cleaner) option is to create a new env: conda create -n your_env_name -c pytorch pytorch=1.2.0=py3.7_cuda92_cudnn7_1.

Oh. Sorry, I was under the impression that you had a GPU. So, you can forget what I had proposed. You’ll need to switch back to CPU only conda install -c pytorch pytorch=1.2.0=py3.7_cpu_1. I’m not totally sure about this, but I think you need to edit the code in the repo you’re trying to run to explicitly use the CPU, e.g., replacing things like model.cuda() with model.cpu() (see here). But again, this is just my guess.

Sorry, IDK exactly. My strategy would be first changing all cuda() calls to cpu(), then letting it run and debugging where it breaks. I don’t think I can help beyond that generic advice.

Please ask questions in comments only. Answer a question only when you are sure!

nvidia-smi gives me CUDA Version: 11.4 while nvcc --version gives me Cuda compilation tools, release 10.1, V10.1.243. What should I do in this case?

Thank you!! This solution worked for me to enable CUDA on Windows 10 / Conda.

@desmond13 nvidia-smi and nvcc —version report different things, a mismatch doesn’t mean you don’t have required versions. Please read this stackoverflow.com/questions/53422407/…

Isn’t CUDA backwards compatible? If so it shouldn’t matter what version of CUDA driver I have installed as long as its the latest right?

The website gave me pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116, but cuda.is_available() still returns False and my script keeps raising AssertionError: Torch not compiled with CUDA enabled.

Make sure you pip installed on the same python interpreter(version) your python project is running on

Related Topics
python
conda
pytorch
torch

Mentions
Ajeet Verma
Tina J
Eliav Louski
Awal
Gilfoyle
Muhammad Hashir Ali
Sinh Nguyen
Oxal
Hussein
Milindsoorya

References
stackoverflow.com/questions/57814535/assertionerror-torch-not-compiled-with-cuda-enabled-in-spite-upgrading-to-cud

#python #machine-learning #pytorch #python-3.7 #torchvision

Вопрос:

Я пытаюсь запустить код из этого репозитория, и мне нужно использовать Pytorch 1.4.0. Я установил версию pytorch только для процессора pip install torch==1.4.0 cpu torchvision==0.5.0 cpu -f https://download.pytorch.org/whl/torch_stable.html .

Я запустил программу, выполнив py -m train_Kfold_CV --device 0 --fold_id 10 --np_data_dir "C:UsersusernameOneDriveDesktopemadeldeenAttnSleepprepare_datasetsedf_20_npz" , но я получаю эту ошибку:

   File "C:UsersusernameAppDataLocalProgramsPythonPython37librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:UsersusernameAppDataLocalProgramsPythonPython37librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:UsersusernameOneDriveDesktopemadeldeenAttnSleeptrain_Kfold_CV.py", line 94, in <module>
    main(config, fold_id)
  File "C:UsersusernameOneDriveDesktopemadeldeenAttnSleeptrain_Kfold_CV.py", line 65, in main
    trainer.train()
  File "C:UsersusernameOneDriveDesktopemadeldeenAttnSleepbasebase_trainer.py", line 66, in train
    result, epoch_outs, epoch_trgs = self._train_epoch(epoch, self.epochs)
  File "C:UsersusernameOneDriveDesktopemadeldeenAttnSleeptrainertrainer.py", line 49, in _train_epoch
    loss = self.criterion(output, target, self.class_weights)
  File "C:UsersusernameOneDriveDesktopemadeldeenAttnSleepmodelloss.py", line 6, in weighted_CrossEntropyLoss
    cr = nn.CrossEntropyLoss(weight=torch.tensor(classes_weights).cuda())
  File "C:UsersusernameAppDataLocalProgramsPythonPython37libsite-packagestorchcuda__init__.py", line 196, in _lazy_init
    _check_driver()
  File "C:UsersusernameAppDataLocalProgramsPythonPython37libsite-packagestorchcuda__init__.py", line 94, in _check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
 

Я изменил количество GPU в конфигурации на 0 и попытался добавить device = torch.device('cpu') в начале программы, но это ничего не дает. Как я могу исправить эту ошибку? Я использую Windows 10 с python 3.7.9, если это поможет

Спасибо

Ответ №1:

Вы используете только процессор pytorch, но в вашем коде есть оператор, подобный cr = nn.CrossEntropyLoss(weight=torch.tensor(classes_weights).cuda()) тому, который пытается переместить тензор на графический процессор.

Чтобы исправить это, удалите все .cuda() операции.

Понравилась статья? Поделить с друзьями:
  • Torch cuda is available false windows
  • Tor как служба в windows 10
  • Tor для windows xp 32 bit скачать бесплатно
  • Tor браузер скачать на русском для windows 7 32 бит
  • Tor браузер скачать на русском для windows 10 64 bit