-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add global_counter to Trainer as optional argument #271
base: master
Are you sure you want to change the base?
Add global_counter to Trainer as optional argument #271
Conversation
else: | ||
self.global_step = tf.Variable(0., name='Global_Step', | ||
trainable=False) | ||
self.global_step = global_step |
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.
This line shouldn't be necessary as it would have already been set. This conflicts with my other comment but either way we can make this more simple in one way or the other.
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.
The last line is a stupid mistake - sorry!
@@ -87,8 +87,11 @@ def __init__(self, train_ops, graph=None, clip_gradients=5.0, | |||
self.validate_trainop_names() | |||
|
|||
self.global_loss = None | |||
self.global_step = tf.Variable(0., name='Global_Step', | |||
trainable=False) | |||
if global_step: |
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.
Here you need to set:
if global_step is None:
global_step = tf.Variable(0., name='Global_Step', trainable=False)
self.global_step = global_step
because 'if Tensor
' raises an exception in TensorFlow.
That looks good @wielandbrendel! I just added a comment to use:
as @braddengross suggested, because the other way will raise a TensorFlow error. |
This PR allows to use tf.train.exponential_decay together with Trainer. It adds an optional argument to pass a global_counter to Trainer, and to hence initialise the global_counter before initializing Trainer. This is necessary if the parameter to be decayed is part of the loss function.