open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.28k stars 9.41k forks source link

How do I compile MMDectionv1.0 successfully on CUDA11.0 #7759

Closed youzi260 closed 2 years ago

youzi260 commented 2 years ago

Hi, I want to implement MMDetectionv1.0 on CUDA11.0, but when I run Python setup.py develop, I am prompted that my CUDA version is too high, I would like to ask how to implement successful compilation in CUDa11.0. Because I can't install the lower VERSION of CUDA on my server.

python setup.py develop /home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/dist.py:516: UserWarning: Normalizing '1.0.rc0+1c9afec' to '1.0rc0+1c9afec' warnings.warn(tmpl.format(locals())) running develop /home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools. warnings.warn( /home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running egg_info writing mmdet.egg-info/PKG-INFO writing dependency_links to mmdet.egg-info/dependency_links.txt writing requirements to mmdet.egg-info/requires.txt writing top-level names to mmdet.egg-info/top_level.txt /home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/torch/utils/cpp_extension.py:387: 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.')) reading manifest file 'mmdet.egg-info/SOURCES.txt' adding license file 'LICENSE' writing manifest file 'mmdet.egg-info/SOURCES.txt' running build_ext Traceback (most recent call last): File "/home/whh/ZTT/zero_shot_detection-master/mmdetection/setup.py", line 131, in setup( File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/init.py", line 87, in setup return distutils.core.setup(attrs) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 148, in setup return run_commands(dist) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 163, in run_commands dist.run_commands() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands self.run_command(cmd) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/dist.py", line 1214, in run_command super().run_command(command) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 986, in run_command cmd_obj.run() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/command/develop.py", line 34, in run self.install_for_development() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/command/develop.py", line 114, in install_for_development self.run_command('build_ext') File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/dist.py", line 1214, in run_command super().run_command(command) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 986, in run_command cmd_obj.run() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 79, in run _build_ext.run(self) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 410, in build_extensions self._check_cuda_version() File "/home/whh/anaconda3/envs/ztt/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 787, in _check_cuda_version raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda)) RuntimeError: The detected CUDA version (11.0) mismatches the version that was used to compile PyTorch (10.2). Please make sure to use the same CUDA versions.

setup.py: import os import platform import subprocess import time from setuptools import Extension, dist, find_packages, setup

from torch.utils.cpp_extension import BuildExtension, CUDAExtension

dist.Distribution().fetch_build_eggs(['Cython', 'numpy>=1.11.1']) import numpy as np # noqa: E402 from Cython.Build import cythonize # noqa: E402

def readme(): with open('README.md', encoding='utf-8') as f: content = f.read() return content

MAJOR = 1 MINOR = 0 PATCH = '' SUFFIX = 'rc0' SHORT_VERSION = '{}.{}.{}{}'.format(MAJOR, MINOR, PATCH, SUFFIX)

version_file = 'mmdet/version.py'

def get_git_hash():

def _minimal_ext_cmd(cmd):
    # construct minimal environment
    env = {}
    for k in ['SYSTEMROOT', 'PATH', 'HOME']:
        v = os.environ.get(k)
        if v is not None:
            env[k] = v
    # LANGUAGE is used on win32
    env['LANGUAGE'] = 'C'
    env['LANG'] = 'C'
    env['LC_ALL'] = 'C'
    out = subprocess.Popen(
        cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
    return out

try:
    out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
    sha = out.strip().decode('ascii')
except OSError:
    sha = 'unknown'

return sha

def get_hash(): if os.path.exists('.git'): sha = get_git_hash()[:7] elif os.path.exists(version_file): try: from mmdet.version import version sha = version.split('+')[-1] except ImportError: raise ImportError('Unable to get git version') else: sha = 'unknown'

return sha

def write_version_py(): content = """# GENERATED VERSION FILE

TIME: {}

version = '{}' short_version = '{}' """ sha = get_hash() VERSION = SHORT_VERSION + '+' + sha

with open(version_file, 'w') as f:
    f.write(content.format(time.asctime(), VERSION, SHORT_VERSION))

def get_version(): with open(version_file, 'r') as f: exec(compile(f.read(), version_file, 'exec')) return locals()['version']

def make_cuda_ext(name, module, sources):

return CUDAExtension(
    name='{}.{}'.format(module, name),
    sources=[os.path.join(*module.split('.'), p) for p in sources],
    extra_compile_args={
        'cxx': [],
        'nvcc': [
            '-D__CUDA_NO_HALF_OPERATORS__',
            '-D__CUDA_NO_HALF_CONVERSIONS__',
            '-D__CUDA_NO_HALF2_OPERATORS__',
        ]
    })

def make_cython_ext(name, module, sources): extra_compile_args = None if platform.system() != 'Windows': extra_compile_args = { 'cxx': ['-Wno-unused-function', '-Wno-write-strings'] }

extension = Extension(
    '{}.{}'.format(module, name),
    [os.path.join(*module.split('.'), p) for p in sources],
    include_dirs=[np.get_include()],
    language='c++',
    extra_compile_args=extra_compile_args)
extension, = cythonize(extension)
return extension

def get_requirements(filename='requirements.txt'): here = os.path.dirname(os.path.realpath(file)) with open(os.path.join(here, filename), 'r') as f: requires = [line.replace('\n', '') for line in f.readlines()] return requires

if name == 'main': write_version_py() setup( name='mmdet', version=get_version(), description='Open MMLab Detection Toolbox and Benchmark', long_description=readme(), author='OpenMMLab', author_email='chenkaidev@gmail.com', keywords='computer vision, object detection', url='https://github.com/open-mmlab/mmdetection', packages=find_packages(exclude=('configs', 'tools', 'demo')), package_data={'mmdet.ops': ['/.so']}, classifiers=[ 'Development Status :: 4 - Beta', 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.10', ], license='Apache License 2.0', setup_requires=['pytest-runner', 'cython', 'numpy'], tests_require=['pytest', 'xdoctest'], install_requires=get_requirements(), ext_modules=[ make_cython_ext( name='soft_nms_cpu', module='mmdet.ops.nms', sources=['src/soft_nms_cpu.pyx']), make_cuda_ext( name='nms_cpu', module='mmdet.ops.nms', sources=['src/nms_cpu.cpp']), make_cuda_ext( name='nms_cuda', module='mmdet.ops.nms', sources=['src/nms_cuda.cpp', 'src/nms_kernel.cu']), make_cuda_ext( name='roi_align_cuda', module='mmdet.ops.roi_align', sources=['src/roi_align_cuda.cpp', 'src/roi_align_kernel.cu']), make_cuda_ext( name='roi_pool_cuda', module='mmdet.ops.roi_pool', sources=['src/roi_pool_cuda.cpp', 'src/roi_pool_kernel.cu']), make_cuda_ext( name='deform_conv_cuda', module='mmdet.ops.dcn', sources=[ 'src/deform_conv_cuda.cpp', 'src/deform_conv_cuda_kernel.cu' ]), make_cuda_ext( name='deform_pool_cuda', module='mmdet.ops.dcn', sources=[ 'src/deform_pool_cuda.cpp', 'src/deform_pool_cuda_kernel.cu' ]), make_cuda_ext( name='sigmoid_focal_loss_cuda', module='mmdet.ops.sigmoid_focal_loss', sources=[ 'src/sigmoid_focal_loss.cpp', 'src/sigmoid_focal_loss_cuda.cu' ]), make_cuda_ext( name='masked_conv2d_cuda', module='mmdet.ops.masked_conv', sources=[ 'src/masked_conv2d_cuda.cpp', 'src/masked_conv2d_kernel.cu' ]), ], cmdclass={'build_ext': BuildExtension}, zip_safe=False)

jbwang1997 commented 2 years ago
image

This error is caused by mismatching the CUDA compilation version and the PyTorch version. You can try to install PyTorch with CUDA 11.0