From 4f3cc3de73564b56edeab2cfe7ac1cc1e1d5315e Mon Sep 17 00:00:00 2001 From: catboxanon <122327233+catboxanon@users.noreply.github.com> Date: Wed, 26 Jul 2023 08:33:19 +0000 Subject: [PATCH] Add setting to disable CN in highres --- scripts/controlnet.py | 2 ++ scripts/hook.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/controlnet.py b/scripts/controlnet.py index ab51c14b6..59bbb60ca 100644 --- a/scripts/controlnet.py +++ b/scripts/controlnet.py @@ -1033,6 +1033,8 @@ def on_ui_settings(): 1, "Model cache size (requires restart)", gr.Slider, {"minimum": 1, "maximum": 5, "step": 1}, section=section)) shared.opts.add_option("control_net_inpaint_blur_sigma", shared.OptionInfo( 7, "ControlNet inpainting Gaussian blur sigma", gr.Slider, {"minimum": 0, "maximum": 64, "step": 1}, section=section)) + shared.opts.add_option("control_net_no_high_res_fix", shared.OptionInfo( + False, "Do not apply ControlNet during highres fix", gr.Checkbox, {"interactive": True}, section=section)) shared.opts.add_option("control_net_no_detectmap", shared.OptionInfo( False, "Do not append detectmap to output", gr.Checkbox, {"interactive": True}, section=section)) shared.opts.add_option("control_net_detectmap_autosaving", shared.OptionInfo( diff --git a/scripts/hook.py b/scripts/hook.py index 96860b1d2..f0d0a5f6b 100644 --- a/scripts/hook.py +++ b/scripts/hook.py @@ -387,6 +387,8 @@ def forward(self, x, timesteps=None, context=None, **kwargs): param.used_hint_cond_latent = None param.used_hint_inpaint_hijack = None + no_high_res_control = is_in_high_res_fix and shared.opts.data.get("control_net_no_high_res_fix", False) + # Convert control image to latent for param in outer.control_params: if param.used_hint_cond_latent is not None: @@ -399,6 +401,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs): # handle prompt token control for param in outer.control_params: + if no_high_res_control: + continue + if param.guidance_stopped: continue @@ -414,6 +419,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs): # handle ControlNet / T2I_Adapter for param in outer.control_params: + if no_high_res_control: + continue + if param.guidance_stopped: continue @@ -524,6 +532,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs): # Handle attention and AdaIn control for param in outer.control_params: + if no_high_res_control: + continue + if param.guidance_stopped: continue @@ -605,7 +616,7 @@ def forward(self, x, timesteps=None, context=None, **kwargs): continue k = int(param.preprocessor['threshold_a']) - if is_in_high_res_fix: + if is_in_high_res_fix and not no_high_res_control: k *= 2 # Inpaint hijack