Skip to content

handle lora scale and clip skip in lpw sd and sdxl community pipelines #8988

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 5 commits into from
Jul 30, 2024

Conversation

noskill
Copy link
Contributor

@noskill noskill commented Jul 26, 2024

What does this PR do?

handle lora scale in cross_attention_kwargs and clip skip

@a-r-r-o-w a-r-r-o-w requested a review from sayakpaul July 26, 2024 12:33
@@ -11,15 +11,19 @@
from diffusers import DiffusionPipeline
from diffusers.configuration_utils import FrozenDict
from diffusers.image_processor import VaeImageProcessor
from diffusers.loaders import FromSingleFileMixin, StableDiffusionLoraLoaderMixin, TextualInversionLoaderMixin
from diffusers.loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we're not using the newer StableDiffusionLoraLoaderMixin here?

@@ -268,6 +292,16 @@ def get_weighted_text_embeddings(
skip_weighting (`bool`, *optional*, defaults to `False`):
Skip the weighting. When the parsing is skipped, it is forced True.
"""
# set lora scale so that monkey patched LoRA
# function of text encoder can correctly access it
if lora_scale is not None and isinstance(pipe, LoraLoaderMixin):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently shipped #8981. I think this should be StableDiffusionLoraLoaderMixin. Maybe @sayakpaul can provide more clarity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoraLoaderMixin is fine but it's just deprecated. Prefer using StableDiffusionLoraLoaderMixin as @a-r-r-o-w mentioned.

Copy link
Member

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks! i think some changes were mistakenly removed here from #8981. could you revert them?

@sayakpaul
Copy link
Member

awesome, thanks! i think some changes were mistakenly removed here from #8981. could you revert them?

What?

@a-r-r-o-w
Copy link
Member

awesome, thanks! i think some changes were mistakenly removed here from #8981. could you revert them?

What?

I don't mean for you to revert 8981 😨 I thought the author of current PR removed your changes by mistake

@noskill
Copy link
Contributor Author

noskill commented Jul 28, 2024

@a-r-r-o-w yes, i removed those changes by mistake, it should be fixed now

Copy link
Member

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! @sayakpaul could take a final look

Comment on lines +300 to +302
# dynamically adjust the LoRA scale
if not USE_PEFT_BACKEND:
adjust_lora_scale_text_encoder(pipe.text_encoder, lora_scale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Because without the PEFT backend, you cannot really do LoRA inference in the recent diffusers versions. No strong opinions either.

Comment on lines +301 to +305
if pipe.text_encoder_2 is not None:
if not USE_PEFT_BACKEND:
adjust_lora_scale_text_encoder(pipe.text_encoder_2, lora_scale)
else:
scale_lora_layers(pipe.text_encoder_2, lora_scale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied these lines from pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py, should i just leave scale_lora_layers(pipe.text_encoder_2, lora_scale) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh then it's okay.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just left two minor comments.

@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.

@sayakpaul
Copy link
Member

@noskill let's fix the code quality issues and then we can merge.

@sayakpaul sayakpaul merged commit f240a93 into huggingface:main Jul 30, 2024
8 checks passed
@sayakpaul
Copy link
Member

Thank you for your contributions!

@noskill noskill deleted the brlpw branch July 30, 2024 08:19
sayakpaul added a commit that referenced this pull request Aug 1, 2024
#8988)

* handle lora scale and clip skip in lpw sd and sdxl

* use StableDiffusionLoraLoaderMixin

* use StableDiffusionXLLoraLoaderMixin

* style

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
sayakpaul added a commit that referenced this pull request Dec 23, 2024
#8988)

* handle lora scale and clip skip in lpw sd and sdxl

* use StableDiffusionLoraLoaderMixin

* use StableDiffusionXLLoraLoaderMixin

* style

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
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.

4 participants