Skip to content

add TextInversion for lpw_stable_diffusion.py #3106

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

Closed
wants to merge 4 commits into from
Closed

add TextInversion for lpw_stable_diffusion.py #3106

wants to merge 4 commits into from

Conversation

NormXU
Copy link

@NormXU NormXU commented Apr 14, 2023

As StableDiffusionLongPromptWeightingPipeline inherits from StableDiffusionPipeline, we can utilize the functions of TextualInversionLoaderMixin directly to convert negative / prompts if any text inversion tokens are available.

# textual inversion: process multi-vector tokens if necessary
if isinstance(self, TextualInversionLoaderMixin):
    prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
    negative_prompt = self.maybe_convert_prompt(negative_prompt, self.tokenizer)

text_embeddings, uncond_embeddings = get_weighted_text_embeddings(
    pipe=self,
    prompt=prompt,
    uncond_prompt=negative_prompt if do_classifier_free_guidance else None,
    max_embeddings_multiples=max_embeddings_multiples,
)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Cool this looks good to me - wdyt @SkyTNT ?

@SkyTNT
Copy link
Contributor

SkyTNT commented Apr 27, 2023

This is already done in lpw_stable_diffusion.py by #3265

@NormXU
Copy link
Author

NormXU commented Apr 28, 2023

Since it is already done, I will close this PR.

@NormXU NormXU closed this Apr 28, 2023
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