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

include_optimizer parameter introduced to push_to_hub_keras() #616

Merged
merged 21 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/huggingface_hub/keras_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def save_pretrained_keras(
model, save_directory: str, config: Optional[Dict[str, Any]] = None
model, save_directory: str, include_optimizer: Optional[Bool], config: Optional[Dict[str, Any]] = None
):
"""Saves a Keras model to save_directory in SavedModel format. Use this if you're using the Functional or Sequential APIs.

Expand All @@ -27,6 +27,8 @@ def save_pretrained_keras(
Specify directory in which you want to save the Keras model.
config (:obj:`dict`, `optional`):
Configuration object to be saved alongside the model weights.
include_optimizer(:obj:`bool`, `optional`):
Whether or not to include optimizer in serialization.
"""
if is_tf_available():
import tensorflow as tf
Expand All @@ -50,7 +52,7 @@ def save_pretrained_keras(
with open(path, "w") as f:
json.dump(config, f)

tf.keras.models.save_model(model, save_directory)
tf.keras.models.save_model(model, save_directory, include_optimizer)
Copy link
Member

Choose a reason for hiding this comment

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

The third argument of save_model is overwrite (doc), so we'll have to specify the keyword argument for include_optimizer



def from_pretrained_keras(*args, **kwargs):
Expand All @@ -69,6 +71,7 @@ def push_to_hub_keras(
git_user: Optional[str] = None,
git_email: Optional[str] = None,
config: Optional[dict] = None,
include_optimizer: Optional[bool] = False,
):
"""
Upload model checkpoint or tokenizer files to the 🤗 Model Hub while synchronizing a local clone of the repo in
Expand Down Expand Up @@ -104,6 +107,8 @@ def push_to_hub_keras(
will override the ``git config user.email`` for committing and pushing files to the hub.
config (:obj:`dict`, `optional`):
Configuration object to be saved alongside the model weights.
include_optimizer (:obj:`bool`, `optional`):
Whether or not to include optimizer during serialization.

Returns:
The url of the commit of your model in the given repository.
Expand Down Expand Up @@ -150,7 +155,7 @@ def push_to_hub_keras(
)
repo.git_pull(rebase=True)

save_pretrained_keras(model, repo_path_or_name, config=config)
save_pretrained_keras(model, repo_path_or_name, config=config, include_optimizer=include_optimizer)

# Commit and push!
repo.git_add(auto_lfs_track=True)
Expand Down