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

[Single File Loading] Handle unexpected keys in CLIP models when accelerate isn't installed. #8462

Merged
merged 9 commits into from
Jun 18, 2024

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Jun 10, 2024

What does this PR do?

Fixes #8578

Since transformers>=4.31.0, the key text_model.embeddings.position_id has been made non-persistent in the CLIP models. This can cause an issue when loading older versions of the checkpoint with single file when accelerate isn't installed, because we rely on strict loading with model.load_state_dict in this case.

This PR

  1. Changes the model.load_state_dict to not use strict loading, so that we can raise a warning about unexpected keys when accelerate isn't installed.

Fixes # (issue)

Before submitting

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.

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

@yiyixuxu
Copy link
Collaborator

ok but is this not used text_model.embeddings.position_id in the model?

@DN6
Copy link
Collaborator Author

DN6 commented Jun 11, 2024

No. Since transformers 4.31.0, the buffer is non-persistent. So it's no longer in the state dict.

Since text_model.embeddings.position_id is just a list of integers, it's create dynamically on based on the model config.
https://github.com/huggingface/transformers/blob/dcdda5324bcc7a750b5e40e11dd795442204ff27/src/transformers/models/clip/modeling_clip.py#L203

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!

@sayakpaul sayakpaul merged commit f69511e into main Jun 18, 2024
17 of 18 checks passed
@sayakpaul sayakpaul deleted the sf-clip-loading branch June 18, 2024 15:39
yiyixuxu added a commit that referenced this pull request Jun 20, 2024
…elerate` isn't installed. (#8462)

* update

* update

* update

* update

* update

---------

Co-authored-by: YiYi Xu <yixu310@gmail.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
sayakpaul added a commit that referenced this pull request Dec 23, 2024
…elerate` isn't installed. (#8462)

* update

* update

* update

* update

* update

---------

Co-authored-by: YiYi Xu <yixu310@gmail.com>
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.

Cannot copy out of meta tensor; no data! with sd_turbo 1.5
4 participants