def test_generate_keras_mode_skip_run_eagerly(self):
     result = test_combinations.keras_mode_combinations(run_eagerly=[False])
     if tf.__internal__.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

            @test_combinations.generate(
                test_combinations.keras_mode_combinations())
            def testBody(self):
                mode = "eager" if tf.executing_eagerly() else "graph"
                should_run_eagerly = test_utils.should_run_eagerly()
                test_params.append((mode, should_run_eagerly))
    def test_combine_combinations(self):
        test_cases = []

        @test_combinations.generate(
            test_combinations.times(
                test_combinations.keras_mode_combinations(),
                test_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 tf.executing_eagerly() else "graph"
                should_run_eagerly = test_utils.should_run_eagerly()
                test_cases.append(
                    (mode, should_run_eagerly, test_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 tf.__internal__.tf2.enabled():
            expected_combinations.extend(
                [
                    ("graph", False, "functional"),
                    ("graph", False, "sequential"),
                    ("graph", False, "subclass"),
                ]
            )

        self.assertAllEqual(sorted(test_cases), expected_combinations)
 def test_generate_keras_mode_eager_only(self):
     result = test_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})
Esempio n. 5
0
# ==============================================================================
"""Tests for SimpleRNN layer."""

import tensorflow.compat.v2 as tf

import copy

from absl.testing import parameterized
import numpy as np

import keras
from keras.testing_infra import test_combinations
from keras.testing_infra import test_utils


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

    @test_utils.run_v2_only