[lora] fix: lora unloading behvaiour by sayakpaul · Pull Request #11822 · huggingface/diffusers · GitHub
Skip to content

[lora] fix: lora unloading behvaiour - #11822

Merged
sayakpaul merged 4 commits into
mainfrom
fix-unload-lora
Jun 28, 2025
Merged

sayakpaul merged 4 commits into
mainfrom
fix-unload-lora

Conversation

@sayakpaul

@sayakpaul sayakpaul commented Jun 27, 2025 •

Copy link
Copy Markdown
Member

What does this PR do?

For the text encoder, we set:

We should also do the same for the denoiser but doesn't:

def unload_lora(self):
if not USE_PEFT_BACKEND:
raise ValueError("PEFT backend is required for `unload_lora()`.")
from ..utils import recurse_remove_peft_layers
recurse_remove_peft_layers(self)
if hasattr(self, "peft_config"):
del self.peft_config

This PR fixes that.

The problem without this would surface when running the test this PR adds (i.e., add an adapter, unload it, and then try to add it again).

I have also taken the liberty to rename a function to add_adapters_to_pipeline() which I think is more appropriate.

@sayakpaul
sayakpaul requested a review from BenjaminBossan June 27, 2025 15:00
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this bugfix, LGTM.

Regarding the name, I believe both are a bit imprecise, as the method both adds and runs asserts. Not a big deal, just my 2c.

@sayakpaul
sayakpaul merged commit 05e7a85 into main Jun 28, 2025
@sayakpaul
sayakpaul deleted the fix-unload-lora branch June 28, 2025 07:36
tolgacangoz pushed a commit to tolgacangoz/diffusers that referenced this pull request Jul 5, 2025
* fix: lora unloading behvaiour

* fix

* update
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