From fe3bd66099d6e27bf45dabbe7f4cc34276194fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Wed, 1 Aug 2018 13:37:26 +0800 Subject: [PATCH 001/340] ENH: register float64 GPU kernel for Conv3d --- tensorflow/core/kernels/conv_ops_3d.cc | 14 +++++++++++++- tensorflow/core/kernels/conv_ops_gpu_3.cu.cc | 5 +++++ tensorflow/python/kernel_tests/conv_ops_3d_test.py | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tensorflow/core/kernels/conv_ops_3d.cc b/tensorflow/core/kernels/conv_ops_3d.cc index a1eed4e68c..009fd3733a 100644 --- a/tensorflow/core/kernels/conv_ops_3d.cc +++ b/tensorflow/core/kernels/conv_ops_3d.cc @@ -525,10 +525,19 @@ namespace functor { const GPUDevice& d, typename TTypes::ConstTensor in, \ const std::array& padding_left, \ const std::array& padding_right, \ - typename TTypes::Tensor out, TensorFormat format); + typename TTypes::Tensor out, TensorFormat format); \ + template <> \ + void NHWCToNCHW::operator()( \ + const GPUDevice& d, typename TTypes::ConstTensor in, \ + typename TTypes::Tensor out); \ + template <> \ + void NCHWToNHWC::operator()( \ + const GPUDevice& d, typename TTypes::ConstTensor in, \ + typename TTypes::Tensor out); DECLARE_GPU_SPEC(Eigen::half); DECLARE_GPU_SPEC(float); +DECLARE_GPU_SPEC(double); #undef DECLARE_GPU_SPEC } // namespace functor @@ -540,6 +549,9 @@ REGISTER_KERNEL_BUILDER( REGISTER_KERNEL_BUILDER( Name("Conv3D").Device(DEVICE_GPU).TypeConstraint("T"), Conv3DOp); +REGISTER_KERNEL_BUILDER( + Name("Conv3D").Device(DEVICE_GPU).TypeConstraint("T"), + Conv3DOp); #endif // GOOGLE_CUDA } // namespace tensorflow diff --git a/tensorflow/core/kernels/conv_ops_gpu_3.cu.cc b/tensorflow/core/kernels/conv_ops_gpu_3.cu.cc index a5fa48f85e..f8520cc307 100644 --- a/tensorflow/core/kernels/conv_ops_gpu_3.cu.cc +++ b/tensorflow/core/kernels/conv_ops_gpu_3.cu.cc @@ -1068,18 +1068,23 @@ template struct functor::PadInput; template struct functor::PadInput; // For 3d ops. +template struct functor::TransformFilter; template struct functor::TransformFilter; template struct functor::TransformFilter; +template struct functor::ReverseTransformFilter; template struct functor::ReverseTransformFilter; template struct functor::ReverseTransformFilter; +template struct functor::NHWCToNCHW; template struct functor::NHWCToNCHW; template struct functor::NHWCToNCHW; +template struct functor::NCHWToNHWC; template struct functor::NCHWToNHWC; template struct functor::NCHWToNHWC; +template struct functor::PadInput; template struct functor::PadInput; template struct functor::PadInput; diff --git a/tensorflow/python/kernel_tests/conv_ops_3d_test.py b/tensorflow/python/kernel_tests/conv_ops_3d_test.py index 0b531125f3..7a0f51dfef 100644 --- a/tensorflow/python/kernel_tests/conv_ops_3d_test.py +++ b/tensorflow/python/kernel_tests/conv_ops_3d_test.py @@ -52,11 +52,11 @@ class Conv3DTest(test.TestCase): def _DtypesToTest(self, use_gpu): if use_gpu: if not test_util.CudaSupportsHalfMatMulAndConv(): - return [dtypes.float32] + return [dtypes.float64, dtypes.float32] else: # It is important that float32 comes before float16 here, # as we will be using its gradients as reference for fp16 gradients. - return [dtypes.float32, dtypes.float16] + return [dtypes.float64, dtypes.float32, dtypes.float16] else: return [dtypes.float64, dtypes.float32, dtypes.float16] -- GitLab From c475edf9513d6bceae992775869fb9dd0b2c848a Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Mon, 24 Sep 2018 05:43:36 +0000 Subject: [PATCH 002/340] Fix for tf.keras.regularizers.{l1,l2}(0.) with tf.get_variable This fix tries to address the issue in 22470 where tf.keras.regularizers.{l1,l2}(l=0.) with tf.get_variable returns ``` AttributeError: 'float' object has no attribute 'name' ``` The issue only happens when `l=0.` as in that case, `regularization = 0.` was returned directly (and `0.` does not have a `name` attribute as a float number) This fix convert regularization = 0. to tensor. This fix fixes 22470. Signed-off-by: Yong Tang --- tensorflow/python/keras/regularizers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/keras/regularizers.py b/tensorflow/python/keras/regularizers.py index 28b6ad4c65..0d139d748c 100644 --- a/tensorflow/python/keras/regularizers.py +++ b/tensorflow/python/keras/regularizers.py @@ -20,6 +20,7 @@ from __future__ import print_function import six +from tensorflow.python.framework import ops from tensorflow.python.keras import backend as K from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object from tensorflow.python.keras.utils.generic_utils import serialize_keras_object @@ -54,7 +55,7 @@ class L1L2(Regularizer): self.l2 = K.cast_to_floatx(l2) def __call__(self, x): - regularization = 0. + regularization = ops.convert_to_tensor(0.) if self.l1: regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x)) if self.l2: -- GitLab From 7f51123b0e8ab0532af04a5ccad3ab9605128db4 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Mon, 24 Sep 2018 05:51:09 +0000 Subject: [PATCH 003/340] Add dtype to convert_to_tensor Signed-off-by: Yong Tang --- tensorflow/python/keras/regularizers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/regularizers.py b/tensorflow/python/keras/regularizers.py index 0d139d748c..fd0748f3ae 100644 --- a/tensorflow/python/keras/regularizers.py +++ b/tensorflow/python/keras/regularizers.py @@ -55,7 +55,7 @@ class L1L2(Regularizer): self.l2 = K.cast_to_floatx(l2) def __call__(self, x): - regularization = ops.convert_to_tensor(0.) + regularization = ops.convert_to_tensor(0., dtype=K.floatx()) if self.l1: regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x)) if self.l2: -- GitLab From 7efb78e55c9993068fdc82df3d2df9d989d111e4 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 10 Oct 2018 14:22:32 +0000 Subject: [PATCH 004/340] Add test case for tf.keras.regularizers.{l1,l2}(0.) with tf.get_variable Signed-off-by: Yong Tang --- tensorflow/python/keras/integration_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tensorflow/python/keras/integration_test.py b/tensorflow/python/keras/integration_test.py index 3c0f73b1c3..0e6fc79dd3 100644 --- a/tensorflow/python/keras/integration_test.py +++ b/tensorflow/python/keras/integration_test.py @@ -26,6 +26,7 @@ from tensorflow.python.keras import testing_utils from tensorflow.python.layers import core as tf_core_layers from tensorflow.python.ops import nn from tensorflow.python.ops import rnn_cell +from tensorflow.python.ops import variable_scope from tensorflow.python.platform import test @@ -312,6 +313,15 @@ class KerasIntegrationTest(test.TestCase): verbose=0) self.assertGreater(history.history['val_acc'][-1], 0.7) + def test_regularizers_with_get_variable(self): + # Test case for GitHub issue 22470. + with self.cached_session(): + v = variable_scope.get_variable( + "v", + shape = [4, 4], + initializer=keras.initializers.glorot_uniform(), + regularizer=keras.regularizers.l2(0.)) + if __name__ == '__main__': test.main() -- GitLab From 406c4ad08f00aafec76e95478f4b1e7d87a5427a Mon Sep 17 00:00:00 2001 From: Alexis Louis Date: Thu, 11 Oct 2018 14:38:47 +0200 Subject: [PATCH 005/340] README Updates Clarification of code examples for fast copy-paste replication. (I did run the code myself and encountered those little missing elements) - Estimator declaration placed after config declaration - loss_fn() incoherent with previous loss variable declaration --- tensorflow/contrib/distribute/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow/contrib/distribute/README.md b/tensorflow/contrib/distribute/README.md index 2e025765e4..2389b89eb6 100644 --- a/tensorflow/contrib/distribute/README.md +++ b/tensorflow/contrib/distribute/README.md @@ -131,7 +131,7 @@ def model_fn(features, labels, mode): return tf.estimator.EstimatorSpec(mode, loss=loss) if mode == tf.estimator.ModeKeys.TRAIN: - train_op = tf.train.GradientDescentOptimizer(0.2).minimize(loss_fn()) + train_op = tf.train.GradientDescentOptimizer(0.2).minimize(loss) return tf.estimator.EstimatorSpec(mode, loss=loss, train_op=train_op) ``` @@ -248,10 +248,10 @@ start multi-worker training using `tf.estimator.train_and_evaluate`: ```python def model_main(): - estimator = ... distribution = tf.contrib.distribute.CollectiveAllReduceStrategy( num_gpus_per_worker=2) config = tf.estimator.RunConfig(train_distribute=distribution) + estimator = tf.estimator.Estimator(model_fn=model_fn, config=config) train_spec = tf.estimator.TrainSpec(input_fn=input_fn) eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn) tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec) @@ -324,13 +324,13 @@ start training. On your laptop, you can run ```python -estimator = ... distribution = tf.contrib.distribute.CollectiveAllReduceStrategy( num_gpus_per_worker=2) config = tf.estimator.RunConfig( experimental_distribute=tf.contrib.distribute.DistributeConfig( train_distribute=distribution, remote_cluster={"worker": ["host1:port", "host2:port", "host3:port"]})) +estimator = tf.estimator.Estimator(model_fn=model_fn, config=config) train_spec = tf.estimator.TrainSpec(input_fn=input_fn) eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn) tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec) -- GitLab From 1bae040045254e1ca51366391d52bb79b8c1b067 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Mon, 15 Oct 2018 22:21:21 +0000 Subject: [PATCH 006/340] Update the documentation for tf.fft This fix is related to 17332. While complex128 has been added in tf, the documentation still says: ``` tf.spectral.fft input: A Tensor. Must be one of the following types: complex64, complex128. A complex64 tensor. ``` This fix updates the documentation so that it matches the actual behavior. Signed-off-by: Yong Tang --- tensorflow/core/api_def/base_api/api_def_FFT.pbtxt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/core/api_def/base_api/api_def_FFT.pbtxt b/tensorflow/core/api_def/base_api/api_def_FFT.pbtxt index 4e48d6c169..0ba2327371 100644 --- a/tensorflow/core/api_def/base_api/api_def_FFT.pbtxt +++ b/tensorflow/core/api_def/base_api/api_def_FFT.pbtxt @@ -3,13 +3,13 @@ op { in_arg { name: "input" description: < Date: Mon, 15 Oct 2018 22:23:22 +0000 Subject: [PATCH 007/340] Update documentation for tf.ifft/ifft2d/fft2d Signed-off-by: Yong Tang --- tensorflow/core/api_def/base_api/api_def_FFT2D.pbtxt | 4 ++-- tensorflow/core/api_def/base_api/api_def_IFFT.pbtxt | 4 ++-- tensorflow/core/api_def/base_api/api_def_IFFT2D.pbtxt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tensorflow/core/api_def/base_api/api_def_FFT2D.pbtxt b/tensorflow/core/api_def/base_api/api_def_FFT2D.pbtxt index 555f8e6067..c7b780a56f 100644 --- a/tensorflow/core/api_def/base_api/api_def_FFT2D.pbtxt +++ b/tensorflow/core/api_def/base_api/api_def_FFT2D.pbtxt @@ -3,13 +3,13 @@ op { in_arg { name: "input" description: < Date: Wed, 24 Oct 2018 01:48:08 +0000 Subject: [PATCH 008/340] Resolved merge conflicts and squashed into one commit --- tensorflow/python/ops/cond_v2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tensorflow/python/ops/cond_v2.py b/tensorflow/python/ops/cond_v2.py index 998c3e08f6..175b53b1a2 100644 --- a/tensorflow/python/ops/cond_v2.py +++ b/tensorflow/python/ops/cond_v2.py @@ -136,11 +136,11 @@ def cond_v2(pred, true_fn, false_fn, name="cond"): # correct output structure tensors = tuple(array_ops.identity(t) for t in tensors) - result = tuple(tensors[:num_cond_outputs]) - if len(result) == 1: - return result[0] - else: - return result + # Packing output tensors in the same nested structure as the true and false + # functions return + result = nest.pack_sequence_as(structure=true_graph.structured_outputs, + flat_sequence=tensors[:num_cond_outputs]) + return result @ops.RegisterGradient("If") -- GitLab From ddd89530bf5022996c2f3564a5af0eda08eb81d2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 24 Oct 2018 01:55:01 +0000 Subject: [PATCH 009/340] Forgot to update tests --- .../kernel_tests/control_flow_ops_py_test.py | 258 ++++++++---------- 1 file changed, 113 insertions(+), 145 deletions(-) diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index 6487503ff9..7a746ca362 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -22,7 +22,6 @@ from __future__ import print_function import collections import math -import sys import time import numpy as np @@ -456,7 +455,7 @@ class ControlFlowTest(test.TestCase): self.assertTrue(ind.dtype == np.int64) def testCondColocation(self): - with self.session(use_gpu=True): + with self.test_session(use_gpu=True): with ops.device("/cpu:0"): v = variables.Variable(7.0) @@ -471,7 +470,7 @@ class ControlFlowTest(test.TestCase): self.assertDeviceEqual(op.device, "/cpu:0") def _testCond_1(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): x = constant_op.constant(10) pred = math_ops.less(1, 2) fn1 = lambda: math_ops.add(x, 1) @@ -510,40 +509,27 @@ class ControlFlowTest(test.TestCase): result = r.eval() self.assertAllEqual(12, result) - @test_util.run_in_graph_and_eager_modes - def testCondPruning(self): - v1 = variables.Variable(7) - v2 = variables.Variable(7) - v3 = variables.Variable(7) + @test_util.disable_control_flow_v2("b/113324949 (ref vars)") + def testCond_4(self): + with self.cached_session(): + v1 = variables.Variable(7) + v2 = variables.Variable(7) + v3 = variables.Variable(7) - def f(): age = constant_op.constant(3) max_age = constant_op.constant(2) pred = math_ops.greater(age, max_age) fn1 = lambda: [state_ops.assign(v1, 1).op, state_ops.assign(v2, 2).op] fn2 = lambda: [state_ops.assign(v3, 3).op, constant_op.constant(10).op] r = control_flow_ops.cond(pred, fn1, fn2) - self.assertEqual(len(r), 2) - return r[1] - f_defun = eager_function.defun(f) - - if not context.executing_eagerly(): - with self.cached_session(): - variables.global_variables_initializer().run() - result = f().eval() - self.assertEqual(True, result) - # Only second cond result was fetched, so v1 assign shouldn't run. - self.assertEqual(7, v1.eval()) - self.assertEqual(2, v2.eval()) - self.assertEqual(7, v3.eval()) - - result = f_defun() - self.assertEqual(True, self.evaluate(result)) - # Both v1 and v2 branch assignments should be run in defun. - self.assertEqual(1, self.evaluate(v1)) - self.assertEqual(2, self.evaluate(v2)) - self.assertEqual(7, self.evaluate(v3)) + variables.global_variables_initializer().run() + self.assertEqual(len(r), 2) + result = r[1].eval() + self.assertAllEqual(True, result) + self.assertAllEqual(7, v1.eval()) + self.assertAllEqual(2, v2.eval()) + self.assertAllEqual(7, v3.eval()) def testCond_5(self): with self.cached_session(): @@ -584,6 +570,85 @@ class ControlFlowTest(test.TestCase): r = control_flow_ops.cond(pred, fn1, fn2) self.assertAllEqual([11, 12], sess.run(r)) + def testCondListOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: [math_ops.add(x, y), math_ops.add(x, y)] + fn2 = lambda: [y, y] + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + self.assertListEqual([210, 210], test_result) + + def testTupleOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: (math_ops.add(x, y), math_ops.add(x, y)) + fn2 = lambda: (y, y) + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + self.assertTupleEqual((210, 210), test_result) + + def testDictOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: {"a": math_ops.add(x, y), "b": math_ops.add(x, y)} + fn2 = lambda: {"a": y, "b": y} + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + self.assertDictEqual({"a": 210, "b": 210}, test_result) + + def testNestedListOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: [[math_ops.add(x, y), math_ops.add(x, y)]] + fn2 = lambda: [[y, y]] + # Pass strict=True flag as cond_v2 allows for tensors to be + # in nested output structures as singletons + r = control_flow_ops.cond(pred, fn1, fn2, strict=True) + test_result = sess.run(r) + self.assertListEqual([[210, 210]], test_result) + + def testNestedTupleOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: ((math_ops.add(x, y), math_ops.add(x, y))) + fn2 = lambda: ((y, y)) + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + self.assertTupleEqual(((210, 210)), test_result) + + def testNestedDictOutput(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: {"a": {"c": math_ops.add(x, y)}, "b": {"d": math_ops.add(x, y)}} + fn2 = lambda: {"a": {"c": y}, "b": {"d": y}} + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + self.assertDictEqual({"a": {"c": 210}, "b": {"d": 210}}, test_result) + + def testCheckNestedOutputStruct(self): + with self.cached_session() as sess: + x = constant_op.constant(10) + y = constant_op.constant(200) + pred = math_ops.less(1, 2) + fn1 = lambda: {"a": math_ops.add(x, y), "b": math_ops.add(x, y)} + fn2 = lambda: {"c": y, "d": y} + with self.assertRaisesRegexp(ValueError, "The two structures don't have the same nested structure"): + r = control_flow_ops.cond(pred, fn1, fn2) + test_result = sess.run(r) + def testCondRef(self): with self.cached_session(): @@ -638,6 +703,8 @@ class ControlFlowTest(test.TestCase): merged_op = control_flow_ops.merge([assign_v, orig_v]) self.assertAllEqual([1.0], sess.run(merged_op.output)) + @test_util.disable_control_flow_v2( + "b/112477618 (Operation returned from cond)") def testCondSwitchIdentity(self): # Make sure the recv identity is not removed by optimization. with session.Session(config=opt_cfg()) as sess: @@ -652,6 +719,8 @@ class ControlFlowTest(test.TestCase): r = control_flow_ops.cond(pred, fn1, fn2) sess.run(r) + @test_util.disable_control_flow_v2( + "b/112477618 (Operation returned from cond)") def testCondRecvIdentity(self): # Make sure the switch identity is not removed by optimization. with session.Session(config=opt_cfg()) as sess: @@ -750,111 +819,6 @@ class ControlFlowTest(test.TestCase): ] self.assertAllEqual(dense_gv, [0.0, 2.0]) - # TODO(b/117945658): reenable - @test_util.run_in_graph_and_eager_modes - def DISABLED_testCondAutoControlDeps(self): - - def branch_fn(): - logging_ops.print_v2("A") - logging_ops.print_v2("B") - with ops.control_dependencies([logging_ops.print_v2("C")]): - return constant_op.constant(10) - - def build_cond(): - return control_flow_ops.cond( - constant_op.constant(True), branch_fn, lambda: 0) - - def build_nested_cond(): - return control_flow_ops.cond( - constant_op.constant(True), build_cond, lambda: 0) - - # In v1 graph mode, pruning should make only "C" print. - if not context.executing_eagerly(): - with self.cached_session(): - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(build_cond().eval(), 10) - self.assertEqual(printed.contents(), "C\n") - - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(build_nested_cond().eval(), 10) - self.assertEqual(printed.contents(), "C\n") - - # In defuns, all prints should execute in program order. - # This doesn't work with legacy control flow. - if control_flow_ops.ENABLE_COND_V2: - - @eager_function.defun - def cond(): - return build_cond() - - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(self.evaluate(cond()), 10) - self.assertEqual(printed.contents(), "A\nB\nC\n") - - @eager_function.defun - def nested_cond(): - return build_nested_cond() - - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(self.evaluate(nested_cond()), 10) - self.assertEqual(printed.contents(), "A\nB\nC\n") - - # TODO(b/117945658): reenable - @test_util.run_in_graph_and_eager_modes - def DISABLED_testWhileAutoControlDeps(self): - - def cond(i, unused_x): - logging_ops.print_v2("A") - return i < 2 - - def body(i, x): - logging_ops.print_v2("B") - with ops.control_dependencies([logging_ops.print_v2("C")]): - x = array_ops.identity(x) - with ops.control_dependencies([logging_ops.print_v2("D")]): - return i + 1, x - - def build_while(): - return control_flow_ops.while_loop( - cond, body, [constant_op.constant(0), constant_op.constant(0)]) - - def build_nested_while(): - return control_flow_ops.cond( - constant_op.constant(True), build_while, lambda: (0, 0)) - - # In v1 graph mode, pruning should make only "D" print. - if not context.executing_eagerly(): - with self.cached_session(): - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(build_while()[0].eval(), 2) - self.assertEqual(printed.contents(), "D\nD\n") - - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(build_nested_while()[0].eval(), 2) - self.assertEqual(printed.contents(), "D\nD\n") - - # In defuns, all prints should execute in program order. - # This doesn't work with legacy control flow. - if control_flow_ops.ENABLE_WHILE_V2: - - @eager_function.defun - def while_loop(): - return build_while()[0] - - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(self.evaluate(while_loop()), 2) - self.assertEqual(printed.contents(), "A\nB\nC\nD\nA\nB\nC\nD\nA\n") - - @eager_function.defun - def nested_while_loop(): - return build_nested_while()[0] - - # TODO(b/117840611): calling nested_while_loop fails in eager - if not context.executing_eagerly(): - with self.captureWritesToStream(sys.stderr) as printed: - self.assertEqual(self.evaluate(nested_while_loop()), 2) - self.assertEqual(printed.contents(), "A\nB\nC\nD\nA\nB\nC\nD\nA\n") - # Microbenchmark: 256,000 iterations/s. @test_util.disable_control_flow_v2("b/116630618 (Times out)") def testWhile_1(self): @@ -1089,7 +1053,7 @@ class ControlFlowTest(test.TestCase): final_without_xla_context = create_while_loop() - with self.session(use_gpu=False) as sess: + with self.test_session(use_gpu=False) as sess: opts = config_pb2.RunOptions(trace_level=config_pb2.RunOptions.FULL_TRACE) run_metadata = config_pb2.RunMetadata() @@ -1205,7 +1169,7 @@ class ControlFlowTest(test.TestCase): self.assertLess(len(unique_allocs), 756) def _testWhile_Gpu_1(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): n = constant_op.constant(1.0) c = lambda x: math_ops.less(x, 10.0) b = lambda x: math_ops.add(x, 1.0) @@ -1217,7 +1181,7 @@ class ControlFlowTest(test.TestCase): self._testWhile_Gpu_1(use_gpu=True) def _testWhile_Gpu_2(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): n = constant_op.constant(1.0) c = lambda x: math_ops.less(x, 10.0) @@ -1359,7 +1323,7 @@ class ControlFlowTest(test.TestCase): [i.get_shape(), tensor_shape.TensorShape([None, 5])]) def _testNestedWhile_1(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): n = constant_op.constant(0) def cpu_sum(s): @@ -1386,7 +1350,7 @@ class ControlFlowTest(test.TestCase): def _testNestedWhile_2(self, use_gpu): # Test the cases that A -> Enter and Exit -> A are partitioned. - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): s0 = constant_op.constant(2.0) def inner_loop(s): @@ -1565,7 +1529,7 @@ class ControlFlowTest(test.TestCase): self.assertAllEqual(10, r.eval()) def _testCondWhile_3(self, use_gpu): - with self.cached_session(use_gpu=use_gpu) as sess: + with self.test_session(use_gpu=use_gpu) as sess: p = array_ops.placeholder(dtypes.bool) n = constant_op.constant(0.0) @@ -1947,7 +1911,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(2048.0, r.eval()) def _testWhileGrad_Mul(self, use_gpu, p_iters): - with self.cached_session(use_gpu=use_gpu) as sess: + with self.test_session(use_gpu=use_gpu) as sess: a = constant_op.constant(3.0, name="a") v = constant_op.constant(2.0, name="v") c = lambda v: math_ops.less(v, 100.0) @@ -1967,7 +1931,7 @@ class ControlFlowTest(test.TestCase): def _testNestedWhileCondWhileGrad(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): v = constant_op.constant(1.0) def inner_loop(s): @@ -2273,7 +2237,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(1.0, g.eval()) # y_f_d = x + 1.0, dy_f_d/dx = 1.0 def _testNestedWhileGrad_Simple(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): v = constant_op.constant(1.0) def inner_loop(s): @@ -2366,7 +2330,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(2.999, var.eval()) def _testWhileCondGrad_Simple(self, use_gpu): - with self.cached_session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): v = ops.convert_to_tensor(2.0, name="v") n = ops.convert_to_tensor(100.0, name="n") one = ops.convert_to_tensor(1.0, name="one") @@ -2777,6 +2741,8 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(4.0, i.eval(feed_dict={d: 1})) self.assertAllClose(2.0 * math.sqrt(2), i.eval(feed_dict={d: 2})) + @test_util.disable_control_flow_v2( + "b/112477618 (Operation returned from cond)") def testCase(self): with self.cached_session(): x = constant_op.constant(1) @@ -2829,6 +2795,8 @@ class ControlFlowTest(test.TestCase): self.assertAllEqual(r6.eval(), 0) + @test_util.disable_control_flow_v2( + "b/112477618 (Operation returned from cond)") def testCaseSideEffects(self): with self.cached_session() as sess: v0 = variables.Variable(-1) @@ -3361,7 +3329,7 @@ class TupleTest(test.TestCase): class AssertTest(test.TestCase): def testGuardedAssertDoesNotCopyWhenTrue(self): - with self.session(use_gpu=True) as sess: + with self.test_session(use_gpu=True) as sess: with ops.device(test.gpu_device_name()): value = constant_op.constant(1.0) with ops.device("/cpu:0"): -- GitLab From 5e8a5e488b80f544cf810404cfd380305638df10 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 24 Oct 2018 01:59:54 +0000 Subject: [PATCH 010/340] Commited wrong test file --- .../kernel_tests/control_flow_ops_py_test.py | 186 ++++++++++++++---- 1 file changed, 148 insertions(+), 38 deletions(-) diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index 7a746ca362..98f8fd4e96 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -22,6 +22,7 @@ from __future__ import print_function import collections import math +import sys import time import numpy as np @@ -455,7 +456,7 @@ class ControlFlowTest(test.TestCase): self.assertTrue(ind.dtype == np.int64) def testCondColocation(self): - with self.test_session(use_gpu=True): + with self.session(use_gpu=True): with ops.device("/cpu:0"): v = variables.Variable(7.0) @@ -470,7 +471,7 @@ class ControlFlowTest(test.TestCase): self.assertDeviceEqual(op.device, "/cpu:0") def _testCond_1(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): x = constant_op.constant(10) pred = math_ops.less(1, 2) fn1 = lambda: math_ops.add(x, 1) @@ -509,27 +510,40 @@ class ControlFlowTest(test.TestCase): result = r.eval() self.assertAllEqual(12, result) - @test_util.disable_control_flow_v2("b/113324949 (ref vars)") - def testCond_4(self): - with self.cached_session(): - v1 = variables.Variable(7) - v2 = variables.Variable(7) - v3 = variables.Variable(7) + @test_util.run_in_graph_and_eager_modes + def testCondPruning(self): + v1 = variables.Variable(7) + v2 = variables.Variable(7) + v3 = variables.Variable(7) + def f(): age = constant_op.constant(3) max_age = constant_op.constant(2) pred = math_ops.greater(age, max_age) fn1 = lambda: [state_ops.assign(v1, 1).op, state_ops.assign(v2, 2).op] fn2 = lambda: [state_ops.assign(v3, 3).op, constant_op.constant(10).op] r = control_flow_ops.cond(pred, fn1, fn2) - - variables.global_variables_initializer().run() self.assertEqual(len(r), 2) - result = r[1].eval() - self.assertAllEqual(True, result) - self.assertAllEqual(7, v1.eval()) - self.assertAllEqual(2, v2.eval()) - self.assertAllEqual(7, v3.eval()) + return r[1] + + f_defun = eager_function.defun(f) + + if not context.executing_eagerly(): + with self.cached_session(): + variables.global_variables_initializer().run() + result = f().eval() + self.assertEqual(True, result) + # Only second cond result was fetched, so v1 assign shouldn't run. + self.assertEqual(7, v1.eval()) + self.assertEqual(2, v2.eval()) + self.assertEqual(7, v3.eval()) + + result = f_defun() + self.assertEqual(True, self.evaluate(result)) + # Both v1 and v2 branch assignments should be run in defun. + self.assertEqual(1, self.evaluate(v1)) + self.assertEqual(2, self.evaluate(v2)) + self.assertEqual(7, self.evaluate(v3)) def testCond_5(self): with self.cached_session(): @@ -546,7 +560,6 @@ class ControlFlowTest(test.TestCase): self.assertAllEqual(4, count.eval()) def testCond_6(self): - with self.cached_session(): v1 = variables.Variable([7]) @@ -603,7 +616,7 @@ class ControlFlowTest(test.TestCase): test_result = sess.run(r) self.assertDictEqual({"a": 210, "b": 210}, test_result) - def testNestedListOutput(self): + def testEmbeddedListOutput(self): with self.cached_session() as sess: x = constant_op.constant(10) y = constant_op.constant(200) @@ -616,7 +629,7 @@ class ControlFlowTest(test.TestCase): test_result = sess.run(r) self.assertListEqual([[210, 210]], test_result) - def testNestedTupleOutput(self): + def testEmbeddedTupleOutput(self): with self.cached_session() as sess: x = constant_op.constant(10) y = constant_op.constant(200) @@ -627,7 +640,7 @@ class ControlFlowTest(test.TestCase): test_result = sess.run(r) self.assertTupleEqual(((210, 210)), test_result) - def testNestedDictOutput(self): + def testEmbeddedDictOutput(self): with self.cached_session() as sess: x = constant_op.constant(10) y = constant_op.constant(200) @@ -703,8 +716,6 @@ class ControlFlowTest(test.TestCase): merged_op = control_flow_ops.merge([assign_v, orig_v]) self.assertAllEqual([1.0], sess.run(merged_op.output)) - @test_util.disable_control_flow_v2( - "b/112477618 (Operation returned from cond)") def testCondSwitchIdentity(self): # Make sure the recv identity is not removed by optimization. with session.Session(config=opt_cfg()) as sess: @@ -719,8 +730,6 @@ class ControlFlowTest(test.TestCase): r = control_flow_ops.cond(pred, fn1, fn2) sess.run(r) - @test_util.disable_control_flow_v2( - "b/112477618 (Operation returned from cond)") def testCondRecvIdentity(self): # Make sure the switch identity is not removed by optimization. with session.Session(config=opt_cfg()) as sess: @@ -819,6 +828,111 @@ class ControlFlowTest(test.TestCase): ] self.assertAllEqual(dense_gv, [0.0, 2.0]) + # TODO(b/117945658): reenable + @test_util.run_in_graph_and_eager_modes + def DISABLED_testCondAutoControlDeps(self): + + def branch_fn(): + logging_ops.print_v2("A") + logging_ops.print_v2("B") + with ops.control_dependencies([logging_ops.print_v2("C")]): + return constant_op.constant(10) + + def build_cond(): + return control_flow_ops.cond( + constant_op.constant(True), branch_fn, lambda: 0) + + def build_nested_cond(): + return control_flow_ops.cond( + constant_op.constant(True), build_cond, lambda: 0) + + # In v1 graph mode, pruning should make only "C" print. + if not context.executing_eagerly(): + with self.cached_session(): + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(build_cond().eval(), 10) + self.assertEqual(printed.contents(), "C\n") + + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(build_nested_cond().eval(), 10) + self.assertEqual(printed.contents(), "C\n") + + # In defuns, all prints should execute in program order. + # This doesn't work with legacy control flow. + if control_flow_ops.ENABLE_COND_V2: + + @eager_function.defun + def cond(): + return build_cond() + + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(self.evaluate(cond()), 10) + self.assertEqual(printed.contents(), "A\nB\nC\n") + + @eager_function.defun + def nested_cond(): + return build_nested_cond() + + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(self.evaluate(nested_cond()), 10) + self.assertEqual(printed.contents(), "A\nB\nC\n") + + # TODO(b/117945658): reenable + @test_util.run_in_graph_and_eager_modes + def DISABLED_testWhileAutoControlDeps(self): + + def cond(i, unused_x): + logging_ops.print_v2("A") + return i < 2 + + def body(i, x): + logging_ops.print_v2("B") + with ops.control_dependencies([logging_ops.print_v2("C")]): + x = array_ops.identity(x) + with ops.control_dependencies([logging_ops.print_v2("D")]): + return i + 1, x + + def build_while(): + return control_flow_ops.while_loop( + cond, body, [constant_op.constant(0), constant_op.constant(0)]) + + def build_nested_while(): + return control_flow_ops.cond( + constant_op.constant(True), build_while, lambda: (0, 0)) + + # In v1 graph mode, pruning should make only "D" print. + if not context.executing_eagerly(): + with self.cached_session(): + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(build_while()[0].eval(), 2) + self.assertEqual(printed.contents(), "D\nD\n") + + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(build_nested_while()[0].eval(), 2) + self.assertEqual(printed.contents(), "D\nD\n") + + # In defuns, all prints should execute in program order. + # This doesn't work with legacy control flow. + if control_flow_ops.ENABLE_WHILE_V2: + + @eager_function.defun + def while_loop(): + return build_while()[0] + + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(self.evaluate(while_loop()), 2) + self.assertEqual(printed.contents(), "A\nB\nC\nD\nA\nB\nC\nD\nA\n") + + @eager_function.defun + def nested_while_loop(): + return build_nested_while()[0] + + # TODO(b/117840611): calling nested_while_loop fails in eager + if not context.executing_eagerly(): + with self.captureWritesToStream(sys.stderr) as printed: + self.assertEqual(self.evaluate(nested_while_loop()), 2) + self.assertEqual(printed.contents(), "A\nB\nC\nD\nA\nB\nC\nD\nA\n") + # Microbenchmark: 256,000 iterations/s. @test_util.disable_control_flow_v2("b/116630618 (Times out)") def testWhile_1(self): @@ -1053,7 +1167,7 @@ class ControlFlowTest(test.TestCase): final_without_xla_context = create_while_loop() - with self.test_session(use_gpu=False) as sess: + with self.session(use_gpu=False) as sess: opts = config_pb2.RunOptions(trace_level=config_pb2.RunOptions.FULL_TRACE) run_metadata = config_pb2.RunMetadata() @@ -1169,7 +1283,7 @@ class ControlFlowTest(test.TestCase): self.assertLess(len(unique_allocs), 756) def _testWhile_Gpu_1(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): n = constant_op.constant(1.0) c = lambda x: math_ops.less(x, 10.0) b = lambda x: math_ops.add(x, 1.0) @@ -1181,7 +1295,7 @@ class ControlFlowTest(test.TestCase): self._testWhile_Gpu_1(use_gpu=True) def _testWhile_Gpu_2(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): n = constant_op.constant(1.0) c = lambda x: math_ops.less(x, 10.0) @@ -1323,7 +1437,7 @@ class ControlFlowTest(test.TestCase): [i.get_shape(), tensor_shape.TensorShape([None, 5])]) def _testNestedWhile_1(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): n = constant_op.constant(0) def cpu_sum(s): @@ -1350,7 +1464,7 @@ class ControlFlowTest(test.TestCase): def _testNestedWhile_2(self, use_gpu): # Test the cases that A -> Enter and Exit -> A are partitioned. - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): s0 = constant_op.constant(2.0) def inner_loop(s): @@ -1529,7 +1643,7 @@ class ControlFlowTest(test.TestCase): self.assertAllEqual(10, r.eval()) def _testCondWhile_3(self, use_gpu): - with self.test_session(use_gpu=use_gpu) as sess: + with self.cached_session(use_gpu=use_gpu) as sess: p = array_ops.placeholder(dtypes.bool) n = constant_op.constant(0.0) @@ -1911,7 +2025,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(2048.0, r.eval()) def _testWhileGrad_Mul(self, use_gpu, p_iters): - with self.test_session(use_gpu=use_gpu) as sess: + with self.cached_session(use_gpu=use_gpu) as sess: a = constant_op.constant(3.0, name="a") v = constant_op.constant(2.0, name="v") c = lambda v: math_ops.less(v, 100.0) @@ -1931,7 +2045,7 @@ class ControlFlowTest(test.TestCase): def _testNestedWhileCondWhileGrad(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): v = constant_op.constant(1.0) def inner_loop(s): @@ -2237,7 +2351,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(1.0, g.eval()) # y_f_d = x + 1.0, dy_f_d/dx = 1.0 def _testNestedWhileGrad_Simple(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): v = constant_op.constant(1.0) def inner_loop(s): @@ -2330,7 +2444,7 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(2.999, var.eval()) def _testWhileCondGrad_Simple(self, use_gpu): - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): v = ops.convert_to_tensor(2.0, name="v") n = ops.convert_to_tensor(100.0, name="n") one = ops.convert_to_tensor(1.0, name="one") @@ -2741,8 +2855,6 @@ class ControlFlowTest(test.TestCase): self.assertAllClose(4.0, i.eval(feed_dict={d: 1})) self.assertAllClose(2.0 * math.sqrt(2), i.eval(feed_dict={d: 2})) - @test_util.disable_control_flow_v2( - "b/112477618 (Operation returned from cond)") def testCase(self): with self.cached_session(): x = constant_op.constant(1) @@ -2795,8 +2907,6 @@ class ControlFlowTest(test.TestCase): self.assertAllEqual(r6.eval(), 0) - @test_util.disable_control_flow_v2( - "b/112477618 (Operation returned from cond)") def testCaseSideEffects(self): with self.cached_session() as sess: v0 = variables.Variable(-1) @@ -3329,7 +3439,7 @@ class TupleTest(test.TestCase): class AssertTest(test.TestCase): def testGuardedAssertDoesNotCopyWhenTrue(self): - with self.test_session(use_gpu=True) as sess: + with self.session(use_gpu=True) as sess: with ops.device(test.gpu_device_name()): value = constant_op.constant(1.0) with ops.device("/cpu:0"): -- GitLab From 183324ff17b4669707731fea957a1648e754960d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 25 Oct 2018 00:34:46 +0000 Subject: [PATCH 011/340] Fixed versioning error --- tensorflow/python/ops/cond_v2.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tensorflow/python/ops/cond_v2.py b/tensorflow/python/ops/cond_v2.py index 175b53b1a2..714cfbf4db 100644 --- a/tensorflow/python/ops/cond_v2.py +++ b/tensorflow/python/ops/cond_v2.py @@ -468,6 +468,10 @@ def _check_same_outputs(true_graph, false_graph): " true_fn: %s\n" " false_fn: %s" % (true_output_types, false_output_types)) + # Make sure both structured outputs for both graphs have the same structure + nest.assert_same_structure(true_graph.structured_outputs, + false_graph.structured_outputs) + def _get_output_shapes(true_graph_outputs, false_graph_outputs): output_shapes = [ -- GitLab From 772566443a8e2f4dc962efd622967f8d2a80319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Fri, 2 Nov 2018 11:14:03 +0800 Subject: [PATCH 012/340] TST: use session instead --- tensorflow/python/kernel_tests/conv_ops_3d_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/kernel_tests/conv_ops_3d_test.py b/tensorflow/python/kernel_tests/conv_ops_3d_test.py index b3e73fa841..3ff23852e0 100644 --- a/tensorflow/python/kernel_tests/conv_ops_3d_test.py +++ b/tensorflow/python/kernel_tests/conv_ops_3d_test.py @@ -413,7 +413,7 @@ class Conv3DTest(test.TestCase): elif data_type == dtypes.float16: tolerance = 1e-3 - with self.cached_session(use_gpu=use_gpu): + with self.session(use_gpu=use_gpu): orig_input_tensor = constant_op.constant( input_data, shape=input_shape, dtype=data_type, name="input") filter_tensor = constant_op.constant( -- GitLab From 7e14f51c49c35fe577f0700ccec8b72c17d9f1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Fri, 2 Nov 2018 11:45:00 +0800 Subject: [PATCH 013/340] ENH: register double for grad --- tensorflow/core/kernels/conv_grad_ops_3d.cc | 8 ++++++++ tensorflow/python/kernel_tests/conv_ops_3d_test.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tensorflow/core/kernels/conv_grad_ops_3d.cc b/tensorflow/core/kernels/conv_grad_ops_3d.cc index bab91f5e86..9271bfdf04 100644 --- a/tensorflow/core/kernels/conv_grad_ops_3d.cc +++ b/tensorflow/core/kernels/conv_grad_ops_3d.cc @@ -1859,6 +1859,14 @@ class Conv3DBackpropFilterOp : public OpKernel { Conv3DBackpropFilterOp); TF_CALL_half(REGISTER_GPU_KERNEL); TF_CALL_float(REGISTER_GPU_KERNEL); +REGISTER_KERNEL_BUILDER( + Name("Conv3DBackpropInput").Device(DEVICE_GPU).TypeConstraint("T"), + Conv3DBackpropInputOp); +REGISTER_KERNEL_BUILDER(Name("Conv3DBackpropInputV2") + .Device(DEVICE_GPU) + .TypeConstraint("T") + .HostMemory("input_sizes"), + Conv3DBackpropInputOp); #undef REGISTER_GPU_KERNEL #endif // GOOGLE_CUDA diff --git a/tensorflow/python/kernel_tests/conv_ops_3d_test.py b/tensorflow/python/kernel_tests/conv_ops_3d_test.py index 3ff23852e0..dd90676f09 100644 --- a/tensorflow/python/kernel_tests/conv_ops_3d_test.py +++ b/tensorflow/python/kernel_tests/conv_ops_3d_test.py @@ -413,7 +413,7 @@ class Conv3DTest(test.TestCase): elif data_type == dtypes.float16: tolerance = 1e-3 - with self.session(use_gpu=use_gpu): + with self.test_session(use_gpu=use_gpu): orig_input_tensor = constant_op.constant( input_data, shape=input_shape, dtype=data_type, name="input") filter_tensor = constant_op.constant( -- GitLab From 92878d5ae1596858c7682a2e93e5fe8969066854 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 2 Nov 2018 20:50:36 +0000 Subject: [PATCH 014/340] Fixed import nest issue --- tensorflow/python/ops/cond_v2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tensorflow/python/ops/cond_v2.py b/tensorflow/python/ops/cond_v2.py index 714cfbf4db..7e6c95ac88 100644 --- a/tensorflow/python/ops/cond_v2.py +++ b/tensorflow/python/ops/cond_v2.py @@ -34,6 +34,8 @@ from tensorflow.python.ops import control_flow_util from tensorflow.python.ops import control_flow_util_v2 as util from tensorflow.python.ops import gen_functional_ops from tensorflow.python.ops import gradients_impl +from tensorflow.python.util import nest + # NOTE(skyewm): TensorFlow uses protected class methods and fields to signify # that they aren't part of the official public API. These protected members -- GitLab From 1994b259d998c0a5c73107beb9750ef43b3797c5 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 10 Oct 2018 14:24:13 +0000 Subject: [PATCH 015/340] Update to avoid useless node in the graph based on review Signed-off-by: Yong Tang --- tensorflow/python/keras/integration_test.py | 2 +- tensorflow/python/keras/regularizers.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tensorflow/python/keras/integration_test.py b/tensorflow/python/keras/integration_test.py index 0e6fc79dd3..dfe62276fe 100644 --- a/tensorflow/python/keras/integration_test.py +++ b/tensorflow/python/keras/integration_test.py @@ -318,7 +318,7 @@ class KerasIntegrationTest(test.TestCase): with self.cached_session(): v = variable_scope.get_variable( "v", - shape = [4, 4], + shape=[4, 4], initializer=keras.initializers.glorot_uniform(), regularizer=keras.regularizers.l2(0.)) diff --git a/tensorflow/python/keras/regularizers.py b/tensorflow/python/keras/regularizers.py index fd0748f3ae..cbcdae214f 100644 --- a/tensorflow/python/keras/regularizers.py +++ b/tensorflow/python/keras/regularizers.py @@ -55,12 +55,14 @@ class L1L2(Regularizer): self.l2 = K.cast_to_floatx(l2) def __call__(self, x): - regularization = ops.convert_to_tensor(0., dtype=K.floatx()) - if self.l1: - regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x)) - if self.l2: - regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x)) - return regularization + if self.l1 or self.l2: + regularization = ops.convert_to_tensor(0., dtype=K.floatx()) + if self.l1: + regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x)) + if self.l2: + regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x)) + return regularization + return None def get_config(self): return {'l1': float(self.l1), 'l2': float(self.l2)} -- GitLab From cc46242fc750feb8da443d6c42ef2e2cf66cb38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Fri, 2 Nov 2018 15:45:36 +0800 Subject: [PATCH 016/340] ENH: register double for grad op --- tensorflow/core/kernels/conv_grad_ops_3d.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tensorflow/core/kernels/conv_grad_ops_3d.cc b/tensorflow/core/kernels/conv_grad_ops_3d.cc index 9271bfdf04..7fe4d8e93d 100644 --- a/tensorflow/core/kernels/conv_grad_ops_3d.cc +++ b/tensorflow/core/kernels/conv_grad_ops_3d.cc @@ -1070,6 +1070,7 @@ namespace functor { DECLARE_GPU_SPEC(Eigen::half); DECLARE_GPU_SPEC(float); +DECLARE_GPU_SPEC(double); #undef DECLARE_GPU_SPEC } // namespace functor @@ -1859,14 +1860,7 @@ class Conv3DBackpropFilterOp : public OpKernel { Conv3DBackpropFilterOp); TF_CALL_half(REGISTER_GPU_KERNEL); TF_CALL_float(REGISTER_GPU_KERNEL); -REGISTER_KERNEL_BUILDER( - Name("Conv3DBackpropInput").Device(DEVICE_GPU).TypeConstraint("T"), - Conv3DBackpropInputOp); -REGISTER_KERNEL_BUILDER(Name("Conv3DBackpropInputV2") - .Device(DEVICE_GPU) - .TypeConstraint("T") - .HostMemory("input_sizes"), - Conv3DBackpropInputOp); +TF_CALL_double(REGISTER_GPU_KERNEL); #undef REGISTER_GPU_KERNEL #endif // GOOGLE_CUDA -- GitLab From 29303bc712888e3f0d57e804c93bb1e7c58368a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Thu, 8 Nov 2018 14:19:30 +0800 Subject: [PATCH 017/340] TST: use cached_session instead --- tensorflow/python/kernel_tests/conv_ops_3d_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/kernel_tests/conv_ops_3d_test.py b/tensorflow/python/kernel_tests/conv_ops_3d_test.py index dd90676f09..b3e73fa841 100644 --- a/tensorflow/python/kernel_tests/conv_ops_3d_test.py +++ b/tensorflow/python/kernel_tests/conv_ops_3d_test.py @@ -413,7 +413,7 @@ class Conv3DTest(test.TestCase): elif data_type == dtypes.float16: tolerance = 1e-3 - with self.test_session(use_gpu=use_gpu): + with self.cached_session(use_gpu=use_gpu): orig_input_tensor = constant_op.constant( input_data, shape=input_shape, dtype=data_type, name="input") filter_tensor = constant_op.constant( -- GitLab From 2ee1c5a0d6b99574f48e7f0de9b94559d824b022 Mon Sep 17 00:00:00 2001 From: Tongxuan Liu Date: Wed, 7 Nov 2018 14:44:12 +0800 Subject: [PATCH 018/340] RendezvousMgr & CancellationMgr are already aborted, shouldn't send RPC call any more When RendezvousMgr & CancellationMgr are already aborted, following RPC couldn't handled by CancellationMgr. At the moment, remote service is already closed, client would hang here. --- tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc | 8 ++++++++ .../core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc b/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc index 94f522c04e..fbccbead03 100644 --- a/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc +++ b/tensorflow/contrib/gdr/gdr_rendezvous_mgr.cc @@ -170,6 +170,14 @@ class GdrRemoteRendezvous : public BaseRemoteRendezvous { // Record "call" in active_ so that it can be aborted cleanly. RegisterCall(call); + // RendezvousMgr already aborted, shouldn't send RPC call any more + if (!call->status().ok()) { + done(call->status(), Args(), Args(), Tensor(), false); + session()->worker_cache->ReleaseWorker(src_worker, rwi); + delete call; + return; + } + // Start "call". Ref(); call->Start([this, call, src_worker, rwi, done]() { diff --git a/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc b/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc index b8cb538503..9fb920404f 100644 --- a/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc +++ b/tensorflow/core/distributed_runtime/rpc/rpc_rendezvous_mgr.cc @@ -244,6 +244,15 @@ void RpcRemoteRendezvous::RecvFromRemoteAsync( // Record "call" in active_ so that it can be aborted cleanly. RegisterCall(call); + // RendezvousMgr already aborted, shouldn't send RPC call any more + if (!call->status().ok()) { + call->done()(call->status(), Args(), Args(), Tensor(), false); + session()->worker_cache->ReleaseWorker(call->src_worker_, call->wi_); + call->wi_ = nullptr; + get_call_freelist()->Release(call, session()->worker_cache.get()); + return; + } + // Start "call". Ref(); call->Start([this, call]() { -- GitLab From 74142f67926917061134678234ebee9683562f77 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 9 Nov 2018 08:13:19 +0000 Subject: [PATCH 019/340] Fixed old tests breaking because cond_v2 implementation preserves nested output structures even with singeltons --- .../python/kernel_tests/control_flow_ops_py_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index 98f8fd4e96..71e4ccddde 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -2097,8 +2097,12 @@ class ControlFlowTest(test.TestCase): [tensor_shape.unknown_shape()]) return gradients_impl.gradients(r, x) - r = control_flow_ops.cond(math_ops.less(1, 2), fn1, lambda: x) - self.assertAllClose(9.0, r.eval(feed_dict={x: 1.0})) + #placed lambda function return tensor in list and set strict flag to True + #as cond_v2 implementation preserves nested output structures even with singeltons + r = control_flow_ops.cond(math_ops.less(1, 2), fn1, lambda: [x], strict=True) + #cannot run eval() on list object so use sess.run() and save output + result = sess.run(r,feed_dict={x: 1.0}) + self.assertAllClose([9.0], result) @test_util.disable_control_flow_v2("b/116340060") def testGradInWhileWrtInitialLoopVal(self): -- GitLab From 8068b6a021e75dc20f5de5902a684e94c3a4b5ef Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 9 Nov 2018 21:54:37 +0000 Subject: [PATCH 020/340] Fixed typo --- tensorflow/python/kernel_tests/control_flow_ops_py_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index 71e4ccddde..95e4c4ba14 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -2086,7 +2086,7 @@ class ControlFlowTest(test.TestCase): def testWhileGradInCond(self): - with self.cached_session(): + with self.cached_session() as sess: n = ops.convert_to_tensor(1.0, name="n") x = array_ops.placeholder(dtypes.float32, shape=None) c = lambda n: math_ops.less(n, 10.0) -- GitLab From 1bb3c61392634bf6a2b6ad5c1c3dc554204fc9fc Mon Sep 17 00:00:00 2001 From: Fei Hu Date: Fri, 9 Nov 2018 17:00:11 -0800 Subject: [PATCH 021/340] parallel_for: add converter for MaxPool3D, MaxPool3DGrad, MaxPool3DGradGrad --- .../ops/parallel_for/control_flow_ops_test.py | 20 ++++++++++++++++++- tensorflow/python/ops/parallel_for/pfor.py | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/ops/parallel_for/control_flow_ops_test.py b/tensorflow/python/ops/parallel_for/control_flow_ops_test.py index 171369b724..d44966078c 100644 --- a/tensorflow/python/ops/parallel_for/control_flow_ops_test.py +++ b/tensorflow/python/ops/parallel_for/control_flow_ops_test.py @@ -794,11 +794,29 @@ class NNTest(PForTest): def test_max_pool(self): x = random_ops.random_uniform([3, 2, 12, 12, 3]) ksize = [1, 3, 3, 1] + strides = [1, 2, 2, 1] def loop_fn(i): x1 = array_ops.gather(x, i) output = nn.max_pool( - x1, ksize, strides=[1, 2, 2, 1], padding="VALID", data_format="NHWC") + x1, ksize, strides=strides, padding="VALID", data_format="NHWC") + loss = nn.l2_loss(output) + ones = array_ops.ones_like(output) + grad = gradient_ops.gradients(loss, x1, grad_ys=ones) + grad_grad = gradient_ops.gradients(grad, ones) + return output, grad, grad_grad + + self._test_loop_fn(loop_fn, 3, loop_fn_dtypes=[dtypes.float32] * 3) + + def test_max_pool3D(self): + x = random_ops.random_uniform([3, 3, 2, 12, 12, 3]) + ksize = [1, 1, 3, 3, 1] + strides = [1, 1, 2, 2, 1] + + def loop_fn(i): + x1 = array_ops.gather(x, i) + output = nn.max_pool3d( + x1, ksize, strides=strides, padding="VALID", data_format="NDHWC") loss = nn.l2_loss(output) ones = array_ops.ones_like(output) grad = gradient_ops.gradients(loss, x1, grad_ys=ones) diff --git a/tensorflow/python/ops/parallel_for/pfor.py b/tensorflow/python/ops/parallel_for/pfor.py index e6f140a941..d789dc65b1 100644 --- a/tensorflow/python/ops/parallel_for/pfor.py +++ b/tensorflow/python/ops/parallel_for/pfor.py @@ -1303,7 +1303,10 @@ def _inputs_with_flattening(pfor_input, input_indices): @RegisterPForWithArgs("Conv2D", dims=[0]) @RegisterPForWithArgs("AvgPool", dims=[0]) @RegisterPForWithArgs("MaxPool", dims=[0]) +@RegisterPForWithArgs("MaxPool3D", dims=[0]) +@RegisterPForWithArgs("MaxPool3DGrad", dims=[0, 1, 2]) @RegisterPForWithArgs("MaxPoolGrad", dims=[0, 1, 2]) +@RegisterPForWithArgs("MaxPool3DGradGrad", dims=[0, 1, 2]) @RegisterPForWithArgs("MaxPoolGradGrad", dims=[0, 1, 2]) @RegisterPForWithArgs("SoftmaxCrossEntropyWithLogits", dims=[0, 1]) def _convert_flatten_batch(pfor_input, op_type, dims): -- GitLab From e9853febd5cf870523ddd99ef6e4fa45cd7047bd Mon Sep 17 00:00:00 2001 From: Anders Huss Date: Mon, 12 Nov 2018 08:59:58 +0100 Subject: [PATCH 022/340] fix issue in expanding of mask in keras.backend.rnn --- tensorflow/python/keras/backend.py | 6 +- tensorflow/python/keras/backend_test.py | 118 ++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 3 deletions(-) diff --git a/tensorflow/python/keras/backend.py b/tensorflow/python/keras/backend.py index 0be6302a98..017491ac76 100644 --- a/tensorflow/python/keras/backend.py +++ b/tensorflow/python/keras/backend.py @@ -3337,9 +3337,9 @@ def rnn(step_function, assert not nest.is_sequence(input_t) rank_diff = len(input_t.shape) - len(mask_t.shape) for _ in range(rank_diff): - mask_t = array_ops.expand_dims(mask_t) - expand_dims = [1] + input_t.shape.as_list()[1:] - return array_ops.tile(mask_t, expand_dims) + mask_t = array_ops.expand_dims(mask_t, -1) + multiples = [1] + input_t.shape.as_list()[1:] + return array_ops.tile(mask_t, multiples) if unroll: if not time_steps: diff --git a/tensorflow/python/keras/backend_test.py b/tensorflow/python/keras/backend_test.py index d8aa3e9b52..edb2af7e01 100644 --- a/tensorflow/python/keras/backend_test.py +++ b/tensorflow/python/keras/backend_test.py @@ -1223,6 +1223,124 @@ class BackendNNOpsTest(test.TestCase, parameterized.TestCase): for s, u_s in zip(additional_state_list[2], additional_state_list[3]): self.assertAllClose(s, u_s, atol=1e-04) + def test_rnn_output_and_state_masking_independent(self): + num_samples = 2 + num_timesteps = 4 + state_and_io_size = 2 + mask_last_num_timesteps = 2 # for second sample only + + # a step function that just outputs inputs, + # but increments states +1 per timestep + def step_function(inputs, states): + return inputs, [s + 1 for s in states] + + inputs_vals = np.random.random( + (num_samples, num_timesteps, state_and_io_size)) + initial_state_vals = np.random.random((num_samples, state_and_io_size)) + # masking of two last timesteps for second sample only + mask_vals = np.ones((num_samples, num_timesteps)) + mask_vals[1, -mask_last_num_timesteps:] = 0 + + # outputs expected to be same as inputs for the first sample + expected_outputs = inputs_vals.copy() + # but for the second sample all outputs in masked region should be the same + # as last output before masked region + expected_outputs[1, -mask_last_num_timesteps:] = \ + expected_outputs[1, -(mask_last_num_timesteps + 1)] + + expected_state = initial_state_vals.copy() + # first state should be incremented for every timestep (no masking) + expected_state[0] += num_timesteps + # second state should not be incremented for last two timesteps + expected_state[1] += (num_timesteps - mask_last_num_timesteps) + + # verify same expected output for `unroll=true/false` + inputs = keras.backend.variable(inputs_vals) + initial_states = [keras.backend.variable(initial_state_vals)] + mask = keras.backend.variable(mask_vals) + for unroll in [True, False]: + last_output, outputs, last_states = keras.backend.rnn( + step_function, + inputs, + initial_states, + mask=mask, + unroll=unroll, + input_length=num_timesteps if unroll else None) + + self.assertAllClose( + keras.backend.eval(outputs), expected_outputs) + self.assertAllClose( + keras.backend.eval(last_states[0]), expected_state) + + def test_rnn_output_num_dim_larger_than_2_masking(self): + num_samples = 3 + num_timesteps = 4 + num_features = 5 + + def step_function(inputs, states): + outputs = keras.backend.tile(keras.backend.expand_dims(inputs), [1, 1, 2]) + return outputs, [keras.backend.identity(s) for s in states] + # Note: cannot just return states (which can be a problem) -> + # tensorflow/python/ops/resource_variable_ops.py", line 824, in set_shape + # NotImplementedError: ResourceVariable does not implement set_shape() + + inputs_vals = np.random.random((num_samples, num_timesteps, num_features)) + initial_state_vals = np.random.random((num_samples, 6)) + mask_vals = np.ones((num_samples, num_timesteps)) + mask_vals[-1, -1] = 0 # final timestep masked for last sample + + expected_outputs = np.repeat(inputs_vals[..., None], repeats=2, axis=-1) + # for the last sample, the final timestep (in masked region) should be the + # same as the second to final output (before masked region) + expected_outputs[-1, -1] = expected_outputs[-1, -2] + + inputs = keras.backend.variable(inputs_vals) + initial_states = [keras.backend.variable(initial_state_vals)] + mask = keras.backend.variable(mask_vals) + for unroll in [True, False]: + last_output, outputs, last_states = keras.backend.rnn( + step_function, + inputs, + initial_states, + mask=mask, + unroll=unroll, + input_length=num_timesteps if unroll else None) + + self.assertAllClose(keras.backend.eval(outputs), expected_outputs) + + def test_rnn_state_num_dim_larger_than_2_masking(self): + num_samples = 3 + num_timesteps = 4 + + def step_function(inputs, states): + return inputs, [s + 1 for s in states] + + inputs_vals = np.random.random((num_samples, num_timesteps, 5)) + initial_state_vals = np.random.random((num_samples, 6, 7)) + mask_vals = np.ones((num_samples, num_timesteps)) + mask_vals[0, -2:] = 0 # final two timesteps masked for first sample + + expected_last_state = initial_state_vals.copy() + expected_last_state[0] += (num_timesteps - 2) + expected_last_state[1:] += num_timesteps + + inputs = keras.backend.variable(inputs_vals) + initial_states = [keras.backend.variable(initial_state_vals)] + mask = keras.backend.variable(mask_vals) + for unroll in [True, False]: + last_output, outputs, last_states = keras.backend.rnn( + step_function, + inputs, + initial_states, + mask=mask, + unroll=unroll, + input_length=num_timesteps if unroll else None) + + # not updated last timestep: + self.assertAllClose( + keras.backend.eval(last_states[0]), + expected_last_state) + def test_normalize_batch_in_training(self): val = np.random.random((10, 3, 10, 10)) x = keras.backend.variable(val) -- GitLab From fc541f794a27918ca6233734ab1f443489ddab5f Mon Sep 17 00:00:00 2001 From: Fei Hu Date: Mon, 12 Nov 2018 21:40:44 -0800 Subject: [PATCH 023/340] Fix the coding style issue --- tensorflow/python/ops/parallel_for/control_flow_ops_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/ops/parallel_for/control_flow_ops_test.py b/tensorflow/python/ops/parallel_for/control_flow_ops_test.py index d44966078c..7d13014687 100644 --- a/tensorflow/python/ops/parallel_for/control_flow_ops_test.py +++ b/tensorflow/python/ops/parallel_for/control_flow_ops_test.py @@ -808,7 +808,7 @@ class NNTest(PForTest): self._test_loop_fn(loop_fn, 3, loop_fn_dtypes=[dtypes.float32] * 3) - def test_max_pool3D(self): + def test_max_pool3d(self): x = random_ops.random_uniform([3, 3, 2, 12, 12, 3]) ksize = [1, 1, 3, 3, 1] strides = [1, 1, 2, 2, 1] @@ -816,7 +816,7 @@ class NNTest(PForTest): def loop_fn(i): x1 = array_ops.gather(x, i) output = nn.max_pool3d( - x1, ksize, strides=strides, padding="VALID", data_format="NDHWC") + x1, ksize, strides=strides, padding="VALID", data_format="NDHWC") loss = nn.l2_loss(output) ones = array_ops.ones_like(output) grad = gradient_ops.gradients(loss, x1, grad_ys=ones) -- GitLab From 8e85fe418aa40e5e4d4d4700dd491f4cbef4b30e Mon Sep 17 00:00:00 2001 From: Peng Yu Date: Wed, 22 Aug 2018 00:05:19 -0400 Subject: [PATCH 024/340] add tensor forest inference kernels --- tensorflow/core/BUILD | 3 + ...i_def_TensorForestCreateTreeVariable.pbtxt | 17 +++ .../api_def_TensorForestTreeDeserialize.pbtxt | 17 +++ ..._def_TensorForestTreeIsInitializedOp.pbtxt | 17 +++ .../api_def_TensorForestTreePredict.pbtxt | 29 ++++ ...def_TensorForestTreeResourceHandleOp.pbtxt | 5 + .../api_def_TensorForestTreeSerialize.pbtxt | 17 +++ .../api_def_TensorForestTreeSize.pbtxt | 17 +++ tensorflow/core/kernels/BUILD | 7 + .../kernels/boosted_trees/boosted_trees.proto | 14 ++ tensorflow/core/kernels/tensor_forest/BUILD | 53 +++++++ .../kernels/tensor_forest/prediction_ops.cc | 93 ++++++++++++ .../kernels/tensor_forest/resource_ops.cc | 135 ++++++++++++++++++ .../core/kernels/tensor_forest/resources.cc | 59 ++++++++ .../core/kernels/tensor_forest/resources.h | 63 ++++++++ tensorflow/core/ops/tensor_forest_ops.cc | 79 ++++++++++ tensorflow/python/BUILD | 22 +++ tensorflow/python/ops/tensor_forest_ops.py | 110 ++++++++++++++ 18 files changed, 757 insertions(+) create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestCreateTreeVariable.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreeDeserialize.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreeIsInitializedOp.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreePredict.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreeResourceHandleOp.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreeSerialize.pbtxt create mode 100644 tensorflow/core/api_def/base_api/api_def_TensorForestTreeSize.pbtxt create mode 100644 tensorflow/core/kernels/tensor_forest/BUILD create mode 100644 tensorflow/core/kernels/tensor_forest/prediction_ops.cc create mode 100644 tensorflow/core/kernels/tensor_forest/resource_ops.cc create mode 100644 tensorflow/core/kernels/tensor_forest/resources.cc create mode 100644 tensorflow/core/kernels/tensor_forest/resources.h create mode 100644 tensorflow/core/ops/tensor_forest_ops.cc create mode 100644 tensorflow/python/ops/tensor_forest_ops.py diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index b7ec445e93..ea99f14aa9 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -1038,6 +1038,7 @@ tf_gen_op_libs( "batch_ops", "bitwise_ops", "boosted_trees_ops", + "tensor_forest_ops", "candidate_sampling_ops", "checkpoint_ops", "collective_ops", @@ -1187,6 +1188,7 @@ cc_library( ":batch_ops_op_lib", ":bitwise_ops_op_lib", ":boosted_trees_ops_op_lib", + ":tensor_forest_ops_op_lib", ":candidate_sampling_ops_op_lib", ":checkpoint_ops_op_lib", ":collective_ops_op_lib", @@ -1340,6 +1342,7 @@ cc_library( "//tensorflow/core/kernels:batch_kernels", "//tensorflow/core/kernels:bincount_op", "//tensorflow/core/kernels:boosted_trees_ops", + "//tensorflow/core/kernels:tensor_forest_ops", "//tensorflow/core/kernels:candidate_sampler_ops", "//tensorflow/core/kernels:checkpoint_ops", "//tensorflow/core/kernels:collective_ops", diff --git a/tensorflow/core/api_def/base_api/api_def_TensorForestCreateTreeVariable.pbtxt b/tensorflow/core/api_def/base_api/api_def_TensorForestCreateTreeVariable.pbtxt new file mode 100644 index 0000000000..fe2ccd9da6 --- /dev/null +++ b/tensorflow/core/api_def/base_api/api_def_TensorForestCreateTreeVariable.pbtxt @@ -0,0 +1,17 @@ +op { + graph_op_name: "TensorForestCreateTreeVariable" + visibility: HIDDEN + in_arg { + name: "tree_handle" + description: <