Skip to content
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

add initial support for Textual Inversion models #179

Closed
ssube opened this issue Feb 18, 2023 · 4 comments
Closed

add initial support for Textual Inversion models #179

ssube opened this issue Feb 18, 2023 · 4 comments
Assignees
Labels
scope/api scope/convert scope/gui status/fixed issues that have been fixed and released type/feature new features
Milestone

Comments

@ssube
Copy link
Owner

ssube commented Feb 18, 2023

https://huggingface.co/docs/diffusers/training/text_inversion

@ssube ssube added status/new issues that have not been confirmed yet type/feature new features labels Feb 18, 2023
@ssube ssube added this to the v0.9 milestone Feb 18, 2023
@ssube ssube added status/progress issues that are in progress and have a branch and removed status/new issues that have not been confirmed yet labels Feb 21, 2023
@ssube ssube modified the milestones: v0.9, v0.8 Feb 21, 2023
@ssube
Copy link
Owner Author

ssube commented Feb 25, 2023

#199 adds support for the sd-concepts family of inversions, but does not support all of the options available from Civitai.

@ssube ssube self-assigned this Feb 25, 2023
ssube added a commit that referenced this issue Mar 2, 2023
@ssube
Copy link
Owner Author

ssube commented Mar 3, 2023

#209 adds support for many of the inversions on Civitai.

The main difference is the shape of the tensor data, with some having an additional axis:

>>> t2["<jungle-punk>"].shape
torch.Size([768])

vs

>>> t = torch.load("autumn.ckpt")
>>> t["string_to_param"]["*"].shape
torch.Size([5, 768])
>>> t = torch.load("ghostly.ckpt")
>>> t["string_to_param"]["*"].shape
torch.Size([10, 768])

Looping over that first axis and generating a token for each layer works, and allows them to be controlled/weighted separately as well. I came across https://www.reddit.com/r/StableDiffusion/comments/zl81na/how_to_use_embeddings_with_pytorch/, and they were kind enough to point out https://github.com/kohya-ss/sd-scripts/blob/main/gen_img_diffusers.py#L2174, which does pretty much the same thing.

This still needs to be documented in the user guide, and may need some token replacement logic, but it definitely works.

@ssube ssube added status/fixed issues that have been fixed and released and removed status/progress issues that are in progress and have a branch labels Mar 3, 2023
@ForserX
Copy link
Contributor

ForserX commented Mar 5, 2023

image
I looked. It turned out to get something similar by throwing a pack of tokens into the prompt. There is a suspicion that they need to be combined somehow.

@ssube
Copy link
Owner Author

ssube commented Mar 8, 2023

The best solution for this is probably a single token that automatically expands into the correct number, #179, but that will require something like model_config.json in the inversion directories.

Until then, I've implemented infinite-length prompts with a range expansion syntax: autumn-{0,4} or winter-{0,9} for the simple case, with an optional third parameter for the step, even-steps-{0,99,2}.

With docs, too:

ssube added a commit that referenced this issue Mar 8, 2023
@ssube ssube changed the title add support for Textual Inversion models add initial support for Textual Inversion models Mar 8, 2023
@ssube ssube closed this as completed Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/api scope/convert scope/gui status/fixed issues that have been fixed and released type/feature new features
Projects
None yet
Development

No branches or pull requests

2 participants