The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Set upscale algorithm to bilinear for stable cascade controlnet.
comfyanonymous03e6e81629b0
diff --git a/comfy/controlnet.py b/comfy/controlnet.pyindex 39344a4da..356d5c0e7 100644--- a/comfy/controlnet.py+++ b/comfy/controlnet.py@@ -39,6 +39,7 @@ class ControlBase:self.global_average_pooling = Falseself.timestep_range = Noneself.compression_ratio = 8+ self.upscale_algorithm = 'nearest-exact'if device is None:device = comfy.model_management.get_torch_device()@@ -80,6 +81,7 @@ class ControlBase:c.timestep_percent_range = self.timestep_percent_rangec.global_average_pooling = self.global_average_poolingc.compression_ratio = self.compression_ratio+ c.upscale_algorithm = self.upscale_algorithmdef inference_memory_requirements(self, dtype):if self.previous_controlnet is not None:@@ -165,7 +167,7 @@ class ControlNet(ControlBase):if self.cond_hint is not None:del self.cond_hintself.cond_hint = None- self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, x_noisy.shape[3] * self.compression_ratio, x_noisy.shape[2] * self.compression_ratio, 'nearest-exact', "center").to(dtype).to(self.device)+ self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, x_noisy.shape[3] * self.compression_ratio, x_noisy.shape[2] * self.compression_ratio, self.upscale_algorithm, "center").to(dtype).to(self.device)if x_noisy.shape[0] != self.cond_hint.shape[0]:self.cond_hint = broadcast_image_to(self.cond_hint, x_noisy.shape[0], batched_number)@@ -435,12 +437,13 @@ def load_controlnet(ckpt_path, model=None):return controlclass T2IAdapter(ControlBase):- def __init__(self, t2i_model, channels_in, compression_ratio, device=None):+ def __init__(self, t2i_model, channels_in, compression_ratio, upscale_algorithm, device=None):super().__init__(device)self.t2i_model = t2i_modelself.channels_in = channels_inself.control_input = Noneself.compression_ratio = compression_ratio+ self.upscale_algorithm = upscale_algorithmdef scale_image_to(self, width, height):unshuffle_amount = self.t2i_model.unshuffle_amount@@ -466,7 +469,7 @@ class T2IAdapter(ControlBase):self.control_input = Noneself.cond_hint = Nonewidth, height = self.scale_image_to(x_noisy.shape[3] * self.compression_ratio, x_noisy.shape[2] * self.compression_ratio)- self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, width, height, 'nearest-exact', "center").float().to(self.device)+ self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, width, height, self.upscale_algorithm, "center").float().to(self.device)if self.channels_in == 1 and self.cond_hint.shape[1] > 1:self.cond_hint = torch.mean(self.cond_hint, 1, keepdim=True)if x_noisy.shape[0] != self.cond_hint.shape[0]:@@ -485,12 +488,13 @@ class T2IAdapter(ControlBase):return self.control_merge(control_input, mid, control_prev, x_noisy.dtype)def copy(self):- c = T2IAdapter(self.t2i_model, self.channels_in, self.compression_ratio)+ c = T2IAdapter(self.t2i_model, self.channels_in, self.compression_ratio, self.upscale_algorithm)self.copy_to(c)return cdef load_t2i_adapter(t2i_data):compression_ratio = 8+ upscale_algorithm = 'nearest-exact'if 'adapter' in t2i_data:t2i_data = t2i_data['adapter']@@ -522,6 +526,7 @@ def load_t2i_adapter(t2i_data):elif "backbone.0.0.weight" in keys:model_ad = comfy.ldm.cascade.controlnet.ControlNet(c_in=t2i_data['backbone.0.0.weight'].shape[1], proj_blocks=[0, 4, 8, 12, 51, 55, 59, 63])compression_ratio = 32+ upscale_algorithm = 'bilinear'else:return None@@ -532,4 +537,4 @@ def load_t2i_adapter(t2i_data):if len(unexpected) > 0:print("t2i unexpected", unexpected)- return T2IAdapter(model_ad, model_ad.input_channels, compression_ratio)+ return T2IAdapter(model_ad, model_ad.input_channels, compression_ratio, upscale_algorithm)diff --git a/comfy/ldm/cascade/controlnet.py b/comfy/ldm/cascade/controlnet.pyindex fdb1ba4d2..c5757308f 100644--- a/comfy/ldm/cascade/controlnet.py+++ b/comfy/ldm/cascade/controlnet.py@@ -86,7 +86,6 @@ class ControlNet(nn.Module):self.unshuffle_amount = 8def forward(self, x):- print(x)x = self.backbone(x)proj_outputs = [None for _ in range(max(self.proj_blocks) + 1)]for i, idx in enumerate(self.proj_blocks):