NVIDIA/apex报错解决过程

https://github.com/NVIDIA/apex

python setup.py install --cuda_ext --cpp_ext

马上报错

File "setup.py", line 106, in <module>
    check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)
  File "setup.py", line 80, in check_cuda_torch_binary_vs_bare_metal
    "https://github.com/NVIDIA/apex/pull/323#discussion_r287021798.  "

RuntimeError: Cuda extensions are being compiled with a version of Cuda that does not match the version used to compile Pytorch binaries.  Pytorch binaries were compiled with Cuda 10.0.
In some cases, a minor-version mismatch will not cause later errors:  https://github.com/NVIDIA/apex/pull/323#discussion_r287021798.  You can try commenting out this check (at your own risk).

Cuda扩展的编译版本与用于编译Pytorch二进制文件的版本不匹配。Pytorch二进制文件是用Cuda 10.0编译的。

查询一下CUDA版本

C:\Users\Cleme>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130

根据错误提示,我定位到cpp_extension.py源代码,发现
在这里插入图片描述
重点是这一句话cuda_home = os.environ.get('CUDA_HOME') or os.environ.get('CUDA_PATH'),因为我的系统安装了CUDA的多个版本
在这里插入图片描述

>>> import os
>>> os.environ.get('CUDA_HOME')
>>> 显示为空
>>> os.environ.get('CUDA_PATH')
'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.0'

原来没有添加CUDA_HOME环境变量,CUDA_PATH也与pytorch对应的cuda版本不一致,才导致安装报错。设置好CUDA_HOME环境变量之后退出终端和pycharm重新打开就可以了。CUDA_PATH与CUDA_HOME的路径是一样的。
在这里插入图片描述
CUDA_PATH_Vxx主要是为了方便我以后在PATH变量中添加不同CUDA版本,上移/下移就能改变它们的优先级。
在这里插入图片描述

>>> os.environ.get('CUDA_HOME')
'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0'
>>> os.environ.get('CUDA_PATH')
'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0'

C:\Users\Cleme>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130
>>> import torch
>>> print(torch.version.cuda)
10.0

最后重新执行安装命令
python setup.py install --cuda_ext --cpp_ext
又报错了,这次显示不支持的Microsoft Visual Studio版本!只支持2013年至2017年的版本(包括usiv)
e)支持!

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\crt/host_config.h(143): fatal error C1189: #error:  -- unsupported Microsoft Visual Studio version! Only the versions between 2013 and 2017 (inclusiv
e) are supported!
error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin\\nvcc.exe' failed with exit status 2

那只能乖乖地把刚刚装上vs2019卸载,重新安装vs2017。或者根据github上面所说,推荐linux。

发布了40 篇原创文章 · 获赞 0 · 访问量 1531

猜你喜欢

转载自blog.csdn.net/zhoumoon/article/details/104928010