python - 尽管我明确下载了 cuda 工具包版本,为什么 conda 仍安装 pytorch CPU 版本?

标签 python pytorch anaconda conda

我跑了:

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

但我测试 cuda 是否存在:

(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

考虑到我运行的命令,这是没有意义的。但是如果你检查 conda 列表,它会因为某种原因安装了 cpu 版本:

(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
为什么?使用 conda 安装准确版本的 pytorch 的正确方法是什么?


为了完整性,我将打印 pip 列表,但这并不重要,因为我还没有运行 pip 命令:

(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

最佳答案

您只安装 pytorch 和其他 CUDA 软件包,但是向 PyToch 添加 CUDA 支持的软件包是 pytoch-cuda ,但缺少。

我建议您查看 PyToch 网站上的入门指南,因为它为您提供了一个简单的复制粘贴命令来安装系统上所需的软件包:https://pytorch.org/get-started/locally/

只需确保选择正确的操作系统、包管理器(在您的情况下为 conda)和正确的 CUDA 版本。 该命令应如下所示(对于 CUDA 11.7):

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

请注意您的设置中缺少的 pytorch-cuda 软件包。

关于python - 尽管我明确下载了 cuda 工具包版本,为什么 conda 仍安装 pytorch CPU 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75023120/

相关文章:

python - InitFont 错误 - OpenCV 3.1 (Python)

deep-learning - 在pytorch中使用位置编码

pytorch - 这个 LSTM 循环代码是否会破坏 PyTorch 中的计算图?

anaconda - Biopython,导入错误, "import Bio"

python - Fabric - 测试与多个主机的 SSH 连接

python - QPaint 使用 mouseevent 进行平移缩放

python - 如何在 python 中过滤 XML 文件中的值

python-3.x - Pytorch 试图使 NN 接收到无效的参数组合

python - CondaVerificationError : || ClobberError: Create a new conda environment with Python 2. 7.x 或 3.7.x

python - VS2017中使用conda环境