comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
56.84k stars 6.02k forks source link

need help with SAMModelLoader failure on Apple Silicon due to CUDA Deserialization Error? #3222

Open martintomov opened 7 months ago

martintomov commented 7 months ago

Issue #60 in comfyui_segment_anything

SAMModelLoader Failure on Apple Silicon due to CUDA Deserialization Error

Has anyone else encountered this issue when trying to run SAMModelLoader for the segment anything functionality on an Apple Silicon Mac? I'm getting an error related to CUDA deserialization, despite the fact that torch.cuda.is_available() returns False. It seems like the model loading process is mistakenly assuming the availability of CUDA on a platform that clearly does not support it, leading to a failure in executing the desired functionality.

Issue Description

When attempting to run SAMModelLoader for the segment anything functionality on an Apple Silicon Mac, an error is encountered indicating a problem with attempting to deserialize an object on a CUDA device, even though torch.cuda.is_available() returns False.

Environment

Error Message

Error occurred when executing SAMModelLoader (segment anything):

Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Expected Behavior

The model loader should detect the absence of CUDA and automatically adjust to use CPU for model deserialization and execution, allowing the functionality to proceed without error, or ideally switch to the GPU Apple Silicon provides.

Actual Behaviour

The process fails with an error message indicating an attempt to deserialize a CUDA object on a system where CUDA is not available, due to torch.cuda.is_available() returning False.

Screenshot

320283574-c9b53012-d557-415c-9979-31955607671a

NeedsMoar commented 7 months ago

Edit: Nevermind, I see you linked to a bug you filed over there.

Comfy probably can't do much about this.

Just FYI I'm running a CUDA card and that extension is linked against such an old version of CUDA that it just errors multiple times trying to import DLLs during startup and most parts won't work, so if it's not up to date for that there's not much chance of getting them to update it to work on mac.

martintomov commented 7 months ago

Thanks for the quick reply!

Yeah, I suspect Comfy can't really solve this, but I wonder what's the current workaround for the issue I'm facing and if others are also facing it.

sagebru5h commented 7 months ago

I'm curious if a workaround was ever discovered for this issue...?

martintomov commented 6 months ago

@sagebru5h

Try using this: https://github.com/MarkoCa1/ComfyUI_Segment_Mask/issues/5

ipaaad4evr commented 2 months ago

Any workarounds for this? Im on m1 max and and find any solution :(