Skip to content

RectifiedAdam: Store 'total_steps' hyperparameter as float #2369

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

Merged
merged 4 commits into from
Feb 7, 2021

Conversation

olesalscheider
Copy link
Contributor

@olesalscheider olesalscheider commented Jan 27, 2021

Description

When restoring the RectifiedAdam optimizer from a checkpoint, restoring fails with the following error message:
ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int32: <tf.Tensor: shape=(), dtype=int32, numpy=0>

The reason is that RectifiedAdam stores total_steps as an integer hyper-parameter:
https://github.com/tensorflow/addons/blob/master/tensorflow_addons/optimizers/rectified_adam.py#L134

OptimizerV2 however creates variables by calling add_weight without a dtype in _create_hypers. In other words, it assumes that all hyper-parameters are floating point parameters.

Fixes #2361

Type of change

Checklist:

  • I've properly formatted my code according to the guidelines
    • By running Black + Flake8
    • By running pre-commit hooks
  • This PR addresses an already submitted issue for TensorFlow Addons
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • This PR contains modifications to C++ custom-ops

How Has This Been Tested?

I have trained a neural network with this optimizer and resumed training in between. Without this change, restoring fails with the error message from above. With this change, it works as intended.

@bot-of-gabrieldemarmiesse

@CyberZHG

You are owner of some files modified in this pull request.
Would you kindly review the changes whenever you have the time to?
Thank you very much.

@olesalscheider
Copy link
Contributor Author

The tests fail because total_steps is int in the constructor. I can fix that, but I am really not sure if this is the right way to handle this, or if this is unintended behavior from tensorflow.

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

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

Thanks! Can you add a test that failed before the fix?

@olesalscheider olesalscheider force-pushed the fix_2361 branch 2 times, most recently from a0f3d4e to 519cb5b Compare January 29, 2021 12:00
@bhack
Copy link
Contributor

bhack commented Jan 29, 2021

It is a little bit confusing as a float.

@olesalscheider
Copy link
Contributor Author

It is a little bit confusing as a float.

That's what I thought. But if the constructor takes an int but stores it as a float internally, the tests fail because the optimizer can't be restored.

@bhack

This comment has been minimized.

@google-cla
Copy link

google-cla bot commented Jan 30, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Jan 30, 2021
@google-cla
Copy link

google-cla bot commented Jan 30, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@bhack
Copy link
Contributor

bhack commented Jan 30, 2021

@googlebot I consent

@google-cla google-cla bot added cla: yes and removed cla: no labels Jan 30, 2021
@bhack bhack requested a review from WindQAQ January 30, 2021 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing to restore RectifiedAdam optimizer from checkpoint
5 participants