-
Notifications
You must be signed in to change notification settings - Fork 585
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
Correctly inject config in PytorchModelHubMixin
#2079
Conversation
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. |
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.
Great! This is going to be very useful
Yes sorry, I've updated the example. |
Co-authored-by: NielsRogge <48327001+NielsRogge@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2079 +/- ##
==========================================
+ Coverage 82.90% 82.91% +0.01%
==========================================
Files 102 102
Lines 9480 9499 +19
==========================================
+ Hits 7859 7876 +17
- Misses 1621 1623 +2 ☔ View full report in Codecov by Sentry. |
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.
Looks great! That is sure to come in handy with model serialization, no need to handle a config on the side anymore. Awesome!
def _save_pretrained(self, save_directory: Path) -> None: | ||
"""Save weights from a Pytorch model to a local directory.""" | ||
save_model_as_safetensor(self.module, str(save_directory / SAFETENSORS_SINGLE_FILE)) |
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.
yess 🎉
Co-authored-by: Lysandre Debut <hi@lysand.re>
Thanks for the review @LysandreJik 🤗 Yes I also expect it to make integrations even more straightforward now :) |
Solves #2079.
With this PR, users don't have to rely on a
config
parameter to configure their model. We read default+passed values automatically to build the config file ourselves. This way, we are able to save a correctconfig.json
file so that reloaded model have exact same config. Only "jsonable" fields are saved in config.json.And ofc it's backward compatible so users that prefer to pass
config.json
directly are still supported.PR is inspired by Inspired by facebookresearch/hiera#26. cc @dbolya with this change, you won't need the
@has_config
decorator anymore 🤗Here is an example to showcase it:
cc @mfuntowicz as well. This shouldn't impact you except that the generated config.json files should be more complete.