GroundingDINO icon indicating copy to clipboard operation
GroundingDINO copied to clipboard

NameError: name '_C' is not defined again and again, it made me mad, cuda installed , nvcc worked well

Open xdfai4x opened this issue 1 year ago • 19 comments

Hi, my os is Ubuntu 24.04 desktop, with a RTX 4090 card, I deploy this project for so many times but I always got this error. Is there anybody can help me with that? here is my environments: $ echo $CUDA_HOME /usr/local/cuda-12.6

$ ll /usr/local/cuda-12.6 drwxr-xr-x 15 root root 4096 Nov 2 19:26 ./ drwxr-xr-x 15 root root 4096 Nov 5 15:31 ../ drwxr-xr-x 3 root root 4096 Nov 2 19:26 bin/ drwxr-xr-x 5 root root 4096 Nov 2 19:26 compute-sanitizer/ drwxr-xr-x 3 root root 4096 Nov 2 19:26 doc/ -rw-r--r-- 1 root root 160 Sep 12 17:51 DOCS -rw-r--r-- 1 root root 63021 Sep 12 17:51 EULA.txt drwxr-xr-x 4 root root 4096 Nov 2 19:26 extras/ drwxr-xr-x 3 root root 4096 Nov 2 19:26 gds/ lrwxrwxrwx 1 root root 28 Sep 12 17:47 include -> targets/x86_64-linux/include/ lrwxrwxrwx 1 root root 24 Sep 12 17:47 lib64 -> targets/x86_64-linux/lib/ drwxr-xr-x 7 root root 4096 Nov 2 19:26 libnvvp/ drwxr-xr-x 2 root root 4096 Nov 2 19:26 nsightee_plugins/ drwxr-xr-x 3 root root 4096 Nov 2 19:26 nvml/ drwxr-xr-x 6 root root 4096 Nov 2 19:26 nvvm/ -rw-r--r-- 1 root root 524 Sep 12 17:51 README drwxr-xr-x 3 root root 4096 Nov 2 19:26 share/ drwxr-xr-x 2 root root 4096 Nov 2 19:26 src/ drwxr-xr-x 3 root root 4096 Nov 2 19:26 targets/ drwxr-xr-x 2 root root 4096 Nov 2 19:26 tools/ -rw-r--r-- 1 root root 3297 Sep 20 02:21 version.json $ ll /usr/local/cuda-12.6/bin drwxr-xr-x 3 root root 4096 Nov 2 19:26 ./ drwxr-xr-x 15 root root 4096 Nov 2 19:26 ../ -rwxr-xr-x 1 root root 88848 Sep 12 18:07 bin2c* lrwxrwxrwx 1 root root 4 Sep 19 23:24 computeprof -> nvvp* -rwxr-xr-x 1 root root 112 Sep 12 22:21 compute-sanitizer* drwxr-xr-x 2 root root 4096 Nov 2 19:26 crt/ -rwxr-xr-x 1 root root 7674584 Sep 12 18:07 cudafe++* -rwxr-xr-x 1 root root 1951 Sep 12 18:51 cuda-gdb* -rwxr-xr-x 1 root root 13757288 Sep 12 18:51 cuda-gdb-minimal* -rwxr-xr-x 1 root root 16040360 Sep 12 18:51 cuda-gdb-python3.10-tui* -rwxr-xr-x 1 root root 16040032 Sep 12 18:51 cuda-gdb-python3.11-tui* -rwxr-xr-x 1 root root 16048512 Sep 12 18:51 cuda-gdb-python3.12-tui* -rwxr-xr-x 1 root root 16040248 Sep 12 18:51 cuda-gdb-python3.8-tui* -rwxr-xr-x 1 root root 16040296 Sep 12 18:51 cuda-gdb-python3.9-tui* -rwxr-xr-x 1 root root 825936 Sep 12 18:51 cuda-gdbserver* -rwxr-xr-x 1 root root 75928 Sep 12 18:00 cu++filt* -rwxr-xr-x 1 root root 708112 Sep 12 17:53 cuobjdump* -rwxr-xr-x 1 root root 1245272 Sep 12 18:07 fatbinary* -rwxr-xr-x 1 root root 3826 Sep 20 02:21 ncu* -rwxr-xr-x 1 root root 3616 Sep 20 02:21 ncu-ui* -rwxr-xr-x 1 root root 1580 Sep 12 18:09 nsight_ee_plugins_manage.sh* -rwxr-xr-x 1 root root 197 Sep 20 02:21 nsight-sys* -rwxr-xr-x 1 root root 743 Sep 20 02:21 nsys* -rwxr-xr-x 1 root root 833 Sep 20 02:21 nsys-ui* -rwxr-xr-x 1 root root 23091656 Sep 12 18:07 nvcc* -rwxr-xr-x 1 root root 10456 Sep 12 18:07 __nvcc_device_query* -rw-r--r-- 1 root root 425 Sep 12 18:07 nvcc.profile -rwxr-xr-x 1 root root 50683896 Sep 12 17:53 nvdisasm* -rwxr-xr-x 1 root root 31360568 Sep 12 18:07 nvlink* -rwxr-xr-x 1 root root 6030656 Sep 20 00:16 nvprof* -rwxr-xr-x 1 root root 113664 Sep 12 17:49 nvprune* -rwxr-xr-x 1 root root 285 Sep 19 23:24 nvvp* -rwxr-xr-x 1 root root 31026944 Sep 12 18:07 ptxas*

$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on Thu_Sep_12_02:18:05_PDT_2024 Cuda compilation tools, release 12.6, V12.6.77 Build cuda_12.6.r12.6/compiler.34841621_0

It really made me so sad, what's the problem? any commets will good, really appriciate. thanks.

xdfai4x avatar Dec 14 '24 09:12 xdfai4x

+1 facing this issue

prashantmetadome avatar Dec 17 '24 09:12 prashantmetadome

me too

JiannBai avatar Dec 17 '24 21:12 JiannBai

I also encountered this error.

phucbienvan avatar Dec 18 '24 06:12 phucbienvan

Same problem here

debryu avatar Dec 19 '24 14:12 debryu

same here

jeffrobot avatar Dec 23 '24 14:12 jeffrobot

Same here. Did the library get updated?

ufxpri avatar Dec 26 '24 04:12 ufxpri

recreate the virtual environment, "pip install groundingdino-py" can solve the problem.

phucbienvan avatar Dec 26 '24 04:12 phucbienvan

When "pip install -e . " , is installed exactly, it will create _C.cpython.so file. Then, you should try cd to the main.py file, try python -c " from groundingdino import _C" . If it can not do it, then try to move the _C.so file to which folder that can do the line code, then you will not met the name '_C' issue again.

NamThanhLe1907 avatar Jan 25 '25 18:01 NamThanhLe1907

I finally found the problem, the PyTorch version and CUDA version are incompatible. If your CUDA version is the same as mine, 12.4, then the PyTorch version cannot be 2.6.0. Version 2.5.1 is a compatible version that works.

  1. check your pytorch version import torch print(torch.__version__)
  2. install the right version pip uninstall torch torchvision torchaudio pip install torch==2.5.1+cu124 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Vincentdu-cn avatar Feb 08 '25 08:02 Vincentdu-cn

Try to build the extention at first: python setup.py clean python setup.py build_ext --inplace

check if you get any errors

uwGZQ avatar Feb 10 '25 23:02 uwGZQ

I meet this problem too;my cuda version is 11.3, install path is /user/local/cuda; And I fixed it by this: step 0: set CUDA_HOME, Make sure CUDA_HOME has the same path with which nvcc result step 1 : conda create -n py38 python=3.8 step 2 : change requirements.txt to this:

torch==1.12.0+cu113 torchvision==0.13.0+cu113 transformers addict yapf timm numpy opencv-python supervision>=0.22.0 pycocotools

step 3: pip install -e . --extra-index-url https://download.pytorch.org/whl/cu113

it works for me

fuyi02 avatar Feb 11 '25 09:02 fuyi02

recreate the virtual environment, "pip install groundingdino-py" can solve the problem.

thanks very much! I sloved from it!

McGrady-175 avatar Mar 25 '25 03:03 McGrady-175

I finally found the problem, the PyTorch version and CUDA version are incompatible. If your CUDA version is the same as mine, 12.4, then the PyTorch version cannot be 2.6.0. Version 2.5.1 is a compatible version that works.

1. check your pytorch version
   `import torch`
   `print(torch.__version__)`

2. install the right version
   `pip uninstall torch torchvision torchaudio`
   `pip install torch==2.5.1+cu124 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124`

it works!

wbfwonderful avatar Mar 31 '25 08:03 wbfwonderful

This is an issue from API changes when upgrading from torch 2.5 to 2.6 with cuda 12.4.

For those wishing to keep using torch 2.6, you can use this https://github.com/IDEA-Research/GroundingDINO/pull/409

QuantuMope avatar Apr 16 '25 23:04 QuantuMope

Try to build the extention at first: python setup.py clean python setup.py build_ext --inplace

check if you get any errors

fix my code. Torch version is 2.4.1+cu118

Kailthen avatar May 22 '25 12:05 Kailthen

cuda12.8适合哪个版本的torch呢?有办法避免这个报错吗?或者直接绕开他

HAOYON-666 avatar Aug 05 '25 07:08 HAOYON-666

python setup.py build_ext --inplace

thank you,already sloved

HanJW2000 avatar Aug 21 '25 03:08 HanJW2000

What version of the cuda12.8 is suitable for torch? Is there a way to avoid this error? Or just around him.

12.8 it's too high view for grounding dino, maybe 12.3 or 12.1 can be better,you drop your cuda

HanJW2000 avatar Aug 21 '25 03:08 HanJW2000

When "pip install -e . " , is installed exactly, it will create _C.cpython.so file. Then, you should try cd to the main.py file, try python -c " from groundingdino import _C" . If it can not do it, then try to move the _C.so file to which folder that can do the line code, then you will not met the name '_C' issue again.

This really helps me. For someone who want to custom,edit or test code on downloaded git, above solution might work.

pip install groundingdino-py

will use groundingdino.py on pip package.. (That is good solution tho)

Thanks

gomduribo avatar Sep 18 '25 11:09 gomduribo