-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
Conversation
try: | ||
array = apply_transpose(transpose, pt_state_dict[name], symbolic_weight.shape) | ||
except tf.errors.InvalidArgumentError: | ||
if not ignore_mismatched_sizes: |
There was a problem hiding this comment.
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)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it.
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this 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
There was a problem hiding this 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.
CI seems back to normal, can you just rebase on main to get the pin on the |
…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>
…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>
What does this PR do?
Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.