diff options
author | 2018-08-29 10:17:53 -0700 | |
---|---|---|
committer | 2018-08-29 10:22:42 -0700 | |
commit | aca93368a979419360c1fd84b53b1766b19ba81a (patch) | |
tree | 2312ef53a30251ec2f5538d43ba066550679f6d9 /tensorflow/python/estimator/canned | |
parent | 8a22fa7037332fc6066459ce8c6fabcd77c6ece4 (diff) |
Add new aggregation mode "ONLY_FIRST_TOWER" and use it for the global
step counter. This allows us to get rid of the increment_var()
function and just use a standard assign_add().
PiperOrigin-RevId: 210743165
Diffstat (limited to 'tensorflow/python/estimator/canned')
5 files changed, 16 insertions, 17 deletions
diff --git a/tensorflow/python/estimator/canned/baseline_test.py b/tensorflow/python/estimator/canned/baseline_test.py index e46a3a156d..1df7216ba6 100644 --- a/tensorflow/python/estimator/canned/baseline_test.py +++ b/tensorflow/python/estimator/canned/baseline_test.py @@ -42,13 +42,13 @@ from tensorflow.python.ops import control_flow_ops from tensorflow.python.ops import data_flow_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import parsing_ops +from tensorflow.python.ops import state_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops import variables from tensorflow.python.platform import gfile from tensorflow.python.platform import test from tensorflow.python.summary.writer import writer_cache from tensorflow.python.training import checkpoint_utils -from tensorflow.python.training import distribute as distribute_lib from tensorflow.python.training import input as input_lib from tensorflow.python.training import optimizer from tensorflow.python.training import queue_runner @@ -490,7 +490,7 @@ class BaselineRegressorTrainingTest(test.TestCase): self.assertEquals(0, loss.shape.ndims) if expected_loss is None: if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() assert_loss = assert_close( math_ops.to_float(expected_loss, name='expected'), @@ -498,7 +498,7 @@ class BaselineRegressorTrainingTest(test.TestCase): name='assert_loss') with ops.control_dependencies((assert_loss,)): if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() mock_optimizer = test.mock.NonCallableMock( @@ -693,13 +693,13 @@ class BaselineClassifierTrainingTest(test.TestCase): # Verify loss. We can't check the value directly, so we add an assert op. self.assertEquals(0, loss.shape.ndims) if expected_loss is None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op assert_loss = assert_close( math_ops.to_float(expected_loss, name='expected'), loss, name='assert_loss') with ops.control_dependencies((assert_loss,)): - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op mock_optimizer = test.mock.NonCallableMock( spec=optimizer.Optimizer, diff --git a/tensorflow/python/estimator/canned/boosted_trees.py b/tensorflow/python/estimator/canned/boosted_trees.py index ef7c217190..d104c961d3 100644 --- a/tensorflow/python/estimator/canned/boosted_trees.py +++ b/tensorflow/python/estimator/canned/boosted_trees.py @@ -38,7 +38,6 @@ from tensorflow.python.ops import state_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops.losses import losses from tensorflow.python.summary import summary -from tensorflow.python.training import distribute as distribute_lib from tensorflow.python.training import session_run_hook from tensorflow.python.training import training_util from tensorflow.python.util.tf_export import estimator_export @@ -876,7 +875,7 @@ def _bt_model_fn( train_op.append(update_model) with ops.control_dependencies([update_model]): - increment_global = distribute_lib.increment_var(global_step) + increment_global = state_ops.assign_add(global_step, 1).op train_op.append(increment_global) return control_flow_ops.group(train_op, name='train_op') diff --git a/tensorflow/python/estimator/canned/dnn_linear_combined.py b/tensorflow/python/estimator/canned/dnn_linear_combined.py index 4945c3ba11..62a1adf78c 100644 --- a/tensorflow/python/estimator/canned/dnn_linear_combined.py +++ b/tensorflow/python/estimator/canned/dnn_linear_combined.py @@ -31,10 +31,10 @@ from tensorflow.python.framework import ops from tensorflow.python.ops import control_flow_ops from tensorflow.python.ops import nn from tensorflow.python.ops import partitioned_variables +from tensorflow.python.ops import state_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops.losses import losses from tensorflow.python.summary import summary -from tensorflow.python.training import distribute as distribute_lib from tensorflow.python.training import sync_replicas_optimizer from tensorflow.python.training import training_util from tensorflow.python.util.tf_export import estimator_export @@ -222,7 +222,7 @@ def _dnn_linear_combined_model_fn(features, train_op = control_flow_ops.group(*train_ops) with ops.control_dependencies([train_op]): - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return head.create_estimator_spec( features=features, diff --git a/tensorflow/python/estimator/canned/dnn_testing_utils.py b/tensorflow/python/estimator/canned/dnn_testing_utils.py index de226ed0ef..11f1e93630 100644 --- a/tensorflow/python/estimator/canned/dnn_testing_utils.py +++ b/tensorflow/python/estimator/canned/dnn_testing_utils.py @@ -44,13 +44,13 @@ from tensorflow.python.ops import init_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import nn from tensorflow.python.ops import partitioned_variables +from tensorflow.python.ops import state_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops import variables as variables_lib from tensorflow.python.platform import test from tensorflow.python.summary import summary as summary_lib from tensorflow.python.summary.writer import writer_cache from tensorflow.python.training import checkpoint_utils -from tensorflow.python.training import distribute as distribute_lib from tensorflow.python.training import gradient_descent from tensorflow.python.training import monitored_session from tensorflow.python.training import optimizer as optimizer_lib @@ -222,7 +222,7 @@ def mock_optimizer(testcase, hidden_units, expected_loss=None): testcase.assertEquals(0, loss.shape.ndims) if expected_loss is None: if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() assert_loss = assert_close( math_ops.to_float(expected_loss, name='expected'), @@ -230,7 +230,7 @@ def mock_optimizer(testcase, hidden_units, expected_loss=None): name='assert_loss') with ops.control_dependencies((assert_loss,)): if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() optimizer_mock = test.mock.NonCallableMagicMock( diff --git a/tensorflow/python/estimator/canned/linear_testing_utils.py b/tensorflow/python/estimator/canned/linear_testing_utils.py index c3934c7a80..65cdd50061 100644 --- a/tensorflow/python/estimator/canned/linear_testing_utils.py +++ b/tensorflow/python/estimator/canned/linear_testing_utils.py @@ -48,13 +48,13 @@ from tensorflow.python.ops import init_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import parsing_ops from tensorflow.python.ops import partitioned_variables +from tensorflow.python.ops import state_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops import variables as variables_lib from tensorflow.python.platform import gfile from tensorflow.python.platform import test from tensorflow.python.summary.writer import writer_cache from tensorflow.python.training import checkpoint_utils -from tensorflow.python.training import distribute as distribute_lib from tensorflow.python.training import gradient_descent from tensorflow.python.training import input as input_lib from tensorflow.python.training import optimizer as optimizer_lib @@ -756,7 +756,7 @@ class BaseLinearRegressorTrainingTest(object): self.assertEquals(0, loss.shape.ndims) if expected_loss is None: if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() assert_loss = assert_close( math_ops.to_float(expected_loss, name='expected'), @@ -764,7 +764,7 @@ class BaseLinearRegressorTrainingTest(object): name='assert_loss') with ops.control_dependencies((assert_loss,)): if global_step is not None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op return control_flow_ops.no_op() mock_optimizer = test.mock.NonCallableMock( @@ -979,13 +979,13 @@ class BaseLinearClassifierTrainingTest(object): # Verify loss. We can't check the value directly, so we add an assert op. self.assertEquals(0, loss.shape.ndims) if expected_loss is None: - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op assert_loss = assert_close( math_ops.to_float(expected_loss, name='expected'), loss, name='assert_loss') with ops.control_dependencies((assert_loss,)): - return distribute_lib.increment_var(global_step) + return state_ops.assign_add(global_step, 1).op mock_optimizer = test.mock.NonCallableMock( spec=optimizer_lib.Optimizer, |