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

Fix bug in Textual Inversion Unloading #9304

Merged
merged 9 commits into from
Oct 19, 2024
Merged

Conversation

bonlime
Copy link
Contributor

@bonlime bonlime commented Aug 28, 2024

What does this PR do?

Fixes Textual inversion unloading bug. To reproduce:

import torch
from diffusers import AutoPipelineForText2Image

pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")

print(pipeline.text_encoder.text_model.embeddings.token_embedding)
pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
pipeline.unload_textual_inversion()
pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
pipeline.unload_textual_inversion()
print(pipeline.text_encoder.text_model.embeddings.token_embedding)

Would print:

Embedding(49408, 768)
Embedding(49409, 768) <- note 49409 instead of 49408 here

Due to incorrect tokenizer size, after adding embedding 2nd time, it's not being correctly reset. After this PR the output would be correct:

Embedding(49408, 768)
Embedding(49408, 768)

Before submitting

- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@bonlime bonlime changed the title Update textual_inversion.py Fix bug in Textual Inversion Unloading Aug 28, 2024
@bonlime
Copy link
Contributor Author

bonlime commented Sep 2, 2024

hi @sayakpaul can you please chech the PR? it's really tiny

@sayakpaul
Copy link
Member

Thanks! Could you also add / update tests for this?

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Sep 28, 2024
@sayakpaul
Copy link
Member

@bonlime a gentle ping here.

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

@github-actions github-actions bot removed the stale Issues that haven't received updates label Sep 29, 2024
@bonlime
Copy link
Contributor Author

bonlime commented Oct 1, 2024

@sayakpaul gentle ping worked :)

@sayakpaul sayakpaul requested a review from yiyixuxu October 2, 2024 13:48
@sayakpaul
Copy link
Member

@yiyixuxu could you give this a look?.

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.

Just a single comment.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Oct 9, 2024

can you make style?

@bonlime
Copy link
Contributor Author

bonlime commented Oct 9, 2024

Fixed style

@yiyixuxu yiyixuxu merged commit 5d3e7bd into huggingface:main Oct 19, 2024
15 checks passed
@yiyixuxu
Copy link
Collaborator

thanks for the PR!

sayakpaul added a commit that referenced this pull request Dec 23, 2024
* Update textual_inversion.py

* add unload test

* add comment

* fix style

---------

Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Your Name <[email protected]>
Co-authored-by: YiYi Xu <[email protected]>
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