detectron2安装报错解决记录

报错信息

Installing collected packages: detectron2
Running setup.py develop for detectron2
error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
?─> [49 lines of output]
    running develop
    running egg_info
    writing detectron2.egg-info/PKG-INFO
    writing dependency_links to detectron2.egg-info/dependency_links.txt
    writing requirements to detectron2.egg-info/requires.txt
    writing top-level names to detectron2.egg-info/top_level.txt
    reading manifest file 'detectron2.egg-info/SOURCES.txt'
    adding license file 'LICENSE'
    writing manifest file 'detectron2.egg-info/SOURCES.txt'
    running build_ext
    building 'detectron2._C' extension
    g++ -pthread -B /root/anaconda3/envs/mr_detr/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/TH -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/root/anaconda3/envs/mr_detr/include/python3.8 -c /root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.cpp -o build/temp.linux-x86_64-cpython-38/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++17
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/TH -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/root/anaconda3/envs/mr_detr/include/python3.8 -c /root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.cu -o build/temp.linux-x86_64-cpython-38/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options '-fPIC' -O3 -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_89,code=compute_89 -gencode=arch=compute_89,code=sm_89 -std=c++17
    nvcc fatal   : Unsupported gpu architecture 'compute_89'
    /root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/setuptools/command/develop.py:41: EasyInstallDeprecationWarning: easy_install command is deprecated.
    !!
    
            ********************************************************************************
            Please avoid running `setup.py and easy_install.
            Instead, use pypa/build, pypa/installer or other
            standards-based tools.
    
            See https://github.com/pypa/setuptools/issues/917 for details.
            ********************************************************************************
    
    !!
      easy_install.initialize_options(self)
    /root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
    !!
    
            ********************************************************************************
            Please avoid running `setup.py directly.
            Instead, use pypa/build, pypa/installer or other
            standards-based tools.
    
            See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
            ********************************************************************************
    
    !!
      self.initialize_options()
    /root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:495: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
      warnings.warn(msg.format('we could not find ninja.'))
    /root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:414: UserWarning: The detected CUDA version (11.3) has a minor version mismatch with the version that was used to compile PyTorch (11.8). Most likely this shouldn't be a problem.
      warnings.warn(CUDA_MISMATCH_WARN.format(cuda_str_version, torch.version.cuda))
    /root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:1965: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation.
    If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST'].
      warnings.warn(
    error: command '/usr/local/cuda/bin/nvcc' failed with exit code 1
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
?─> [49 lines of output]
running develop
running egg_info
writing detectron2.egg-info/PKG-INFO
writing dependency_links to detectron2.egg-info/dependency_links.txt
writing requirements to detectron2.egg-info/requires.txt
writing top-level names to detectron2.egg-info/top_level.txt
reading manifest file ‘detectron2.egg-info/SOURCES.txt’
adding license file ‘LICENSE’
writing manifest file ‘detectron2.egg-info/SOURCES.txt’
running build_ext
building 'detectron2.C’ extension
g++ -pthread -B /root/anaconda3/envs/mr_detr/compiler_compat -Wl,–sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/TH -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/root/anaconda3/envs/mr_detr/include/python3.8 -c /root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.cpp -o build/temp.linux-x86_64-cpython-38/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE="gcc" -DPYBIND11_STDLIB="libstdcpp" -DPYBIND11_BUILD_ABI="cxxabi1011" -DTORCH_EXTENSION_NAME=C -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++17
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/usr/local/cuda/bin/nvcc -DWITH_CUDA -I/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/TH -I/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/root/anaconda3/envs/mr_detr/include/python3.8 -c /root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.cu -o build/temp.linux-x86_64-cpython-38/root/maweiyi/Mr.DETR-main/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.o -D__CUDA_NO_HALF_OPERATORS
-D__CUDA_NO_HALF_CONVERSIONS
-D__CUDA_NO_BFLOAT16_CONVERSIONS
_ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ‘-fPIC’ -O3 -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=“_gcc” -DPYBIND11_STDLIB=“_libstdcpp” -DPYBIND11_BUILD_ABI=“_cxxabi1011” -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_89,code=compute_89 -gencode=arch=compute_89,code=sm_89 -std=c++17
nvcc fatal : Unsupported gpu architecture ‘compute_89’
/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/setuptools/command/develop.py:41: EasyInstallDeprecationWarning: easy_install command is deprecated.

!!

        ********************************************************************************
        Please avoid running `setup.py and easy_install.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running `setup.py directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:495: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
  warnings.warn(msg.format('we could not find ninja.'))
/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:414: UserWarning: The detected CUDA version (11.3) has a minor version mismatch with the version that was used to compile PyTorch (11.8). Most likely this shouldn't be a problem.
  warnings.warn(CUDA_MISMATCH_WARN.format(cuda_str_version, torch.version.cuda))
/root/anaconda3/envs/mr_detr/lib/python3.8/site-packages/torch/utils/cpp_extension.py:1965: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation.
If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST'].
  warnings.warn(
error: command '/usr/local/cuda/bin/nvcc' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

根本原因

nvcc fatal : Unsupported gpu architecture ‘compute_89’

chatGPT解释: 这是因为系统的 nvcc(CUDA 编译器)不支持 compute_89 架构(即 NVIDIA Ada Lovelace 架构,如 RTX 4090),而 setup.py 尝试为此架构编译代码。

在编译某个模块(python setup.py develop)时,系统调用了一个较旧的 nvcc 编译器,它不支持 RTX 4090 的 Compute Capability(compute_89)。

nvcc fatal   : Unsupported gpu architecture 'compute_89'

意味着你的 CUDA toolkit 的版本太低,尽管你下载的是 CUDA 11.8,但实际使用的是 较旧版本的 nvcc(可能是 11.3 或以下)。

⚠️ CUDA / PyTorch 版本不一致
错误日志中有:

The detected CUDA version (11.3) has a minor version mismatch with the version that was used to compile PyTorch (11.8)

也就是说:

  • PyTorch 是用 CUDA 11.8 编译的(PyTorch 自带编译信息)

  • 但系统中实际运行时 检测到的 CUDA Runtime 是 11.3

检查步骤

pytorch和cuda版本问题

我当时下载pytorch的时候,用nvidia-smi命令查了我的服务器的最高支持的版本,
发现是12.0,所以我去官网pytorch官网下载了11.8的pytorch,然后安装detectron2遇到了如上的问题,后来我查了自己服务器的cuda版本,发现现有的cuda版本是11.3,所以我的pytorch版本和现有的cuda版本不匹配,造成了错误。

如何查看系统的cuda安装版本

ls /usr/local/ | grep cuda

我的输出

cuda
cuda-11
cuda-11.3

可以看到我的cuda版本是11.3,所以需要的是11.3版本对应的pytorch。

解决方案

安装11.3cuda版本的pytorch

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113

在python环境下输出torch版本,可以看到安装的版本是对的

import torch
print(torch.__version__)
1.12.1+cu113

然后运行安装detectron2命令

python -m pip install -e detectron2

成功!!
detectron2安装报错解决记录_第1张图片

你可能感兴趣的:(python,深度学习,人工智能)