GroundingDINO安装报错合集解决
本文是GroundingDINO安装报错的合集文章,后续都会收录在这篇文章中。
1、隔离环境构建引起的问题;
× Getting requirements to build editable did not run successfully. │exit code: 1 ╰─> [29 lines of output]
/home/hirol/miniconda3/envs/my_env/bin/python3.10:
No module named pip Traceback (most recent call last): File "<string>", line 32, in install_torch ModuleNotFoundError: No module named 'torch'
错误原因类似于:没有pip, 没有torch,这种非常离谱的原因。
首先明确自己的虚拟环境中确实已经装上了这类环境。可以通过 pip list show查看。
然后这类问题出现的原因,一般都是在构建GroundingDINO的时候,在setup.py中默认会给你构建起一个新的临时的隔离环境。而这个隔离环境一般就是什么都没有。
那么,我们就需要放弃构建这个隔离环境,让它在当前的虚拟环境中编译。
cd .../GroundingDINO-main# 这个让没有 .git 的源码也能给出一个版本号
export SETUPTOOLS_SCM_PRETEND_VERSION=0.1.0# 指定你的 GPU 架构,带 PTX 以便前向兼容
export TORCH_CUDA_ARCH_LIST="12.0+PTX"# 告诉 pip:不要用 PEP517 隔离构建(两道保险)
export PIP_USE_PEP517=0
export PIP_NO_BUILD_ISOLATION=1# 如果你有 CUDA 12.8 toolkit(而不只是驱动),也建议显式指定:
# export CUDA_HOME=/usr/local/cuda-12.8
# export PATH=$CUDA_HOME/bin:$PATH
# export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
然后运行关键命令:
pip install . --no-deps --no-build-isolation -v
验证:
python - <<'PY'
import torch, groundingdino, os, inspect
print("Torch:", torch.__version__, "CUDA avail:", torch.cuda.is_available())
print("GroundingDINO path:", os.path.dirname(inspect.getfile(groundingdino)))
PY
2、因为CUDA版本引起的问题
类似于这种:一大串:
building 'groundingdino._C' extension creating /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn [1/4] /usr/local/cuda-12.8/bin/nvcc --generate-dependencies-with-compile --dependency-output /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/cuda_version.o.d -DWITH_CUDA -I/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda-12.8/include -I/home/hirol/miniconda3/envs/my_env/include/python3.10 -c -c /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/cuda_version.cu -o /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/cuda_version.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'"'"'' -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -gencode=arch=compute_120,code=compute_120 -gencode=arch=compute_120,code=sm_120 -std=c++17 [2/4] c++ -MMD -MF /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cpu.o.d -pthread -B /home/hirol/miniconda3/envs/my_env/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/hirol/miniconda3/envs/my_env/include -fPIC -O2 -isystem /home/hirol/miniconda3/envs/my_env/include -fPIC -DWITH_CUDA -I/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda-12.8/include -I/home/hirol/miniconda3/envs/my_env/include/python3.10 -c -c /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cpu.cpp -o /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -std=c++17 [3/4] /usr/local/cuda-12.8/bin/nvcc --generate-dependencies-with-compile --dependency-output /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.o.d -DWITH_CUDA -I/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda-12.8/include -I/home/hirol/miniconda3/envs/my_env/include/python3.10 -c -c /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu -o /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_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'"'"'' -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -gencode=arch=compute_120,code=compute_120 -gencode=arch=compute_120,code=sm_120 -std=c++17 FAILED: [code=2] /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.o /usr/local/cuda-12.8/bin/nvcc --generate-dependencies-with-compile --dependency-output /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.o.d -DWITH_CUDA -I/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda-12.8/include -I/home/hirol/miniconda3/envs/my_env/include/python3.10 -c -c /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu -o /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_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'"'"'' -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -gencode=arch=compute_120,code=compute_120 -gencode=arch=compute_120,code=sm_120 -std=c++17 /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu(65): error: no suitable conversion function from "const at::DeprecatedTypeProperties" to "c10::ScalarType" exists [&] { const auto& the_type = value.type(); constexpr const char* at_dispatch_name = "ms_deform_attn_forward_cuda"; at::ScalarType _st = ::detail::scalar_type(the_type); ; switch (_st) { case at::ScalarType::Double: { do { if constexpr (!at::should_include_kernel_dtype( at_dispatch_name, at::ScalarType::Double)) { if (!(false)) { ::c10::detail::torchCheckFail( __func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(65), (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", "dtype '", toString(at::ScalarType::Double), "' not selected for kernel tag ", at_dispatch_name))); }; } } while (0); using scalar_t [[maybe_unused]] = c10::impl::ScalarTypeToCPPTypeT<at::ScalarType::Double>; return ([&] { ms_deformable_im2col_cuda(at::cuda::getCurrentCUDAStream(), value.data<scalar_t>() + n * im2col_step_ * per_value_size, spatial_shapes.data<int64_t>(), level_start_index.data<int64_t>(), sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size, batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point, columns.data<scalar_t>()); })(); } case at::ScalarType::Float: { do { if constexpr (!at::should_include_kernel_dtype( at_dispatch_name, at::ScalarType::Float)) { if (!(false)) { ::c10::detail::torchCheckFail( __func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(65), (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", "dtype '", toString(at::ScalarType::Float), "' not selected for kernel tag ", at_dispatch_name))); }; } } while (0); using scalar_t [[maybe_unused]] = c10::impl::ScalarTypeToCPPTypeT<at::ScalarType::Float>; return ([&] { ms_deformable_im2col_cuda(at::cuda::getCurrentCUDAStream(), value.data<scalar_t>() + n * im2col_step_ * per_value_size, spatial_shapes.data<int64_t>(), level_start_index.data<int64_t>(), sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size, batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point, columns.data<scalar_t>()); })(); } default: if (!(false)) { throw ::c10::NotImplementedError( {__func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(65)}, (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", '"', at_dispatch_name, "\" not implemented for '", toString(_st), "'"))); }; } }() ^ /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu(135): error: no suitable conversion function from "const at::DeprecatedTypeProperties" to "c10::ScalarType" exists [&] { const auto& the_type = value.type(); constexpr const char* at_dispatch_name = "ms_deform_attn_backward_cuda"; at::ScalarType _st = ::detail::scalar_type(the_type); ; switch (_st) { case at::ScalarType::Double: { do { if constexpr (!at::should_include_kernel_dtype( at_dispatch_name, at::ScalarType::Double)) { if (!(false)) { ::c10::detail::torchCheckFail( __func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(135), (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", "dtype '", toString(at::ScalarType::Double), "' not selected for kernel tag ", at_dispatch_name))); }; } } while (0); using scalar_t [[maybe_unused]] = c10::impl::ScalarTypeToCPPTypeT<at::ScalarType::Double>; return ([&] { ms_deformable_col2im_cuda(at::cuda::getCurrentCUDAStream(), grad_output_g.data<scalar_t>(), value.data<scalar_t>() + n * im2col_step_ * per_value_size, spatial_shapes.data<int64_t>(), level_start_index.data<int64_t>(), sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size, batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point, grad_value.data<scalar_t>() + n * im2col_step_ * per_value_size, grad_sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, grad_attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size); })(); } case at::ScalarType::Float: { do { if constexpr (!at::should_include_kernel_dtype( at_dispatch_name, at::ScalarType::Float)) { if (!(false)) { ::c10::detail::torchCheckFail( __func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(135), (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", "dtype '", toString(at::ScalarType::Float), "' not selected for kernel tag ", at_dispatch_name))); }; } } while (0); using scalar_t [[maybe_unused]] = c10::impl::ScalarTypeToCPPTypeT<at::ScalarType::Float>; return ([&] { ms_deformable_col2im_cuda(at::cuda::getCurrentCUDAStream(), grad_output_g.data<scalar_t>(), value.data<scalar_t>() + n * im2col_step_ * per_value_size, spatial_shapes.data<int64_t>(), level_start_index.data<int64_t>(), sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size, batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point, grad_value.data<scalar_t>() + n * im2col_step_ * per_value_size, grad_sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size, grad_attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size); })(); } default: if (!(false)) { throw ::c10::NotImplementedError( {__func__, "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu", static_cast<uint32_t>(135)}, (::c10::detail::torchCheckMsgImpl( "Expected " "false" " to be true, but got false. " "(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)", '"', at_dispatch_name, "\" not implemented for '", toString(_st), "'"))); }; } }() ^ 2 errors detected in the compilation of "/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu". [4/4] c++ -MMD -MF /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/vision.o.d -pthread -B /home/hirol/miniconda3/envs/my_env/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/hirol/miniconda3/envs/my_env/include -fPIC -O2 -isystem /home/hirol/miniconda3/envs/my_env/include -fPIC -DWITH_CUDA -I/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include -I/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda-12.8/include -I/home/hirol/miniconda3/envs/my_env/include/python3.10 -c -c /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/vision.cpp -o /home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/build/temp.linux-x86_64-cpython-310/home/hirol/Documents/ljx/Action_Controller/Detector/GroundingDINO-main/groundingdino/models/GroundingDINO/csrc/vision.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -std=c++17 ninja: build stopped: subcommand failed. Traceback (most recent call last): File "/home/hirol/miniconda3/envs/my_env/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 2620, in _run_ninja_build subprocess.run( File "/home/hirol/miniconda3/envs/my_env/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 2.
因为CUDA版本太新,然后GroundingDINO的编译版本太老(通常问题都是出现在groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu文件中),有些老的C++用法已经被丢弃(比如value.type())。
解决方案:
cd ..../GroundingDINO-main #(自己的GroudingDINO的路径)# 先保存备份
cp groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu{,.bak}python - <<'PY'
import re,sys,io
p="groundingdino/models/GroundingDINO/csrc/MsDeformAttn/ms_deform_attn_cuda.cu"
s=open(p,"r").read()# 1) forward 分支:去掉 DeprecatedTypeProperties -> 直接用 value.scalar_type()
s=re.sub(
r'const auto& the_type = value\.type\(\);\s*constexpr const char\* at_dispatch_name = "ms_deform_attn_forward_cuda";\s*at::ScalarType _st = ::detail::scalar_type\(the_type\);',
r'constexpr const char* at_dispatch_name = "ms_deform_attn_forward_cuda";\n at::ScalarType _st = value.scalar_type();',
s)# 2) backward 分支同理
s=re.sub(
r'const auto& the_type = value\.type\(\);\s*constexpr const char\* at_dispatch_name = "ms_deform_attn_backward_cuda";\s*at::ScalarType _st = ::detail::scalar_type\(the_type\);',
r'constexpr const char* at_dispatch_name = "ms_deform_attn_backward_cuda";\n at::ScalarType _st = value.scalar_type();',
s)# 3) 统一把 .data<T>() 改为 .data_ptr<T>()
s=re.sub(r'(\w+)\.data<([^>]+)>\(\)', r'\1.data_ptr<\2>()', s)open(p,"w").write(s)
print("Patched:", p)
PY
然后再重新编译:
python setup.py clean
pip install . --no-deps --no-build-isolation -v
应该就可以了。
由于博主经常装GroundingDINO,但是之前装的一些问题都忘记了,目前就只能记得这些(dbq)。所以就写了这些。如果有哪些没提到的,大家可以在评论区提问,或者是哪天村长自己遇到了新的,或者是村长在遇到的再补充。