From 192f351663dcdbb7648ce3e17720355c46df3358 Mon Sep 17 00:00:00 2001 From: a2569875 Date: Sun, 23 Apr 2023 20:05:17 +0800 Subject: [PATCH] An option for troubleshooting --- scripts/composable_lora_script.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/composable_lora_script.py b/scripts/composable_lora_script.py index 86e537b..a75cf1b 100644 --- a/scripts/composable_lora_script.py +++ b/scripts/composable_lora_script.py @@ -40,10 +40,18 @@ class ComposableLoraScript(scripts.Script): opt_uc_diffusion_model = gr.Checkbox(value=False, label="Use Lora in uc diffusion model") opt_plot_lora_weight = gr.Checkbox(value=False, label="Plot the LoRA weight in all steps") opt_single_no_uc = gr.Checkbox(value=False, label="Don't use LoRA in uc if there're no subprompts") + unload_ext = gr.Checkbox(value=False, label="Unload (If you got a corrupted image, try uncheck [Enabled] and checking this option and generate an image without LoRA, and then turn off this option.)") + def enabled_changed(opt_enabled: bool, opt_unload_ext: bool): + if opt_enabled: + unload_ext.interactive=False + return False + else: + unload_ext.interactive=True + return opt_unload_ext + enabled.change(enabled_changed, inputs=[enabled, unload_ext], outputs=[unload_ext]) + return [enabled, opt_composable_with_step, opt_uc_text_model_encoder, opt_uc_diffusion_model, opt_plot_lora_weight, opt_single_no_uc, unload_ext] - return [enabled, opt_composable_with_step, opt_uc_text_model_encoder, opt_uc_diffusion_model, opt_plot_lora_weight, opt_single_no_uc] - - def process(self, p: StableDiffusionProcessing, enabled: bool, opt_composable_with_step: bool, opt_uc_text_model_encoder: bool, opt_uc_diffusion_model: bool, opt_plot_lora_weight: bool, opt_single_no_uc: bool): + def process(self, p: StableDiffusionProcessing, enabled: bool, opt_composable_with_step: bool, opt_uc_text_model_encoder: bool, opt_uc_diffusion_model: bool, opt_plot_lora_weight: bool, opt_single_no_uc: bool, unload_ext : bool): composable_lora.enabled = enabled composable_lora.opt_uc_text_model_encoder = opt_uc_text_model_encoder composable_lora.opt_uc_diffusion_model = opt_uc_diffusion_model @@ -57,8 +65,9 @@ class ComposableLoraScript(scripts.Script): composable_lora.backup_lora_Linear_forward = torch.nn.Linear.forward composable_lora.backup_lora_Conv2d_forward = torch.nn.Conv2d.forward if (composable_lora.should_reload() or (torch.nn.Linear.forward != composable_lora.lora_Linear_forward)): - torch.nn.Linear.forward = composable_lora.lora_Linear_forward - torch.nn.Conv2d.forward = composable_lora.lora_Conv2d_forward + if enabled or not unload_ext: + torch.nn.Linear.forward = composable_lora.lora_Linear_forward + torch.nn.Conv2d.forward = composable_lora.lora_Conv2d_forward composable_lora.reset_step_counters()