Grounded-Segment-Anything
Grounded-Segment-Anything copied to clipboard
NameError: name '_C' is not defined
File "Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/ms_deform_attn.py", line 53, in forward output = _C.ms_deform_attn_forward(
You should set CUDA_HOME before installing the repo~ here is an example
export CUDA_HOME=/path/to/cuda-11.3/
pip install ...
In my case, CUDA_HOME can be automatically set via 'torch'.
However, I met this bug because installing GroundingDINO without a GPU. After reinstalling it with GPU, it runs normally.
@Andy1621 can you specify what you did?
@jasonborn0 You have to make sure your GroundingDINO is installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is --device "cuda", which calls the bug.
https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103
I met the same error with an annaconda env, and I solved it through:
cd GroundingDINO python setup.py build.py python setup.py install.py
This will install the groundingdino with GPU. But in my case, some extra library such as config, datasets miss after using the command above.
ModuleNotFoundError: No module named 'groundingdino.config'
So I copy them into the env library, and it works!
I met the same error with an annaconda env, and I solved it through:
cd GroundingDINO python setup.py build.py python setup.py install.py
This will install the groundingdino with GPU. But in my case, some extra library such as config, datasets miss after using the command above.
ModuleNotFoundError: No module named 'groundingdino.config'
So I copy them into the env library, and it works!
Hi Hsintein-Ng, could you please elaborate more on how you've installed on conda environmen?
@kyungmnlee I install the conda environment through following https://github.com/facebookresearch/segment-anything Then, I install the package in requirements.txt in https://github.com/IDEA-Research/Grounded-Segment-Anything Next, I update the torch version to 2.0 Finally, I use the setup.py in GroundingDINO to install it with GPU.
I met the same error with an annaconda env, and I solved it through:
cd GroundingDINO python setup.py build.py python setup.py install.py
This will install the groundingdino with GPU. But in my case, some extra library such as config, datasets miss after using the command above.
ModuleNotFoundError: No module named 'groundingdino.config'
So I copy them into the env library, and it works!
It should be:
cd GroundingDINO python setup.py build python setup.py install
pip3 install Cython
I run it OK ,but when I updated GroundingDINO/groundingdino, and in my code device = torch.device('cuda') . then I run it again , It's failed !
I fixed it by python -m pip install -e GroundingDINO or device="cpu" , then I run it again , It's OK !
As above guys said
The groundingdino._C isn't installed without GPU.
Have a try !
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug.https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103
Is there any way to verify if it's installed via GPU or not? I have cuda available and CUDA_HOME is also set up properly, also I can see this structure after the python -m pip install -e GroundingDINO .
I can find a file with _C name but still I face error for device =cuda
I have set CUDA_HOME and install pytorch==1.10.0 with CUDA 11.3 and cudnn 8.2.0, and then install the groundingdino with both "python -m pip install -e GroundingDINO" and "cd GroundingDINO; python setup.py build; python setup.py install", but I still get the "Failed to load custom C++ ops. Running on CPU mode Only! " error. When I input "from groundingdino import _C" in python environment, it return "undefined symbol: _ZN6caffe28TypeMeta21_typeMetaDataInstanceIdEEPKNS_6detail12TypeMetaDataEv" error, what should I do?
You should set
CUDA_HOMEbefore installing the repo~ here is an exampleexport CUDA_HOME=/path/to/cuda-11.3/ pip install ...
Simply setting up CUDA HOME, won't work it also needs the same CUDA version that the pytorch supports for e.g I have CUDA 12.1 setup and also the CUDA HOME pointing the same, yet I get this error when it tries to build _C file
raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda))
RuntimeError:
The detected CUDA version (12.1) mismatches the version that was used to compile
PyTorch (11.8). Please make sure to use the same CUDA versions.
In my case,
CUDA_HOMEcan be automatically set via 'torch'. However, I met this bug because installingGroundingDINOwithout a GPU. After reinstalling it with GPU, it runs normally.
For running on CPU, ignore the error add --cpu-only at the end of the command. I should work that way.
You should set
CUDA_HOMEbefore installing the repo~ here is an exampleexport CUDA_HOME=/path/to/cuda-11.3/ pip install ...Simply setting up CUDA HOME, won't work it also needs the same CUDA version that the pytorch supports for e.g I have CUDA 12.1 setup and also the CUDA HOME pointing the same, yet I get this error when it tries to build _C file
raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda)) RuntimeError: The detected CUDA version (12.1) mismatches the version that was used to compile PyTorch (11.8). Please make sure to use the same CUDA versions.
In case of CUDA and PyTorch correct version mismatch, use command like this e.g "pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cu114/torch_stable.html"
Install PyTorch according to your CUDA version.
Does ROCm not support it?
cd GroundingDINO
export PATH=/usr/local/cuda/bin:$PATH
export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
pip install -e .
And then I fixed all error...... That is crazy!
You should set
CUDA_HOMEbefore installing the repo~ here is an exampleexport CUDA_HOME=/path/to/cuda-11.3/ pip install ...Simply setting up CUDA HOME, won't work it also needs the same CUDA version that the pytorch supports for e.g I have CUDA 12.1 setup and also the CUDA HOME pointing the same, yet I get this error when it tries to build _C file
raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda)) RuntimeError: The detected CUDA version (12.1) mismatches the version that was used to compile PyTorch (11.8). Please make sure to use the same CUDA versions.In case of CUDA and PyTorch correct version mismatch, use command like this e.g "pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cu114/torch_stable.html"
Install PyTorch according to your CUDA version.
Thanks, the above solution works! For me, I got this bug while running a processing job in SM pipeline. Here's the messy Dockerfile I've used :)
FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-devel
ENV CUDA_HOME /usr/local/cuda-11.6/
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
git
RUN pip install Cython numpy
RUN pip install torch==2.0.1 torchvision==0.15.2 torchaudio -f https://download.pytorch.org/whl/cu116/torch_stable.html
RUN pip install git+https://github.com/IDEA-Research/GroundingDINO.git
Once again, please make sure your PyTorch wheel file is compatible with your CUDA version :)
I met the same problem,then I solved it as follows:
- set up the enviroment export AM_I_DOCKER=False export BUILD_WITH_CUDA=True export CUDA_HOME=/path/to/cuda-11.3/
- remove the build files, then run python setup.py install
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug. https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103Is there any way to verify if it's installed via
GPUor not? I have cuda available and CUDA_HOME is also set up properly, also I can see this structure after thepython -m pip install -e GroundingDINO.
I can find a file with
_Cname but still I face error for device =cuda
I got the _C file as well under groundingdino, but i also failed to import it. The CUDA_HOME is set properly.
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug. https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103Is there any way to verify if it's installed via
GPUor not? I have cuda available and CUDA_HOME is also set up properly, also I can see this structure after thepython -m pip install -e GroundingDINO.I can find a file with
_Cname but still I face error for device =cudaI got the _C file as well under groundingdino, but i also failed to import it. The CUDA_HOME is set properly.
same here
Any suggestions?
@BrandonHanx I installed GroundingDINO alone and it works, but when replacing it with the folder in MAM the issure remains. Have you solved it?
try: from groundingdino import _C except Exception as e: warnings.warn("Failed to load custom C++ ops. Running on CPU mode Only!")
ms_deform_attn.py:31 show error below :
_C.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNSt15__exception_ptr13exception_ptr9_M_addrefEv
how can l sovel this problem?
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug.https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103
I encountered this issue in Win10, CUDA v11.7, and Python 3.10.
I found the value of torch.cuda.is_available() in the GroundingDINO\setup.py file is False.
This problem seems to be caused by the creation of an isolated dependency environment during pip install, which installs the CPU version of torch.
For me, this issue can be resolved by using pip install -e GroundingDINO --no-build-isolation (with proper CUDA_HOME).
By the way, I tested torch==1.13.1+cu117 torchvision==0.14.1+cu117 and torch==2.0.1+cu117 torchvision==0.15.2+cu117, both work for me.
I hope this information is helpful.
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug. https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103I encountered this issue in Win10, CUDA v11.7, and Python 3.10. I found the value of
torch.cuda.is_available()in the GroundingDINO\setup.py file isFalse. This problem seems to be caused by the creation of an isolated dependency environment duringpip install, which installs the CPU version of torch. For me, this issue can be resolved by usingpip install -e GroundingDINO --no-build-isolation(with proper CUDA_HOME).By the way, I tested
torch==1.13.1+cu117 torchvision==0.14.1+cu117andtorch==2.0.1+cu117 torchvision==0.15.2+cu117, both work for me. I hope this information is helpful.
Thanks, artonnet. This also solves my issue!
In my case the problem was caused by ABI incompatibility. System GCC was used at building time, but python binary comes from conda. Installing gcc/gxx from conda solves the issue:
conda install gcc_linux-64
conda install gxx_linux-64
I've had a lot of warning issues since I fixed this issue,I don't understand the reason for the warning, hope it helps me out, thank you
@jasonborn0 You have to make sure your
GroundingDINOis installed with a GPU instead of CPU. The groundingdino._C isn't installed without GPU. And the default hyperparameter is--device "cuda", which calls the bug. https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/ab1c44b2d01e695967af7007c3193a4b4066a6bc/GroundingDINO/setup.py#L73-L103I encountered this issue in Win10, CUDA v11.7, and Python 3.10. I found the value of
torch.cuda.is_available()in the GroundingDINO\setup.py file isFalse. This problem seems to be caused by the creation of an isolated dependency environment duringpip install, which installs the CPU version of torch. For me, this issue can be resolved by usingpip install -e GroundingDINO --no-build-isolation(with proper CUDA_HOME).By the way, I tested
torch==1.13.1+cu117 torchvision==0.14.1+cu117andtorch==2.0.1+cu117 torchvision==0.15.2+cu117, both work for me. I hope this information is helpful.
That solve my problem as well. Thank you very much!!!
I was using RHEL9 container
My torch.version.cuda was 12.1
CUDA_HOME was set to /usr/local/cuda-12.5/
Still got the same error. But the above comment by @somuchtome solved the issue:-
After going to the Grounded-Segment-Anything/GroundingDINO folder
pip install -e . --no-build-isolation This solution worked :heart: