-
Notifications
You must be signed in to change notification settings - Fork 6.1k
ENH: Improve speed of function expanding LoRA scales #11834
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
ENH: Improve speed of function expanding LoRA scales #11834
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -52,7 +54,7 @@ def _maybe_expand_lora_scales( | |||
weight_for_adapter, | |||
blocks_with_transformer, | |||
transformer_per_block, | |||
unet.state_dict(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a private function, this should be more than okay to break
Thanks for this contribution! |
* 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 <[email protected]>
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_adapters
becomes slower the more adapters are already loaded, but since it speeds up the whole process by a factor of approximately 10x,set_adapters
is much less of a bottleneck.Before submitting
documentation guidelines, and
here are tips on formatting docstrings.