之所以报这个错,是因为你没有成功的安装apex,注意~:不是pip install apex
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-6o4wusvf/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-6o4wusvf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' --cpp_ext --cuda_ext install --record /tmp/pip-record-07hjl8r1/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7/apex Check the logs for full command output.
Exception information:
Traceback (most recent call last):
处理方法:第一步使用这个命令查看你的机器支持的cuda版本:
nvcc --version
第二步:使用下面的命令查看你当前安装的cuda的版本。
pip list
注意:安装apex必须保证二者版本一致。即机器所支持的版本比如是11.0,那你就安装对应torch版本的cuda。
先使用下面命令卸载你机器原来的torch
!pip uninstall -y torch torchvision torchaudio
再使用下面的命令安装,比如我这里机器所支持的是11.0版本的cuda
!pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
接下来再安装apex:
!git clone https://github.com/NVIDIA/apex
%cd apex
!pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
以上工作就完成了。