Exemplo n.º 1
0
 def test_generate_keras_mode_skip_run_eagerly(self):
   result = combinations.keras_mode_combinations(run_eagerly=[False])
   if tf2.enabled():
     self.assertLen(result, 1)
     self.assertEqual(result[0], {"mode": "eager", "run_eagerly": False})
   else:
     self.assertLen(result, 2)
     self.assertEqual(result[0], {"mode": "eager", "run_eagerly": False})
     self.assertEqual(result[1], {"mode": "graph", "run_eagerly": False})
        class ExampleTest(parameterized.TestCase):
            def runTest(self):
                pass

            @combinations.generate(combinations.keras_mode_combinations())
            def testBody(self):
                mode = "eager" if context.executing_eagerly() else "graph"
                should_run_eagerly = testing_utils.should_run_eagerly()
                test_params.append((mode, should_run_eagerly))
Exemplo n.º 3
0
  def test_combine_combinations(self):
    test_cases = []

    @combinations.generate(combinations.times(
        combinations.keras_mode_combinations(),
        combinations.keras_model_type_combinations()))
    class ExampleTest(parameterized.TestCase):

      def runTest(self):
        pass

      @parameterized.named_parameters(dict(testcase_name="_arg",
                                           arg=True))
      def testBody(self, arg):
        del arg
        mode = "eager" if context.executing_eagerly() else "graph"
        should_run_eagerly = testing_utils.should_run_eagerly()
        test_cases.append((mode, should_run_eagerly,
                           testing_utils.get_model_type()))

    ts = unittest.makeSuite(ExampleTest)
    res = unittest.TestResult()
    ts.run(res)

    expected_combinations = [
        ("eager", False, "functional"),
        ("eager", False, "sequential"),
        ("eager", False, "subclass"),
        ("eager", True, "functional"),
        ("eager", True, "sequential"),
        ("eager", True, "subclass"),
    ]

    if not tf2.enabled():
      expected_combinations.extend([
          ("graph", False, "functional"),
          ("graph", False, "sequential"),
          ("graph", False, "subclass"),
      ])

    self.assertAllEqual(sorted(test_cases), expected_combinations)
Exemplo n.º 4
0
import copy

from absl.testing import parameterized
import numpy as np

from tensorflow.python import keras
from tensorflow.python.eager import context
from tensorflow.python.framework import dtypes
from tensorflow.python.keras import combinations
from tensorflow.python.keras import testing_utils
from tensorflow.python.platform import test
from tensorflow.python.training import gradient_descent


@combinations.generate(combinations.keras_mode_combinations())
class SimpleRNNLayerTest(test.TestCase, parameterized.TestCase):
    def test_return_sequences_SimpleRNN(self):
        num_samples = 2
        timesteps = 3
        embedding_dim = 4
        units = 2
        testing_utils.layer_test(keras.layers.SimpleRNN,
                                 kwargs={
                                     'units': units,
                                     'return_sequences': True
                                 },
                                 input_shape=(num_samples, timesteps,
                                              embedding_dim))

    @testing_utils.run_v2_only
Exemplo n.º 5
0
 def test_generate_keras_mode_eager_only(self):
   result = combinations.keras_mode_combinations(mode=["eager"])
   self.assertLen(result, 2)
   self.assertEqual(result[0], {"mode": "eager", "run_eagerly": True})
   self.assertEqual(result[1], {"mode": "eager", "run_eagerly": False})