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

Proposed fix for TF example now running on safetensors. #23208

Merged
merged 4 commits into from
May 9, 2023
Merged

Conversation

Narsil
Copy link
Contributor

@Narsil Narsil commented May 8, 2023

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

try:
array = apply_transpose(transpose, pt_state_dict[name], symbolic_weight.shape)
except tf.errors.InvalidArgumentError:
if not ignore_mismatched_sizes:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could instead check shapes directly here but since there are many transposes here I decided to go for the simpler try except. (The only reason why this might not be ok is because InvalidArgumentError might cover more than just invalid shapes)

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

General idea looks good to me! When loading a PyTorch checkpoint, we gather the mismatched_keys in a list and throw a warning at the end with the weights left as random, would be nice to have the same behavior.

if not ignore_mismatched_sizes:
raise
else:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should keep track of those in a mismatched_keys list and return it at the end of this function, so it can be shown as a warning at the end (that's what we do for standard load).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added only with output_loading_info (to respect pre-existing code).

array = apply_transpose(transpose, pt_state_dict[name], symbolic_weight.shape)
except tf.errors.InvalidArgumentError:
if not ignore_mismatched_sizes:
raise
Copy link
Collaborator

@sgugger sgugger May 8, 2023

Choose a reason for hiding this comment

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

Here we could add "n\tYou may consider adding `ignore_mismatched_sizes=True` in the model `from_pretrained` method." to the error message as we do in PyToch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 8, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

LGTM! The test failures mostly look like timeouts in connections to the Hub, which I guess is related to our current downtime

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Let's wait for the Hub to be back to run the tests again.

@sgugger
Copy link
Collaborator

sgugger commented May 9, 2023

CI seems back to normal, can you just rebase on main to get the pin on the tensofrlow_probability?

@sgugger sgugger merged commit c34a525 into main May 9, 2023
@sgugger sgugger deleted the fix_tf_example branch May 9, 2023 17:04
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
…23208)

* Proposed fix for TF example now running on safetensors.

* Adding more warnings and returning keys.

* Trigger CI

* Trigger CI

---------

Co-authored-by: Sylvain Gugger <Sylvain.gugger@gmail.com>
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
…23208)

* Proposed fix for TF example now running on safetensors.

* Adding more warnings and returning keys.

* Trigger CI

* Trigger CI

---------

Co-authored-by: Sylvain Gugger <Sylvain.gugger@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.

4 participants