Skip to content

[lora] fix: lora unloading behvaiour #11822

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

Merged
merged 4 commits into from
Jun 28, 2025
Merged

[lora] fix: lora unloading behvaiour #11822

merged 4 commits into from
Jun 28, 2025

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Jun 27, 2025

What does this PR do?

For the text encoder, we set:

text_encoder._hf_peft_config_loaded = None

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

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

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
32 checks passed
@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