mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
update lora methods
This commit is contained in:
Submodule extensions-builtin/sd-dynamic-thresholding updated: 5349f00872...c60fe071e5
Submodule extensions-builtin/sd-extension-system-info updated: 9d3c0ca0f2...19d190e71b
Submodule extensions-builtin/sd-webui-controlnet updated: 5ae9b4a1a0...af34f51449
+2
-2
@@ -575,8 +575,8 @@
|
||||
{"id":"","label":"Enable VAE tiling","localized":"","hint":"Divide large images into overlapping tiles with limited VRAM. Might result in a minor increase in processing time. Use with Enable Attention Slicing"},
|
||||
{"id":"","label":"Enable attention slicing","localized":"","hint":"Performs attention computation in steps instead of all at once. 10% slower inference times. Greatly reduces memory usage. Best used, period"},
|
||||
{"id":"","label":"Diffusers model loading variant","localized":"","hint":""},
|
||||
{"id":"","label":"Diffusers VAE loading variant","localized":"","hint":""}
|
||||
|
||||
{"id":"","label":"Diffusers VAE loading variant","localized":"","hint":""},
|
||||
{"id":"","label":"Diffusers LoRA loading variant","localized":"","hint":"'sequential apply' loads and applies each LoRA in order of appearance, 'merge and apply' loads all LoRAs and merges them in-memory before applying to model, 'diffusers default' uses single LoRA loading method"}
|
||||
],
|
||||
"scripts": [
|
||||
{"id":"","label":"Script","localized":"","hint":""},
|
||||
|
||||
@@ -13,7 +13,7 @@ lora_state = { # TODO Lora state for Diffusers
|
||||
def unload_diffusers_lora():
|
||||
try:
|
||||
pipe = shared.sd_model
|
||||
if shared.opts.diffusers_lora_loader == "Diffusers":
|
||||
if shared.opts.diffusers_lora_loader == "diffusers default":
|
||||
pipe.unload_lora_weights()
|
||||
pipe._remove_text_encoder_monkey_patch() # pylint: disable=W0212
|
||||
proc_cls_name = next(iter(pipe.unet.attn_processors.values())).__class__.__name__
|
||||
@@ -24,9 +24,9 @@ def unload_diffusers_lora():
|
||||
lora_state['all_loras'].reverse()
|
||||
lora_state['multiplier'].reverse()
|
||||
for i, lora_network in enumerate(lora_state['all_loras']):
|
||||
if shared.opts.diffusers_lora_loader == "kohya-merge":
|
||||
if shared.opts.diffusers_lora_loader == "merge and apply":
|
||||
lora_network.restore_from(multiplier=lora_state['multiplier'][i])
|
||||
if shared.opts.diffusers_lora_loader == "kohya-apply":
|
||||
if shared.opts.diffusers_lora_loader == "sequential apply":
|
||||
lora_network.unapply_to()
|
||||
lora_state['active'] = False
|
||||
lora_state['loaded'] = 0
|
||||
@@ -43,7 +43,7 @@ def load_diffusers_lora(name, lora, strength = 1.0):
|
||||
lora_state['active'] = True
|
||||
lora_state['loaded'] += 1
|
||||
lora_state['multiplier'].append(strength)
|
||||
if shared.opts.diffusers_lora_loader == "Diffusers":
|
||||
if shared.opts.diffusers_lora_loader == "diffusers default":
|
||||
pipe.load_lora_weights(lora.filename, cache_dir=shared.opts.diffusers_dir, local_files_only=True, lora_scale=strength)
|
||||
shared.log.info(f"Diffusers LoRA loaded: {name} {lora_state['multiplier']}")
|
||||
else:
|
||||
@@ -55,9 +55,9 @@ def load_diffusers_lora(name, lora, strength = 1.0):
|
||||
text_encoders = pipe.text_encoder
|
||||
lora_network: LoRANetwork = create_network_from_weights(text_encoders, pipe.unet, lora_sd, multiplier=strength)
|
||||
lora_network.load_state_dict(lora_sd)
|
||||
if shared.opts.diffusers_lora_loader == "kohya-merge":
|
||||
if shared.opts.diffusers_lora_loader == "merge and apply":
|
||||
lora_network.merge_to(multiplier=strength)
|
||||
if shared.opts.diffusers_lora_loader == "kohya-apply":
|
||||
if shared.opts.diffusers_lora_loader == "sequential apply":
|
||||
lora_network.to(pipe.device, dtype=pipe.unet.dtype)
|
||||
lora_network.apply_to(multiplier=strength)
|
||||
lora_state['all_loras'].append(lora_network)
|
||||
|
||||
@@ -93,7 +93,7 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
|
||||
args['callback_steps'] = 1
|
||||
if 'callback' in possible:
|
||||
args['callback'] = diffusers_callback
|
||||
if 'cross_attention_kwargs' in possible and lora_state['active'] and shared.opts.diffusers_lora_loader == "Diffusers":
|
||||
if 'cross_attention_kwargs' in possible and lora_state['active'] and shared.opts.diffusers_lora_loader == "diffusers default":
|
||||
args['cross_attention_kwargs'] = { 'scale': lora_state['multiplier'][0]}
|
||||
for arg in kwargs:
|
||||
if arg in possible:
|
||||
|
||||
+1
-1
@@ -409,7 +409,7 @@ options_templates.update(options_section(('diffusers', "Diffusers Settings"), {
|
||||
"diffusers_attention_slicing": OptionInfo(True if devices.backend == "ipex" else False, "Enable attention slicing"),
|
||||
"diffusers_model_load_variant": OptionInfo("default", "Diffusers model loading variant", gr.Radio, lambda: {"choices": ['default', 'fp32', 'fp16']}),
|
||||
"diffusers_vae_load_variant": OptionInfo("default", "Diffusers VAE loading variant", gr.Radio, lambda: {"choices": ['default', 'fp32', 'fp16']}),
|
||||
"diffusers_lora_loader": OptionInfo("default", "Diffusers LoRA loading variant", gr.Radio, lambda: {"choices": ['kohya-apply', 'kohya-merge', 'Diffusers']}),
|
||||
"diffusers_lora_loader": OptionInfo("sequential apply", "Diffusers LoRA loading variant", gr.Radio, lambda: {"choices": ['sequential apply', 'merge and apply', 'diffusers default']}),
|
||||
# "diffusers_force_zeros": OptionInfo(False, "Force zeros for prompts when empty"),
|
||||
# "diffusers_aesthetics_score": OptionInfo(6.0, "Require aesthetic score", gr.Slider, {"minimum": 0, "maximum": 10, "step": 0.1}),
|
||||
}))
|
||||
|
||||
+1
-1
Submodule wiki updated: f76cc3a9ac...35142f02ae
Reference in New Issue
Block a user