Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodes): skip on duplicate loras instead of erroring #6685

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 47 additions & 40 deletions invokeai/app/invocations/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,33 @@ def invoke(self, context: InvocationContext) -> LoRALoaderOutput:
if not context.models.exists(lora_key):
raise Exception(f"Unkown lora: {lora_key}!")

if self.unet is not None and any(lora.lora.key == lora_key for lora in self.unet.loras):
raise Exception(f'LoRA "{lora_key}" already applied to unet')

if self.clip is not None and any(lora.lora.key == lora_key for lora in self.clip.loras):
raise Exception(f'LoRA "{lora_key}" already applied to clip')

output = LoRALoaderOutput()

if self.unet is not None:
output.unet = self.unet.model_copy(deep=True)
output.unet.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,

if any(lora.lora.key == lora_key for lora in self.unet.loras):
context.logger.warning(f'LoRA "{lora_key}" already applied to UNet, skipping')
else:
output.unet.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,
)
)
)

if self.clip is not None:
output.clip = self.clip.model_copy(deep=True)
output.clip.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,

if any(lora.lora.key == lora_key for lora in self.clip.loras):
context.logger.warning(f'LoRA "{lora_key}" already applied to CLIP, skipping')
else:
output.clip.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,
)
)
)

return output

Expand Down Expand Up @@ -264,6 +266,7 @@ def invoke(self, context: InvocationContext) -> LoRALoaderOutput:

for lora in loras:
if lora.lora.key in added_loras:
context.logger.warning(f'LoRA "{lora.lora.key}" already applied, skipping')
continue

if not context.models.exists(lora.lora.key):
Expand Down Expand Up @@ -334,43 +337,46 @@ def invoke(self, context: InvocationContext) -> SDXLLoRALoaderOutput:
if not context.models.exists(lora_key):
raise Exception(f"Unknown lora: {lora_key}!")

if self.unet is not None and any(lora.lora.key == lora_key for lora in self.unet.loras):
raise Exception(f'LoRA "{lora_key}" already applied to unet')

if self.clip is not None and any(lora.lora.key == lora_key for lora in self.clip.loras):
raise Exception(f'LoRA "{lora_key}" already applied to clip')

if self.clip2 is not None and any(lora.lora.key == lora_key for lora in self.clip2.loras):
raise Exception(f'LoRA "{lora_key}" already applied to clip2')

output = SDXLLoRALoaderOutput()

if self.unet is not None:
output.unet = self.unet.model_copy(deep=True)
output.unet.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,

if any(lora.lora.key == lora_key for lora in self.unet.loras):
context.logger.warning(f'LoRA "{lora_key}" already applied to UNet, skipping')
else:
output.unet.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,
)
)
)

if self.clip is not None:
output.clip = self.clip.model_copy(deep=True)
output.clip.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,

if any(lora.lora.key == lora_key for lora in self.clip.loras):
context.logger.warning(f'LoRA "{lora_key}" already applied to CLIP, skipping')
else:
output.clip.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,
)
)
)

if self.clip2 is not None:
output.clip2 = self.clip2.model_copy(deep=True)
output.clip2.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,

if any(lora.lora.key == lora_key for lora in self.clip2.loras):
context.logger.warning(f'LoRA "{lora_key}" already applied to CLIP2, skipping')
else:
output.clip2.loras.append(
LoRAField(
lora=self.lora,
weight=self.weight,
)
)
)

return output

Expand Down Expand Up @@ -414,6 +420,7 @@ def invoke(self, context: InvocationContext) -> SDXLLoRALoaderOutput:

for lora in loras:
if lora.lora.key in added_loras:
context.logger.warning(f'LoRA "{lora.lora.key}" already applied, skipping')
continue

if not context.models.exists(lora.lora.key):
Expand Down
Loading