mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
refactor(lora): remove the lora_apply_te setting
Text encoder networks now apply unconditionally in the native path. - remove the option, the per-request parameter and the control threading - collapse activate_filtered into plain activate at all call sites - drop the toggle from the prompt embed cache key - register the retired key so existing configs load without warnings
This commit is contained in:
@@ -403,7 +403,7 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
sequential_seed: bool | None = None,
|
||||
# prompt/attention overrides
|
||||
prompt_attention: str | None = None, prompt_mean_norm: bool | None = None, diffusers_zeros_prompt_pad: bool | None = None,
|
||||
te_pooled_embeds: bool | None = None, lora_apply_te: bool | None = None, te_complex_human_instruction: str | None = None, te_use_mask: bool | None = None,
|
||||
te_pooled_embeds: bool | None = None, te_complex_human_instruction: str | None = None, te_use_mask: bool | None = None,
|
||||
# generation modifier overrides (hijack)
|
||||
freeu_enabled: bool | None = None, freeu_b1: float | None = None, freeu_b2: float | None = None, freeu_s1: float | None = None, freeu_s2: float | None = None,
|
||||
hypertile_unet_enabled: bool | None = None, hypertile_hires_only: bool | None = None, hypertile_unet_tile: int | None = None, hypertile_unet_min_tile: int | None = None,
|
||||
@@ -586,7 +586,7 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
# prompt/attention overrides
|
||||
prompt_attention=prompt_attention, prompt_mean_norm=prompt_mean_norm,
|
||||
diffusers_zeros_prompt_pad=diffusers_zeros_prompt_pad, te_pooled_embeds=te_pooled_embeds,
|
||||
lora_apply_te=lora_apply_te, te_complex_human_instruction=te_complex_human_instruction, te_use_mask=te_use_mask,
|
||||
te_complex_human_instruction=te_complex_human_instruction, te_use_mask=te_use_mask,
|
||||
# generation modifier overrides (hijack)
|
||||
freeu_enabled=freeu_enabled, freeu_b1=freeu_b1, freeu_b2=freeu_b2, freeu_s1=freeu_s1, freeu_s2=freeu_s2,
|
||||
hypertile_unet_enabled=hypertile_unet_enabled, hypertile_hires_only=hypertile_hires_only,
|
||||
|
||||
@@ -321,7 +321,7 @@ class Detailer():
|
||||
pc.disable_extra_networks = True # disable processing_diffusers from handling network activation since its handled here
|
||||
network_same = len(p.network_data.values()) == len(pc.network_data.values()) and all(x == y for x, y in zip(p.network_data.values(), pc.network_data.values()))
|
||||
if not network_same:
|
||||
extra_networks.activate_filtered(pc, pc.network_data)
|
||||
extra_networks.activate(pc, pc.network_data)
|
||||
log.debug(f'Detail: model="{i+1}:{name}" item={j+1}/{len(items)} box={item.box} label="{item.label}" score={item.score:.2f} seg={detailer_opt(p, "detailer_segmentation")} network={network_same} prompt="{pc.prompt}"')
|
||||
pc.init_images = [image]
|
||||
pc.image_mask = [item.mask]
|
||||
|
||||
@@ -121,15 +121,6 @@ def activate(p: StableDiffusionProcessing, extra_network_data: defaultdict[str,
|
||||
p.network_data = extra_network_data
|
||||
|
||||
|
||||
def activate_filtered(p: StableDiffusionProcessing, extra_network_data: defaultdict[str, list[ExtraNetworkParams]] | None = None, step=0):
|
||||
"""activate with text encoder components gated on lora_apply_te; must run before prompt encode so te networks affect embeds"""
|
||||
apply_te = getattr(p, 'lora_apply_te', None)
|
||||
if apply_te is None:
|
||||
apply_te = shared.opts.lora_apply_te
|
||||
exclude = [] if apply_te else ['text_encoder', 'text_encoder_2', 'text_encoder_3']
|
||||
activate(p, extra_network_data, step=step, exclude=exclude)
|
||||
|
||||
|
||||
def deactivate(p: StableDiffusionProcessing, extra_network_data: defaultdict[str, list[ExtraNetworkParams]] | None = None, force: bool | None = None):
|
||||
"""call deactivate for extra networks in extra_network_data in specified order, then call deactivate for all remaining registered networks"""
|
||||
if p.disable_extra_networks:
|
||||
|
||||
@@ -216,7 +216,7 @@ def face_id(
|
||||
p.subseeds = p.all_subseeds[n * p.batch_size:(n+1) * p.batch_size]
|
||||
p.prompts, p.network_data = extra_networks.parse_prompts(p.prompts, p.network_data)
|
||||
|
||||
extra_networks.activate_filtered(p, p.network_data)
|
||||
extra_networks.activate(p, p.network_data)
|
||||
ip_model_dict.update({
|
||||
"prompt": p.prompts[0],
|
||||
"negative_prompt": p.negative_prompts[0],
|
||||
|
||||
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
||||
import builtins
|
||||
|
||||
cmd_opts = cmd_args.parse_args()
|
||||
compatibility_opts = ['clip_skip', 'uni_pc_lower_order_final', 'uni_pc_order', 'xformers_options']
|
||||
compatibility_opts = ['clip_skip', 'uni_pc_lower_order_final', 'uni_pc_order', 'xformers_options', 'lora_apply_te']
|
||||
removed_values = { # a stored choice that no longer exists is kept by validate, so it has to be rewritten or it selects nothing
|
||||
'cross_attention_optimization': (['Batch matrix-matrix', 'Dynamic Attention BMM'], 'Scaled-Dot-Product'),
|
||||
}
|
||||
|
||||
@@ -254,7 +254,6 @@ class StableDiffusionProcessing:
|
||||
prompt_mean_norm: bool | None = None,
|
||||
diffusers_zeros_prompt_pad: bool | None = None,
|
||||
te_pooled_embeds: bool | None = None,
|
||||
lora_apply_te: bool | None = None,
|
||||
te_complex_human_instruction: str | None = None,
|
||||
te_use_mask: bool | None = None,
|
||||
# generation modifier overrides (hijack)
|
||||
@@ -543,7 +542,6 @@ class StableDiffusionProcessing:
|
||||
self.prompt_mean_norm = prompt_mean_norm
|
||||
self.diffusers_zeros_prompt_pad = diffusers_zeros_prompt_pad
|
||||
self.te_pooled_embeds = te_pooled_embeds
|
||||
self.lora_apply_te = lora_apply_te
|
||||
self.te_complex_human_instruction = te_complex_human_instruction
|
||||
self.te_use_mask = te_use_mask
|
||||
# generation modifier overrides (hijack)
|
||||
|
||||
@@ -149,7 +149,7 @@ def process_base(p: processing.StableDiffusionProcessing):
|
||||
if 'detailer' in p.ops:
|
||||
desc = 'Detail'
|
||||
p.prompts, p.network_data = extra_networks.parse_prompts(p.prompts, p.network_data)
|
||||
extra_networks.activate_filtered(p) # networks must patch weights before prompt encode so te loras affect embeds
|
||||
extra_networks.activate(p) # networks must patch weights before prompt encode so te loras affect embeds
|
||||
base_args = set_pipeline_args(
|
||||
p=p,
|
||||
model=shared.sd_model,
|
||||
@@ -313,7 +313,7 @@ def process_hires(p: processing.StableDiffusionProcessing, output):
|
||||
prompts, p.network_data = extra_networks.parse_prompts(prompts)
|
||||
reset_prompts = True
|
||||
if reset_prompts or ('base' in p.skip):
|
||||
extra_networks.activate_filtered(p)
|
||||
extra_networks.activate(p)
|
||||
|
||||
hires_args = set_pipeline_args(
|
||||
p=p,
|
||||
|
||||
@@ -130,11 +130,8 @@ class PromptEmbedder:
|
||||
# unpack EN data in case of TE LoRA
|
||||
en_data = p.network_data
|
||||
en_data = [idx.items for item in en_data.values() for idx in item]
|
||||
apply_te = getattr(p, 'lora_apply_te', None)
|
||||
if apply_te is None:
|
||||
apply_te = shared.opts.lora_apply_te
|
||||
effective_batch = 1 if self.allsame else self.batchsize
|
||||
key = str([self.prompts, self.negative_prompts, effective_batch, self.clip_skip, self.steps, en_data, apply_te])
|
||||
key = str([self.prompts, self.negative_prompts, effective_batch, self.clip_skip, self.steps, en_data])
|
||||
item = cache.get(key)
|
||||
if not item:
|
||||
if not any(flatten(emb) for emb in [self.prompt_embeds,
|
||||
|
||||
@@ -699,7 +699,6 @@ def create_settings(cmd_opts):
|
||||
"lora_apply_tags": OptionInfo(0, "LoRA auto-apply tags", gr.Slider, {"minimum": -1, "maximum": 32, "step": 1}),
|
||||
|
||||
"lora_apply_sep": OptionInfo("<h2>Apply method</h2>", "", gr.HTML),
|
||||
"lora_apply_te": OptionInfo(False, "LoRA native apply to text encoder"),
|
||||
"lora_fuse_native": OptionInfo(True, "LoRA native fuse with model"),
|
||||
"lora_fuse_diffusers": OptionInfo(False, "LoRA diffusers fuse with model"),
|
||||
|
||||
|
||||
@@ -861,7 +861,6 @@
|
||||
{"id":"","label":"Load custom Diffusers pipeline","localized":"","hint":"","ui":"settings_huggingface"},
|
||||
{"id":"","label":"LoRA force reload always","localized":"","hint":"Forces LoRA networks to reload from storage on every generation, even if already cached.<br>Useful for debugging or when LoRA files are being modified externally.<br>Disable for normal use to benefit from caching.","ui":"settings_lora"},
|
||||
{"id":"","label":"LoRA load using Diffusers method","localized":"","hint":"Alternative method uses diffusers built-in LoRA capabilities instead of native SD.Next implementation (may reduce LoRA compatibility)","ui":"settings_lora"},
|
||||
{"id":"","label":"LoRA native apply to text encoder","localized":"","hint":"","ui":"settings_lora"},
|
||||
{"id":"","label":"LoRA native fuse with model","localized":"","hint":"Merge LoRA into the model for lower memory usage.<br><br><b style=\"color: #ef4444\">Warning:</b> After removing or switching a LoRA, you may still see its style in generated images. To get a clean model, reload it from the model selector.","ui":"settings_lora"},
|
||||
{"id":"","label":"LoRA diffusers fuse with model","localized":"","hint":"Merge LoRA into the model for lower memory usage and torch.compile compatibility.<br><br><b style=\"color: #ef4444\">Warning:</b> After removing or switching a LoRA, you may still see its style in generated images. To get a clean model, reload it from the model selector.","ui":"settings_lora"},
|
||||
{"id":"","label":"LoRA quantized apply method","localized":"","hint":"How networks are applied to SDNQ-quantized model weights:<br>- <b>exact</b>: adapters are carried alongside the quantized weights at full precision; apply and removal are exact and the quantized weights are never modified. The carried factors take additional VRAM, growing with adapter rank, size and count<br>- <b>requantize</b>: adapters are merged into the quantized weights, matching the behavior of earlier releases. Uses no additional VRAM (a weight backup for network removal is held in system RAM); on models quantized below 8 bits rounding typically loses much of the adapter effect, with strong adapters retaining more<br><br>With <b>requantize</b> selected, the host rank, calibration and cache options below have no effect.<br><br>Default is <b>exact</b>.","ui":"settings_lora"},
|
||||
|
||||
Reference in New Issue
Block a user