Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: Failed to map segment from shared object for _C.so #360

Open
VoyageWang opened this issue Oct 7, 2024 · 1 comment
Open

Comments

@VoyageWang
Copy link

ImportError: Failed to map segment from shared object for _C.so

描述: run the code: python demo_video.py segmentation/evf-sam2-multitask
ImportError: /EVF-SAM/model/segment_anything_2/sam2/_C.so: failed to map segment from shared object

I have successfully compiled the code using python setup.py build_ext --inplace

/miniconda3/envs/evf-sam/lib/python3.10/site-packages/torch/utils/cpp_extension.py:428: UserWarning: There are no g++ version bounds defined for CUDA version 12.1
warnings.warn(f'There are no {compiler_name} version bounds defined for CUDA version {cuda_str_version}')
building 'sam2._C' extension
/miniconda3/envs/evf-sam/lib/python3.10/site-packages/torch/utils/cpp_extension.py:1967: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation.
If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST'].
warnings.warn(
Emitting ninja build file EVF-SAM/model/segment_anything_2/build/temp.linux-x86_64-cpython-310/build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: no work to do.
g++ -pthread -B /miniconda3/envs/evf-sam/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -O2 -isystem miniconda3/envs/evf-sam/include -fPIC -O2 -isystem miniconda3/envs/evf-sam/include -pthread -B miniconda3/envs/evf-sam/compiler_compat -shared //EVF-SAM/model/segment_anything_2/build/temp.linux-x86_64-cpython-310/sam2/csrc/connected_components.o -Lminiconda3/envs/evf-sam/lib/python3.10/site-packages/torch/lib -L/cuda/cuda-12.1/lib64 -lc10 -ltorch -ltorch_cpu -ltorch_python -lcudart -lc10_cuda -ltorch_cuda -o build/lib.linux-x86_64-cpython-310/sam2/_C.so
copying build/lib.linux-x86_64-cpython-310/sam2/_C.so -> sam2

How to solve it, thanks for your attention!!!!

Thanks for your reply! I have tried the original sam2 repo, which is ok for me. However, it stiff faces the same issue when I try evf-sam2. The environment is here:

OS: [Ubuntu 20.04]
Python版本: [ 3.10]
PyTorch版本: [ 2.3.1]
CUDA版本: [12.1]
GPU型号: [ NVIDIA RTX 3090]

@ronghanghu
Copy link
Contributor

ronghanghu commented Oct 7, 2024

Hi @VoyageWang, the build error you saw (especially the line UserWarning: There are no g++ version bounds defined for CUDA version 12.1) might suggest that your GCC (g++) compiler version doesn't match (and is likely too new for) your CUDA version 12.1. For CUDA 12.1, it maximum supported gcc version is GCC 12.2 (more details of supported compiler versions are in https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html). You could resolve it by installing a GCC version compatible with your CUDA version.

Meanwhile, as an alternative workaround, you can also skip building the CUDA extension for SAM 2, which should still give similar results in most cases.

pip uninstall -y SAM-2 && SAM2_BUILD_CUDA=0 pip install -e ".[notebooks]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants