add load textual inversion embeddings to stable diffusion#2009
add load textual inversion embeddings to stable diffusion#2009patrickvonplaten merged 55 commits intohuggingface:mainfrom
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
patil-suraj
left a comment
There was a problem hiding this comment.
Thanks a lot for working on this @piEsposito , this will make loading embeddings very easy!
Instead of adding methods to every pipeline, we could create TextualInversionLoaderMixin class with a method load_textual_inversion_embeddings in pipelines/loaders.py, and the pipelines which can do text inversion can subclass from that mixin.
Also, left some comments below, more specifically.
- We should follow the
embeddingsformat of the textual inversion script so that we can load all the embeddings in https://huggingface.co/sd-concepts-library - We could also support loading single vector embedding from
auto1111and then extend it to multiple embeddings.
Thanks!
src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py
Outdated
Show resolved
Hide resolved
|
@patil-suraj I'm addressing your review on the next few days, thanks! |
|
@patil-suraj Github somehow un-requested review from a bunch of HF people. Can you please add them again? |
|
@sayakpaul @pcuenca @williamberman could you take a final look here? Made the PR now ready for diffusers design - should work for all use cases. |
| image = pipe( | ||
| "An logo of a turtle in Style-Winter with <low-poly-hd-logos-icons>", generator=generator, output_type="np" | ||
| ).images[0] | ||
| # np.save("/home/patrick/diffusers-images/text_inv/winter_logo_style.npy", image) |
There was a problem hiding this comment.
| # np.save("/home/patrick/diffusers-images/text_inv/winter_logo_style.npy", image) |
williamberman
left a comment
There was a problem hiding this comment.
if we could squash and rebase on main, that would be nice.
Also assuming tests pass
sayakpaul
left a comment
There was a problem hiding this comment.
Let's ship this thing!
Excellent tests, btw. Let's make them pass.
| embedding = state_dict["string_to_param"]["*"] | ||
|
|
||
| if token is not None and loaded_token != token: | ||
| logger.warn(f"The loaded token: {loaded_token} is overwritten by the passed token {token}.") |
There was a problem hiding this comment.
Wouldn't we want to do the opposite override? (What comes in the state_dict is what gets added)
There was a problem hiding this comment.
Interesting, I'd say what gets passed has priority! If you do:
load_textual_inversion("./textual_inversion", token="<special-token>")I think the token should be "<special-token>" no matter what's in the dict - it's similar to how we do from_pretrained(unet=unet) overrides
|
Come on folks everything but an unrelated test in MPS is passing let's get this thing merged! |
| embeddings = [e for e in embedding] # noqa: C416 | ||
| else: | ||
| tokens = [token] | ||
| embeddings = [embedding] if len(embedding.shape) > 1 else [embedding[0]] |
There was a problem hiding this comment.
I was trying the latest version and I wasn't getting anything related to the embeddings, after changing this I was able to get good results. I'm not sure how this would work with len(embedding.shape) greater than 1 but at least when the shape has only one dimension this seems to fix it.
| embeddings = [embedding] if len(embedding.shape) > 1 else [embedding[0]] | |
| embeddings = [embedding[0]] if len(embedding.shape) > 1 else [embedding] |
| embeddings = [embedding] if len(embedding.shape) > 1 else [embedding[0]] | |
| embeddings = [embedding] if len(embedding.shape) <= 1 else [embedding[0]] |
There was a problem hiding this comment.
Hmm cannot reproduce this one - my tests are passing just fine on this branch
There was a problem hiding this comment.
I followed diffusers/examples/textual_inversion to train my own embedding and got learned_embeds.bin file in the end, then use the example here.
pretrained_path = 'xxx'
embedding_path = 'learned_embeds.bin'
pipe = DiffusionPipeline.from_pretrained(pretrained_path, torch_dtype=torch.float16)
pipe.load_textual_inversion(embedding_path)It is not working to show any concept from my enbedding token. I have to modify the same with @GuiyeC for the file src/diffusers/loaders.py to make it correctly.
There was a problem hiding this comment.
I created a PR with the fix for this where I try to explain the problem a bit more.
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
|
Ok let's merge it 🚀 Puuh big PR - thanks so much for kickstarting this @piEsposito and for everybody involved here. Hope that the final solution / design works for everybody |
|
Thanks for getting this over the finish line guys! WIsh I could've been of
more help. Great work -- I look forward to using the feature.
Best
Evan Jones
Website: www.ea-jones.com
…On Thu, Mar 30, 2023 at 1:08 PM Patrick von Platen ***@***.***> wrote:
Merged #2009 <#2009> into
main.
—
Reply to this email directly, view it on GitHub
<#2009 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ2T6AKXJ6GJT7NP6LQGKNLW6W42LANCNFSM6AAAAAAT4ZUCKY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Gosh forgot the most important part: Docs! 😅 In case someone has some spare time for a quick PR on docs on how to use it (both A1111 and |
|
@piEsposito @patrickvonplaten Cheers this is done! But yes Docs are needed to show newbies like me how to use it, the discuss here is too long to read them all lol. |
|
@blx0102 would you be up for contributing a PR? :) |
|
Opened a quick PR here: #3068 |
…e#2009) * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add case for parsing embedding from auto1111 UI format Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> * fix style after rebase * move textual inversion mixin to loaders * move mixin inheritance to DiffusionPipeline from StableDiffusionPipeline) * update dummy class name * addressed allo comments * fix old dangling import * fix style * proposal * remove bogus * Apply suggestions from code review Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> * finish * make style * up * fix code quality * fix code quality - again * fix code quality - 3 * fix alt diffusion code quality * fix model editing pipeline * Apply suggestions from code review Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Finish --------- Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
…e#2009) * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add case for parsing embedding from auto1111 UI format Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> * fix style after rebase * move textual inversion mixin to loaders * move mixin inheritance to DiffusionPipeline from StableDiffusionPipeline) * update dummy class name * addressed allo comments * fix old dangling import * fix style * proposal * remove bogus * Apply suggestions from code review Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> * finish * make style * up * fix code quality * fix code quality - again * fix code quality - 3 * fix alt diffusion code quality * fix model editing pipeline * Apply suggestions from code review Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Finish --------- Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
…e#2009) * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add load textual inversion embeddings draft * fix quality * fix typo * make fix copies * move to textual inversion mixin * make it accept from sd-concept library * accept list of paths to embeddings * fix styling of stable diffusion pipeline * add dummy TextualInversionMixin * add docstring to textualinversionmixin * add case for parsing embedding from auto1111 UI format Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> * fix style after rebase * move textual inversion mixin to loaders * move mixin inheritance to DiffusionPipeline from StableDiffusionPipeline) * update dummy class name * addressed allo comments * fix old dangling import * fix style * proposal * remove bogus * Apply suggestions from code review Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> * finish * make style * up * fix code quality * fix code quality - again * fix code quality - 3 * fix alt diffusion code quality * fix model editing pipeline * Apply suggestions from code review Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Finish --------- Co-authored-by: Evan Jones <evan.a.jones3@gmail.com> Co-authored-by: Ana Tamais <aninhamoraestamais@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Will Berman <wlbberman@gmail.com> Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Should close #1985