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

Ensure backwards compatibility for legacy H5 saving format #682

Merged
merged 27 commits into from
Aug 9, 2023

Conversation

nkovela1
Copy link
Collaborator

@nkovela1 nkovela1 commented Aug 8, 2023

This PR ensures backwards compatibility for the legacy H5 saving format, particularly paying attention to differences in configs, arguments, and deserialization methods between tf.keras and Keras Core.

A few tests have been added showing a tf.keras model saved into H5 and then loaded into Keras Core to become a Keras Core model.
The test suite will be expanded in subsequent PRs to ensure greater coverage.

Copy link
Contributor

@fchollet fchollet 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 PR!

model.add(layers.TimeDistributed(layers.Dense(3)))
model.compile(optimizer="rmsprop", loss="mse")

tf_keras_model = tf.keras.Sequential()
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future tf.keras will be Keras Core. So can we avoid depending on it, and instead depend on a static artifact? Maybe either downloaded or checked into git?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, however, for now as I develop and expand this testing suite I will keep this dependency for debugging purposes/changes. After the full testing suite is done (in the next PR or so), I will generate them as h5 artifacts and add them to that PR.

@@ -484,6 +484,12 @@ def deserialize(config, custom_objects=None):
arg_spec = inspect.getfullargspec(cls.from_config)
custom_objects = custom_objects or {}

# TODO(nkovela): Replace during Keras 3.0 release
# Replace keras refs with keras_core
Copy link
Contributor

Choose a reason for hiding this comment

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

After the swap, the replacement should go the other way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, fixed the TODO comment.

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

LGTM

@fchollet fchollet merged commit 610f91c into keras-team:main Aug 9, 2023
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.

2 participants