-
Notifications
You must be signed in to change notification settings - Fork 615
Implement MovingAverage optimizer #215
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
Conversation
@seanpmorgan @facaiy Sorry about the delay on this. Could you take a look at this PR? Also, I've made a few changes to the API. In contrib, we had to use I've included a docstring with an example that should show the new API usage. Let me know what you think. |
* Port MovingAverageOptimizer from tf.contrib.opt * Inherits base Keras optimizer_v2 * `swapping_saver` replaced with `assign_average_vars` * Update test cases for TF2.X * Update docs
Thank you for your PR :). I left a few reviews above |
b47ae08
to
d2420c9
Compare
@Smokrow Made a change regarding the internal function, and I've left comments regarding the colab notebook example and paper. Thanks for taking the time to review this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LSTM! Thanks for the contribution! Could you make the tests more compatible with eager modes? And other minor requests are in the comments
Also, do we really need to override |
* Use _set_hyper() and _get_hyper() instead of member variables for average_decay, num_updates and sequential_update * Remove _create_slots() from MovingAverage * Use _serialize_hyperparameter() in get_config() * Replace if-else with tf.cond() to work with tensors * Use absolute import of tensorflow_addons in moving_average_test.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Squadrick, I'm not aware that using _set_hyper
for bool and None type will result in lots of works. Could you revert sequential_update
and num_updates
to the original implementation? Sorry for any convenience caused.
* Tests modified for static and eager execution * num_updates and sequential_update reverted back to instance variables * Type check of num_updates and sequential_update
@WindQAQ Reverted them back and added support for eager execution along with the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very close! Seems that some test cases fail? And also make sure to run make code-format
before committing. Thanks for the contribution :-)
@WindQAQ Had to wrap all |
It's likely to be the difference caused by generator. Anyway, thanks for the contribution! I'm looking forward to seeing the example colab notebook :-) |
|
||
with tf.name_scope(name): | ||
self._ema = tf.train.ExponentialMovingAverage( | ||
average_decay, num_updates=num_updates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the constructor pass optimizer.iterations
as num_updates
?
base_config = self._optimizer.get_config() | ||
return dict(list(base_config.items()) + list(config.items())) | ||
|
||
def assign_average_vars(self, var_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkpoints are usually saved in regular intervals. Is it a standard practice to continue training with the averaged variables after saving a checkpoint?
Closes #5