From fd2d57244797563acfea925ce9e85f4a2ebb5d83 Mon Sep 17 00:00:00 2001 From: "kosinkadink1@gmail.com" Date: Wed, 25 Sep 2024 19:46:33 +0900 Subject: [PATCH] Modified ControlNet/T2IAdapter get_control function to receive transformer_options as additional parameter, made the model_options stored in extra_args in inner_sample be a clone of the original model_options instead of same ref --- comfy/controlnet.py | 8 ++++---- comfy/samplers.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/comfy/controlnet.py b/comfy/controlnet.py index 9dfd69977..9bc1023f6 100644 --- a/comfy/controlnet.py +++ b/comfy/controlnet.py @@ -201,10 +201,10 @@ class ControlNet(ControlBase): self.strength_type = strength_type self.concat_mask = concat_mask - def get_control(self, x_noisy, t, cond, batched_number): + def get_control(self, x_noisy, t, cond, batched_number, transformer_options): control_prev = None if self.previous_controlnet is not None: - control_prev = self.previous_controlnet.get_control(x_noisy, t, cond, batched_number) + control_prev = self.previous_controlnet.get_control(x_noisy, t, cond, batched_number, transformer_options) if self.timestep_range is not None: if t[0] > self.timestep_range[0] or t[0] < self.timestep_range[1]: @@ -674,10 +674,10 @@ class T2IAdapter(ControlBase): height = math.ceil(height / unshuffle_amount) * unshuffle_amount return width, height - def get_control(self, x_noisy, t, cond, batched_number): + def get_control(self, x_noisy, t, cond, batched_number, transformer_options): control_prev = None if self.previous_controlnet is not None: - control_prev = self.previous_controlnet.get_control(x_noisy, t, cond, batched_number) + control_prev = self.previous_controlnet.get_control(x_noisy, t, cond, batched_number, transformer_options) if self.timestep_range is not None: if t[0] > self.timestep_range[0] or t[0] < self.timestep_range[1]: diff --git a/comfy/samplers.py b/comfy/samplers.py index 94a14182f..819e5c13a 100644 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -271,9 +271,6 @@ def outer_calc_cond_batch(model: 'BaseModel', conds: List[List[Dict]], x_in: tor c = cond_cat(c) timestep_ = torch.cat([timestep] * batch_chunks) - if control is not None: - c['control'] = control.get_control(input_x, timestep_, c, len(cond_or_uncond)) - transformer_options = {} if 'transformer_options' in model_options: transformer_options = model_options['transformer_options'].copy() @@ -295,6 +292,9 @@ def outer_calc_cond_batch(model: 'BaseModel', conds: List[List[Dict]], x_in: tor c['transformer_options'] = transformer_options + if control is not None: + c['control'] = control.get_control(input_x, timestep_, c, len(cond_or_uncond), transformer_options) + if 'model_function_wrapper' in model_options: output = model_options['model_function_wrapper'](model.apply_model, {"input": input_x, "timestep": timestep_, "c": c, "cond_or_uncond": cond_or_uncond}).chunk(batch_chunks) else: @@ -769,7 +769,7 @@ class CFGGuider: self.conds = process_conds(self.inner_model, noise, self.conds, device, latent_image, denoise_mask, seed) - extra_args = {"model_options": self.model_options, "seed":seed} + extra_args = {"model_options": comfy.model_patcher.create_model_options_clone(self.model_options), "seed": seed} samples = sampler.sample(self, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar) return self.inner_model.process_latent_out(samples.to(torch.float32))