Charlie Parker
Charlie Parker

Reputation: 5267

why does conda install the pytorch CPU version despite me putting explicitly to download the cuda toolkit version?

I ran:

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

but I test if cuda is there:

(base) brando9~ $ python -c "import torch; print(torch.__version__); print((torch.randn(2, 4).cuda() @ torch.randn(4, 1).cuda()))"

1.13.1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/lfs/ampere4/0/brando9/miniconda/lib/python3.10/site-packages/torch/cuda/__init__.py", line 221, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

which doesn't make sense given the command I ran. But if you check the conda list it installed the cpu version for some reason:

(base) brando9~ $ conda list
# packages in environment at /lfs/ampere4/0/brando9/miniconda:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main
_openmp_mutex             5.1                       1_gnu
blas                      1.0                         mkl
brotlipy                  0.7.0           py310h7f8727e_1002
bzip2                     1.0.8                h7b6447c_0
ca-certificates           2022.12.7            ha878542_0    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310h5eee18b_3
charset-normalizer        2.0.4              pyhd3eb1b0_0
conda                     22.11.1         py310hff52083_1    conda-forge
conda-content-trust       0.1.3           py310h06a4308_0
conda-package-handling    1.9.0           py310h5eee18b_1
cryptography              38.0.1          py310h9ce1e76_0
cudatoolkit               11.1.1              ha002fc5_10    conda-forge
ffmpeg                    4.3                  hf484d3e_0    pytorch
freetype                  2.10.4               h0708190_1    conda-forge
giflib                    5.2.1                h36c2ea0_2    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gnutls                    3.6.13               h85f3911_1    conda-forge
idna                      3.4             py310h06a4308_0
intel-openmp              2021.4.0          h06a4308_3561
jpeg                      9e                   h166bdaf_1    conda-forge
lame                      3.100             h7f98852_1001    conda-forge
lcms2                     2.12                 h3be6417_0
ld_impl_linux-64          2.38                 h1181459_1
lerc                      3.0                  h295c915_0
libdeflate                1.8                  h7f8727e_5
libffi                    3.4.2                h6a678d5_6
libgcc-ng                 11.2.0               h1234567_1
libgomp                   11.2.0               h1234567_1
libiconv                  1.17                 h166bdaf_0    conda-forge
libpng                    1.6.37               hbc83047_0
libstdcxx-ng              11.2.0               h1234567_1
libtiff                   4.4.0                hecacb30_2
libuuid                   1.41.5               h5eee18b_0
libwebp                   1.2.4                h11a3e52_0
libwebp-base              1.2.4                h5eee18b_0
lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
mkl                       2021.4.0           h06a4308_640
mkl-service               2.4.0           py310ha2c4b55_0    conda-forge
mkl_fft                   1.3.1           py310h2b4bcf5_1    conda-forge
mkl_random                1.2.2           py310h00e6091_0
ncurses                   6.3                  h5eee18b_3
nettle                    3.6                  he412f7d_0    conda-forge
numpy                     1.23.5          py310hd5efca6_0
numpy-base                1.23.5          py310h8e6c178_0
openh264                  2.1.1                h4ff587b_0
openssl                   1.1.1s               h7f8727e_0
pillow                    9.3.0           py310hace64e9_1
pip                       22.3.1          py310h06a4308_0
pluggy                    1.0.0           py310h06a4308_1
pycosat                   0.6.4           py310h5eee18b_0
pycparser                 2.21               pyhd3eb1b0_0
pyopenssl                 22.0.0             pyhd3eb1b0_0
pysocks                   1.7.1           py310h06a4308_0
python                    3.10.8               h7a1cb2a_1
python_abi                3.10                    2_cp310    conda-forge
pytorch                   1.13.1             py3.10_cpu_0    pytorch
pytorch-mutex             1.0                         cpu    pytorch
readline                  8.2                  h5eee18b_0
requests                  2.28.1          py310h06a4308_0
ruamel.yaml               0.17.21         py310h5eee18b_0
ruamel.yaml.clib          0.2.6           py310h5eee18b_1
setuptools                65.5.0          py310h06a4308_0
six                       1.16.0             pyhd3eb1b0_1
sqlite                    3.40.0               h5082296_0
tk                        8.6.12               h1ccaba5_0
toolz                     0.12.0          py310h06a4308_0
torchaudio                0.13.1                py310_cpu    pytorch
torchvision               0.14.1                py310_cpu    pytorch
tqdm                      4.64.1          py310h06a4308_0
typing_extensions         4.4.0              pyha770c72_0    conda-forge
tzdata                    2022g                h04d1e81_0
urllib3                   1.26.13         py310h06a4308_0
wheel                     0.37.1             pyhd3eb1b0_0
xz                        5.2.8                h5eee18b_0
zlib                      1.2.13               h5eee18b_0
zstd                      1.5.2                ha4553b6_0

why? What is the right way to install an exact version of pytorch using conda?


For completness I will print pip list but it shouldn't matter since I've not ran a pip command yet:

(base) brando9~ $ pip list
Package                Version
---------------------- ---------
brotlipy               0.7.0
certifi                2022.12.7
cffi                   1.15.1
charset-normalizer     2.0.4
conda                  22.11.1
conda-content-trust    0.1.3
conda-package-handling 1.9.0
cryptography           38.0.1
idna                   3.4
mkl-fft                1.3.1
mkl-random             1.2.2
mkl-service            2.4.0
numpy                  1.23.5
Pillow                 9.3.0
pip                    22.3.1
pluggy                 1.0.0
pycosat                0.6.4
pycparser              2.21
pyOpenSSL              22.0.0
PySocks                1.7.1
requests               2.28.1
ruamel.yaml            0.17.21
ruamel.yaml.clib       0.2.6
setuptools             65.5.0
six                    1.16.0
toolz                  0.12.0
torch                  1.13.1
torchaudio             0.13.1
torchvision            0.14.1
tqdm                   4.64.1
typing_extensions      4.4.0
urllib3                1.26.13
wheel                  0.37.1

Upvotes: 3

Views: 2978

Answers (3)

PRUDHVI DARUVURI
PRUDHVI DARUVURI

Reputation: 1

Try this. This worked for me.

pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/cu111/torch_stable.html

Upvotes: 0

Charlie Parker
Charlie Parker

Reputation: 5267

I think this might work but I've not tested it (url I got it from https://pytorch.org/get-started/previous-versions/#v191):

# - bellow doesn't work, idk why. ref SO Q: https://stackoverflow.com/questions/75023120/why-does-conda-install-the-pytorch-cpu-version-despite-me-putting-explicitly-to
#conda install pytorch torchvision torchaudio pytorch-cuda=11.1 -c pytorch -c nvidia
conda install pytorch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1 cudatoolkit=11.3 -c pytorch -c conda-forge
# - test pytorch
python -c "import torch; print(torch.__version__); print((torch.randn(2, 4).cuda() @ torch.randn(4, 1).cuda()))"

pip install worked so I'm doing that. See answer here: Why is pip not letting me install torch==1.9.1+cu111 in a new conda env when I have another conda env that has exactly that version?

Upvotes: 0

feldim2425
feldim2425

Reputation: 424

You only install pytorch and the additional CUDA packages however the package adding CUDA support to PyToch is pytoch-cuda which is missing.

I recommend checking the getting-started guide on the PyToch website as it gives you a easy copy-paste command to install the packages you need on your system: https://pytorch.org/get-started/locally/

Just make sure to select the correct OS, package manager (conda in your case), and the correct CUDA version. The command should look something like this (for CUDA 11.7):

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

Note the pytorch-cuda package that is missing in your setup.

Upvotes: 2

Related Questions