diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aaa87845..27b3eb034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,8 @@ can remove artifacts and hard edges of inpaint area but also remove some details from original - **chaiNNer** fix `NaN` issues due to autocast - **Upscale** increase limit from 4x to 8x given the quality of some upscalers - - **Extra Networks** fix sort + - **Extra Networks** fix sort + - **LoRA** add support for LyCORIS GLora networks - disable google fonts check on server startup - fix torchvision/basicsr compatibility - fix styles quick save diff --git a/extensions-builtin/Lora/network_glora.py b/extensions-builtin/Lora/network_glora.py new file mode 100644 index 000000000..3c54a14cc --- /dev/null +++ b/extensions-builtin/Lora/network_glora.py @@ -0,0 +1,30 @@ + +import network + +class ModuleTypeGLora(network.ModuleType): + def create_module(self, net: network.Network, weights: network.NetworkWeights): + if all(x in weights.w for x in ["a1.weight", "a2.weight", "alpha", "b1.weight", "b2.weight"]): + return NetworkModuleGLora(net, weights) + return None + +# adapted from https://github.com/KohakuBlueleaf/LyCORIS +class NetworkModuleGLora(network.NetworkModule): # pylint: disable=abstract-method + def __init__(self, net: network.Network, weights: network.NetworkWeights): + super().__init__(net, weights) + + if hasattr(self.sd_module, 'weight'): + self.shape = self.sd_module.weight.shape + + self.w1a = weights.w["a1.weight"] + self.w1b = weights.w["b1.weight"] + self.w2a = weights.w["a2.weight"] + self.w2b = weights.w["b2.weight"] + + def calc_updown(self, orig_weight): # pylint: disable=arguments-differ + w1a = self.w1a.to(orig_weight.device, dtype=orig_weight.dtype) + w1b = self.w1b.to(orig_weight.device, dtype=orig_weight.dtype) + w2a = self.w2a.to(orig_weight.device, dtype=orig_weight.dtype) + w2b = self.w2b.to(orig_weight.device, dtype=orig_weight.dtype) + output_shape = [w1a.size(0), w1b.size(1)] + updown = (w2b @ w1b) + ((orig_weight @ w2a) @ w1a) + return self.finalize_updown(updown, orig_weight, output_shape) diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index cc0c34bc3..006eaf5bb 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -11,6 +11,7 @@ import network_oft import network_lokr import network_full import network_norm +import network_glora import lora_convert import torch import diffusers.models.lora @@ -37,6 +38,7 @@ module_types = [ network_lokr.ModuleTypeLokr(), network_full.ModuleTypeFull(), network_norm.ModuleTypeNorm(), + network_glora.ModuleTypeGLora(), ] convert_diffusers_name_to_compvis = lora_convert.convert_diffusers_name_to_compvis # supermerger compatibility item diff --git a/html/locale_en.json b/html/locale_en.json index 14ea99c9b..8bce40518 100644 --- a/html/locale_en.json +++ b/html/locale_en.json @@ -500,7 +500,7 @@ {"id":"","label":"Show previews of all images generated in a batch as a grid","localized":"","hint":""}, {"id":"","label":"Play a sound when images are finished generating","localized":"","hint":""}, {"id":"","label":"Path to notification sound","localized":"","hint":""}, - {"id":"","label":"Live preview display period","localized":"","hint":""}, + {"id":"","label":"Live preview display period","localized":"","hint":"Request preview image every n steps, set to 0 to disable"}, {"id":"","label":"Full VAE","localized":"","hint":""}, {"id":"","label":"Approximate","localized":"","hint":"Cheap neural network approximation. Very fast compared to VAE, but produces pictures with 4 times smaller horizontal/vertical resolution and lower quality"}, {"id":"","label":"Simple","localized":"","hint":"Very cheap approximation. Very fast compared to VAE, but produces pictures with 8 times smaller horizontal/vertical resolution and extremely low quality"}, diff --git a/modules/processing_diffusers.py b/modules/processing_diffusers.py index 1fe11b817..a6490fb58 100644 --- a/modules/processing_diffusers.py +++ b/modules/processing_diffusers.py @@ -651,6 +651,8 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro ) shared.state.sampling_steps = refiner_args['num_inference_steps'] try: + shared.sd_refiner.register_to_config(requires_aesthetics_score=shared.opts.diffusers_aesthetics_score) + print('HERE req', shared.sd_refiner.config.requires_aesthetics_score) refiner_output = shared.sd_refiner(**refiner_args) # pylint: disable=not-callable except AssertionError as e: shared.log.info(e) diff --git a/modules/shared.py b/modules/shared.py index d88d651bd..c6facfd21 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -496,7 +496,7 @@ options_templates.update(options_section(('live-preview', "Live Previews"), { "show_progress_grid": OptionInfo(True, "Show previews of all images generated in a batch as a grid", gr.Checkbox, {"visible": False}), "notification_audio_enable": OptionInfo(False, "Play a sound when images are finished generating"), "notification_audio_path": OptionInfo("html/notification.mp3","Path to notification sound", component_args=hide_dirs, folder=True), - "show_progress_every_n_steps": OptionInfo(1, "Live preview display period", gr.Slider, {"minimum": -1, "maximum": 32, "step": 1}), + "show_progress_every_n_steps": OptionInfo(1, "Live preview display period", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}), "show_progress_type": OptionInfo("Approximate", "Live preview method", gr.Radio, {"choices": ["Simple", "Approximate", "TAESD", "Full VAE"]}), "live_preview_content": OptionInfo("Combined", "Live preview subject", gr.Radio, {"choices": ["Combined", "Prompt", "Negative prompt"], "visible": False}), "live_preview_refresh_period": OptionInfo(500, "Progress update period", gr.Slider, {"minimum": 0, "maximum": 5000, "step": 25}), diff --git a/modules/ui.py b/modules/ui.py index 6f6213c2e..65b70f3fc 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -366,7 +366,7 @@ def create_toprow(is_img2img: bool = False, id_part: str = None): negative_token_button = gr.Button(visible=False, elem_id=f"{id_part}_negative_token_button") with gr.Row(elem_id=f"{id_part}_styles_row"): styles = gr.Dropdown(label="Styles", elem_id=f"{id_part}_styles", choices=[style.name for style in modules.shared.prompt_styles.styles.values()], value=[], multiselect=True) - styles_btn_refresh = create_refresh_button(styles, modules.shared.prompt_styles.reload, lambda: {"choices": list(modules.shared.prompt_styles.styles)}, f"{id_part}_styles_refresh") + _styles_btn_refresh = create_refresh_button(styles, modules.shared.prompt_styles.reload, lambda: {"choices": list(modules.shared.prompt_styles.styles)}, f"{id_part}_styles_refresh") # styles_btn_refresh = ToolButton(symbols.refresh, elem_id=f"{id_part}_styles_refresh", visible=True) # styles_btn_refresh.click(fn=lambda: gr.update(choices=[style.name for style in modules.shared.prompt_styles.styles.values()]), inputs=[], outputs=[styles]) styles_btn_select = gr.Button('Select', elem_id=f"{id_part}_styles_select", visible=False) diff --git a/wiki b/wiki index faa2defd1..6317f96f9 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit faa2defd19badfef74a1e4f54b695a68c7651224 +Subproject commit 6317f96f9b5ade24e8ea5c8e796d5c22c412cfd6