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

PatchModelAddDownscale is not compatible with controlnet #3022

Closed
jesenzhang opened this issue Mar 12, 2024 · 5 comments · May be fixed by #3917
Closed

PatchModelAddDownscale is not compatible with controlnet #3022

jesenzhang opened this issue Mar 12, 2024 · 5 comments · May be fixed by #3917

Comments

@jesenzhang
Copy link

jesenzhang commented Mar 12, 2024

PatchModelAddDownscale is not compatible with controlnet
image

@asagi4
Copy link
Contributor

asagi4 commented Mar 12, 2024

You probably mean "not compatible".

I have a local patch for this, but I haven't bothered submitting it upstream.

commit fa12952d61477ff903b2dd43a195c9c0a1e8e245
Author: asagi4 <[email protected]>
Date:   Mon Nov 20 19:53:06 2023 +0200

    Interpolate control if size does not match

diff --git a/comfy/ldm/modules/diffusionmodules/openaimodel.py b/comfy/ldm/modules/diffusionmodules/openaimodel.py
index d782eff..45d880a 100644
--- a/comfy/ldm/modules/diffusionmodules/openaimodel.py
+++ b/comfy/ldm/modules/diffusionmodules/openaimodel.py
@@ -358,6 +358,8 @@ def apply_control(h, control, name):
         ctrl = control[name].pop()
         if ctrl is not None:
             try:
+                if ctrl.shape[2] != h.shape[2] or ctrl.shape[3] != h.shape[3]:
+                    ctrl = F.interpolate(ctrl.float(), size=(h.shape[2], h.shape[3]), mode="bicubic", align_corners=False).to(h.dtype)
                 h += ctrl
             except:
                 logging.warning("warning control could not be applied {} {}".format(h.shape, ctrl.shape))

@jesenzhang jesenzhang changed the title PatchModelAddDownscale is not incompatible with controlnet PatchModelAddDownscale is not compatible with controlnet Mar 13, 2024
@jesenzhang
Copy link
Author

You probably mean "not compatible".

I have a local patch for this, but I haven't bothered submitting it upstream.

commit fa12952d61477ff903b2dd43a195c9c0a1e8e245
Author: asagi4 <[email protected]>
Date:   Mon Nov 20 19:53:06 2023 +0200

    Interpolate control if size does not match

diff --git a/comfy/ldm/modules/diffusionmodules/openaimodel.py b/comfy/ldm/modules/diffusionmodules/openaimodel.py
index d782eff..45d880a 100644
--- a/comfy/ldm/modules/diffusionmodules/openaimodel.py
+++ b/comfy/ldm/modules/diffusionmodules/openaimodel.py
@@ -358,6 +358,8 @@ def apply_control(h, control, name):
         ctrl = control[name].pop()
         if ctrl is not None:
             try:
+                if ctrl.shape[2] != h.shape[2] or ctrl.shape[3] != h.shape[3]:
+                    ctrl = F.interpolate(ctrl.float(), size=(h.shape[2], h.shape[3]), mode="bicubic", align_corners=False).to(h.dtype)
                 h += ctrl
             except:
                 logging.warning("warning control could not be applied {} {}".format(h.shape, ctrl.shape))

I tried it and it worked,Thanks!

@tgitit
Copy link

tgitit commented Apr 29, 2024

PatchModelAddDownscale still creates these warnings when used with controlnet.

warning control could not be applied torch.Size([2, 1280, 9, 6]) torch.Size([2, 1280, 18, 12])
warning control could not be applied torch.Size([2, 1280, 9, 6]) torch.Size([2, 1280, 18, 12])
warning control could not be applied torch.Size([2, 1280, 9, 6]) torch.Size([2, 1280, 18, 12])
warning control could not be applied torch.Size([2, 1280, 18, 12]) torch.Size([2, 1280, 36, 24])
warning control could not be applied torch.Size([2, 1280, 18, 12]) torch.Size([2, 1280, 36, 24])
etc

@Goodwillson
Copy link

Thank you for the patch, it works. Could be included into comfy?

@stephennilor
Copy link

stephennilor commented Jul 1, 2024

Thanks! You should submit this as PR, it seems like it mostly works but really should be included in Comfy by now and iterated on in some capacity given that this is essentially what is needed to get it from not working at all to functioning!

You probably mean "not compatible".

I have a local patch for this, but I haven't bothered submitting it upstream.

commit fa12952d61477ff903b2dd43a195c9c0a1e8e245
Author: asagi4 <[email protected]>
Date:   Mon Nov 20 19:53:06 2023 +0200

    Interpolate control if size does not match

diff --git a/comfy/ldm/modules/diffusionmodules/openaimodel.py b/comfy/ldm/modules/diffusionmodules/openaimodel.py
index d782eff..45d880a 100644
--- a/comfy/ldm/modules/diffusionmodules/openaimodel.py
+++ b/comfy/ldm/modules/diffusionmodules/openaimodel.py
@@ -358,6 +358,8 @@ def apply_control(h, control, name):
         ctrl = control[name].pop()
         if ctrl is not None:
             try:
+                if ctrl.shape[2] != h.shape[2] or ctrl.shape[3] != h.shape[3]:
+                    ctrl = F.interpolate(ctrl.float(), size=(h.shape[2], h.shape[3]), mode="bicubic", align_corners=False).to(h.dtype)
                 h += ctrl
             except:
                 logging.warning("warning control could not be applied {} {}".format(h.shape, ctrl.shape))

... plus i keep having to add it manually when Comfy gets updated :P

asagi4 added a commit to asagi4/ComfyUI that referenced this issue Jul 1, 2024
Fixes PatchModelAddDownscale when used with controlnets, and possibly some other
nodes doing similar things as well.

Fixes comfyanonymous#3022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants