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

Tensorflow 2.11 update breaks use of Keras optimizers, quick fix included. #2

Open
hjalmarheld opened this issue Jan 10, 2023 · 3 comments

Comments

@hjalmarheld
Copy link

The current code is incompatible with Tensorflow 2.11 due to updates of the optimizer API:s.

The Adam and RMSprop optimizers no longer has the get_weights() method.

See some info here. A quick fix is to simply pass to the legacy namespace.

This implies changing one row in trainer.py and one row in trainer_serialize.ipynb.

In trainer.py change:
optimzier = config.train("optimizer", "RMSprop", help="Optimizer" )
to:
optimzier = config.train("optimizer", tf.keras.optimizers.legacy.RMSprop(), help="Optimizer" )

And in trainer_serialize.ipynb equivalently set the optimizer as:

...
# trainer
from tensorflow.keras.optimizers.legacy import Adam
config.trainer.train.optimizer = Adam()
...

Apparently the old optimizers are to be kept indefinitely thus this should be a relatively stable solution.

@hansbuehler
Copy link
Owner

Much appreciated. I will incorporate in the next update. Is there a 2.11 compatible way for caching an optimizer with its internal state?

NB the main reason I've added this is because I am struggling with AWS SageMaker's propensity to die on me with 504 Gateway timeouts. The machine dies; I have to stop/start/and re-run the whole lot again. Caching at at least allows to continue training at the last caching point.
Do you happen to have an idea how to address the issue of AWS dying?

@hjalmarheld
Copy link
Author

I haven't dug into the details to be frank, but I found that SciKeras had a similar problem. See discussion here. They seem to since have implemented another approach, with new util functions found here.

As for SageMaker, are you talking about notebook instances? Sounds like it could a RAM issue. Have you tried running it on a larger instance?

@hansbuehler
Copy link
Owner

hansbuehler commented Jan 24, 2023 via email

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

No branches or pull requests

2 participants