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

Add keras mixin #230

Merged
merged 10 commits into from
Aug 10, 2021
Merged

Add keras mixin #230

merged 10 commits into from
Aug 10, 2021

Conversation

nateraw
Copy link
Contributor

@nateraw nateraw commented Jul 27, 2021

Adds mixin for keras

@nateraw nateraw marked this pull request as ready for review July 27, 2021 16:31
@nateraw nateraw changed the title Nate/add keras mixin Add keras mixin Jul 27, 2021
@Rocketknight1
Copy link
Member

One question! What's the connection between this and the existing PushToHubMixin here? Are we deprecating that one in favour of this?

@nateraw
Copy link
Contributor Author

nateraw commented Jul 27, 2021

One question! What's the connection between this and the existing PushToHubMixin here? Are we deprecating that one in favour of this?

@Rocketknight1 That's a hard-coded integration w/ transformers, AFAIK. In the future, it would probably be nice to use these Mixins directly instead and deprecate PushToHubMixin and other hub-related functions in transformers, but since these are changing a bit more rapidly, its probably for the best to leave the PushToHubMixin as-is for now.

tests/test_keras_mixin.py Outdated Show resolved Hide resolved
Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a couple of questions

src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Solid, I like what you've done with it! And the testing suite is very nice, too. LGTM!

src/huggingface_hub/file_download.py Outdated Show resolved Hide resolved
self._save_pretrained(save_directory)
self._save_pretrained(save_directory, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

The kwargs are advertised as the kwargs to be passed to push_to_hub yet they're passed to _save_pretrained. I'd argue the kwargs to pass to each method ought to be different!

Comment on lines +71 to +77
revision,
cache_dir,
force_download,
proxies,
resume_download,
local_files_only,
use_auth_token,
Copy link
Member

Choose a reason for hiding this comment

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

My intuition tells me all of these should be optional kwargs, even if they're only supposed to be called internally

src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks a lot

src/huggingface_hub/file_download.py Outdated Show resolved Hide resolved
tests/test_keras_mixin.py Outdated Show resolved Hide resolved
tests/test_keras_mixin.py Show resolved Hide resolved
Comment on lines +57 to +58
class HubMixingCommonTest(unittest.TestCase):
_api = HfApi(endpoint=ENDPOINT_STAGING)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this super class really needed? We only have one test class so maybe the API wrapper should be instantiated in setUpClass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're probably right. I didn't want to mess with it too much, though. again, just following the previous file. I did find the superclass useful (if I remember right) when I played around with parametrizing the tests so we could run them over TF/PyTorch/etc.

@osanseviero
Copy link
Contributor

Just a parenthesis discussion for a potential follow-up PR. Given that TF 2 suggested way of saving models is through SavedModels, should we also consider this use case? It's the recommended file format that is portable with TF Lite, TF Serving, etc.

Pros

  • Much, much easier to use and save (easier to work with custom code, etc).
  • Easy to connect with other tools of TF ecosystem (TensorFlow Serving for example)

Cons

  • As discussed in the email, this was needed in transformers to only reload a part of a model from a checkpoint pre-trained with another architecture, which was only possible with the .h5 format.
  • Probably other things I'm not aware of.

@nateraw, does the existing solution work with custom objects such as custom layers? Or will this only work if loaded with the same class? If not, I guess we can't use the created repos out of the box in the Inference API.

@nateraw nateraw force-pushed the nate/add-keras-mixin branch from cd4acc2 to e7c4dbc Compare August 10, 2021 22:11
@nateraw
Copy link
Contributor Author

nateraw commented Aug 10, 2021

@osanseviero I'm not sure if this supports custom layers/objects 😅 . I think we definitely want to use savedmodel going forward. This is a good first effort, but the next PR should be to use SavedModel. Didn't want to mess with this one too much just to keep things similar to whats available elsewhere in the HF ecosystem.

@nateraw nateraw merged commit 32f14ab into huggingface:main Aug 10, 2021
@nateraw nateraw deleted the nate/add-keras-mixin branch August 10, 2021 23:02
@nateraw nateraw mentioned this pull request Aug 17, 2021
2 tasks
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