ENH: Improve speed of function expanding LoRA scales#11834
Merged
sayakpaul merged 3 commits intohuggingface:mainfrom Jun 30, 2025
Merged
ENH: Improve speed of function expanding LoRA scales#11834sayakpaul merged 3 commits intohuggingface:mainfrom
sayakpaul merged 3 commits intohuggingface:mainfrom
Conversation
Resolves huggingface#11816 The following call proved to be a bottleneck when setting a lot of LoRA adapters in diffusers: https://github.com/huggingface/diffusers/blob/cdaf84a708eadf17d731657f4be3fa39d09a12c0/src/diffusers/loaders/peft.py#L482 This is because we would repeatedly call unet.state_dict(), even though in the standard case, it is not necessary: https://github.com/huggingface/diffusers/blob/cdaf84a708eadf17d731657f4be3fa39d09a12c0/src/diffusers/loaders/unet_loader_utils.py#L55 This PR fixes this by deferring this call, so that it is only run when it's necessary, not earlier.
|
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. |
sayakpaul
approved these changes
Jun 30, 2025
| weight_for_adapter, | ||
| blocks_with_transformer, | ||
| transformer_per_block, | ||
| unet.state_dict(), |
Member
There was a problem hiding this comment.
Since this is a private function, this should be more than okay to break
Member
|
Thanks for this contribution! |
tolgacangoz
pushed a commit
to tolgacangoz/diffusers
that referenced
this pull request
Jul 5, 2025
* ENH Improve speed of expanding LoRA scales Resolves huggingface#11816 The following call proved to be a bottleneck when setting a lot of LoRA adapters in diffusers: https://github.com/huggingface/diffusers/blob/cdaf84a708eadf17d731657f4be3fa39d09a12c0/src/diffusers/loaders/peft.py#L482 This is because we would repeatedly call unet.state_dict(), even though in the standard case, it is not necessary: https://github.com/huggingface/diffusers/blob/cdaf84a708eadf17d731657f4be3fa39d09a12c0/src/diffusers/loaders/unet_loader_utils.py#L55 This PR fixes this by deferring this call, so that it is only run when it's necessary, not earlier. * Small fix --------- Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Resolves #11816
The following call proved to be a bottleneck when setting a lot of LoRA adapters in diffusers:
diffusers/src/diffusers/loaders/peft.py
Line 482 in cdaf84a
This is because we would repeatedly call
unet.state_dict(), even though in the standard case, it is not necessary:diffusers/src/diffusers/loaders/unet_loader_utils.py
Line 55 in cdaf84a
This PR fixes this by deferring this call, so that it is only run when it's necessary, not earlier.
Note: This PR doesn't change the fact that
set_adaptersbecomes slower the more adapters are already loaded, but since it speeds up the whole process by a factor of approximately 10x,set_adaptersis much less of a bottleneck.Before submitting
documentation guidelines, and
here are tips on formatting docstrings.