我跑过去:
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 list,但这不重要,因为我还没有运行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
2条答案
按热度按时间e3bfsja21#
您只需要安装
pytorch
和其他CUDA包,但是将CUDA支持添加到PyToch的包是pytoch-cuda
,该包丢失。我建议查看PyToch网站上的入门指南,因为它提供了一个简单的复制-粘贴命令来安装你需要的软件包:https://pytorch.org/get-started/locally/
只需确保选择了正确的操作系统、软件包管理器(在您的例子中为conda)和正确的CUDA版本,命令应该如下所示(适用于CUDA 11.7):
康达安装pytorch Torch 视觉 Torch 音频pytorch-cuda=11.7 -c pytorch -c英伟达
注意您的设置中缺少的
pytorch-cuda
包。j1dl9f462#
我认为这可能会工作,但我还没有测试它(url我从https://pytorch.org/get-started/previous-versions/#v191):
pip安装工作,所以我这样做.看到这里的答案: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?