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

test: add xfail test for SavedModel restoring optimizer weights #15661

Closed
Closed
Changes from all commits
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
17 changes: 14 additions & 3 deletions keras/saving/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,20 @@ def _assert_same_weights_and_metrics(self, model, loaded_model):
if testing_utils.get_save_format() == 'tf':
# TODO(b/153110928): Keras TF format doesn't restore optimizer weights
# currently.
return
self.assertAllClose(model.optimizer.weights,
loaded_model.optimizer.weights)
try:
self.assertAllClose(model.optimizer.weights,
loaded_model.optimizer.weights)
except (AssertionError, ValueError):
# Both errors can be raised, depending on the if shapes happen to be the same or not
return # expected failure, but the test can't continue
else:
raise AssertionError(
"This test should have failed since SavedModel does not support restoring"
" optimizer weights"
)
else:
self.assertAllClose(model.optimizer.weights,
Copy link
Contributor

@bhack bhack Jan 25, 2022

Choose a reason for hiding this comment

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

Honestly I would move this in a separate test function decorating it like in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/eager/def_function_test.py#L243 with a reference to the Github ticket.

So when it is implemented the test will fail and we have a pointer to the original issue/feature request.
Then we could remove the decorator or simplify/unify the original test (the current method).

Copy link
Contributor

Choose a reason for hiding this comment

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

@adriangb Can you handle this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I'll have bandwidth anytime soon

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem the comment itself is 6 months old

loaded_model.optimizer.weights)

# In V1/Graph mode, the model isn't built, so the metrics are not loaded
# immediately (requires model to be called on some data before building
Expand Down