Disable some TF2 incompatible tests from running in v2 mode.

These are all tests under tensorflow/compiler/tests/

PiperOrigin-RevId: 294429998
Change-Id: I2d6615793adea4f21a8492a356324c333b7948b1
This commit is contained in:
Tres Popp 2020-02-11 06:59:59 -08:00 committed by TensorFlower Gardener
parent ca8cf9f8ba
commit f6a6128b2e
8 changed files with 63 additions and 7 deletions

View File

@ -1081,7 +1081,10 @@ tf_xla_py_test(
# TensorArray ops are not implemented in the on-demand compilation model yet. # TensorArray ops are not implemented in the on-demand compilation model yet.
disabled_backends = ["cpu_ondemand"], disabled_backends = ["cpu_ondemand"],
python_version = "PY3", python_version = "PY3",
tags = ["config-cuda-only"], tags = [
"config-cuda-only",
"v1only",
],
use_xla_device = False, use_xla_device = False,
deps = [ deps = [
":xla_test", ":xla_test",

View File

@ -24,6 +24,8 @@ from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.compiler.tests import xla_test from tensorflow.compiler.tests import xla_test
from tensorflow.python.framework import constant_op from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes 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 array_ops
from tensorflow.python.ops import linalg_ops from tensorflow.python.ops import linalg_ops
from tensorflow.python.ops import math_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]) matrices[i] = np.dot(matrices[i].T, matrices[i])
self._verifyCholesky(matrices, atol=1e-4) 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: for dtype in self.float_types:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
linalg_ops.cholesky(np.array([[1., 2., 3.], [3., 4., 5.]], dtype=dtype)) 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.]]], [[[1., 2., 3.], [3., 4., 5.]], [[1., 2., 3.], [3., 4., 5.]]],
dtype=dtype)) 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: for dtype in self.float_types:
tensor3 = constant_op.constant([1., 2.], dtype=dtype) tensor3 = constant_op.constant([1., 2.], dtype=dtype)
with self.assertRaises(ValueError): with self.assertRaises(ValueError):

View File

@ -25,6 +25,7 @@ import numpy as np
from tensorflow.compiler.tests import test_utils from tensorflow.compiler.tests import test_utils
from tensorflow.core.protobuf import config_pb2 from tensorflow.core.protobuf import config_pb2
from tensorflow.python.compiler.xla import jit from tensorflow.python.compiler.xla import jit
from tensorflow.python.framework import ops
from tensorflow.python.layers import layers from tensorflow.python.layers import layers
from tensorflow.python.ops import array_ops from tensorflow.python.ops import array_ops
from tensorflow.python.ops import variables from tensorflow.python.ops import variables
@ -138,4 +139,7 @@ class DenseLayerTest(test.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " + os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " +
os.environ.get("TF_XLA_FLAGS", "")) 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() test.main()

View File

@ -648,4 +648,7 @@ class LazyCompilationTest(test.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " + os.environ["TF_XLA_FLAGS"] = ("--tf_xla_enable_lazy_compilation=true " +
os.environ.get("TF_XLA_FLAGS", "")) 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() test.main()

View File

@ -321,4 +321,7 @@ if __name__ == '__main__':
) )
global FLAGS # pylint:disable=global-at-module-level global FLAGS # pylint:disable=global-at-module-level
FLAGS, unparsed = parser.parse_known_args() 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) test.main(argv=[sys.argv[0]] + unparsed)

View File

@ -25,6 +25,8 @@ import numpy as np
from tensorflow.compiler.tests import xla_test from tensorflow.compiler.tests import xla_test
from tensorflow.python.framework import constant_op from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes 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 array_ops
from tensorflow.python.ops import linalg_ops from tensorflow.python.ops import linalg_ops
from tensorflow.python.ops import math_ops from tensorflow.python.ops import math_ops
@ -133,7 +135,8 @@ class MatrixTriangularSolveOpTest(xla_test.XLATestCase):
self._VerifyTriangularSolve( self._VerifyTriangularSolve(
a.astype(np.float32), b.astype(np.float32), True, False, 1e-4) 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) rng = np.random.RandomState(0)
for dtype in self.float_types: for dtype in self.float_types:
a = rng.randn(3, 4).astype(dtype) a = rng.randn(3, 4).astype(dtype)
@ -143,7 +146,19 @@ class MatrixTriangularSolveOpTest(xla_test.XLATestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
linalg_ops.matrix_triangular_solve(a, b) 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 randn = np.random.RandomState(0).randn
for dtype in self.float_types: for dtype in self.float_types:
lhs = constant_op.constant(randn(3, 3), dtype=dtype) lhs = constant_op.constant(randn(3, 3), dtype=dtype)

View File

@ -44,11 +44,11 @@ def _make_converter(dtype):
return np.asarray(x).astype(dtype.as_numpy_dtype) return np.asarray(x).astype(dtype.as_numpy_dtype)
return _converter return _converter
# This lets me define `fn` repeatedly to pass to xla.compile. # This lets me define `fn` repeatedly to pass to xla.compile.
# #
# pylint: disable=function-redefined # pylint: disable=function-redefined
@test_util.run_v1_only("b/") # Support TF2 list operations
@test_util.with_control_flow_v2 @test_util.with_control_flow_v2
class TensorArrayTest(xla_test.XLATestCase): class TensorArrayTest(xla_test.XLATestCase):

View File

@ -27,6 +27,7 @@ from tensorflow.compiler.xla import xla_data_pb2
from tensorflow.python.framework import dtypes from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors from tensorflow.python.framework import errors
from tensorflow.python.framework import function from tensorflow.python.framework import function
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape from tensorflow.python.framework import tensor_shape
from tensorflow.python.ops import array_ops from tensorflow.python.ops import array_ops
from tensorflow.python.platform import googletest from tensorflow.python.platform import googletest
@ -410,4 +411,7 @@ class XlaOpsShapeInferenceTest(xla_test.XLATestCase, parameterized.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
# This test is using Tensorflow sessions which are not compatible with eager
# mode.
ops.disable_eager_execution()
googletest.main() googletest.main()