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

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