-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: implement apply_lora_scale to remove boilerplate. #12994
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
base: main
Are you sure you want to change the base?
Conversation
|
@DN6 would love to know your thoughts! |
|
|
||
| from ...configuration_utils import ConfigMixin, register_to_config | ||
| from ...loaders import FluxTransformer2DLoadersMixin, FromOriginalModelMixin, PeftAdapterMixin | ||
| from ...utils import USE_PEFT_BACKEND, logging, scale_lora_layers, unscale_lora_layers |
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.
This yields 21 LoC deletions. We have this pattern in about 32 files. So, this amounts for a 672 deletions. Not bad, IMO.
|
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. |
|
|
||
| self.gradient_checkpointing = False | ||
|
|
||
| @apply_lora_scale("joint_attention_kwargs") |
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.
Nice! 👍🏽 Design looks good to me.
What does this PR do?
Currently, we have this pattern throughout the modeling implementations:
IMO, this is not pretty and should possibly be minimized for a clean and self-contained implementation of the
forward().Hence, this PR introduces a decorator
apply_lora_scalethat can be used to decorate the forward method of a model supporting LoRA. I think this will help us reduce a bunch of boilerplate code.For keeping the PR simple, I have only applied the decorator to
src/diffusers/models/transformers/transformer_flux.pyThe LoRA tests for it are passing, indicating this direction might be a nice one.