62

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
Tina J
  • 4,983
  • 13
  • 59
  • 125
  • 1
    Not clear from the question, but it sounds like you downloaded software from the web. If you are using a Conda environment, you need to use `conda` to install it. E.g., `conda install -c pytorch pytorch=1.2.0` The default PyTorch on the `pytorch` channel is the CUDA build and installs the CUDA toolkit itself. – merv Sep 06 '19 at 19:29
  • @merv Yes that's what I did exactly. Doing it again, `# All requested packages already installed.` – Tina J Sep 07 '19 at 01:50
  • okay, then I'd say add your `conda list` to the question since that might be informative. – merv Sep 07 '19 at 01:54
  • 1
    @merv just added. Yeah idk why it says `py3.7_cpu_1` for pytorch! ^_^ – Tina J Sep 07 '19 at 02:00
  • 2
    Maybe try forcing the CUDA version: `conda install -c pytorch pytorch=1.2.0=py3.7_cuda92_cudnn7_1` or [browse the files](https://anaconda.org/pytorch/pytorch/files?version=1.2.0) for a different compatible version. – merv Sep 07 '19 at 02:08
  • can I uninstall that and re-install with your command? – Tina J Sep 07 '19 at 02:09
  • 1
    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`. – merv Sep 07 '19 at 02:13
  • @merv Thanks. They worked. But when trying to run `Found no NVIDIA driver on your system.`. I have no GPU, but doesn't it automatically run it on CPU when no gpu is there?! How to fix it? `model.cuda()` – Tina J Sep 07 '19 at 02:56
  • 3
    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](https://github.com/swathikirans/violence-recognition-pytorch/blob/master/main-run-vr.py#L106)). But again, this is just my guess. – merv Sep 07 '19 at 14:52
  • Yeah i need to know exactly what to change. There are some cuda() with arguments also. Do I need to change them as well? Saw somewhere saying change to .device...but that didn't work. – Tina J Sep 07 '19 at 18:19
  • 2
    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. – merv Sep 07 '19 at 18:24
  • No problem. Thanks. – Tina J Sep 07 '19 at 19:19
  • To clarify on some of the above comments, simply installing pytorch with the cuda toolkit enabled DOES NOT install CUDA itself. Cuda must be installed separately, which can be done even without a GPU (see https://stackoverflow.com/questions/20186848/can-i-compile-a-cuda-program-without-having-a-cuda-device) – DerekG Jan 20 '21 at 04:18

11 Answers11

38

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:\Software\Python\Python39\python.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
Eliav Louski
  • 3,593
  • 2
  • 28
  • 52
  • 1
    Thank you!! This solution worked for me to enable CUDA on Windows 10 / Conda. – P.O.W. Jan 01 '22 at 11:36
  • 6
    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`. – Zylann Sep 06 '22 at 21:02
  • Make sure you pip installed on the same python interpreter(version) your python project is running on – Eliav Louski Oct 16 '22 at 17:27
  • I have the same issue as Zylann, how do you ensure you installed it on the same python interpreter? – Titus Buckworth Feb 03 '23 at 10:22
  • Thanks, worked for me! Strange that the official PyTorch website provides conda install instructions, which do not work. – Christian Mar 05 '23 at 09:16
  • For me what finally worked in conda was: `conda install "pytorch=*=*cuda*" pytorch-cuda -c pytorch -c nvidia`. This forced conda to only get versions of pytorch where the build name contains "cuda". – Tim Goodman May 03 '23 at 12:53
  • 2
    If you still getting `False`, you may have to install the previous version without Cuda support via `pip3 uninstall torch torchvision torchaudio` before. – User Rebo May 04 '23 at 10:17
11

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.

Gilfoyle
  • 3,282
  • 3
  • 47
  • 83
10

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

Hussein
  • 111
  • 1
  • 5
  • I moved some pythod directories from one drive to another, and afterwards kept getting torch.cuda.is_available() == false, until your post. Thank you! – Elijah Apr 24 '23 at 23:49
  • Thank you, I solved it by creating new conda environment. It was colision with older pytorch, which was not supporting my CUDA version. – Jaroslav Štreit May 02 '23 at 09:00
  • Thank you, solved my problem. dk why conda can't solve the env for some versions. – Mobin Jun 08 '23 at 01:47
3

try this:

conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
Sinh Nguyen
  • 4,277
  • 3
  • 18
  • 26
oxal
  • 39
  • 5
3

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.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch

For CUDA 10.0 use:

conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.0 -c pytorch

For CUDA 9.2 use:

conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=9.2 -c pytorch

You can also visit this link to see pytorch and the corresponding torchvision version.

Awal
  • 160
  • 1
  • 2
  • 8
  • 3
    `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? – desmond13 Nov 23 '21 at 16:48
  • @desmond13 nvidia-smi and nvcc --version report different things, a mismatch doesn't mean you don't have required versions. Please read this https://stackoverflow.com/questions/53422407/different-cuda-versions-shown-by-nvcc-and-nvidia-smi – Raymond Jan 19 '22 at 22:40
  • 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? – jaroslawj Aug 18 '22 at 22:24
2

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.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
2

It seems like you do not have Pytorch installed with CUDA support.

Try checking your CUDA version using

nvcc --version

or

nvidia-smi

Install from the original pytorch distribution into your conda environment https://pytorch.org/get-started/locally/

Configure Pytorch for Mac M1 chips

Step 1: Install Xcode Install the Command Line Tools:

xcode-select --install

Step 2: Setup a new conda environment

conda create -n torch-gpu python=3.8
conda activate torch-gpu

Step 2: Install PyTorch packages

conda install pytorch torchvision torchaudio -c pytorch-nightly

Step 3: Install Jupyter notebook for validating installation

conda install -c conda-forge jupyter jupyterlab
jupter-notebook

Create new notebook file and execute this code

dtype = torch.float
device = torch.device("mps")

# Create random input and output data
x = torch.linspace(-math.pi, math.pi, 2000, device=device, dtype=dtype)
y = torch.sin(x)

# Randomly initialize weights
a = torch.randn((), device=device, dtype=dtype)
b = torch.randn((), device=device, dtype=dtype)
c = torch.randn((), device=device, dtype=dtype)
d = torch.randn((), device=device, dtype=dtype)

learning_rate = 1e-6
for t in range(2000):
    # Forward pass: compute predicted y
    y_pred = a + b * x + c * x ** 2 + d * x ** 3

    # Compute and print loss
    loss = (y_pred - y).pow(2).sum().item()
    if t % 100 == 99:
        print(t, loss)

# Backprop to compute gradients of a, b, c, d with respect to loss
    grad_y_pred = 2.0 * (y_pred - y)
    grad_a = grad_y_pred.sum()
    grad_b = (grad_y_pred * x).sum()
    grad_c = (grad_y_pred * x ** 2).sum()
    grad_d = (grad_y_pred * x ** 3).sum()

    # Update weights using gradient descent
    a -= learning_rate * grad_a
    b -= learning_rate * grad_b
    c -= learning_rate * grad_c
    d -= learning_rate * grad_d


print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')

If you don’t see any error, everything works as expected!

Ref: https://towardsdatascience.com/installing-pytorch-on-apple-m1-chip-with-gpu-acceleration-3351dc44d67c

HamzaMushtaq
  • 1,660
  • 13
  • 13
1

pyenv local 3.8.6 poetry env use $(pyenv which python) poetry run pip install -U pip 'setuptools==59.5.0' poetry install

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 12 '23 at 11:02
  • It is not clear how this solves the problem. Please modify your answer and add some explanation. – Azhar Khan Feb 13 '23 at 09:45
0

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
0

I was have this problem. My solution is non-Russian IP. Pycharm & Keras not work too.

StasGT
  • 11
  • 1
  • Without VPN or proxy, for cod: print(torch.cuda.is_available()) print(torch.cuda.device_count()) print(torch.__version__) print(torch.version.cuda) result: Fails 0 "something"+cpu None – StasGT Feb 02 '23 at 09:32
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '23 at 03:22
0

inside of jupyter notebook IDE, run this code:

! pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

and test again!