ComfyUI_Comfyroll_CustomNodes icon indicating copy to clipboard operation
ComfyUI_Comfyroll_CustomNodes copied to clipboard

AttributeError: 'ImageModelDescriptor' object has no attribute 'cpu'

Open WangGosh opened this issue 1 year ago • 5 comments

I deployed ComfyUI on the DSW server of Alibaba Cloud. When I tried to zoom in with the enlarged model, it displayed this error image image image

WangGosh avatar May 31 '24 15:05 WangGosh

pytorch2.1.2tensorflow2.14.0-gpu-py310-cu121-ubuntu22.04 This is my system environment

WangGosh avatar May 31 '24 15:05 WangGosh

I stopped using a1111 for a few months. When I tried it today again today, I'm getting the same error...

Moxie1776 avatar Jun 06 '24 08:06 Moxie1776

Can confirm this when trying out the DemonCore Workflow from Civitai, which depends on these nodes for upscaling.

After having searched and found a hint on stackoverflow, I made a desperate attempt that finally worked:

diff --git a/nodes/functions_upscale.py b/nodes/functions_upscale.py
index 2c25f03..a6c748c 100644
--- a/nodes/functions_upscale.py
+++ b/nodes/functions_upscale.py
@@ -54,7 +54,8 @@ def upscale_with_model(upscale_model, image):
             if tile < 128:
                 raise e

-    upscale_model.cpu()
+    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
+    upscale_model.to(device)
     s = torch.clamp(s.movedim(-3,-1), min=0, max=1.0)
     return s

speters avatar Jun 28 '24 05:06 speters

Can confirm this when trying out the DemonCore Workflow from Civitai, which depends on these nodes for upscaling.

After having searched and found a hint on stackoverflow, I made a desperate attempt that finally worked:

diff --git a/nodes/functions_upscale.py b/nodes/functions_upscale.py
index 2c25f03..a6c748c 100644
--- a/nodes/functions_upscale.py
+++ b/nodes/functions_upscale.py
@@ -54,7 +54,8 @@ def upscale_with_model(upscale_model, image):
             if tile < 128:
                 raise e

-    upscale_model.cpu()
+    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
+    upscale_model.to(device)
     s = torch.clamp(s.movedim(-3,-1), min=0, max=1.0)
     return s

Nice, works great for me. have you already made a PR for this fix?

DGdev91 avatar Jul 08 '24 19:07 DGdev91

No, I didn't make a PR. The @Suzie1 account seems pretty inactive since Feb'24, so I didn't bother.

speters avatar Jul 09 '24 08:07 speters