解决安装detectron2报错The detected CUDA version mismatches the version that was used to compile

报错内容       

           File "/root/miniconda3/envs/llava/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
            self.build_extensions()
          File "/root/miniconda3/envs/llava/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 525, in build_extensions
            _check_cuda_version(compiler_name, compiler_version)
          File "/root/miniconda3/envs/llava/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 413, in _check_cuda_version
            raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda))
        RuntimeError:
        The detected CUDA version (11.3) mismatches the version that was used to compile
        PyTorch (12.1). Please make sure to use the same CUDA versions.

解决方案

看到这既然是cuda和pytorch对比导致的错误,但是众所周知其实问题没那么大,然后往上看看到了


          File "/root/miniconda3/envs/llava/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 525, in build_extensions
            _check_cuda_version(compiler_name, compiler_version)

那解决不了问题就解决提出问题的代码,修改该部分代码为

        if cuda_ext and not IS_HIP_EXTENSION:
           pass # _check_cuda_version(compiler_name, compiler_version)

考虑到部分人不知道怎么找到这段代码,我教你

(1)方法一:ctrl+左键按一下报错里的_check_cuda_version(compiler_name, compiler_version)

(2)方法二:按照路径,一点点找~

然后重新安装detectron2,安装成功。就是说嘛,能有啥事呀,搞这么严格的匹配!

喜欢就点个赞把~

猜你喜欢

转载自blog.csdn.net/m0_51516317/article/details/139423784