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

cannot import name '_C' from 'sam2' (/home/suw469/segment-anything-2/sam2/__init__.py) #131

Closed
lindawang0122ds opened this issue Aug 3, 2024 · 14 comments

Comments

@lindawang0122ds
Copy link

Here is my original code, which I pasted from the demo code provided by sam2 called video_predictor_example.ipynb:

ann_frame_idx = 0 # the frame index we interact with
ann_obj_id = 1 # give a unique id to each object we interact with (it can be any integers)

Let's add a positive click at (x, y) = (210, 350) to get started

points = np.array([[210, 350]], dtype=np.float32)

for labels, 1 means positive click and 0 means negative click

labels = np.array([1], np.int32)
_, out_obj_ids, out_mask_logits = predictor.add_new_points(
inference_state=inference_state,
frame_idx=ann_frame_idx,
obj_id=ann_obj_id,
points=points,
labels=labels,
)

show the results on the current (interacted) frame

plt.figure(figsize=(12, 8))
plt.title(f"frame {ann_frame_idx}")
plt.imshow(Image.open(os.path.join(video_dir, frame_names[ann_frame_idx])))
show_points(points, labels, plt.gca())
show_mask((out_mask_logits[0] > 0.0).cpu().numpy(), plt.gca(), obj_id=out_obj_ids[0])

Following is the error message I encountered, which I cannot import name '_C' from 'sam2' (/home/suw469/segment-anything-2/sam2/init.py)

ImportError Traceback (most recent call last)
Cell In[31], line 8
6 # for labels, 1 means positive click and 0 means negative click
7 labels = np.array([1], np.int32)
----> 8 _, out_obj_ids, out_mask_logits = predictor.add_new_points(
9 inference_state=inference_state,
10 frame_idx=ann_frame_idx,
11 obj_id=ann_obj_id,
12 points=points,
13 labels=labels,
14 )
16 # show the results on the current (interacted) frame
17 plt.figure(figsize=(12, 8))

File ~/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator..decorate_context(*args, **kwargs)
112 @functools.wraps(func)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)

File ~/segment-anything-2/sam2/sam2_video_predictor.py:221, in SAM2VideoPredictor.add_new_points(self, inference_state, frame_idx, obj_id, points, labels, clear_old_points, normalize_coords)
219 # Clamp the scale of prev_sam_mask_logits to avoid rare numerical issues.
220 prev_sam_mask_logits = torch.clamp(prev_sam_mask_logits, -32.0, 32.0)
--> 221 current_out, _ = self._run_single_frame_inference(
222 inference_state=inference_state,
223 output_dict=obj_output_dict, # run on the slice of a single object
224 frame_idx=frame_idx,
225 batch_size=1, # run on the slice of a single object
226 is_init_cond_frame=is_init_cond_frame,
227 point_inputs=point_inputs,
228 mask_inputs=None,
229 reverse=reverse,
230 # Skip the memory encoder when adding clicks or mask. We execute the memory encoder
231 # at the beginning of propagate_in_video (after user finalize their clicks). This
232 # allows us to enforce non-overlapping constraints on all objects before encoding
233 # them into memory.
234 run_mem_encoder=False,
235 prev_sam_mask_logits=prev_sam_mask_logits,
236 )
237 # Add the output to the output dict (to be used as future memory)
238 obj_temp_output_dict[storage_key][frame_idx] = current_out

File ~/segment-anything-2/sam2/sam2_video_predictor.py:810, in SAM2VideoPredictor._run_single_frame_inference(self, inference_state, output_dict, frame_idx, batch_size, is_init_cond_frame, point_inputs, mask_inputs, reverse, run_mem_encoder, prev_sam_mask_logits)
808 # potentially fill holes in the predicted masks
809 if self.fill_hole_area > 0:
--> 810 pred_masks_gpu = fill_holes_in_mask_scores(
811 pred_masks_gpu, self.fill_hole_area
812 )
813 pred_masks = pred_masks_gpu.to(storage_device, non_blocking=True)
814 # "maskmem_pos_enc" is the same across frames, so we only need to store one copy of it

File ~/segment-anything-2/sam2/utils/misc.py:223, in fill_holes_in_mask_scores(mask, max_area)
220 # Holes are those connected components in background with area <= self.max_area
221 # (background regions are those with mask scores <= 0)
222 assert max_area > 0, "max_area must be positive"
--> 223 labels, areas = get_connected_components(mask <= 0)
224 is_hole = (labels > 0) & (areas <= max_area)
225 # We fill holes with a small positive mask score (0.1) to change them to foreground.

File ~/segment-anything-2/sam2/utils/misc.py:61, in get_connected_components(mask)
47 def get_connected_components(mask):
48 """
49 Get the connected components (8-connectivity) of binary masks of shape (N, 1, H, W).
50
(...)
59 components for foreground pixels and 0 for background pixels.
60 """
---> 61 from sam2 import _C
63 return _C.get_connected_componnets(mask.to(torch.uint8).contiguous())

ImportError: cannot import name '_C' from 'sam2' (/home/suw469/segment-anything-2/sam2/init.py)

@lindawang0122ds
Copy link
Author

I tried to run video_predictor_example.ipynb inside the segment-anything-2 package but encountered the same ImportError as above. So not sure if there are additional setting I should adjust to run the code.

@Hanley-Yeung
Copy link

I have also encountered the same error while using Colab and it has not been resolved yet.

@ronghanghu
Copy link
Contributor

Hi, we have added INSTALL.md as an installation FAQ.

Regarding this error:

This is usually because you haven't run the pip install -e ".[demo]" step above or the installation failed. Please install SAM 2 first, and see the other issues if your installation fails. (You may also try python setup.py build_ext --inplace in the repo root as others suggested in #77)

@lindawang0122ds
Copy link
Author

Hi @ronghanghu, thank you for your suggestion. I tried pip install -e ".[demo]" but got the following error message:

[suw469@compute-g-17-158 ~]$ cd segment-anything-2
[suw469@compute-g-17-158 segment-anything-2]$ pip install -e ".[demo]"
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///home/suw469/segment-anything-2
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... error
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/torch/_subclasses/functional_tensor.py:258: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)
cpu = _conversion_method_template(device=torch.device("cpu"))
Traceback (most recent call last):
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in
main()
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
return hook(config_settings)
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 458, in get_requires_for_build_editable
return self.get_requires_for_build_wheel(config_settings)
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 313, in run_setup
exec(code, locals())
File "", line 70, in
File "", line 51, in get_extensions
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1076, in CUDAExtension
library_dirs += library_paths(cuda=True)
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1207, in library_paths
if (not os.path.exists(_join_cuda_home(lib_dir)) and
File "/tmp/pip-build-env-nyuaa9uh/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 2416, in _join_cuda_home
raise OSError('CUDA_HOME environment variable is not set. '
OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable 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.

@lindawang0122ds
Copy link
Author

Based on this suggestion: You may also try python setup.py build_ext --inplace in the repo root as others suggested in #77

Could I ask what is repo root? Does it mean that I should first "cd segment-anything-2" and then "python setup.py build_ext --inplace"?

@Hanley-Yeung
Copy link

基于这个建议:您也可以尝试在 repo 根目录中使用 python setup.py build_ext --inplace,就像 #77 中其他人建议的那样

我能问一下什么是回购根吗?这是否意味着我应该先“cd segment-anything-2”,然后“python setup.py build_ext --inplace”?

I have tried
!pip install -e .
%cd segment-anything-2
!python setup.py build_ext --inplace
is OK

@lindawang0122ds
Copy link
Author

Thank you for your suggestion. I tried to create a jupyter notebook Test.ipynb at /home/suw469 and run the following code:
!pip install -e .
%cd segment-anything-2
!python setup.py build_ext --inplace

However, I got the following error message:
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///home/suw469/segment-anything-2
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... error
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
/tmp/pip-build-env-c9tvd11_/overlay/lib/python3.10/site-packages/torch/_subclasses/functional_tensor.py:258: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)
cpu = _conversion_method_template(device=torch.device("cpu"))
Traceback (most recent call last):
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in
main()
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/n/app/python/3.10.11.conda/lib/python3.10/site-packages/pip/vendor/pyproject_hooks/in_process/in_process.py", line 132, in get_requires_for_build_editable
return hook(config_settings)
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 458, in get_requires_for_build_editable
return self.get_requires_for_build_wheel(config_settings)
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
return self.get_build_requires(config_settings, requirements=[])
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 297, in get_build_requires
self.run_setup()
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 313, in run_setup
exec(code, locals())
File "", line 70, in
File "", line 51, in get_extensions
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1076, in CUDAExtension
library_dirs += library_paths(cuda=True)
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1207, in library_paths
if (not os.path.exists(join_cuda_home(lib_dir)) and
File "/tmp/pip-build-env-c9tvd11
/overlay/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 2416, in _join_cuda_home
raise OSError('CUDA_HOME environment variable is not set. '
OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable 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.
[Errno 2] No such file or directory: 'segment-anything-2'
/home/suw469/segment-anything-2
/home/suw469/.local/lib/python3.10/site-packages/IPython/core/magics/osm.py:393: UserWarning: This is now an optional IPython functionality, using bookmarks requires you to install the pickleshare library.
bkms = self.shell.db.get('bookmarks', {})
Traceback (most recent call last):
File "/home/suw469/segment-anything-2/setup.py", line 70, in
ext_modules=get_extensions(),
File "/home/suw469/segment-anything-2/setup.py", line 51, in get_extensions
ext_modules = [CUDAExtension("sam2._C", srcs, extra_compile_args=compile_args)]
File "/home/suw469/.local/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1077, in CUDAExtension
library_dirs += library_paths(cuda=True)
File "/home/suw469/.local/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 1204, in library_paths
if (not os.path.exists(_join_cuda_home(lib_dir)) and
File "/home/suw469/.local/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 2419, in _join_cuda_home
raise OSError('CUDA_HOME environment variable is not set. '
OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

I don't know why the system couldn't find the directory but my path to segment-anything-2 is:
/home/suw469/segment-anything-2

@ronghanghu
Copy link
Contributor

Hi @lindawang0122ds, regarding this latest error you saw:

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

As mentioned in INSTALL.md, this usually happens because the installation step cannot find the CUDA toolkits (that contain the NVCC compiler) to build a custom CUDA kernel in SAM 2. Please install CUDA toolkits or the version that matches the CUDA version for your PyTorch installation. If the error persists after installing CUDA toolkits, you may explicitly specify CUDA_HOME via

export CUDA_HOME=/usr/local/cuda  # change to your CUDA toolkit path

and rerun the installation.

Also, you should make sure

python -c 'import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME)'

print (True, a directory with cuda) to verify that the CUDA toolkits are correctly set up.

@ldiangelis
Copy link

Hi @lindawang0122ds, regarding this latest error you saw:

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

As mentioned in INSTALL.md, this usually happens because the installation step cannot find the CUDA toolkits (that contain the NVCC compiler) to build a custom CUDA kernel in SAM 2. Please install CUDA toolkits or the version that matches the CUDA version for your PyTorch installation. If the error persists after installing CUDA toolkits, you may explicitly specify CUDA_HOME via

export CUDA_HOME=/usr/local/cuda  # change to your CUDA toolkit path

and rerun the installation.

Also, you should make sure

python -c 'import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME)'

print (True, a directory with cuda) to verify that the CUDA toolkits are correctly set up.

Setting path and reinstall works. Thank you!

@lindawang0122ds
Copy link
Author

Thank you for your suggestion. It looks like my current Linux system doesn't have CUDA Toolkit yet so I will try to install it to setup the environment. Just to double check, is CUDA Toolkit the necessary requirement to run the segment-anything-2 model? I'm a bit worried about whether my Linux system could allow installing the CUDA Toolkit so wanna know if there are alternative way to setup the environment.

@ronghanghu
Copy link
Contributor

Hi @lindawang0122ds, we have recently made the CUDA extension step optional (in #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).

@lindawang0122ds
Copy link
Author

Thank you for your suggestion @ronghanghu! I add CUDA Toolkit to my environment and specify the path. However, there is still error during install -e. I also verified my environment and the output is: True /n/app/cuda/12.1-gcc-9.2.0. So I think I do have CUDA Toolkit there. I'm not quite sure if the error is related to the CUDA Toolkit version or other issue. Could you give me some suggestion on that? Following is the output error:

[suw469@compute-g-17-157 segment-anything-2]$ export CUDA_HOME=/n/app/cuda/12.1-gcc-9.2.0
[suw469@compute-g-17-157 segment-anything-2]$ pip install -e ".[demo]"
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///home/suw469/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: hydra-core>=1.3.2 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (1.3.2)
Collecting iopath>=0.1.10
Using cached iopath-0.1.10-py3-none-any.whl
Requirement already satisfied: pillow>=9.4.0 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (10.3.0)
Requirement already satisfied: torchvision>=0.18.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (0.18.1)
Requirement already satisfied: tqdm>=4.66.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (4.66.4)
Requirement already satisfied: numpy>=1.24.4 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (1.26.4)
Requirement already satisfied: torch>=2.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (2.3.1)
Collecting jupyter>=1.0.0
Using cached jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting matplotlib>=3.9.1
Using cached matplotlib-3.9.1.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB)
Requirement already satisfied: opencv-python>=4.7.0 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (4.10.0.84)
Requirement already satisfied: omegaconf<2.4,>=2.2 in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (2.3.0)
Requirement already satisfied: antlr4-python3-runtime==4.9.* in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (4.9.3)
Requirement already satisfied: packaging in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (24.1)
Requirement already satisfied: portalocker in /home/suw469/.local/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (2.8.2)
Requirement already satisfied: typing-extensions in /home/suw469/.local/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (4.12.2)
Collecting qtconsole
Using cached qtconsole-5.5.2-py3-none-any.whl (123 kB)
Requirement already satisfied: ipykernel in /home/suw469/.local/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (6.29.4)
Collecting ipywidgets
Using cached ipywidgets-8.1.3-py3-none-any.whl (139 kB)
Requirement already satisfied: nbconvert in /home/suw469/.local/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (7.16.4)
Requirement already satisfied: notebook in /home/suw469/.local/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (7.2.1)
Collecting jupyter-console
Using cached jupyter_console-6.6.3-py3-none-any.whl (24 kB)
Requirement already satisfied: fonttools>=4.22.0 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (4.53.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (1.4.5)
Requirement already satisfied: python-dateutil>=2.7 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (2.9.0.post0)
Requirement already satisfied: cycler>=0.10 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (0.12.1)
Requirement already satisfied: contourpy>=1.0.1 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (1.2.1)
Requirement already satisfied: pyparsing>=2.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (3.1.2)
Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (11.4.5.107)
Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: filelock in /n/app/python/3.10.11.conda/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.12.0)
Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: fsspec in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2024.6.0)
Requirement already satisfied: sympy in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (1.12.1)
Requirement already satisfied: networkx in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.3)
Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (8.9.2.26)
Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.3.1)
Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (10.3.2.106)
Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2.20.5)
Requirement already satisfied: triton==2.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2.3.1)
Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: jinja2 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.1.4)
Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.0.106)
Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (11.0.2.54)
Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/suw469/.local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=2.3.1->SAM-2==1.0) (12.5.40)
Requirement already satisfied: PyYAML>=5.1.0 in /home/suw469/.local/lib/python3.10/site-packages (from omegaconf<2.4,>=2.2->hydra-core>=1.3.2->SAM-2==1.0) (6.0.1)
Requirement already satisfied: six>=1.5 in /home/suw469/.local/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.9.1->SAM-2==1.0) (1.16.0)
Requirement already satisfied: psutil in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.9.8)
Requirement already satisfied: jupyter-core!=5.0.,>=4.12 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.7.2)
Requirement already satisfied: debugpy>=1.6.5 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.8.1)
Requirement already satisfied: nest-asyncio in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.6.0)
Requirement already satisfied: traitlets>=5.4.0 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.14.3)
Requirement already satisfied: comm>=0.1.1 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.2.2)
Requirement already satisfied: pyzmq>=24 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (26.0.3)
Requirement already satisfied: tornado>=6.1 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (6.4.1)
Requirement already satisfied: matplotlib-inline>=0.1 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.1.7)
Requirement already satisfied: jupyter-client>=6.1.12 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (8.6.2)
Requirement already satisfied: ipython>=7.23.1 in /home/suw469/.local/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (8.25.0)
Collecting widgetsnbextension~=4.0.11
Using cached widgetsnbextension-4.0.11-py3-none-any.whl (2.3 MB)
Collecting jupyterlab-widgets~=3.0.11
Using cached jupyterlab_widgets-3.0.11-py3-none-any.whl (214 kB)
Requirement already satisfied: MarkupSafe>=2.0 in /home/suw469/.local/lib/python3.10/site-packages (from jinja2->torch>=2.3.1->SAM-2==1.0) (2.1.5)
Requirement already satisfied: pygments in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (2.18.0)
Requirement already satisfied: prompt-toolkit>=3.0.30 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (3.0.47)
Requirement already satisfied: bleach!=5.0.0 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (6.1.0)
Requirement already satisfied: jupyterlab-pygments in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.3.0)
Requirement already satisfied: beautifulsoup4 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (4.12.3)
Requirement already satisfied: mistune<4,>=2.0.3 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (3.0.2)
Requirement already satisfied: nbclient>=0.5.0 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.10.0)
Requirement already satisfied: defusedxml in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.7.1)
Requirement already satisfied: pandocfilters>=1.4.1 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (1.5.1)
Requirement already satisfied: nbformat>=5.7 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (5.10.4)
Requirement already satisfied: tinycss2 in /home/suw469/.local/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)
Requirement already satisfied: jupyter-server<3,>=2.4.0 in /home/suw469/.local/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (2.14.1)
Requirement already satisfied: jupyterlab<4.3,>=4.2.0 in /home/suw469/.local/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (4.2.2)
Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in /home/suw469/.local/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (2.27.2)
Requirement already satisfied: notebook-shim<0.3,>=0.2 in /home/suw469/.local/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (0.2.4)
Collecting qtpy>=2.4.0
Using cached QtPy-2.4.1-py3-none-any.whl (93 kB)
Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /home/suw469/.local/lib/python3.10/site-packages (from sympy->torch>=2.3.1->SAM-2==1.0) (1.3.0)
Requirement already satisfied: webencodings in /home/suw469/.local/lib/python3.10/site-packages (from bleach!=5.0.0->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.5.1)
Requirement already satisfied: jedi>=0.16 in /home/suw469/.local/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.19.1)
Requirement already satisfied: exceptiongroup in /home/suw469/.local/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.2.1)
Requirement already satisfied: decorator in /home/suw469/.local/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.1.1)
Requirement already satisfied: stack-data in /home/suw469/.local/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.6.3)
Requirement already satisfied: pexpect>4.3 in /home/suw469/.local/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (4.9.0)
Requirement already satisfied: platformdirs>=2.5 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-core!=5.0.
,>=4.12->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (3.11.0)
Requirement already satisfied: anyio>=3.1.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (4.4.0)
Requirement already satisfied: prometheus-client>=0.9 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.20.0)
Requirement already satisfied: terminado>=0.8.3 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.18.1)
Requirement already satisfied: jupyter-server-terminals>=0.4.4 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.5.3)
Requirement already satisfied: send2trash>=1.8.2 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.8.3)
Requirement already satisfied: websocket-client>=1.7 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.8.0)
Requirement already satisfied: overrides>=5.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (7.7.0)
Requirement already satisfied: argon2-cffi>=21.1 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (23.1.0)
Requirement already satisfied: jupyter-events>=0.9.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.10.0)
Requirement already satisfied: httpx>=0.25.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.27.0)
Requirement already satisfied: async-lru>=1.0.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.4)
Requirement already satisfied: jupyter-lsp>=2.0.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.2.5)
Requirement already satisfied: setuptools>=40.1.0 in /n/app/python/3.10.11.conda/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (66.0.0)
Requirement already satisfied: tomli>=1.2.2 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.1)
Requirement already satisfied: babel>=2.10 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.15.0)
Requirement already satisfied: requests>=2.31 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.32.3)
Requirement already satisfied: json5>=0.9.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.9.25)
Requirement already satisfied: jsonschema>=4.18.0 in /home/suw469/.local/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (4.22.0)
Requirement already satisfied: fastjsonschema>=2.15 in /home/suw469/.local/lib/python3.10/site-packages (from nbformat>=5.7->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (2.20.0)
Requirement already satisfied: wcwidth in /home/suw469/.local/lib/python3.10/site-packages (from prompt-toolkit>=3.0.30->jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (0.2.13)
Requirement already satisfied: soupsieve>1.2 in /home/suw469/.local/lib/python3.10/site-packages (from beautifulsoup4->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (2.5)
Requirement already satisfied: idna>=2.8 in /home/suw469/.local/lib/python3.10/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (3.7)
Requirement already satisfied: sniffio>=1.1 in /home/suw469/.local/lib/python3.10/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.1)
Requirement already satisfied: argon2-cffi-bindings in /home/suw469/.local/lib/python3.10/site-packages (from argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (21.2.0)
Requirement already satisfied: certifi in /home/suw469/.local/lib/python3.10/site-packages (from httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2024.6.2)
Requirement already satisfied: httpcore==1.* in /home/suw469/.local/lib/python3.10/site-packages (from httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.0.5)
Requirement already satisfied: h11<0.15,>=0.13 in /home/suw469/.local/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.14.0)
Requirement already satisfied: parso<0.9.0,>=0.8.3 in /home/suw469/.local/lib/python3.10/site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.8.4)
Requirement already satisfied: attrs>=22.2.0 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (23.2.0)
Requirement already satisfied: rpds-py>=0.7.1 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.18.1)
Requirement already satisfied: referencing>=0.28.4 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.35.1)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2023.12.1)
Requirement already satisfied: rfc3339-validator in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.1.4)
Requirement already satisfied: python-json-logger>=2.0.4 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.7)
Requirement already satisfied: rfc3986-validator>=0.1.1 in /home/suw469/.local/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.1.1)
Requirement already satisfied: ptyprocess>=0.5 in /home/suw469/.local/lib/python3.10/site-packages (from pexpect>4.3->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.7.0)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/suw469/.local/lib/python3.10/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.2.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/suw469/.local/lib/python3.10/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (3.3.2)
Requirement already satisfied: pure-eval in /home/suw469/.local/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.2.2)
Requirement already satisfied: asttokens>=2.1.0 in /home/suw469/.local/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (2.4.1)
Requirement already satisfied: executing>=1.2.0 in /home/suw469/.local/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (2.0.1)
Requirement already satisfied: fqdn in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.5.1)
Requirement already satisfied: jsonpointer>1.13 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (3.0.0)
Requirement already satisfied: webcolors>=1.11 in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (24.6.0)
Requirement already satisfied: isoduration in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (20.11.0)
Requirement already satisfied: uri-template in /home/suw469/.local/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)
Requirement already satisfied: cffi>=1.0.1 in /home/suw469/.local/lib/python3.10/site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.16.0)
Requirement already satisfied: pycparser in /home/suw469/.local/lib/python3.10/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.22)
Requirement already satisfied: arrow>=0.15.0 in /home/suw469/.local/lib/python3.10/site-packages (from isoduration->jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)
Requirement already satisfied: types-python-dateutil>=2.8.10 in /home/suw469/.local/lib/python3.10/site-packages (from arrow>=0.15.0->isoduration->jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.9.0.20240316)
Building wheels for collected packages: SAM-2
Building editable for SAM-2 (pyproject.toml) ... done
Created wheel for SAM-2: filename=SAM_2-1.0-0.editable-cp310-cp310-linux_x86_64.whl size=11401 sha256=649c6895b552bfdace6ed19f945a13270a2911ad51d629cb29f6d9fa46c00da1
Stored in directory: /tmp/pip-ephem-wheel-cache-mm5kwrfq/wheels/f5/ff/57/dbbaca034196142bf028d1de97737fe105d495bb297a8a0567
Successfully built SAM-2
Installing collected packages: widgetsnbextension, qtpy, jupyterlab-widgets, iopath, matplotlib, ipywidgets, SAM-2, qtconsole, jupyter-console, jupyter
Attempting uninstall: matplotlib
Found existing installation: matplotlib 3.9.0
Uninstalling matplotlib-3.9.0:
Successfully uninstalled matplotlib-3.9.0
ERROR: Could not install packages due to an OSError: [Errno 16] Device or resource busy: '.nfs0086f1a583af85880000004e'

[suw469@compute-g-17-157 segment-anything-2]$ python -c 'import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME)'
True /n/app/cuda/12.1-gcc-9.2.0

@lindawang0122ds
Copy link
Author

Just to update, I created a .ipynb file in /home/suw469 (where my segment anything model has the path: /home/suw469/segment-anything-2) and run the following python code:

os.environ['CUDA_HOME'] = '/n/app/cuda/12.1-gcc-9.2.0'
%cd segment-anything-2
!pip install -e .
!python setup.py build_ext --inplace

Following is the output for the above code. Does the output message confirm that I'm all set? I didn't encounter any error message this time. But since the last output message is copying something I'm a bit confused so wanna double check.

/home/suw469/segment-anything-2
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///home/suw469/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: pillow>=9.4.0 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (10.3.0)
Requirement already satisfied: iopath>=0.1.10 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (0.1.10)
Requirement already satisfied: torchvision>=0.18.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (0.18.1)
Requirement already satisfied: numpy>=1.24.4 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (1.26.4)
Requirement already satisfied: tqdm>=4.66.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (4.66.4)
Requirement already satisfied: torch>=2.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (2.3.1)
Requirement already satisfied: hydra-core>=1.3.2 in /home/suw469/.local/lib/python3.10/site-packages (from SAM-2==1.0) (1.3.2)
Requirement already satisfied: antlr4-python3-runtime==4.9.* in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (4.9.3)
Requirement already satisfied: omegaconf<2.4,>=2.2 in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (2.3.0)
Requirement already satisfied: packaging in /home/suw469/.local/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (24.1)
Requirement already satisfied: portalocker in /home/suw469/.local/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (2.8.2)
Requirement already satisfied: typing-extensions in /home/suw469/.local/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (4.12.2)
Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.3.1)
Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2.20.5)
Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: networkx in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.3)
Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (11.4.5.107)
Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (10.3.2.106)
Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (8.9.2.26)
Requirement already satisfied: jinja2 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.1.4)
Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (11.0.2.54)
Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: sympy in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (1.12.1)
Requirement already satisfied: fsspec in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2024.6.0)
Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.105)
Requirement already satisfied: filelock in /n/app/python/3.10.11.conda/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.12.0)
Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (12.1.0.106)
Requirement already satisfied: triton==2.3.1 in /home/suw469/.local/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2.3.1)
Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/suw469/.local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=2.3.1->SAM-2==1.0) (12.5.40)
Requirement already satisfied: PyYAML>=5.1.0 in /home/suw469/.local/lib/python3.10/site-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 /home/suw469/.local/lib/python3.10/site-packages (from jinja2->torch>=2.3.1->SAM-2==1.0) (2.1.5)
Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /home/suw469/.local/lib/python3.10/site-packages (from sympy->torch>=2.3.1->SAM-2==1.0) (1.3.0)
Building wheels for collected packages: SAM-2
Building editable for SAM-2 (pyproject.toml) ... done
Created wheel for SAM-2: filename=SAM_2-1.0-0.editable-cp310-cp310-linux_x86_64.whl size=11401 sha256=b4d2466ad195f720b0c713749a018b4c1de31ec01dd7bebcc6fa2d0e313db5c5
Stored in directory: /tmp/pip-ephem-wheel-cache-77adhinl/wheels/f5/ff/57/dbbaca034196142bf028d1de97737fe105d495bb297a8a0567
Successfully built SAM-2
Installing collected packages: SAM-2
Successfully installed SAM-2-1.0
running build_ext
/home/suw469/.local/lib/python3.10/site-packages/torch/utils/cpp_extension.py:499: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
warnings.warn(msg.format('we could not find ninja.'))
/home/suw469/.local/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
/home/suw469/.local/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(
/n/app/cuda/12.1-gcc-9.2.0/bin/nvcc -I/home/suw469/.local/lib/python3.10/site-packages/torch/include -I/home/suw469/.local/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/home/suw469/.local/lib/python3.10/site-packages/torch/include/TH -I/home/suw469/.local/lib/python3.10/site-packages/torch/include/THC -I/n/app/cuda/12.1-gcc-9.2.0/include -I/n/app/python/3.10.11.conda/include/python3.10 -c sam2/csrc/connected_components.cu -o build/temp.linux-x86_64-cpython-310/sam2/csrc/connected_components.o -D__CUDA_NO_HALF_OPERATORS
_ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options '-fPIC' -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE="_gcc" -DPYBIND11_STDLIB="_libstdcpp" -DPYBIND11_BUILD_ABI="_cxxabi1011" -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_75,code=compute_75 -gencode=arch=compute_75,code=sm_75 -std=c++17
creating build/lib.linux-x86_64-cpython-310
creating build/lib.linux-x86_64-cpython-310/sam2
g++ -pthread -B /n/app/python/3.10.11.conda/compiler_compat -shared -Wl,-rpath,/n/app/python/3.10.11.conda/lib -Wl,-rpath-link,/n/app/python/3.10.11.conda/lib -L/n/app/python/3.10.11.conda/lib -Wl,-rpath,/n/app/python/3.10.11.conda/lib -Wl,-rpath-link,/n/app/python/3.10.11.conda/lib -L/n/app/python/3.10.11.conda/lib build/temp.linux-x86_64-cpython-310/sam2/csrc/connected_components.o -L/home/suw469/.local/lib/python3.10/site-packages/torch/lib -L/n/app/cuda/12.1-gcc-9.2.0/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

@ronghanghu
Copy link
Contributor

Hi @lindawang0122ds

Following is the output for the above code. Does the output message confirm that I'm all set? I didn't encounter any error message this time. But since the last output message is copying something I'm a bit confused so wanna double check.

Yes, the output you pasted, everything looks correct now. You have successfully build the CUDA extension "_C.so", which should appear under sam2/_C.so in your local repo now.

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

4 participants