Skip to content

Instantly share code, notes, and snippets.

@elibixby
Created September 6, 2017 21:45
Show Gist options
  • Save elibixby/161f8f6d2875be7d21c0c30914555df6 to your computer and use it in GitHub Desktop.
Save elibixby/161f8f6d2875be7d21c0c30914555df6 to your computer and use it in GitHub Desktop.
class MyEstimator(TowerEstimator, DNNClassifier):
pass
def my_optimizer_fn(grads_and_vars, params):
optimizer = AdagradOptimizer(learning_rate=params.learning_rate, momentum=params.momentum)
return optimizer.apply_gradients(grads_and_vars)
estimator = MyEstimator(feature_columns=feature_columns,
layers=[100, 80, 60, 40],
optimizer_fn=my_optimizer_fn,
params=HParams(learning_rate=0.5, momentum=0.1))
estimator.fit(input_fn=my_input_fn)
@isaprykin
Copy link

grads_and_vars were computed with tf.gradients, right?

Not with some optimizer.

@elibixby
Copy link
Author

elibixby commented Sep 6, 2017

Correct. They are the result of averaging the gradients across all the towers. So if you want to clip or gate you'll have to do it manually here.

@elibixby
Copy link
Author

elibixby commented Sep 6, 2017

Yet another reason to stick optimizer in EstimatorSpec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment