From f6a6128b2ec89af740ad285198cc441517f201b7 Mon Sep 17 00:00:00 2001 From: Tres Popp Date: Tue, 11 Feb 2020 06:59:59 -0800 Subject: [PATCH] Disable some TF2 incompatible tests from running in v2 mode. These are all tests under tensorflow/compiler/tests/ PiperOrigin-RevId: 294429998 Change-Id: I2d6615793adea4f21a8492a356324c333b7948b1 --- tensorflow/compiler/tests/BUILD | 5 +++- tensorflow/compiler/tests/cholesky_op_test.py | 28 +++++++++++++++++-- tensorflow/compiler/tests/dense_layer_test.py | 4 +++ tensorflow/compiler/tests/jit_test.py | 3 ++ tensorflow/compiler/tests/lstm_test.py | 3 ++ .../tests/matrix_triangular_solve_op_test.py | 19 +++++++++++-- .../compiler/tests/tensor_array_ops_test.py | 4 +-- tensorflow/compiler/tests/xla_ops_test.py | 4 +++ 8 files changed, 63 insertions(+), 7 deletions(-) diff --git a/tensorflow/compiler/tests/BUILD b/tensorflow/compiler/tests/BUILD index 8bacdfee41a..ec81b8b508e 100644 --- a/tensorflow/compiler/tests/BUILD +++ b/tensorflow/compiler/tests/BUILD @@ -1081,7 +1081,10 @@ tf_xla_py_test( # TensorArray ops are not implemented in the on-demand compilation model yet. disabled_backends = ["cpu_ondemand"], python_version = "PY3", - tags = ["config-cuda-only"], + tags = [ + "config-cuda-only", + "v1only", + ], use_xla_device = False, deps = [ ":xla_test", diff --git a/tensorflow/compiler/tests/cholesky_op_test.py b/tensorflow/compiler/tests/cholesky_op_test.py index 0a739df1163..4bd2dfd9244 100644 --- a/tensorflow/compiler/tests/cholesky_op_test.py +++ b/tensorflow/compiler/tests/cholesky_op_test.py @@ -24,6 +24,8 @@ from six.moves import xrange # pylint: disable=redefined-builtin from tensorflow.compiler.tests import xla_test from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes +from tensorflow.python.framework import errors +from tensorflow.python.framework import test_util from tensorflow.python.ops import array_ops from tensorflow.python.ops import linalg_ops from tensorflow.python.ops import math_ops @@ -83,7 +85,19 @@ class CholeskyOpTest(xla_test.XLATestCase): matrices[i] = np.dot(matrices[i].T, matrices[i]) self._verifyCholesky(matrices, atol=1e-4) - def testNonSquareMatrix(self): + @test_util.run_v2_only + def testNonSquareMatrixV2(self): + for dtype in self.float_types: + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.cholesky(np.array([[1., 2., 3.], [3., 4., 5.]], dtype=dtype)) + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.cholesky( + np.array( + [[[1., 2., 3.], [3., 4., 5.]], [[1., 2., 3.], [3., 4., 5.]]], + dtype=dtype)) + + @test_util.run_v1_only("Different error types") + def testNonSquareMatrixV1(self): for dtype in self.float_types: with self.assertRaises(ValueError): linalg_ops.cholesky(np.array([[1., 2., 3.], [3., 4., 5.]], dtype=dtype)) @@ -93,7 +107,17 @@ class CholeskyOpTest(xla_test.XLATestCase): [[[1., 2., 3.], [3., 4., 5.]], [[1., 2., 3.], [3., 4., 5.]]], dtype=dtype)) - def testWrongDimensions(self): + @test_util.run_v2_only + def testWrongDimensionsV2(self): + for dtype in self.float_types: + tensor3 = constant_op.constant([1., 2.], dtype=dtype) + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.cholesky(tensor3) + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.cholesky(tensor3) + + @test_util.run_v1_only("Different error types") + def testWrongDimensionsV1(self): for dtype in self.float_types: tensor3 = constant_op.constant([1., 2.], dtype=dtype) with self.assertRaises(ValueError): diff --git a/tensorflow/compiler/tests/dense_layer_test.py b/tensorflow/compiler/tests/dense_layer_test.py index 8e653d2511c..23e143ad576 100644 --- a/tensorflow/compiler/tests/dense_layer_test.py +++ b/tensorflow/compiler/tests/dense_layer_test.py @@ -25,6 +25,7 @@ import numpy as np from tensorflow.compiler.tests import test_utils from tensorflow.core.protobuf import config_pb2 from tensorflow.python.compiler.xla import jit +from tensorflow.python.framework import ops from tensorflow.python.layers import layers from tensorflow.python.ops import array_ops from tensorflow.python.ops import variables @@ -138,4 +139,7 @@ class DenseLayerTest(test.TestCase): if __name__ == "__main__": os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " + os.environ.get("TF_XLA_FLAGS", "")) + # This test is using Tensorflow sessions which are not compatible with eager + # mode. + ops.disable_eager_execution() test.main() diff --git a/tensorflow/compiler/tests/jit_test.py b/tensorflow/compiler/tests/jit_test.py index 3bde1574f0e..9574156b387 100644 --- a/tensorflow/compiler/tests/jit_test.py +++ b/tensorflow/compiler/tests/jit_test.py @@ -648,4 +648,7 @@ class LazyCompilationTest(test.TestCase): if __name__ == "__main__": os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " + os.environ.get("TF_XLA_FLAGS", "")) + # This test is using Tensorflow sessions which are not compatible with eager + # mode. + ops.disable_eager_execution() test.main() diff --git a/tensorflow/compiler/tests/lstm_test.py b/tensorflow/compiler/tests/lstm_test.py index 05a32c839e4..1b9ff92f845 100644 --- a/tensorflow/compiler/tests/lstm_test.py +++ b/tensorflow/compiler/tests/lstm_test.py @@ -321,4 +321,7 @@ if __name__ == '__main__': ) global FLAGS # pylint:disable=global-at-module-level FLAGS, unparsed = parser.parse_known_args() + # This test is using Tensorflow sessions which are not compatible with eager + # mode. + ops.disable_eager_execution() test.main(argv=[sys.argv[0]] + unparsed) diff --git a/tensorflow/compiler/tests/matrix_triangular_solve_op_test.py b/tensorflow/compiler/tests/matrix_triangular_solve_op_test.py index 58157168182..b07b254c600 100644 --- a/tensorflow/compiler/tests/matrix_triangular_solve_op_test.py +++ b/tensorflow/compiler/tests/matrix_triangular_solve_op_test.py @@ -25,6 +25,8 @@ import numpy as np from tensorflow.compiler.tests import xla_test from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes +from tensorflow.python.framework import errors +from tensorflow.python.framework import test_util from tensorflow.python.ops import array_ops from tensorflow.python.ops import linalg_ops from tensorflow.python.ops import math_ops @@ -133,7 +135,8 @@ class MatrixTriangularSolveOpTest(xla_test.XLATestCase): self._VerifyTriangularSolve( a.astype(np.float32), b.astype(np.float32), True, False, 1e-4) - def testNonSquareCoefficientMatrix(self): + @test_util.run_deprecated_v1 + def testNonSquareCoefficientMatrixV1(self): rng = np.random.RandomState(0) for dtype in self.float_types: a = rng.randn(3, 4).astype(dtype) @@ -143,7 +146,19 @@ class MatrixTriangularSolveOpTest(xla_test.XLATestCase): with self.assertRaises(ValueError): linalg_ops.matrix_triangular_solve(a, b) - def testWrongDimensions(self): + @test_util.run_v2_only + def testWrongDimensionsV2(self): + randn = np.random.RandomState(0).randn + for dtype in self.float_types: + lhs = constant_op.constant(randn(3, 3), dtype=dtype) + rhs = constant_op.constant(randn(4, 3), dtype=dtype) + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.matrix_triangular_solve(lhs, rhs) + with self.assertRaises(errors.InvalidArgumentError): + linalg_ops.matrix_triangular_solve(lhs, rhs) + + @test_util.run_v1_only("Different error types") + def testWrongDimensionsV1(self): randn = np.random.RandomState(0).randn for dtype in self.float_types: lhs = constant_op.constant(randn(3, 3), dtype=dtype) diff --git a/tensorflow/compiler/tests/tensor_array_ops_test.py b/tensorflow/compiler/tests/tensor_array_ops_test.py index 1bc88509542..c07bcbef5b4 100644 --- a/tensorflow/compiler/tests/tensor_array_ops_test.py +++ b/tensorflow/compiler/tests/tensor_array_ops_test.py @@ -44,11 +44,11 @@ def _make_converter(dtype): return np.asarray(x).astype(dtype.as_numpy_dtype) return _converter + # This lets me define `fn` repeatedly to pass to xla.compile. # # pylint: disable=function-redefined - - +@test_util.run_v1_only("b/") # Support TF2 list operations @test_util.with_control_flow_v2 class TensorArrayTest(xla_test.XLATestCase): diff --git a/tensorflow/compiler/tests/xla_ops_test.py b/tensorflow/compiler/tests/xla_ops_test.py index 4d33a430441..3c2fcbc0fcc 100644 --- a/tensorflow/compiler/tests/xla_ops_test.py +++ b/tensorflow/compiler/tests/xla_ops_test.py @@ -27,6 +27,7 @@ from tensorflow.compiler.xla import xla_data_pb2 from tensorflow.python.framework import dtypes from tensorflow.python.framework import errors from tensorflow.python.framework import function +from tensorflow.python.framework import ops from tensorflow.python.framework import tensor_shape from tensorflow.python.ops import array_ops from tensorflow.python.platform import googletest @@ -410,4 +411,7 @@ class XlaOpsShapeInferenceTest(xla_test.XLATestCase, parameterized.TestCase): if __name__ == '__main__': + # This test is using Tensorflow sessions which are not compatible with eager + # mode. + ops.disable_eager_execution() googletest.main()