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 and RuntimeError in infer #18

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

Failed to build SAM-2 and RuntimeError in infer #18

flashingtt opened this issue Jul 30, 2024 · 16 comments

Comments

@flashingtt
Copy link

When I run the command

pip install -e .

There is an error:

RuntimeError:
The detected CUDA version (11.8) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.

I try to use the command below to fix this error:

pip install --no-build-isolation -e .

Although I build SAM-2 successfully, there is another error when I run the inference image segmentation script:

RuntimeError: GET was unable to find an engine to execute this computation

Does anyone have the same problem?

@XinhanWang
Copy link

I have the same problem
RuntimeError:
The detected CUDA version (11.8) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.

@Kiran-valetcloset
Copy link

I too have the same problem. I have installed the cuda toolkit 11.8, checked it from nvcc -V command and installed pytorch using 11.8 cuda too, but I still get the same error.

@laiwenq
Copy link

laiwenq commented Jul 30, 2024

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

@flashingtt
Copy link
Author

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

@laiwenq Thank you for your reply. I have tried

pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118
pip install --no-build-isolation -e .

Then I build SAM2 successfully, but failed to infer.
Is it a problem with the cuda version? My current version is 11.8, and I will upgrade to 12.1 later and try again.

@fangli333
Copy link

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

@laiwenq Thank you for your reply. I have tried

pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118
pip install --no-build-isolation -e .

Then I build SAM2 successfully, but failed to infer. Is it a problem with the cuda version? My current version is 11.8, and I will upgrade to 12.1 later and try again.

did you solve it?

@laiwenq
Copy link

laiwenq commented Jul 30, 2024

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

@laiwenq Thank you for your reply. I have tried

pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118
pip install --no-build-isolation -e .

Then I build SAM2 successfully, but failed to infer. Is it a problem with the cuda version? My current version is 11.8, and I will upgrade to 12.1 later and try again.

Can you post what error you're seeing? I have no problem with torch==2.3.1 and cuda version 12.1, it is worth trying upgrade your cuda.

@flashingtt
Copy link
Author

@laiwenq @fangli333 @HB16888 @Kiran-valetcloset @ChinaStark
After I upgraded my cuda to 12.1, all problems were solved. I can follow the official step-by-step installation smoothly.
Thanks to @laiwenq 's help.

@proxi666
Copy link

perhaps, we need cuda 12+ for it to run?

@aryansaurav
Copy link

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

@majnas
Copy link

majnas commented Jul 31, 2024

            .-/+oossssoo+/-.               dev@av1 
        `:+ssssssssssssssssss+:`           ------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 23.10 x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: GE76 Raider 11UH REV:1.0 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 6.5.0-44-generic 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 15 mins 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 3012 (dpkg), 23 (snap) 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: zsh 5.9 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: 2048x1152, 1920x1080, 2560x1440 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: GNOME 45.2 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Mutter 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: Adwaita 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Yaru-viridian [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: Yaru-viridian [GTK2/3] 
  +sssssssssdmydMMMMMMMMddddyssssssss+     Terminal: gnome-terminal 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      CPU: 11th Gen Intel i9-11980HK (16) @ 4.900GHz 
    .ossssssssssssssssssdMMMNysssso.       GPU: NVIDIA GeForce RTX 3080 Mobile / Max-Q 8GB/16GB 
      -+sssssssssssssssssyyyssss+-         GPU: Intel TigerLake-H GT1 [UHD Graphics] 
        `:+ssssssssssssssssss+:`           Memory: 3764MiB / 31787MiB 
            .-/+oossssoo+/-.
                                                                   
                                                                   

I have tested gcc-9/10/11 none of them worked. finally upgrade cuda toolkit to 12.1 solved the problem

wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run
sudo sh cuda_12.1.0_530.30.02_linux.run --toolkit --toolkitpath=/usr/local/cuda-12.1 --override
pip list
Package                  Version      Editable project location
------------------------ ------------ ---------------------------------------------------------
antlr4-python3-runtime   4.9.3
asttokens                2.4.1
comm                     0.2.2
contourpy                1.2.1
cycler                   0.12.1
debugpy                  1.8.2
decorator                5.1.1
executing                2.0.1
filelock                 3.13.1
fonttools                4.53.1
fsspec                   2024.2.0
hydra-core               1.3.2
iopath                   0.1.10
ipykernel                6.29.5
ipython                  8.26.0
jedi                     0.19.1
Jinja2                   3.1.3
jupyter_client           8.6.2
jupyter_core             5.7.2
kiwisolver               1.4.5
MarkupSafe               2.1.5
matplotlib               3.9.1
matplotlib-inline        0.1.7
mpmath                   1.3.0
nest-asyncio             1.6.0
networkx                 3.2.1
numpy                    1.26.3
nvidia-cublas-cu11       11.11.3.6
nvidia-cuda-cupti-cu11   11.8.87
nvidia-cuda-nvrtc-cu11   11.8.89
nvidia-cuda-runtime-cu11 11.8.89
nvidia-cudnn-cu11        8.7.0.84
nvidia-cufft-cu11        10.9.0.58
nvidia-curand-cu11       10.3.0.86
nvidia-cusolver-cu11     11.4.1.48
nvidia-cusparse-cu11     11.7.5.86
nvidia-nccl-cu11         2.20.5
nvidia-nvtx-cu11         11.8.86
omegaconf                2.3.0
opencv-python            4.10.0.84
packaging                24.1
parso                    0.8.4
pexpect                  4.9.0
pillow                   10.2.0
pip                      24.0
platformdirs             4.2.2
portalocker              2.10.1
prompt_toolkit           3.0.47
psutil                   6.0.0
ptyprocess               0.7.0
pure_eval                0.2.3
Pygments                 2.18.0
pyparsing                3.1.2
python-dateutil          2.9.0.post0
PyYAML                   6.0.1
pyzmq                    26.0.3
SAM-2                    1.0          /home/dev/Documents/other_repositories/segment-anything-2
setuptools               69.1.0
six                      1.16.0
stack-data               0.6.3
sympy                    1.12
torch                    2.3.1+cu118
torchaudio               2.3.1+cu118
torchvision              0.18.1+cu118
tornado                  6.4.1
tqdm                     4.66.4
traitlets                5.14.3
triton                   2.3.1
typing_extensions        4.9.0
wcwidth                  0.2.13
wheel                    0.42.0

@aryansaurav
Copy link

Indeed, so it seems the basic required config are something like:
CUDA >12.1
PyTorch 2.4 (latest would be better, but earlier versions might work too)
gcc (9.3 or higher)

of course, this is assuming a GPU machine.

if you have one or more missing in the above list, worth trying to fix that first

@YichiZhang98
Copy link

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

Thank you for your reply. I have tried but failed to build.

The error shows as follows.

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)

My cuda version 12.1 bu it still not work.

@Yan-0-0-Ye
Copy link

您可以将 cuda 升级到 12.1。否则手动安装依赖项,例如,pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

感谢您的回复。我试过但未能构建。

错误如下所示。

注意:此错误源自子进程,可能不是 pip 的问题。错误:无法为 SAM-2 构建可编辑内容 无法生成 SAM-2 错误:错误:无法为某些基于 pyproject.toml 的项目 (SAM-2) 构建可安装轮子

我的 cuda 版本 12.1 bu 它仍然不起作用。

hello, do you solve it?

@laiwenq
Copy link

laiwenq commented Aug 7, 2024

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

Thank you for your reply. I have tried but failed to build.

The error shows as follows.

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)

My cuda version 12.1 bu it still not work.

Sorry just see this now. Check your cuda version by running nvcc -V in the command line and see if you are actually using 12.1.

@Yan-0-0-Ye
Copy link

You can upgrade your cuda to 12.1. Otherwise manually install the dependencies, e.g., pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

Thank you for your reply. I have tried but failed to build.
The error shows as follows.
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)
My cuda version 12.1 bu it still not work.

Sorry just see this now. Check your cuda version by running nvcc -V in the command line and see if you are actually using 12.1.

thanks!

@ronghanghu
Copy link
Contributor

Hi, we have recently made the CUDA extension step optional (in https://github.com/facebookresearch/segment-anything-2/pull/155) 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