Skip to content

[LoRA] Make sure LoRA can be disabled after it's run#2128

Merged
patrickvonplaten merged 1 commit into
mainfrom
fix_lora_offsetting
Jan 26, 2023
Merged

[LoRA] Make sure LoRA can be disabled after it's run#2128
patrickvonplaten merged 1 commit into
mainfrom
fix_lora_offsetting

Conversation

@patrickvonplaten

@patrickvonplaten patrickvonplaten commented Jan 26, 2023

Copy link
Copy Markdown
Contributor

As very nicely stated by @jorgemcgomes in #2124 (comment) it's currently not possible to "disable" LoRA attention processors.

This PR fixes this by hacking a bit into PyTorch's module dict (think it's fine & safe though :-))

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Jan 26, 2023

Copy link
Copy Markdown

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten

Copy link
Copy Markdown
Contributor Author

Sorry already merging now as I need it for another PR

@patrickvonplaten patrickvonplaten merged commit f653ded into main Jan 26, 2023
@patil-suraj patil-suraj deleted the fix_lora_offsetting branch January 26, 2023 21:17
Comment on lines +158 to +166
# if current processor is in `self._modules` and if passed `processor` is not, we need to
# pop `processor` from `self._modules`
if (
hasattr(self, "processor")
and isinstance(self.processor, torch.nn.Module)
and not isinstance(processor, torch.nn.Module)
):
logger.info(f"You are removing possibly trained weights of {self.processor} with {processor}")
self._modules.pop("processor")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! But what happens when processor is a module ? Do we just overwrite it ? Would be nice to add more comments here, found it a bit hard to understand at first glance.

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants