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

Failed to build SAM-2 #21

Closed
patermars opened this issue Jul 30, 2024 · 16 comments
Closed

Failed to build SAM-2 #21

patermars opened this issue Jul 30, 2024 · 16 comments

Comments

@patermars
Copy link

When I tried to install SAM 2 using these command, it displayed this issue:

git clone [email protected]:facebookresearch/segment-anything-2.git

cd segment-anything-2; pip install -e .

Error:
Cloning into 'segment-anything-2'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
/bin/bash: line 1: cd: segment-anything-2: No such file or directory
Obtaining file:///content
ERROR: file:///content does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found

On fixing the git clone issue by replacing the clone link with the github link in address bar, it displayed:

Error:

Cloning into 'segment-anything-2'...
remote: Enumerating objects: 285, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 285 (delta 2), reused 1 (delta 1), pack-reused 279
Receiving objects: 100% (285/285), 42.91 MiB | 26.78 MiB/s, done.
Resolving deltas: 100% (10/10), done.
Obtaining file:///content/segment-anything-2
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: torch>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from SAM-2==1.0) (2.3.1+cu121)
Requirement already satisfied: torchvision>=0.18.1 in /usr/local/lib/python3.10/dist-packages (from SAM-2==1.0) (0.18.1+cu121)
Requirement already satisfied: numpy>=1.24.4 in /usr/local/lib/python3.10/dist-packages (from SAM-2==1.0) (1.26.4)
Requirement already satisfied: tqdm>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from SAM-2==1.0) (4.66.4)
Collecting hydra-core>=1.3.2 (from SAM-2==1.0)
  Using cached hydra_core-1.3.2-py3-none-any.whl.metadata (5.5 kB)
Collecting iopath>=0.1.10 (from SAM-2==1.0)
  Using cached iopath-0.1.10-py3-none-any.whl
Requirement already satisfied: pillow>=9.4.0 in /usr/local/lib/python3.10/dist-packages (from SAM-2==1.0) (9.4.0)
Collecting omegaconf<2.4,>=2.2 (from hydra-core>=1.3.2->SAM-2==1.0)
  Using cached omegaconf-2.3.0-py3-none-any.whl.metadata (3.9 kB)
Collecting antlr4-python3-runtime==4.9.* (from hydra-core>=1.3.2->SAM-2==1.0)
  Using cached antlr4_python3_runtime-4.9.3-py3-none-any.whl
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from hydra-core>=1.3.2->SAM-2==1.0) (24.1)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from iopath>=0.1.10->SAM-2==1.0) (4.12.2)
Collecting portalocker (from iopath>=0.1.10->SAM-2==1.0)
  Using cached portalocker-2.10.1-py3-none-any.whl.metadata (8.5 kB)
Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (3.15.4)
Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (1.13.1)
Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (3.3)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (3.1.4)
Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (2024.6.1)
Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cudnn-cu12==8.9.2.26 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cudnn_cu12-8.9.2.26-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cublas-cu12==12.1.3.1 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cufft-cu12==11.0.2.54 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-curand-cu12==10.3.2.106 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-nccl-cu12==2.20.5 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl.metadata (1.8 kB)
Collecting nvidia-nvtx-cu12==12.1.105 (from torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.7 kB)
Requirement already satisfied: triton==2.3.1 in /usr/local/lib/python3.10/dist-packages (from torch>=2.3.1->SAM-2==1.0) (2.3.1)
Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch>=2.3.1->SAM-2==1.0)
  Using cached nvidia_nvjitlink_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)
Requirement already satisfied: PyYAML>=5.1.0 in /usr/local/lib/python3.10/dist-packages (from omegaconf<2.4,>=2.2->hydra-core>=1.3.2->SAM-2==1.0) (6.0.1)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=2.3.1->SAM-2==1.0) (2.1.5)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=2.3.1->SAM-2==1.0) (1.3.0)
Using cached hydra_core-1.3.2-py3-none-any.whl (154 kB)
Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
Using cached nvidia_cudnn_cu12-8.9.2.26-py3-none-manylinux1_x86_64.whl (731.7 MB)
Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)
Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)
Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)
Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)
Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)
Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)
Using cached omegaconf-2.3.0-py3-none-any.whl (79 kB)
Using cached portalocker-2.10.1-py3-none-any.whl (18 kB)
Using cached nvidia_nvjitlink_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (21.3 MB)
Building wheels for collected packages: SAM-2
  error: subprocess-exited-with-error
  
  × Building editable for SAM-2 (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building editable for SAM-2 (pyproject.toml) ... error
  ERROR: Failed building editable for SAM-2
Failed to build SAM-2
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (SAM-2)

Environment:

Python = Python 3.10.12
Google Colab + T4

Kindly fix or tell me any workaround for this part.

@yahooo-m
Copy link

+1

1 similar comment
@TimLL123456
Copy link

+1

@emi-dm
Copy link

emi-dm commented Jul 30, 2024

It's not possible to install it in a CPU only machine! Same error

@yahooo-m
Copy link

It's not possible to install it in a CPU only machine! Same error

I install it in an Nvidia V100. Same error

@ChinaStark
Copy link

CUDA 12.1 ?

@mahmuod-aboalhassan
Copy link

+1

It's not possible to install it in a CPU only machine! Same error

also the same not working with CPU

@laiwenq
Copy link

laiwenq commented Jul 30, 2024

  1. Download the Zip file instead of directly building sam2.
  2. Unzip the file, cd to the directory where you find setup.py
  3. Try pip install -e .
  4. If it fails, try to manually install torch==2.3.1 with cuda 12.1 (see Failed to build SAM-2 and RuntimeError in infer #18 )
  5. Repeat step 3.

@proxi666
Copy link

  1. Download the Zip file instead of directly building sam2.
  2. Unzip the file, cd to the directory where you find setup.py
  3. Try pip install -e .
  4. If it fails, try to manually install torch==2.3.1 with cuda 12.1 (see Failed to build SAM-2 and RuntimeError in infer #18 )
  5. Repeat step 3.

basically upgrading cuda from 11.8 to cuda 12.1 solves the issue...

@aryansaurav
Copy link

You have to update gcc to version 9.3 or higher.. worked for me! worth a try.

@aryansaurav
Copy link

aryansaurav commented Jul 30, 2024 via email

@zinccat
Copy link

zinccat commented Jul 30, 2024

For cuda 11.8, you'll need to install the pytorch built on it first
pip3 install torch==2.3.1+cu118 torchvision==0.18.1+cu118 torchaudio --index-url https://download.pytorch.org/whl/cu118
Then pip install --no-build-isolation -e .

@patermars
Copy link
Author

  1. Download the Zip file instead of directly building sam2.
  2. Unzip the file, cd to the directory where you find setup.py
  3. Try pip install -e .
  4. If it fails, try to manually install torch==2.3.1 with cuda 12.1 (see Failed to build SAM-2 and RuntimeError in infer #18 )
  5. Repeat step 3.

Thanks, Some guy in another issue told me yesterday about this way around, it worked for me. Thanks for helping out others.

@cjxxu
Copy link

cjxxu commented Aug 6, 2024

torch 2.4.0+cu121
torchaudio 2.4.0+cu121
torchvision 0.19.0+cu121
error: command 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\nvcc' failed with exit code 2
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building editable for SAM-2
Failed to build SAM-2
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (SAM-2)

I have the same problem too, don't know how to fix

@cheezafizz
Copy link

gcc version was also the problem for me

After executing the following, I finally got the installation done without any error.

conda create -n sam python=3.11
conda activate sam
conda install -c nvidia cuda-toolkit=12.1
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
conda install -c conda-forge gxx
git clone https://github.com/facebookresearch/segment-anything-2.git
cd segment-anything-2; pip install -e .

@ronghanghu
Copy link
Contributor

Hi, these errors are likely due to an error in building the SAM 2 CUDA extension. We have recently made the CUDA extension step optional (in #155 and #175) as a workaround to this problem.

You can pull the latest code and reinstall via

# run the line below inside the SAM 2 repo
git pull;
pip uninstall -y SAM-2;
rm -f sam2/*.so;
pip install -e ".[demo]"

which allows using SAM 2 without CUDA extension (the results should stay the same in most cases, see INSTALL.md for details).

@ronghanghu
Copy link
Contributor

Hi, this is likely due to an error in building the SAM 2 CUDA extension. We have recently made the CUDA extension step optional (in #155 and #175) as a workaround to this problem.

You can pull the latest code and reinstall via

# run the line below inside the SAM 2 repo
git pull;
pip uninstall -y SAM-2;
rm -f sam2/*.so;
pip install -e ".[demo]"

which allows using SAM 2 without CUDA extension (the results should stay the same in most cases, see INSTALL.md for details).

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

No branches or pull requests