comfyui_segment_anything icon indicating copy to clipboard operation
comfyui_segment_anything copied to clipboard

Error occurred when executing GroundingDinoSAMSegment (segment anything):

Open xjmxxxx opened this issue 1 year ago • 8 comments

Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_mm)

File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/node.py", line 314, in main (images, masks) = sam_segment( File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/node.py", line 236, in sam_segment masks, _, _ = predictor.predict_torch( File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/sam_hq/predictor.py", line 114, in predict_torch sparse_embeddings, dense_embeddings = self.model.prompt_encoder( File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 158, in forward box_embeddings = self._embed_boxes(boxes) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 97, in _embed_boxes corner_embedding = self.pe_layer.forward_with_coords(coords, self.input_image_size) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 214, in forward_with_coords return self._pe_encoding(coords.to(torch.float)) # B x N x C File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 189, in _pe_encoding coords = coords @ self.positional_encoding_gaussian_matrix

xjmxxxx avatar Dec 26 '23 16:12 xjmxxxx

im getting the exact same errror, have you been able to fix it ?

Nebuluss avatar Dec 30 '23 11:12 Nebuluss

2023-12-30 12:14:30,636 - root - ERROR - !!! Exception during processing !!! 2023-12-30 12:14:30,637 - root - ERROR - Traceback (most recent call last): File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\node.py", line 325, in main (images, masks) = sam_segment( ^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\node.py", line 247, in sam_segment masks, _, _ = predictor.predict_torch( ^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\sam_hq\predictor.py", line 114, in predict_torch sparse_embeddings, dense_embeddings = self.model.prompt_encoder( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 158, in forward box_embeddings = self._embed_boxes(boxes) ^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 97, in _embed_boxes corner_embedding = self.pe_layer.forward_with_coords(coords, self.input_image_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 214, in forward_with_coords return self._pe_encoding(coords.to(torch.float)) # B x N x C ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 189, in _pe_encoding coords = coords @ self.positional_encoding_gaussian_matrix ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_mm)

Nebuluss avatar Dec 30 '23 11:12 Nebuluss

Same here too

RamonGuthrie avatar Jan 15 '24 16:01 RamonGuthrie

samesies

qdesp avatar Jan 17 '24 03:01 qdesp

I had this same error. Two things to try:

  1. in the SAM loader, choose a smaller SAM model, like SAM vit-b
  2. in SAM loader, turn off "auto" and choose "prefer GPU"

LankyPoet avatar Feb 02 '24 03:02 LankyPoet

Solution given by ttulttul, posted as a reply to a similar issue:

Make sure you are using SAMModelLoader (Segment Anything) rather than "SAM Model Loader". Doing so resolved this issue for me. Must be something about how the two model loaders deliver the model data.

https://github.com/storyicon/comfyui_segment_anything/issues/10#issuecomment-1795181782

AugmentedRealityCat avatar Feb 28 '24 06:02 AugmentedRealityCat

Same issue, and I found the reason is, there are two nodes: One is "SAM Model Loader", from "WS Node Suite", DO NOT USE THIS; The other is "SAMModelLoader", from "segment anything", DO USE THIS;

See this picture: image

puke3615 avatar May 26 '24 06:05 puke3615

Solution given by ttulttul, posted as a reply to a similar issue:

Make sure you are using SAMModelLoader (Segment Anything) rather than "SAM Model Loader". Doing so resolved this issue for me. Must be something about how the two model loaders deliver the model data.

#10 (comment)

This solved the problem for me, too.

image

fdtory avatar Jun 14 '24 05:06 fdtory