Remove passing experimental_run_tf_function in most tests.

The experimental_run_tf_function parameter no longer has any effect.

I didn't remove the functionality from testing_util.py and keras_parameterized.py to run with experimental_run_tf_function being True and False. I will remove that functionality in a future change.

PiperOrigin-RevId: 297674422
Change-Id: I5b1e67f78b4c3b60242241fb4dc2018f0ace6013
This commit is contained in:
Reed Wanderman-Milne 2020-02-27 13:31:01 -08:00 committed by TensorFlower Gardener
parent 9ca4b6f117
commit b7014702fd
65 changed files with 564 additions and 1192 deletions
tensorflow/python
distribute
keras
saved_model

View File

@ -37,30 +37,24 @@ class KerasSaveLoadTest(test_base.TestSavedModelBase):
distribution,
saved_dir,
predict_dataset,
experimental_run_tf_function,
output_name='output_1'):
restored_keras_model = save.load_model(saved_dir)
restored_keras_model._experimental_run_tf_function = (
experimental_run_tf_function)
return restored_keras_model.predict(
predict_dataset, steps=test_base.PREDICT_STEPS)
@combinations.generate(test_base.simple_models_with_strategies())
def test_save_no_strategy_restore_strategy(self, model_and_input,
distribution,
experimental_run_tf_function):
distribution):
self.run_test_save_no_strategy_restore_strategy(
model_and_input, distribution, experimental_run_tf_function)
model_and_input, distribution)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategies(),
combinations.combine(save_in_scope=[True, False])))
def test_save_strategy_restore_no_strategy(self, model_and_input,
distribution, save_in_scope,
experimental_run_tf_function):
distribution, save_in_scope):
self.run_test_save_strategy_restore_no_strategy(
model_and_input, distribution, save_in_scope,
experimental_run_tf_function)
model_and_input, distribution, save_in_scope)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategy_pairs(),
@ -68,13 +62,11 @@ class KerasSaveLoadTest(test_base.TestSavedModelBase):
def test_save_strategy_restore_strategy(self, model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function):
save_in_scope):
self.run_test_save_strategy_restore_strategy(model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function)
save_in_scope)
if __name__ == '__main__':

View File

@ -52,14 +52,10 @@ class SimpleFunctionalModel(model_collection_base.ModelAndInput):
model = keras.Model(inputs=x, outputs=y)
optimizer = gradient_descent.SGD(learning_rate=0.001)
experimental_run_tf_function = kwargs.pop('experimental_run_tf_function',
None)
assert experimental_run_tf_function is not None
model.compile(
loss='mse',
metrics=['mae'],
optimizer=optimizer,
experimental_run_tf_function=experimental_run_tf_function)
optimizer=optimizer)
return model
@ -81,14 +77,10 @@ class SimpleSequentialModel(model_collection_base.ModelAndInput):
5, dtype=dtypes.float32, name=output_name, input_dim=3)
model.add(y)
optimizer = gradient_descent.SGD(learning_rate=0.001)
experimental_run_tf_function = kwargs.pop('experimental_run_tf_function',
None)
assert experimental_run_tf_function is not None
model.compile(
loss='mse',
metrics=['mae'],
optimizer=optimizer,
experimental_run_tf_function=experimental_run_tf_function)
optimizer=optimizer)
return model
@ -115,15 +107,11 @@ class SimpleSubclassModel(model_collection_base.ModelAndInput):
def get_model(self, **kwargs):
model = _SimpleModel()
optimizer = gradient_descent.SGD(learning_rate=0.001)
experimental_run_tf_function = kwargs.pop('experimental_run_tf_function',
None)
assert experimental_run_tf_function is not None
model.compile(
loss='mse',
metrics=['mae'],
cloning=False,
optimizer=optimizer,
experimental_run_tf_function=experimental_run_tf_function)
optimizer=optimizer)
return model

View File

@ -45,7 +45,6 @@ class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):
distribution,
saved_dir,
predict_dataset,
experimental_run_tf_function,
output_name='output_1'):
return test_base.load_and_run_with_saved_model_api(distribution, saved_dir,
predict_dataset,
@ -53,20 +52,17 @@ class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):
@combinations.generate(test_base.simple_models_with_strategies())
def test_save_no_strategy_restore_strategy(self, model_and_input,
distribution,
experimental_run_tf_function):
distribution):
self.run_test_save_no_strategy_restore_strategy(
model_and_input, distribution, experimental_run_tf_function)
model_and_input, distribution)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategies(),
combinations.combine(save_in_scope=[True, False])))
def test_save_strategy_restore_no_strategy(self, model_and_input,
distribution, save_in_scope,
experimental_run_tf_function):
distribution, save_in_scope):
self.run_test_save_strategy_restore_no_strategy(
model_and_input, distribution, save_in_scope,
experimental_run_tf_function)
model_and_input, distribution, save_in_scope)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategy_pairs(),
@ -74,13 +70,11 @@ class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):
def test_save_strategy_restore_strategy(self, model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function):
save_in_scope):
self.run_test_save_strategy_restore_strategy(model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function)
save_in_scope)
if __name__ == '__main__':

View File

@ -39,7 +39,6 @@ class SavedModelKerasModelTest(test_base.TestSavedModelBase):
distribution,
saved_dir,
predict_dataset,
experimental_run_tf_function,
output_name='output_1'):
return test_base.load_and_run_with_saved_model_api(distribution, saved_dir,
predict_dataset,
@ -47,20 +46,17 @@ class SavedModelKerasModelTest(test_base.TestSavedModelBase):
@combinations.generate(test_base.simple_models_with_strategies())
def test_save_no_strategy_restore_strategy(self, model_and_input,
distribution,
experimental_run_tf_function):
distribution):
self.run_test_save_no_strategy_restore_strategy(
model_and_input, distribution, experimental_run_tf_function)
model_and_input, distribution)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategies(),
combinations.combine(save_in_scope=[True, False])))
def test_save_strategy_restore_no_strategy(self, model_and_input,
distribution, save_in_scope,
experimental_run_tf_function):
distribution, save_in_scope):
self.run_test_save_strategy_restore_no_strategy(
model_and_input, distribution, save_in_scope,
experimental_run_tf_function)
model_and_input, distribution, save_in_scope)
@combinations.generate(
combinations.times(test_base.simple_models_with_strategy_pairs(),
@ -68,13 +64,11 @@ class SavedModelKerasModelTest(test_base.TestSavedModelBase):
def test_save_strategy_restore_strategy(self, model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function):
save_in_scope):
self.run_test_save_strategy_restore_strategy(model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function)
save_in_scope)
class SavedModelTFModuleTest(test_base.TestSavedModelBase):
@ -108,28 +102,24 @@ class SavedModelTFModuleTest(test_base.TestSavedModelBase):
distribution,
saved_dir,
predict_dataset,
experimental_run_tf_function,
output_name='output_1'):
del output_name, experimental_run_tf_function
del output_name
model = saved_model.load(saved_dir)
return self._predict_with_model(distribution, model, predict_dataset)
@combinations.generate(test_base.tfmodule_models_with_strategies())
def test_save_no_strategy_restore_strategy(self, model_and_input,
distribution,
experimental_run_tf_function):
distribution):
self.run_test_save_no_strategy_restore_strategy(
model_and_input, distribution, experimental_run_tf_function)
model_and_input, distribution)
@combinations.generate(
combinations.times(test_base.tfmodule_models_with_strategies(),
combinations.combine(save_in_scope=[True, False])))
def test_save_strategy_restore_no_strategy(
self, model_and_input, distribution, save_in_scope,
experimental_run_tf_function):
self, model_and_input, distribution, save_in_scope):
self.run_test_save_strategy_restore_no_strategy(
model_and_input, distribution, save_in_scope,
experimental_run_tf_function)
model_and_input, distribution, save_in_scope)
@combinations.generate(
combinations.times(test_base.tfmodule_models_with_strategy_pairs(),
@ -137,13 +127,11 @@ class SavedModelTFModuleTest(test_base.TestSavedModelBase):
def test_save_strategy_restore_strategy(self, model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function):
save_in_scope):
self.run_test_save_strategy_restore_strategy(model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function)
save_in_scope)
if __name__ == '__main__':

View File

@ -78,8 +78,7 @@ def simple_models_with_strategies():
return combinations.combine(
model_and_input=simple_models,
distribution=strategies,
mode=['eager'],
experimental_run_tf_function=[True, False])
mode=['eager'])
def simple_models_with_strategy_pairs():
@ -87,16 +86,14 @@ def simple_models_with_strategy_pairs():
model_and_input=simple_models,
distribution_for_saving=strategies,
distribution_for_restoring=strategies,
mode=['eager'],
experimental_run_tf_function=[True, False])
mode=['eager'])
def tfmodule_models_with_strategies():
return combinations.combine(
model_and_input=[model_combinations.simple_tfmodule_model],
distribution=strategies,
mode=['eager'],
experimental_run_tf_function=[True])
mode=['eager'])
def tfmodule_models_with_strategy_pairs():
@ -104,8 +101,7 @@ def tfmodule_models_with_strategy_pairs():
model_and_input=[model_combinations.simple_tfmodule_model],
distribution_for_saving=strategies,
distribution_for_restoring=strategies,
mode=['eager'],
experimental_run_tf_function=[True])
mode=['eager'])
def load_and_run_with_saved_model_api(distribution, saved_dir, predict_dataset,
@ -154,7 +150,6 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
distribution,
saved_dir,
predict_dataset,
experimental_run_tf_function,
output_name='output_1'):
"""Load the model and run 1 step of predict with it.
@ -166,8 +161,6 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
saved_dir: the string representing the path where the model is saved.
predict_dataset: the data used to do the predict on the model for
cross_replica context.
experimental_run_tf_function: Whether to use the single execution path
for models.
output_name: the string representing the name of the output layer of the
model.
"""
@ -193,14 +186,12 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
return predict_dataset
def run_test_save_no_strategy_restore_strategy(self, model_and_input,
distribution,
experimental_run_tf_function):
distribution):
"""Save a model without DS, and restore it with DS."""
saved_dir = os.path.join(self.get_temp_dir(), '0')
model = model_and_input.get_model(
experimental_run_tf_function=experimental_run_tf_function)
model = model_and_input.get_model()
x_train, y_train, x_predict = model_and_input.get_data()
batch_size = model_and_input.get_batch_size()
predict_dataset = self._get_predict_dataset(x_predict, batch_size)
@ -214,22 +205,19 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
result_after_save = self._load_and_run_model(
distribution=distribution,
saved_dir=saved_dir,
predict_dataset=predict_dataset,
experimental_run_tf_function=experimental_run_tf_function)
predict_dataset=predict_dataset)
tolerance = get_tolerance(None, distribution)
self.assertAllClose(result_before_save, result_after_save, atol=tolerance)
def run_test_save_strategy_restore_no_strategy(self, model_and_input,
distribution, save_in_scope,
experimental_run_tf_function):
distribution, save_in_scope):
"""Save a model with DS, and restore it without DS."""
saved_dir = os.path.join(self.get_temp_dir(), '1')
with distribution.scope():
model = model_and_input.get_model(
experimental_run_tf_function=experimental_run_tf_function)
model = model_and_input.get_model()
x_train, y_train, x_predict = model_and_input.get_data()
batch_size = model_and_input.get_batch_size()
@ -247,8 +235,7 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
load_result = self._load_and_run_model(
distribution=None,
saved_dir=saved_dir,
predict_dataset=predict_dataset,
experimental_run_tf_function=experimental_run_tf_function)
predict_dataset=predict_dataset)
tolerance = get_tolerance(distribution, None)
self.assertAllClose(result_before_save, load_result, atol=tolerance)
@ -256,14 +243,12 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
def run_test_save_strategy_restore_strategy(self, model_and_input,
distribution_for_saving,
distribution_for_restoring,
save_in_scope,
experimental_run_tf_function):
save_in_scope):
"""Save a model with DS, and restore it with potentially different DS."""
saved_dir = os.path.join(self.get_temp_dir(), '2')
with distribution_for_saving.scope():
model = model_and_input.get_model(
experimental_run_tf_function=experimental_run_tf_function)
model = model_and_input.get_model()
x_train, y_train, x_predict = model_and_input.get_data()
batch_size = model_and_input.get_batch_size()
@ -283,8 +268,7 @@ class TestSavedModelBase(test.TestCase, parameterized.TestCase):
load_result = self._load_and_run_model(
distribution=distribution_for_restoring,
saved_dir=saved_dir,
predict_dataset=predict_dataset,
experimental_run_tf_function=experimental_run_tf_function)
predict_dataset=predict_dataset)
tolerance = get_tolerance(distribution_for_saving,
distribution_for_restoring)

View File

@ -140,8 +140,7 @@ class CallbackCountsTest(keras_parameterized.TestCase):
model.compile(
adam.AdamOptimizer(0.001),
'binary_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
@parameterized.named_parameters(('with_numpy', _get_numpy()),
@ -257,8 +256,7 @@ class KerasCallbacksTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=[keras.metrics.CategoricalAccuracy(name='my_acc')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
@keras_parameterized.run_with_all_model_types
@ -1516,8 +1514,7 @@ class TestTensorBoardV2(keras_parameterized.TestCase):
model.compile(
opt,
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def test_TensorBoard_default_logdir(self):
@ -1703,7 +1700,7 @@ class TestTensorBoardV2(keras_parameterized.TestCase):
)
def test_custom_summary(self):
if not testing_utils.should_run_tf_function():
if not context.executing_eagerly():
self.skipTest('Custom summaries only supported in V2 code path.')
def scalar_v2_mock(name, data, step=None):
@ -1732,8 +1729,7 @@ class TestTensorBoardV2(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
tb_cbk = keras.callbacks.TensorBoard(self.logdir, update_freq=1)
x, y = np.ones((10, 5)), np.ones((10, 5))
model.fit(x, y, batch_size=2, validation_data=(x, y), callbacks=[tb_cbk])
@ -1801,8 +1797,7 @@ class TestTensorBoardV2NonParameterizedTest(keras_parameterized.TestCase):
model.compile(
opt,
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def _get_trace_file(self, logdir):

View File

@ -254,11 +254,9 @@ def all_strategy_combinations():
def all_strategy_combinations_plus_run_distributed():
return (combinations.combine(
distribution=strategies_minus_tpu,
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]) + combinations.combine(
mode=['graph', 'eager']) + combinations.combine(
distribution=tpu_strategies,
mode=['graph', 'eager'],
experimental_run_tf_function=[False]))
mode=['graph', 'eager']))
def all_strategy_minus_default_and_tpu_combinations():
@ -294,12 +292,10 @@ def strategy_and_optimizer_combinations():
strategy_combinations.nadam_optimizer_keras_v2_fn,
strategy_combinations.rmsprop_optimizer_keras_v2_fn,
strategy_combinations.ftrl_optimizer_keras_v2_fn
],
experimental_run_tf_function=[True, False]))
]))
tpu_strategies_graph = combinations.combine(
distribution=tpu_strategies,
mode=['graph'],
experimental_run_tf_function=[True],
optimizer=[
strategy_combinations.adagrad_optimizer_v1_fn,
strategy_combinations.adam_optimizer_v1_fn,
@ -313,7 +309,6 @@ def strategy_and_optimizer_combinations():
tpu_strategies_eager = combinations.combine(
distribution=tpu_strategies,
mode=['eager'],
experimental_run_tf_function=[False],
optimizer=[
strategy_combinations.adagrad_optimizer_keras_v2_fn,
strategy_combinations.adam_optimizer_keras_v2_fn,
@ -428,8 +423,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
distribution, 64, steps=10, batch_size=13)
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_calling_model_with_numpy_arrays(self, distribution,
experimental_run_tf_function):
def test_calling_model_with_numpy_arrays(self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -440,8 +434,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
inputs = np.zeros((64, 3), dtype=np.float32)
targets = np.zeros((64, 4), dtype=np.float32)
@ -464,8 +457,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model.predict(inputs, batch_size=8)
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_calling_model_with_mixed_precision(self, distribution,
experimental_run_tf_function):
def test_calling_model_with_mixed_precision(self, distribution):
if isinstance(distribution,
(tpu_strategy.TPUStrategy, tpu_strategy.TPUStrategyV1)):
policy_name = 'mixed_bfloat16'
@ -485,8 +477,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
# We need to pass float32 since TPUs do not support float64, even though
# these arrays will immediately be casted to bfloat16 on TPUs. We also
@ -509,8 +500,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model.predict(inputs, batch_size=8)
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_operator_overload_mixed_precision(self, distribution,
experimental_run_tf_function):
def test_operator_overload_mixed_precision(self, distribution):
# Regression test that tests a fixed bug does not reoccur. Adding an
# AutoCastVariable to a tensor on a TPU, where the variable was the LHS of
# the '+' operator, used to cause the gradient w.r.t. the variable to be
@ -565,8 +555,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
optimizer.apply_gradients(zip(gradients, model.trainable_variables))
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_calling_model_with_nested_numpy_arrays(self, distribution,
experimental_run_tf_function):
def test_calling_model_with_nested_numpy_arrays(self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -575,8 +564,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
input_a_np = np.asarray(np.random.random((64, 3)), dtype=np.float32)
input_b_np = np.asarray(np.random.random((64, 5)), dtype=np.float32)
@ -600,18 +588,15 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
@combinations.generate(
combinations.combine(
distribution=strategies_minus_tpu,
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def test_numpy_with_sample_weights(self, distribution,
experimental_run_tf_function):
mode=['graph', 'eager']))
def test_numpy_with_sample_weights(self, distribution):
with self.cached_session(), distribution.scope():
model = get_sample_weights_model()
optimizer = rmsprop.RMSPropOptimizer(learning_rate=0.001)
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
inputs = np.array([[0], [1], [2], [3]], np.float32)
targets = np.array([[2], [4], [6], [8]], np.float32)
@ -642,8 +627,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
self.assertAllClose(result, 13.5)
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_flatten_predict_outputs(self, distribution,
experimental_run_tf_function):
def test_flatten_predict_outputs(self, distribution):
with self.cached_session():
with distribution.scope():
model = multi_input_output_model()
@ -652,8 +636,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
# We take 6 input samples with each input having a dimension of 3 or 5.
input_a_np = np.asarray(np.random.random((6, 3)), dtype=np.float32)
@ -715,10 +698,8 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
@combinations.generate(
combinations.times(
tpu_strategy_combinations_graph_only(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_predict_with_partial_batch(self, distribution,
experimental_run_tf_function):
tpu_strategy_combinations_graph_only()))
def test_predict_with_partial_batch(self, distribution):
with self.cached_session():
optimizer = gradient_descent.GradientDescentOptimizer(0.001)
loss = 'mse'
@ -727,8 +708,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model_with_ds_strategy = get_model()
model_with_ds_strategy.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
cpu_model = get_model()
cpu_model.compile(optimizer, loss)
@ -780,10 +760,9 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
@combinations.generate(
combinations.times(
tpu_strategy_combinations_graph_only(),
combinations.combine(experimental_run_tf_function=[True, False])))
tpu_strategy_combinations_graph_only()))
def test_predict_multi_output_model_with_partial_batch(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
optimizer = gradient_descent.GradientDescentOptimizer(0.001)
loss = 'mse'
@ -792,8 +771,7 @@ class TestDistributionStrategyWithNumpyArrays(test.TestCase,
model_with_ds_strategy = simple_multi_inputs_multi_outputs_model()
model_with_ds_strategy.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
cpu_model = simple_multi_inputs_multi_outputs_model()
cpu_model.compile(optimizer, loss)
@ -820,8 +798,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
parameterized.TestCase):
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_calling_model_on_same_dataset(self, distribution,
experimental_run_tf_function):
def test_calling_model_on_same_dataset(self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -832,8 +809,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
dataset = get_dataset(distribution)
@ -856,7 +832,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_model_interleaved_eval_same_as_direct_eval(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -864,16 +840,14 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
user_controlled_model.compile(
optimizer_fn(0.001),
loss='mse',
metrics=['mae', keras.metrics.CategoricalAccuracy()],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mae', keras.metrics.CategoricalAccuracy()])
interleaved_model = get_model()
interleaved_model.set_weights(user_controlled_model.get_weights())
interleaved_model.compile(
optimizer_fn(0.001),
loss='mse',
metrics=['mae', keras.metrics.CategoricalAccuracy()],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mae', keras.metrics.CategoricalAccuracy()])
dataset = get_dataset(distribution)
@ -908,8 +882,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
[x[2] for x in user_controlled_output])
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_fit_with_tuple_and_dict_dataset_inputs(self, distribution,
experimental_run_tf_function):
def test_fit_with_tuple_and_dict_dataset_inputs(self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -920,8 +893,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
input_a_np = np.random.random((10, 3)).astype('float32')
input_b_np = np.random.random((10, 5)).astype('float32')
@ -948,7 +920,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_fit_with_dictionary_in_the_dataset_b135161171(
self, distribution, experimental_run_tf_function):
self, distribution):
def custom_loss(predict, label, weight):
bce = keras.losses.binary_crossentropy(label, predict)
@ -968,8 +940,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
outputs=[predict, my_loss])
model.add_loss(model.get_layer('my_loss').output)
model.compile(
optimizer='adam',
experimental_run_tf_function=experimental_run_tf_function)
optimizer='adam')
if context.executing_eagerly():
@ -993,7 +964,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_fit_eval_and_predict_methods_on_dataset_without_steps(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -1004,8 +975,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
inputs = np.zeros((1000, 3), dtype=np.float32)
targets = np.zeros((1000, 4), dtype=np.float32)
@ -1030,10 +1000,9 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(
combinations.times(
strategy_minus_tpu_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
strategy_minus_tpu_combinations()))
def test_on_dataset_with_unknown_cardinality_without_steps(
self, distribution, experimental_run_tf_function, mode):
self, distribution, mode):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -1044,8 +1013,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
inputs = np.zeros((1000, 3), dtype=np.float32)
targets = np.zeros((1000, 4), dtype=np.float32)
@ -1087,10 +1055,8 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(
combinations.times(
tpu_strategy_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_on_dataset_with_unknown_cardinality(self, distribution,
experimental_run_tf_function):
tpu_strategy_combinations()))
def test_on_dataset_with_unknown_cardinality(self, distribution):
with self.cached_session():
with distribution.scope():
model = get_model()
@ -1099,8 +1065,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
gradient_descent.GradientDescentOptimizer(0.001),
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
inputs = np.zeros((1000, 3), dtype=np.float32)
targets = np.zeros((1000, 4), dtype=np.float32)
@ -1133,7 +1098,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_fit_eval_and_predict_methods_on_dataset(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -1144,8 +1109,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
dataset = get_dataset(distribution)
@ -1154,8 +1118,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.predict(get_predict_dataset(distribution), steps=2)
@combinations.generate(strategy_and_optimizer_combinations())
def test_fit_eval_and_predict_with_optimizer(self, distribution, optimizer,
experimental_run_tf_function):
def test_fit_eval_and_predict_with_optimizer(self, distribution, optimizer):
with self.cached_session():
with distribution.scope():
@ -1164,8 +1127,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
loss = 'mse'
model.compile(
optimizer(),
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
dataset = get_dataset(distribution)
@ -1179,10 +1141,8 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
strategy_combinations.one_device_strategy
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def test_dataset_wrong_input_shape(self, distribution,
experimental_run_tf_function, mode):
mode=['graph', 'eager']))
def test_dataset_wrong_input_shape(self, distribution, mode):
if mode == 'graph':
self.skipTest(
'TODO(b/120943676, b/120957836): Re-enable for graph once the '
@ -1195,8 +1155,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
# Wrong input shape
inputs = np.zeros((10, 5), dtype=np.float32)
@ -1213,10 +1172,9 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
distribution=[
strategy_combinations.mirrored_strategy_with_gpu_and_cpu
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
mode=['graph', 'eager']))
def test_dataset_external_batch_input_validation(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
@ -1225,8 +1183,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
# Batching is done outside tf.data's `batch`
inputs = np.zeros((100, 10, 3), dtype=np.float32)
@ -1242,10 +1199,8 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
strategy_combinations.mirrored_strategy_with_two_gpus
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def test_learning_phase_value(self, distribution,
experimental_run_tf_function):
mode=['graph', 'eager']))
def test_learning_phase_value(self, distribution):
# TODO(anjalisridhar): Modify this test to use Lambdas since we can compare
# meaningful values. Currently we don't pass the learning phase if the
# Lambda layer uses the learning phase.
@ -1264,8 +1219,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
batch_size = 8
if isinstance(distribution, mirrored_strategy.MirroredStrategy):
@ -1295,8 +1249,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
self.assertArrayNear(output, ref_output, 1e-1)
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def testOptimizerWithCallbacks(self, distribution,
experimental_run_tf_function):
def testOptimizerWithCallbacks(self, distribution):
with self.cached_session():
with distribution.scope():
model = get_model()
@ -1304,8 +1257,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
dataset = get_dataset(distribution)
@ -1363,10 +1315,9 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(
combinations.times(
tpu_strategy_combinations_graph_only(),
combinations.combine(experimental_run_tf_function=[True, False])))
tpu_strategy_combinations_graph_only()))
def test_predict_with_dataset_with_partial_batch(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
optimizer = gradient_descent.GradientDescentOptimizer(0.001)
loss = 'mse'
@ -1375,8 +1326,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model_with_ds_strategy = get_model()
model_with_ds_strategy.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
cpu_model = get_model()
cpu_model.compile(optimizer, loss)
@ -1397,10 +1347,9 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(
combinations.times(
tpu_strategy_combinations_graph_only(),
combinations.combine(experimental_run_tf_function=[True, False])))
tpu_strategy_combinations_graph_only()))
def test_predict_multi_output_model_with_dataset_with_partial_batch(
self, distribution, experimental_run_tf_function):
self, distribution):
with self.cached_session():
optimizer = gradient_descent.GradientDescentOptimizer(0.001)
loss = 'mse'
@ -1409,8 +1358,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
model_with_ds_strategy = simple_multi_inputs_multi_outputs_model()
model_with_ds_strategy.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
cpu_model = simple_multi_inputs_multi_outputs_model()
cpu_model.compile(optimizer, loss)
@ -1490,18 +1438,15 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
@combinations.generate(
combinations.combine(
distribution=strategies_minus_tpu,
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def test_dataset_with_sample_weights(self, distribution,
experimental_run_tf_function):
mode=['graph', 'eager']))
def test_dataset_with_sample_weights(self, distribution):
with self.cached_session(), distribution.scope():
model = get_sample_weights_model()
optimizer = rmsprop.RMSPropOptimizer(learning_rate=0.001)
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
inputs = np.array([[0], [1], [2], [3]], np.float32)
targets = np.array([[2], [4], [6], [8]], np.float32)
@ -1553,9 +1498,8 @@ class TestRegularizerLoss(test.TestCase, parameterized.TestCase):
@combinations.generate(
combinations.times(
strategy_combinations.all_strategy_combinations_minus_default(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_regularizer_loss(self, distribution, experimental_run_tf_function):
strategy_combinations.all_strategy_combinations_minus_default()))
def test_regularizer_loss(self, distribution):
batch_size = 2
if not distributed_training_utils.global_batch_size_supported(distribution):
batch_size //= distribution.num_replicas_in_sync
@ -1576,8 +1520,7 @@ class TestRegularizerLoss(test.TestCase, parameterized.TestCase):
opt = gradient_descent_keras.SGD(1.)
model.compile(
opt,
loss=TestRegularizerLoss.loss_fn,
experimental_run_tf_function=experimental_run_tf_function)
loss=TestRegularizerLoss.loss_fn)
model.fit(
x=np.array([[1.], [1.]], dtype=np.float32),
y=np.array([[1.], [1.]], dtype=np.float32),
@ -1591,7 +1534,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_distribution_strategy_on_sequential_model(
self, distribution, experimental_run_tf_function):
self, distribution):
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
optimizer = optimizer_fn(learning_rate=0.001)
@ -1599,8 +1542,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
inputs = np.zeros((20, 10), np.float32)
targets = np.zeros((20, 2), np.float32)
@ -1611,7 +1553,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(all_strategy_combinations_plus_run_distributed())
def test_distribution_strategy_on_functional_model(
self, distribution, experimental_run_tf_function):
self, distribution):
with distribution.scope():
optimizer_fn = gradient_descent_keras.SGD
optimizer = optimizer_fn(learning_rate=0.001)
@ -1619,8 +1561,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
loss = 'mse'
model.compile(
optimizer,
loss,
experimental_run_tf_function=experimental_run_tf_function)
loss)
inputs = np.zeros((64, 3), dtype=np.float32)
targets = np.zeros((64, 4), dtype=np.float32)
@ -1631,10 +1572,8 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
combinations.times(
all_strategy_combinations_minus_default(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_distribution_strategy_one_dimensional(self, distribution,
experimental_run_tf_function):
all_strategy_combinations_minus_default()))
def test_distribution_strategy_one_dimensional(self, distribution):
with distribution.scope():
inp = keras.layers.Input(shape=(10,))
out = keras.layers.Dense(3, activation='softmax')(inp)
@ -1642,8 +1581,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
model.compile(
optimizer='rmsprop',
loss='sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['sparse_categorical_accuracy'])
x = np.random.random((64, 10)).astype('float32')
y = np.random.randint(3, size=64)
@ -1657,14 +1595,13 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
strategy_combinations.mirrored_strategy_with_two_gpus
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False],
reduction=[
loss_reduction.ReductionV2.AUTO,
loss_reduction.ReductionV2.SUM_OVER_BATCH_SIZE,
loss_reduction.ReductionV2.SUM
]))
def test_distribution_strategy_with_loss_reduction_types(
self, distribution, experimental_run_tf_function, reduction):
self, distribution, reduction):
np.random.seed(_RANDOM_SEED)
def _get_model():
@ -1689,8 +1626,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
ds_model = _get_model()
ds_model.compile(
'sgd',
loss=keras.losses.MeanSquaredError(reduction=reduction),
experimental_run_tf_function=experimental_run_tf_function)
loss=keras.losses.MeanSquaredError(reduction=reduction))
ds_history = ds_model.fit(
dataset, steps_per_epoch=2, epochs=1, shuffle=False)
self.assertArrayNear(history.history['loss'], ds_history.history['loss'],
@ -1698,10 +1634,9 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
combinations.times(
all_strategy_combinations_minus_default(),
combinations.combine(experimental_run_tf_function=[True, False])))
all_strategy_combinations_minus_default()))
def test_distribution_strategy_with_symbolic_add_loss(
self, mode, distribution, experimental_run_tf_function):
self, mode, distribution):
def _make_model_with_add_loss():
inputs = keras.Input((10,))
@ -1722,7 +1657,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
with distribution.scope():
ds_model = _make_model_with_add_loss()
ds_model.compile(
'sgd', experimental_run_tf_function=experimental_run_tf_function)
'sgd')
ds_history = ds_model.fit(x, epochs=1)
self.assertAllClose(history.history, ds_history.history)
@ -1761,10 +1696,9 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
combinations.times(
all_strategy_minus_default_and_tpu_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
all_strategy_minus_default_and_tpu_combinations()))
def test_distribution_strategy_with_add_metric_in_call(
self, distribution, experimental_run_tf_function):
self, distribution):
class Bias(keras.layers.Layer):
@ -1799,8 +1733,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
self.assertLen(ds_model.metrics, 1)
ds_model.compile(
'sgd',
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
ds_history = ds_model.fit(
x, y, validation_data=(x, y), validation_steps=2, epochs=2)
# includes stateful loss metric in eager.
@ -1817,10 +1750,9 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
strategy_combinations.mirrored_strategy_with_two_gpus,
],
mode=['eager'],
experimental_run_tf_function=[False]))
mode=['eager']))
def test_distribution_strategy_with_add_metric_object(
self, distribution, experimental_run_tf_function):
self, distribution):
class Bias(keras.layers.Layer):
@ -1855,8 +1787,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
self.assertLen(ds_model.metrics, 1)
ds_model.compile(
'sgd',
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
ds_history = ds_model.fit(
x, y, validation_data=(x, y), validation_steps=2, epochs=2)
# includes stateful loss metric in eager.
@ -1868,10 +1799,9 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
# TODO(phillypham): Why does validation_steps > 1 not work on TPUs?
combinations.times(
all_strategy_minus_default_and_tpu_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
all_strategy_minus_default_and_tpu_combinations()))
def test_distribution_strategy_with_add_metric_outside_call(
self, distribution, experimental_run_tf_function):
self, distribution):
def _make_model_with_add_metric():
inputs = keras.Input((10,))
@ -1897,8 +1827,7 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
self.assertLen(ds_model.metrics, 1)
ds_model.compile(
'sgd',
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
ds_history = ds_model.fit(
x, y, validation_data=(x, y), validation_steps=2, epochs=2)
# includes stateful loss metric in eager.
@ -1910,10 +1839,8 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
combinations.combine(
distribution=strategies_minus_tpu,
mode=['eager'],
experimental_run_tf_function=[True]))
def test_sparse_tensor_outputs(self, distribution,
experimental_run_tf_function):
mode=['eager']))
def test_sparse_tensor_outputs(self, distribution):
class ToSparse(keras.layers.Layer):
"""Create a sparse tensor based on a given dense tensor."""
@ -1925,7 +1852,6 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
return sparse_tensor.SparseTensor(indices, values, dense_shape=shape)
model = keras.Sequential([ToSparse()])
model._experimental_run_tf_function = experimental_run_tf_function
# Define some input data with additional padding.
input_data = np.array([[1, 0, 0], [2, 3, 0]])
@ -1942,10 +1868,8 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
@combinations.generate(
combinations.combine(
distribution=strategies_minus_tpu,
mode=['eager'],
experimental_run_tf_function=[True]))
def test_ragged_tensor_outputs(self, distribution,
experimental_run_tf_function):
mode=['eager']))
def test_ragged_tensor_outputs(self, distribution):
class ToRagged(keras.layers.Layer):
"""Create a ragged tensor based on a given dense tensor."""
@ -1960,7 +1884,6 @@ class TestDistributionStrategyWithKerasModels(test.TestCase,
inputs, padding=self._padding, ragged_rank=self._ragged_rank)
model = keras.Sequential([ToRagged(padding=0)])
model._experimental_run_tf_function = experimental_run_tf_function
# Define some input data with additional padding.
input_data = np.array([[1, 0, 0], [2, 3, 0]])

View File

@ -67,8 +67,7 @@ def graph_mode_test_configuration():
def all_strategy_and_input_config_combinations():
return (combinations.times(
combinations.combine(
distribution=all_strategies,
experimental_run_tf_function=[True, False]),
distribution=all_strategies),
eager_mode_test_configuration() + graph_mode_test_configuration()))
@ -100,12 +99,10 @@ def test_combinations_for_embedding_model():
return (combinations.times(
combinations.combine(
distribution=strategies_for_embedding_models(),
experimental_run_tf_function=[True, False]),
distribution=strategies_for_embedding_models()),
(graph_mode_test_configuration())) + combinations.times(
combinations.combine(
distribution=eager_mode_strategies,
experimental_run_tf_function=[False]),
distribution=eager_mode_strategies),
(eager_mode_test_configuration())))
@ -249,13 +246,11 @@ def get_correctness_test_inputs(use_numpy, use_validation_data,
def fit_eval_and_predict(initial_weights,
input_fn,
model_fn,
experimental_run_tf_function=None,
distribution=None,
is_stateful_model=False):
"""Generates results for fit/predict/evaluate for given model."""
training_inputs, eval_inputs, predict_inputs = input_fn()
model = model_fn(
experimental_run_tf_function=experimental_run_tf_function,
initial_weights=initial_weights,
distribution=distribution,
input_shapes=get_shapes(training_inputs['x']))
@ -426,7 +421,6 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
def get_model(self,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
raise NotImplementedError
@ -434,7 +428,6 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
distribution,
use_numpy,
use_validation_data,
experimental_run_tf_function=None,
with_batch_norm=None,
is_stateful_model=False,
partial_last_batch=None,
@ -457,7 +450,6 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
# This is used to initialize the model for both the distribution and
# non-distribution run.
model = self.get_model(
experimental_run_tf_function=experimental_run_tf_function,
input_shapes=get_shapes(x_train))
initial_weights = model.get_weights()
@ -489,14 +481,12 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
initial_weights,
input_fn=ds_input_fn,
model_fn=self.get_model,
experimental_run_tf_function=experimental_run_tf_function,
distribution=distribution,
is_stateful_model=is_stateful_model)
results_without_ds = fit_eval_and_predict(
initial_weights,
input_fn=nods_input_fn,
model_fn=self.get_model,
experimental_run_tf_function=experimental_run_tf_function,
distribution=None,
is_stateful_model=is_stateful_model)
@ -538,14 +528,12 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
return training_input, None, None
def run_dynamic_lr_test(self,
distribution,
experimental_run_tf_function=None):
distribution):
with self.cached_session():
self.set_up_test_config()
x_train, y_train, _ = self.get_data()
model = self.get_model(
experimental_run_tf_function=experimental_run_tf_function,
input_shapes=get_shapes(x_train))
initial_weights = model.get_weights()
update_freq = None
@ -587,13 +575,11 @@ class TestDistributionStrategyCorrectnessBase(test.TestCase,
initial_weights,
input_fn=ds_input_fn,
model_fn=self.get_model,
experimental_run_tf_function=experimental_run_tf_function,
distribution=distribution)
results_without_ds = fit_eval_and_predict(
initial_weights,
input_fn=nods_input_fn,
model_fn=self.get_model,
experimental_run_tf_function=experimental_run_tf_function,
distribution=None)
compare_results(
results_with_ds, results_without_ds, distribution, testcase=self)

View File

@ -33,15 +33,13 @@ from tensorflow.python.training import gradient_descent
def all_strategy_combinations_with_eager_and_graph_modes():
return (combinations.combine(
distribution=keras_correctness_test_base.all_strategies,
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
mode=['graph', 'eager']))
def all_strategy_combinations_with_graph_mode():
return (combinations.combine(
distribution=keras_correctness_test_base.all_strategies,
mode=['graph'],
experimental_run_tf_function=[True, False]))
mode=['graph']))
def is_default_strategy(strategy):
@ -53,7 +51,6 @@ class TestDistributionStrategyDnnCorrectness(
keras_correctness_test_base.TestDistributionStrategyCorrectnessBase):
def get_model(self,
experimental_run_tf_function,
initial_weights=None,
distribution=None,
input_shapes=None):
@ -75,8 +72,7 @@ class TestDistributionStrategyDnnCorrectness(
model.compile(
loss=keras.losses.mean_squared_error,
optimizer=gradient_descent_keras.SGD(0.05),
metrics=['mse'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mse'])
return model
def get_data(self):
@ -103,10 +99,8 @@ class TestDistributionStrategyDnnCorrectness(
@combinations.generate(
keras_correctness_test_base.all_strategy_and_input_config_combinations())
def test_dnn_correctness(self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
def test_dnn_correctness(self, distribution, use_numpy, use_validation_data):
self.run_correctness_test(distribution, use_numpy, use_validation_data)
@combinations.generate(
keras_correctness_test_base.test_combinations_with_tpu_strategies())
@ -131,16 +125,14 @@ class TestDistributionStrategyDnnCorrectness(
training_epochs=1)
@combinations.generate(all_strategy_combinations_with_graph_mode())
def test_dnn_with_dynamic_learning_rate(self, distribution,
experimental_run_tf_function):
self.run_dynamic_lr_test(distribution, experimental_run_tf_function)
def test_dnn_with_dynamic_learning_rate(self, distribution):
self.run_dynamic_lr_test(distribution)
class TestDistributionStrategyDnnMetricCorrectness(
keras_correctness_test_base.TestDistributionStrategyCorrectnessBase):
def get_model(self,
experimental_run_tf_function,
distribution=None,
input_shapes=None):
with distribution.scope():
@ -150,18 +142,16 @@ class TestDistributionStrategyDnnMetricCorrectness(
model.compile(
loss=keras.losses.mean_squared_error,
optimizer=gradient_descent_keras.SGD(0.05),
metrics=[keras.metrics.BinaryAccuracy()],
experimental_run_tf_function=experimental_run_tf_function)
metrics=[keras.metrics.BinaryAccuracy()])
return model
def run_metric_correctness_test(self, distribution,
experimental_run_tf_function):
def run_metric_correctness_test(self, distribution):
with self.cached_session():
self.set_up_test_config()
x_train, y_train, _ = self.get_data()
model = self.get_model(
experimental_run_tf_function, distribution=distribution)
distribution=distribution)
batch_size = 64
batch_size = (
@ -174,16 +164,14 @@ class TestDistributionStrategyDnnMetricCorrectness(
self.assertEqual(history.history['binary_accuracy'], [1.0, 1.0])
@combinations.generate(all_strategy_combinations_with_eager_and_graph_modes())
def test_simple_dnn_metric_correctness(self, distribution,
experimental_run_tf_function):
self.run_metric_correctness_test(distribution, experimental_run_tf_function)
def test_simple_dnn_metric_correctness(self, distribution):
self.run_metric_correctness_test(distribution)
class TestDistributionStrategyDnnMetricEvalCorrectness(
keras_correctness_test_base.TestDistributionStrategyCorrectnessBase):
def get_model(self,
experimental_run_tf_function,
distribution=None,
input_shapes=None):
with distribution.scope():
@ -197,17 +185,15 @@ class TestDistributionStrategyDnnMetricEvalCorrectness(
model.compile(
loss='mae',
metrics=['accuracy', keras.metrics.BinaryAccuracy()],
optimizer=gradient_descent.GradientDescentOptimizer(0.001),
experimental_run_tf_function=experimental_run_tf_function)
optimizer=gradient_descent.GradientDescentOptimizer(0.001))
return model
def run_eval_metrics_correctness_test(self, distribution,
experimental_run_tf_function):
def run_eval_metrics_correctness_test(self, distribution):
with self.cached_session():
self.set_up_test_config()
model = self.get_model(
experimental_run_tf_function, distribution=distribution)
distribution=distribution)
# verify correctness of stateful and stateless metrics.
x = np.ones((100, 4)).astype('float32')
@ -226,10 +212,8 @@ class TestDistributionStrategyDnnMetricEvalCorrectness(
self.assertEqual(outs[2], 0.)
@combinations.generate(all_strategy_combinations_with_eager_and_graph_modes())
def test_identity_model_metric_eval_correctness(self, distribution,
experimental_run_tf_function):
self.run_eval_metrics_correctness_test(distribution,
experimental_run_tf_function)
def test_identity_model_metric_eval_correctness(self, distribution):
self.run_eval_metrics_correctness_test(distribution)
class SubclassedModel(keras.Model):
@ -260,7 +244,6 @@ class TestDistributionStrategyDnnCorrectnessWithSubclassedModel(
TestDistributionStrategyDnnCorrectness):
def get_model(self,
experimental_run_tf_function,
initial_weights=None,
distribution=None,
input_shapes=None):
@ -270,53 +253,46 @@ class TestDistributionStrategyDnnCorrectnessWithSubclassedModel(
model.compile(
loss=keras.losses.mean_squared_error,
optimizer=gradient_descent_keras.SGD(0.05),
metrics=['mse'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mse'])
return model
@combinations.generate(
keras_correctness_test_base.all_strategy_and_input_config_combinations())
def test_dnn_correctness(self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
def test_dnn_correctness(self, distribution, use_numpy, use_validation_data):
if (context.executing_eagerly()) or is_default_strategy(distribution):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
elif K.is_tpu_strategy(distribution) and not context.executing_eagerly():
with self.assertRaisesRegexp(
ValueError,
'Expected `model` argument to be a functional `Model` instance, '
'but got a subclass model instead.'):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
else:
with self.assertRaisesRegexp(
ValueError,
'We currently do not support distribution strategy with a '
'`Sequential` model that is created without `input_shape`/'
'`input_dim` set in its first layer or a subclassed model.'):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
@combinations.generate(all_strategy_combinations_with_graph_mode())
def test_dnn_with_dynamic_learning_rate(self, distribution,
experimental_run_tf_function):
if ((not experimental_run_tf_function and context.executing_eagerly() and
not K.is_tpu_strategy(distribution)) or
def test_dnn_with_dynamic_learning_rate(self, distribution):
if ((context.executing_eagerly() and not K.is_tpu_strategy(distribution)) or
is_default_strategy(distribution)):
self.run_dynamic_lr_test(distribution, experimental_run_tf_function)
self.run_dynamic_lr_test(distribution)
elif K.is_tpu_strategy(distribution):
with self.assertRaisesRegexp(
ValueError,
'Expected `model` argument to be a functional `Model` instance, '
'but got a subclass model instead.'):
self.run_dynamic_lr_test(distribution, experimental_run_tf_function)
self.run_dynamic_lr_test(distribution)
else:
with self.assertRaisesRegexp(
ValueError,
'We currently do not support distribution strategy with a '
'`Sequential` model that is created without `input_shape`/'
'`input_dim` set in its first layer or a subclassed model.'):
self.run_dynamic_lr_test(distribution, experimental_run_tf_function)
self.run_dynamic_lr_test(distribution)
@combinations.generate(
keras_correctness_test_base.test_combinations_with_tpu_strategies())

View File

@ -33,7 +33,6 @@ class DistributionStrategyEmbeddingModelCorrectnessTest(
max_words=10,
initial_weights=None,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
del input_shapes
with keras_correctness_test_base.MaybeDistributionScope(distribution):
@ -53,28 +52,23 @@ class DistributionStrategyEmbeddingModelCorrectnessTest(
model.compile(
optimizer=gradient_descent_keras.SGD(learning_rate=0.1),
loss='sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['sparse_categorical_accuracy'])
return model
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
def test_embedding_model_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
use_validation_data):
self.use_distributed_dense = False
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
def test_embedding_time_distributed_model_correctness(
self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
self, distribution, use_numpy, use_validation_data):
self.use_distributed_dense = True
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
@ -85,7 +79,6 @@ class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
max_words=10,
initial_weights=None,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
del input_shapes
with keras_correctness_test_base.MaybeDistributionScope(distribution):
@ -119,7 +112,6 @@ class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
model.compile(
optimizer=gradient_descent_keras.SGD(learning_rate=0.1),
loss='mse',
experimental_run_tf_function=experimental_run_tf_function,
metrics=['mse'])
return model
@ -156,10 +148,8 @@ class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
def test_siamese_embedding_model_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
use_validation_data):
self.run_correctness_test(distribution, use_numpy, use_validation_data)
if __name__ == '__main__':

View File

@ -32,7 +32,6 @@ class DistributionStrategyCnnCorrectnessTest(
def get_model(self,
initial_weights=None,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
del input_shapes
with keras_correctness_test_base.MaybeDistributionScope(distribution):
@ -60,8 +59,7 @@ class DistributionStrategyCnnCorrectnessTest(
model.compile(
optimizer=gradient_descent.SGD(learning_rate=0.1),
loss='sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['sparse_categorical_accuracy'])
return model
@ -95,38 +93,32 @@ class DistributionStrategyCnnCorrectnessTest(
@combinations.generate(
keras_correctness_test_base.all_strategy_and_input_config_combinations())
def test_cnn_correctness(self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
def test_cnn_correctness(self, distribution, use_numpy, use_validation_data):
self.run_correctness_test(distribution, use_numpy, use_validation_data)
@combinations.generate(
keras_correctness_test_base.all_strategy_and_input_config_combinations())
def test_cnn_with_batch_norm_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
use_validation_data):
self.skipTest('Flakily times out, b/134670856')
self.run_correctness_test(
distribution,
use_numpy,
use_validation_data,
with_batch_norm='regular',
experimental_run_tf_function=experimental_run_tf_function)
with_batch_norm='regular')
@combinations.generate(
keras_correctness_test_base.all_strategy_and_input_config_combinations())
def test_cnn_with_sync_batch_norm_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
if not context.executing_eagerly() or not experimental_run_tf_function:
use_validation_data):
if not context.executing_eagerly():
self.skipTest('SyncBatchNorm is not enabled in graph mode.')
self.run_correctness_test(
distribution,
use_numpy,
use_validation_data,
with_batch_norm='sync',
experimental_run_tf_function=experimental_run_tf_function)
with_batch_norm='sync')
@combinations.generate(
keras_correctness_test_base.test_combinations_with_tpu_strategies() +

View File

@ -107,10 +107,8 @@ class MirroredStrategyOptimizerV2Test(test.TestCase, parameterized.TestCase):
distribution=[
strategy_combinations.central_storage_strategy_with_two_gpus,
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def testOptimizerWithKerasModelAndNumpyArrays(self, distribution,
experimental_run_tf_function):
mode=['graph', 'eager']))
def testOptimizerWithKerasModelAndNumpyArrays(self, distribution):
self.skipTest('b/130309197')
with self.cached_session():
with distribution.scope():
@ -121,8 +119,7 @@ class MirroredStrategyOptimizerV2Test(test.TestCase, parameterized.TestCase):
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
inputs = np.zeros((64, 3), dtype=np.float32)
targets = np.zeros((64, 4), dtype=np.float32)

View File

@ -64,7 +64,7 @@ class KerasPremadeModelsTest(test.TestCase, parameterized.TestCase):
with distribution.scope():
model = linear.LinearModel()
opt = gradient_descent.SGD(learning_rate=0.1)
model.compile(opt, 'mse', experimental_run_tf_function=True)
model.compile(opt, 'mse')
if data_fn == get_numpy:
inputs, output = get_numpy()
hist = model.fit(inputs, output, epochs=5)
@ -82,8 +82,7 @@ class KerasPremadeModelsTest(test.TestCase, parameterized.TestCase):
dnn_opt = adagrad.Adagrad(learning_rate=0.1)
wide_deep_model.compile(
optimizer=[linear_opt, dnn_opt],
loss='mse',
experimental_run_tf_function=True)
loss='mse')
if data_fn == get_numpy:
inputs, output = get_numpy()
hist = wide_deep_model.fit(inputs, output, epochs=5)

View File

@ -43,7 +43,6 @@ class _DistributionStrategyRnnModelCorrectnessTest(
max_words=10,
initial_weights=None,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
del input_shapes
rnn_cls = self._get_layer_class()
@ -66,8 +65,7 @@ class _DistributionStrategyRnnModelCorrectnessTest(
model.compile(
optimizer=optimizer_fn(learning_rate=0.1),
loss='sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['sparse_categorical_accuracy'])
return model
@ -85,11 +83,9 @@ class DistributionStrategyGruModelCorrectnessTest(
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
def test_gru_model_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
use_validation_data):
self.skipTest('Test is sensitive to TF random seed, b/TBD')
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
class DistributionStrategyLstmModelCorrectnessTest(
@ -106,17 +102,14 @@ class DistributionStrategyLstmModelCorrectnessTest(
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
def test_lstm_model_correctness(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
use_validation_data):
self.run_correctness_test(distribution, use_numpy, use_validation_data)
@combinations.generate(
keras_correctness_test_base.test_combinations_for_embedding_model())
@testing_utils.enable_v2_dtype_behavior
def test_lstm_model_correctness_mixed_precision(self, distribution, use_numpy,
use_validation_data,
experimental_run_tf_function):
use_validation_data):
if isinstance(distribution,
(tpu_strategy.TPUStrategy, tpu_strategy.TPUStrategyV1)):
policy_name = 'mixed_bfloat16'
@ -124,8 +117,7 @@ class DistributionStrategyLstmModelCorrectnessTest(
policy_name = 'mixed_float16'
with policy.policy_scope(policy_name):
self.run_correctness_test(distribution, use_numpy, use_validation_data,
experimental_run_tf_function)
self.run_correctness_test(distribution, use_numpy, use_validation_data)
if __name__ == '__main__':

View File

@ -40,8 +40,7 @@ def test_combinations_for_stateful_embedding_model():
distribution=strategies_for_stateful_embedding_model(),
mode='graph',
use_numpy=False,
use_validation_data=False,
experimental_run_tf_function=[True, False]))
use_validation_data=False))
class DistributionStrategyStatefulLstmModelCorrectnessTest(
@ -52,7 +51,6 @@ class DistributionStrategyStatefulLstmModelCorrectnessTest(
max_words=10,
initial_weights=None,
distribution=None,
experimental_run_tf_function=None,
input_shapes=None):
del input_shapes
batch_size = keras_correctness_test_base._GLOBAL_BATCH_SIZE
@ -86,22 +84,18 @@ class DistributionStrategyStatefulLstmModelCorrectnessTest(
# doesn't work and enable for DistributionStrategy more generally.
@combinations.generate(test_combinations_for_stateful_embedding_model())
def disabled_test_stateful_lstm_model_correctness(
self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
self, distribution, use_numpy, use_validation_data):
self.run_correctness_test(
distribution,
use_numpy,
use_validation_data,
is_stateful_model=True,
experimental_run_tf_function=experimental_run_tf_function)
is_stateful_model=True)
@combinations.generate(
combinations.times(
keras_correctness_test_base.test_combinations_with_tpu_strategies(),
combinations.combine(experimental_run_tf_function=[True, False])))
keras_correctness_test_base.test_combinations_with_tpu_strategies()))
def test_incorrectly_use_multiple_cores_for_stateful_lstm_model(
self, distribution, use_numpy, use_validation_data,
experimental_run_tf_function):
self, distribution, use_numpy, use_validation_data):
with self.assertRaisesRegexp(
ValueError,
'RNNs with stateful=True not yet supported with '
@ -110,8 +104,7 @@ class DistributionStrategyStatefulLstmModelCorrectnessTest(
distribution,
use_numpy,
use_validation_data,
is_stateful_model=True,
experimental_run_tf_function=experimental_run_tf_function)
is_stateful_model=True)
if __name__ == '__main__':

View File

@ -74,16 +74,14 @@ class TestDistributionStrategyWithCallbacks(test.TestCase,
@combinations.generate(
combinations.times(
keras_test_lib.all_strategy_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_callbacks_in_fit(self, distribution, experimental_run_tf_function):
keras_test_lib.all_strategy_combinations()))
def test_callbacks_in_fit(self, distribution):
with distribution.scope():
model = keras_test_lib.get_model()
model.compile(
optimizer='sgd',
loss='mse',
metrics=['mae'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mae'])
dataset = keras_test_lib.get_dataset(distribution)
counter = Counter()
@ -130,16 +128,14 @@ class TestDistributionStrategyWithCallbacks(test.TestCase,
@combinations.generate(
combinations.times(
keras_test_lib.all_strategy_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_callbacks_in_eval(self, distribution, experimental_run_tf_function):
keras_test_lib.all_strategy_combinations()))
def test_callbacks_in_eval(self, distribution):
with distribution.scope():
model = keras_test_lib.get_model()
model.compile(
optimizer='sgd',
loss='mse',
metrics=['mae'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mae'])
dataset = keras_test_lib.get_dataset(distribution)
counter = Counter()
@ -156,17 +152,14 @@ class TestDistributionStrategyWithCallbacks(test.TestCase,
@combinations.generate(
combinations.times(
keras_test_lib.all_strategy_combinations(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_callbacks_in_predict(self, distribution,
experimental_run_tf_function):
keras_test_lib.all_strategy_combinations()))
def test_callbacks_in_predict(self, distribution):
with distribution.scope():
model = keras_test_lib.get_model()
model.compile(
optimizer='sgd',
loss='mse',
metrics=['mae'],
experimental_run_tf_function=experimental_run_tf_function)
metrics=['mae'])
dataset = keras_test_lib.get_dataset(distribution)
counter = Counter()
@ -240,10 +233,8 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
distribution=[
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
def test_unsupported_features(self, distribution,
experimental_run_tf_function, mode):
mode=['graph', 'eager']))
def test_unsupported_features(self, distribution, mode):
with self.cached_session():
with distribution.scope():
model = keras_test_lib.get_model()
@ -253,8 +244,7 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
dataset = keras_test_lib.get_dataset(distribution)
# Test with validation split
@ -294,10 +284,9 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
strategy_combinations.one_device_strategy,
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
mode=['graph', 'eager']))
def test_distribution_strategy_on_subclassed_model(
self, distribution, experimental_run_tf_function):
self, distribution):
with distribution.scope():
class _SimpleMLP(keras.Model):
@ -318,10 +307,10 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
'`Sequential` model that is created without `input_shape`/'
'`input_dim` set in its first layer or a subclassed model.'):
model.compile(
'sgd', experimental_run_tf_function=experimental_run_tf_function)
'sgd')
else:
model.compile(
'sgd', experimental_run_tf_function=experimental_run_tf_function)
'sgd')
@combinations.generate(
combinations.combine(
@ -329,10 +318,9 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
strategy_combinations.one_device_strategy,
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False]))
mode=['graph', 'eager']))
def test_distribution_strategy_on_deferred_sequential_model(
self, distribution, experimental_run_tf_function):
self, distribution):
with distribution.scope():
model = keras.models.Sequential()
model.add(keras.layers.Dense(16, activation='relu'))
@ -340,7 +328,7 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
if context.executing_eagerly():
model.compile(
'sgd', experimental_run_tf_function=experimental_run_tf_function)
'sgd')
else:
with self.assertRaisesRegexp(
ValueError,
@ -349,7 +337,7 @@ class TestDistributionStrategyErrorCases(test.TestCase, parameterized.TestCase):
'`input_shape`/`input_dim` set in its first layer or '
'a subclassed model.'):
model.compile(
'sgd', experimental_run_tf_function=experimental_run_tf_function)
'sgd')
@combinations.generate(
keras_test_lib.all_strategy_combinations_minus_default())
@ -375,10 +363,9 @@ class TestDistributionStrategyWithLossMasking(test.TestCase,
strategy_combinations.mirrored_strategy_with_gpu_and_cpu,
],
mode=['graph', 'eager'],
experimental_run_tf_function=[True, False],
optimizer=strategy_combinations.gradient_descent_optimizer_keras_v2_fn
))
def test_masking(self, distribution, experimental_run_tf_function, optimizer):
def test_masking(self, distribution, optimizer):
with self.cached_session():
np.random.seed(1337)
x = np.array([[[1], [1]], [[0], [0]]])
@ -390,8 +377,7 @@ class TestDistributionStrategyWithLossMasking(test.TestCase,
keras.layers.Dense(1, kernel_initializer='one')))
model.compile(
loss='mse',
optimizer=optimizer(),
experimental_run_tf_function=experimental_run_tf_function)
optimizer=optimizer())
y = np.array([[[1], [1]], [[1], [1]]])
dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
dataset = dataset.repeat(100)
@ -408,11 +394,9 @@ class TestDistributionStrategyWithNormalizationLayer(test.TestCase,
keras_test_lib.all_strategy_combinations(),
combinations.combine(
fused=[True, False],
experimental_run_tf_function=[True, False],
optimizer=strategy_combinations
.gradient_descent_optimizer_keras_v2_fn)))
def test_batchnorm_correctness(self, distribution, fused, optimizer,
experimental_run_tf_function):
def test_batchnorm_correctness(self, distribution, fused, optimizer):
with self.cached_session():
with distribution.scope():
model = keras.models.Sequential()
@ -425,8 +409,7 @@ class TestDistributionStrategyWithNormalizationLayer(test.TestCase,
model.add(norm)
model.compile(
loss='mse',
optimizer=optimizer(),
experimental_run_tf_function=experimental_run_tf_function)
optimizer=optimizer())
# centered on 5.0, variance 10.0
x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 10, 20, 30))
@ -455,18 +438,15 @@ class TestDistributionStrategySaveLoadWeights(test.TestCase,
combinations.times(
keras_test_lib.all_strategy_combinations_minus_default(),
combinations.combine(
experimental_run_tf_function=[True, False],
optimizer=strategy_combinations.rmsprop_optimizer_keras_v2_fn)))
def test_save_load_h5(self, distribution, optimizer,
experimental_run_tf_function):
def test_save_load_h5(self, distribution, optimizer):
with self.cached_session():
dataset = keras_test_lib.get_dataset(distribution)
with distribution.scope():
model = keras_test_lib.get_model()
model.compile(
optimizer(),
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
model.fit(dataset, epochs=1, steps_per_epoch=1)
weights_file = tempfile.mktemp('.h5')
@ -475,8 +455,7 @@ class TestDistributionStrategySaveLoadWeights(test.TestCase,
model_2 = keras_test_lib.get_model()
model_2.compile(
optimizer(),
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
model_2.load_weights(weights_file)
model_2.predict(
keras_test_lib.get_predict_dataset(distribution), steps=2)
@ -486,10 +465,8 @@ class TestDistributionStrategySaveLoadWeights(test.TestCase,
combinations.times(
keras_test_lib.all_strategy_combinations_minus_default(),
combinations.combine(
experimental_run_tf_function=[True, False],
optimizer=strategy_combinations.rmsprop_optimizer_keras_v2_fn)))
def test_save_load_trackable(self, distribution, optimizer,
experimental_run_tf_function):
def test_save_load_trackable(self, distribution, optimizer):
# TODO(b/123533246): Enable the test for TPU once bug is fixed
if (isinstance(distribution,
(tpu_strategy.TPUStrategy, tpu_strategy.TPUStrategyV1)) and
@ -501,8 +478,7 @@ class TestDistributionStrategySaveLoadWeights(test.TestCase,
model = keras_test_lib.get_model()
model.compile(
optimizer(),
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
model.fit(dataset, epochs=1, steps_per_epoch=1)
weights_file = tempfile.mktemp()
@ -511,8 +487,7 @@ class TestDistributionStrategySaveLoadWeights(test.TestCase,
model_2 = keras_test_lib.get_model()
model_2.compile(
optimizer(),
'mse',
experimental_run_tf_function=experimental_run_tf_function)
'mse')
model_2.load_weights(weights_file)
model_2.predict(
keras_test_lib.get_predict_dataset(distribution), steps=2)
@ -523,10 +498,8 @@ class TestDistributionStrategyValidation(test.TestCase, parameterized.TestCase):
@combinations.generate(
combinations.times(
keras_test_lib.all_strategy_combinations_minus_default(),
combinations.combine(experimental_run_tf_function=[True, False])))
def test_layer_outside_scope(self, distribution,
experimental_run_tf_function):
keras_test_lib.all_strategy_combinations_minus_default()))
def test_layer_outside_scope(self, distribution):
with self.cached_session():
with self.assertRaisesRegexp(
ValueError, 'was not created in the distribution strategy'):
@ -540,8 +513,7 @@ class TestDistributionStrategyValidation(test.TestCase, parameterized.TestCase):
model.compile(
optimizer,
loss,
metrics=metrics,
experimental_run_tf_function=experimental_run_tf_function)
metrics=metrics)
@combinations.generate(
keras_test_lib.all_strategy_combinations_minus_default())

View File

@ -314,8 +314,6 @@ class BaseLayerTest(keras_parameterized.TestCase):
def get_learning_phase_value():
model = keras.models.Sequential([LearningPhaseLayer(input_shape=(1,))])
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = (
testing_utils.should_run_tf_function())
return np.sum(model(np.ones((1, 1))))
self.assertEqual(get_learning_phase_value(), 0)
@ -413,8 +411,7 @@ class BaseLayerTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x, y = np.ones((10, 10)), np.ones((10, 10))
# Checks that variables get initialized.
model.fit(x, y, batch_size=2, epochs=2)
@ -466,8 +463,7 @@ class BaseLayerTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.random.random((3, 10))
out = model.predict(inputs)
self.assertAllClose(model.layers[-1].get_weights()[0], kernel_value)
@ -999,8 +995,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
train_loss = model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(train_loss, 0.)
test_loss = model.test_on_batch(np.ones((2, 3)), np.ones((2, 3)))
@ -1024,8 +1019,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
train_loss = model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(train_loss, 2 * 3)
test_loss = model.test_on_batch(np.ones((2, 3)), np.ones((2, 3)))
@ -1049,8 +1043,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
for _ in range(3):
_, train_metric = model.train_on_batch(np.ones((2, 3)),
np.ones((2, 3)))
@ -1083,8 +1076,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(keras.backend.get_value(layer.counter), 1.)
@ -1117,8 +1109,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(keras.backend.get_value(layer.counter), 6.)
else:
@ -1153,8 +1144,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(loss, 2 * 3)
else:
@ -1168,7 +1158,6 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
1, kernel_regularizer=keras.regularizers.l2(1e-4), input_shape=(1,))
])
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
def assert_graph(t):
if not context.executing_eagerly():
@ -1210,8 +1199,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(history.history['sum'][-1], 2 * 3)
else:
@ -1239,8 +1227,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -1273,8 +1260,7 @@ class AutographControlFlowTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 3, 4))
y = np.ones(shape=(10, 3, 2))

View File

@ -165,7 +165,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
layer.set_total(15)
@ -182,7 +181,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
self.assertAllEqual([[16], [17], [18]], model.predict([1., 2., 3.]))
@ -195,7 +193,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
layer.adapt(input_dataset)
@ -216,7 +213,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
self.assertAllEqual([[16], [17], [18]], model.predict([1., 2., 3.]))
@ -228,7 +224,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
combiner = layer._combiner
updates = combiner.extract(combiner.compute(input_dataset))
@ -248,7 +243,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
self.assertAllEqual([[16], [17], [18]], model.predict([1., 2., 3.]))
@ -262,7 +256,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
layer.adapt(input_dataset)
@ -280,7 +273,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
self.assertAllEqual([[16], [17], [18]], model.predict([1., 2., 3.]))
@ -298,7 +290,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
combiner = layer._combiner
updates = combiner.extract(combiner.compute(input_dataset))
@ -317,8 +308,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = (
testing_utils.should_run_tf_function())
return (model, layer)
input_dataset = np.array([1, 2, 3, 4, 5])
@ -344,8 +333,6 @@ class PreprocessingLayerTest(keras_parameterized.TestCase):
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = (
testing_utils.should_run_tf_function())
return (model, layer)
input_dataset = np.array([1, 2, 3, 4, 5])

View File

@ -60,8 +60,7 @@ class SimpleBiasTest(keras_parameterized.TestCase):
model.compile(
keras.optimizer_v2.gradient_descent.SGD(0.1),
'mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def test_simple_bias_fit(self):
@ -99,8 +98,7 @@ class MultipleInputTest(keras_parameterized.TestCase):
model.compile(
keras.optimizer_v2.gradient_descent.SGD(0.1),
'mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
@parameterized.named_parameters(('subclassed', True), ('functional', False))

View File

@ -60,8 +60,7 @@ class FeatureColumnsIntegrationTest(keras_parameterized.TestCase):
optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = {'a': np.random.random((10, 1))}
y = np.random.randint(20, size=(10, 1))
@ -83,8 +82,7 @@ class FeatureColumnsIntegrationTest(keras_parameterized.TestCase):
optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y = np.random.randint(20, size=(100, 1))
y = np_utils.to_categorical(y, num_classes=20)
@ -147,8 +145,7 @@ class FeatureColumnsIntegrationTest(keras_parameterized.TestCase):
optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = {'a': np.random.random((10, 1)), 'b': np.random.random((10, 1))}
y = np.random.randint(20, size=(10, 1))
@ -169,8 +166,7 @@ class FeatureColumnsIntegrationTest(keras_parameterized.TestCase):
optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y = np.random.randint(20, size=(100, 1))
y = np_utils.to_categorical(y, num_classes=20)

View File

@ -761,7 +761,6 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
output = a(b(a(b(x))))
m = keras.models.Model(x, output)
m.run_eagerly = testing_utils.should_run_eagerly()
m._experimental_run_tf_function = testing_utils.should_run_tf_function()
output_val = m.predict(x_val)
@ -789,7 +788,6 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
m = keras.models.Model(inputs=input_layer, outputs=output)
m.run_eagerly = testing_utils.should_run_eagerly()
m._experimental_run_tf_function = testing_utils.should_run_tf_function()
x_val = np.random.random((10, 16, 9, 3))
output_val = m.predict(x_val)
@ -818,8 +816,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.train_on_batch(x, y)
self.assertEqual(loss, 0) # In inference mode, output is equal to input.
@ -838,8 +835,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[np.ones((10, 5, 10)), np.zeros((10, 5))],
y=np.zeros((10, 100)),
@ -857,8 +853,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[np.ones((10, 5, 10)), np.zeros((10, 5))],
y=np.zeros((10, 100)),
@ -887,8 +882,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[3 * np.ones((10, 10)), 7 * np.ones((10, 10))],
y=10 * np.ones((10, 10)),
@ -902,8 +896,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[3 * np.ones((10, 10)), 7 * np.ones((10, 10))],
y=10 * np.ones((10, 10)),
@ -928,8 +921,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[3 * np.ones((10, 10)), 7 * np.ones((10, 10))],
y=10 * np.ones((10, 10)),
@ -942,8 +934,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[3 * np.ones((10, 10)), 7 * np.ones((10, 10))],
y=10 * np.ones((10, 10)),
@ -976,8 +967,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
input_data = [
ragged_factory_ops.constant([[3.0, 3.0], [3.0, 3.0], [3.0]]),
ragged_factory_ops.constant([[7.0, 7.0], [7.0, 7.0], [7.0]])
@ -993,8 +983,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x=input_data, y=expected_data)
# Check that second input was correctly added to first.
self.assertEqual(history.history['loss'][0], 0.0)
@ -1026,8 +1015,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[np.ones((10, 10)), 2 * np.ones((10, 10)), 3 * np.ones((10, 10))],
y=15 * np.ones((10, 10)),
@ -1040,8 +1028,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(
x=[np.ones((10, 10)), 2 * np.ones((10, 10)), 3 * np.ones((10, 10))],
y=15 * np.ones((10, 10)),
@ -1066,14 +1053,11 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
o = keras.layers.add(o)
model = keras.Model(i, o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
i2 = keras.layers.Input(shape=(3, 2, 1))
o2 = model(i2)
model2 = keras.Model(i2, o2)
model2.run_eagerly = testing_utils.should_run_eagerly()
model2._experimental_run_tf_function = testing_utils.should_run_tf_function(
)
x = np.random.random((4, 3, 2, 1))
out = model2.predict(x)
@ -1091,8 +1075,7 @@ class NetworkConstructionTest(keras_parameterized.TestCase):
loss='mse',
optimizer='sgd',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
json_str = model.to_json()
keras.models.model_from_json(json_str)
@ -1398,8 +1381,7 @@ class DefaultShapeInferenceBehaviorTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_input = np.random.randint(
low=1, high=5, size=(10, 3, 4)).astype('float32')
@ -1607,15 +1589,13 @@ class AddLossTest(keras_parameterized.TestCase):
x = np.ones((10, 10))
model.compile(
'sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, batch_size=2, epochs=1)
model2 = model.from_config(model.get_config())
model2.compile(
'sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model2.set_weights(initial_weights)
model2.fit(x, batch_size=2, epochs=1)
@ -1639,16 +1619,14 @@ class AddLossTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=1)
model2 = model.from_config(model.get_config())
model2.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model2.set_weights(initial_weights)
model2.fit(x, y, batch_size=2, epochs=1)

View File

@ -77,8 +77,7 @@ class TestSequential(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((batch_size, input_dim))
y = np.random.random((batch_size, num_classes))
model.fit(x, y, epochs=1)
@ -88,8 +87,7 @@ class TestSequential(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y = np.random.random((batch_size, num_hidden))
model.fit(x, y, epochs=1)
@ -117,8 +115,7 @@ class TestSequential(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=[keras.metrics.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(len(model.layers), 2)
with self.assertRaisesRegexp(
ValueError, 'Weights for model .* have not yet been created'):
@ -145,8 +142,7 @@ class TestSequential(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=[keras.metrics.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(len(model.layers), 2)
with self.assertRaisesRegexp(
ValueError, 'Weights for model .* have not yet been created'):
@ -276,8 +272,7 @@ class TestSequential(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=[keras.metrics.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertFalse(model.built)
x = np.random.random((batch_size, input_dim))
@ -291,8 +286,7 @@ class TestSequential(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=[keras.metrics.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((batch_size, input_dim))
y = np.random.random((batch_size, num_classes))
new_model.train_on_batch(x, y)
@ -331,8 +325,7 @@ class TestSequential(keras_parameterized.TestCase):
model.compile(
'rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((1, 2)), np.zeros((1, 5)))
@keras_parameterized.run_all_keras_modes
@ -344,8 +337,7 @@ class TestSequential(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((2, 6))
y = np.random.random((2, 5))
model.fit(x, y, epochs=1)
@ -376,7 +368,6 @@ class TestSequential(keras_parameterized.TestCase):
keras.layers.Lambda(lambda x: x[0])
])
seq.run_eagerly = testing_utils.should_run_eagerly()
seq._experimental_run_tf_function = testing_utils.should_run_tf_function()
preds = seq.predict([['tensorflow eager']])
self.assertEqual(preds.shape, (1,))
@ -458,8 +449,7 @@ class TestSequentialEagerIntegration(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((2, 6))
y = np.random.random((2, 5))
@ -472,8 +462,7 @@ class TestSequentialEagerIntegration(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.build((None, 6))

View File

@ -133,8 +133,7 @@ class PrintTrainingInfoTest(keras_parameterized.TestCase,
model.compile(
loss="mae",
optimizer="adam",
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
x={

View File

@ -63,8 +63,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
optimizer,
loss,
metrics=metrics,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((10, 3), np.float32)
targets = np.zeros((10, 4), np.float32)
@ -89,8 +88,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
optimizer,
loss,
metrics=metrics,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((10, 3), np.float32)
targets = np.zeros((10, 4), np.float32)
@ -151,8 +149,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
input_a_np = np.random.random((10, 3)).astype(dtype=np.float32)
input_b_np = np.random.random((10, 3)).astype(dtype=np.float32)
@ -200,8 +197,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
optimizer,
loss,
metrics=metrics,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((10, 3), np.float32)
targets = np.zeros((10, 4), np.float32)
@ -247,8 +243,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
optimizer,
loss='sparse_categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((10, 3), dtype=np.float32)
targets = np.random.randint(0, 4, size=10, dtype=np.int32)
@ -272,8 +267,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
'rmsprop',
loss='mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((40, 2), dtype=np.float32)
inputs[10:20, :] = 2
@ -344,8 +338,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((100, 3), dtype=np.float32)
targets = np.random.randint(0, 4, size=100, dtype=np.int32)
@ -368,8 +361,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((100, 3), dtype=np.float32)
targets = np.random.randint(0, 4, size=100, dtype=np.int32)
@ -408,8 +400,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((100, 3), dtype=np.float32)
targets = np.random.randint(0, 4, size=100, dtype=np.int32)
@ -445,8 +436,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((100, 3), dtype=np.float32)
targets = np.random.randint(0, 4, size=100, dtype=np.int32)
@ -501,8 +491,7 @@ class TestTrainingWithDataset(keras_parameterized.TestCase):
model = keras.Model(inp, out)
model.compile(
'rmsprop', loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.zeros((100, 4), dtype=np.float32)
targets = np.random.randint(0, 2, size=100, dtype=np.int32)
@ -551,8 +540,7 @@ class TestMetricsWithDatasets(keras_parameterized.TestCase):
loss='binary_crossentropy',
metrics=['accuracy', metrics_module.BinaryAccuracy()],
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np.random.seed(123)
x = np.random.randint(10, size=(100, 4)).astype(np.float32)

View File

@ -56,8 +56,7 @@ class TrainingTest(keras_parameterized.TestCase):
model = DynamicModel()
model.compile(
'rmsprop', 'mae',
run_eagerly=True,
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=True)
hist = model.fit(np.zeros((1, 1)), np.zeros((1, 1)))
self.assertEqual(hist.history['loss'][-1], 1)
self.assertEqual(len(model.trainable_weights), 2)
@ -93,7 +92,6 @@ class TrainingTest(keras_parameterized.TestCase):
metrics=metrics,
loss_weights=loss_weights,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function(),
sample_weight_mode=None)
input_a = array_ops.zeros(shape=(10, 3))
@ -163,8 +161,7 @@ class TrainingTest(keras_parameterized.TestCase):
optimizer,
loss,
metrics=metrics,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = array_ops.zeros(shape=(10, 3))
targets = array_ops.zeros(shape=(10, 4))
@ -251,8 +248,7 @@ class CorrectnessTest(keras_parameterized.TestCase):
model.compile(
loss='sparse_categorical_crossentropy',
optimizer=rmsprop.RMSprop(learning_rate=0.001, **optimizer_kwargs),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((100, 4))
np.random.seed(123)
y = np.random.randint(0, 1, size=(100, 1))
@ -273,8 +269,7 @@ class CorrectnessTest(keras_parameterized.TestCase):
model.compile(
loss='sparse_categorical_crossentropy',
optimizer=rmsprop.RMSprop(learning_rate=0.001, clipvalue=0.0),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((100, 4))
np.random.seed(123)
y = np.random.randint(0, 1, size=(100, 1))
@ -296,8 +291,7 @@ class CorrectnessTest(keras_parameterized.TestCase):
model.compile(
loss='sparse_categorical_crossentropy',
optimizer=rmsprop.RMSprop(learning_rate=0.001),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((100, 4), dtype=np.float32)
np.random.seed(123)
y = np.random.randint(0, 1, size=(100, 1))

View File

@ -139,8 +139,7 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
loss='mse',
optimizer=rmsprop.RMSprop(1e-3),
metrics=['mae', metrics_module.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.evaluate_generator(custom_generator_threads(),
steps=5,
@ -165,7 +164,6 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
model = testing_utils.get_small_mlp(
num_hidden=3, num_classes=4, input_dim=2)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model.predict_generator(custom_generator_threads(),
steps=5,
@ -204,8 +202,7 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
loss='mse',
optimizer=rmsprop.RMSprop(1e-3),
metrics=['mae', metrics_module.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit_generator(custom_generator(mode=3),
steps_per_epoch=5,
@ -242,8 +239,7 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=rmsprop.RMSprop(1e-3),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
with self.assertRaises(ValueError):
model.fit_generator(invalid_generator(),
@ -287,8 +283,7 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
model.compile(
rmsprop.RMSprop(0.001),
'binary_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
ones_generator(),
steps_per_epoch=2,
@ -303,8 +298,7 @@ class TestGeneratorMethods(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=rmsprop.RMSprop(1e-3),
metrics=['mae', metrics_module.CategoricalAccuracy()],
experimental_run_tf_function=testing_utils.should_run_tf_function())
metrics=['mae', metrics_module.CategoricalAccuracy()])
model.fit_generator(custom_generator_changing_batch_size(),
steps_per_epoch=5,
epochs=1,

View File

@ -150,7 +150,6 @@ class CoreLayerIntegrationTest(keras_parameterized.TestCase):
layer_kwargs):
batch_size = 2
run_eagerly = testing_utils.should_run_eagerly()
experimental_run_tf_function = testing_utils.should_run_tf_function()
def map_fn(_):
x = keras.backend.random_uniform(shape=data_shape)
@ -169,12 +168,10 @@ class CoreLayerIntegrationTest(keras_parameterized.TestCase):
layer = keras.layers.Dense(1, activation=None)(layer)
model = keras.models.Model(inp, layer)
model.compile(loss='mse', optimizer='sgd', run_eagerly=run_eagerly,
experimental_run_tf_function=experimental_run_tf_function)
model.compile(loss='mse', optimizer='sgd', run_eagerly=run_eagerly)
model.fit(dataset, verbose=2, epochs=2)
model.compile(loss='mse', optimizer='sgd', run_eagerly=run_eagerly,
experimental_run_tf_function=experimental_run_tf_function)
model.compile(loss='mse', optimizer='sgd', run_eagerly=run_eagerly)
model.fit(dataset.repeat(2), verbose=2, epochs=2, steps_per_epoch=2)
eval_dataset = dataset_ops.DatasetV2.range(4).map(map_fn).batch(batch_size)

View File

@ -75,8 +75,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
hist = model.fit(x=np.array([0.]), y=np.array([0.]))
self.assertAllClose(hist.history['loss'][0], 10000)
@ -94,8 +93,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
loss='mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.ones((40, 2), dtype=np.float32)
targets = np.ones((40, 1), dtype=np.float32)
@ -128,8 +126,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
loss='mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.ones((40, 2), dtype=np.float32)
targets = np.ones((40, 1), dtype=np.float32)
@ -163,8 +160,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
loss=loss_fn,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(inputs, targets)
model.test_on_batch(inputs, targets)
self.assertEqual(model.predict(inputs).dtype, np.float64)
@ -197,8 +193,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
loss='mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.ones((40, 2), dtype=np.float32)
targets = np.ones((40, 1), dtype=np.float32)
@ -237,8 +232,7 @@ class TrainingTest(keras_parameterized.TestCase):
loss,
metrics=[metrics_module.CategoricalAccuracy(), 'mae'],
loss_weights=loss_weights,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
input_a_np = np.random.random((10, 3))
input_b_np = np.random.random((10, 3))
@ -350,8 +344,7 @@ class TrainingTest(keras_parameterized.TestCase):
optimizer,
loss,
metrics=[metrics_module.CategoricalAccuracy(), 'mae'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
[input_a_np, input_b_np], [output_d_np, output_e_np],
epochs=1,
@ -371,8 +364,7 @@ class TrainingTest(keras_parameterized.TestCase):
loss,
metrics=metrics,
loss_weights=loss_weights,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
[input_a_np, input_b_np], [output_d_np, output_e_np],
epochs=1,
@ -386,8 +378,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
optimizer,
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# This will work
model.fit([input_a_np], output_d_np, epochs=1)
@ -397,8 +388,7 @@ class TrainingTest(keras_parameterized.TestCase):
# Test execution on inputs that are lists of scalars.
# TF2 and TF1 have slightly different semantics:
if (testing_utils.should_run_tf_function()
or testing_utils.should_run_eagerly()):
if context.executing_eagerly():
# In TF2 to avoid any ambiguity when there are nested lists
# the entire input gets converted to a
# single numpy array (& it only works in the case of a single io model)
@ -442,8 +432,7 @@ class TrainingTest(keras_parameterized.TestCase):
metrics=['mae', metrics_module.CategoricalAccuracy()],
loss_weights=loss_weights,
sample_weight_mode=None,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
input_a_np = np.random.random((10, 3))
input_b_np = np.random.random((10, 3))
@ -586,7 +575,7 @@ class TrainingTest(keras_parameterized.TestCase):
)
def test_sequence_input_types(self, input_type):
"""Ensure that namedtuples and tuples are plumbed identically."""
if not testing_utils.should_run_tf_function():
if not context.executing_eagerly():
self.skipTest('Improved checking is only present in data_adapter.')
xy_function, x_function = self._make_sequence_input_functions(input_type)
@ -600,8 +589,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(xy_function(use_namedtuple=False), **fit_kwargs)
model.evaluate(xy_function(use_namedtuple=False), **evaluate_kwargs)
@ -660,8 +648,7 @@ class TrainingTest(keras_parameterized.TestCase):
loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
@keras_parameterized.run_all_keras_modes
def test_that_trainable_disables_updates(self):
@ -679,8 +666,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
assert not model.updates
x1 = model.predict(val_a)
@ -692,8 +678,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
assert model.updates
model.train_on_batch(val_a, val_out)
@ -704,8 +689,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
assert not model.updates
x1 = model.predict(val_a)
@ -867,8 +851,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
RMSPropOptimizer(learning_rate=0.001),
loss='sparse_categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Test with Numpy data
x_train = np.random.random((10, 3, 4)).astype(np.float32)
y_train = np.random.randint(0, 5, size=(10, 3)).astype(np.float32)
@ -911,8 +894,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
RMSPropOptimizer(learning_rate=0.001),
loss='binary_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
with test.mock.patch.object(sys, 'stdout', mock_stdout):
model.fit(
np.ones((10, 10), 'float32'), np.ones((10, 1), 'float32'), epochs=10)
@ -1098,8 +1080,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
class ValCounter(keras.callbacks.Callback):
@ -1129,8 +1110,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
with self.assertRaisesRegexp(
ValueError, '`validation_steps` should not be specified if '
@ -1176,8 +1156,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((10, 10))
y = np.ones((10, 10))
@ -1193,8 +1172,7 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((10, 10)).astype(np.float64)
y = np.ones((10, 10)).astype(np.float64)
dataset = dataset_ops.Dataset.from_tensor_slices((x, y)).batch(2)
@ -1225,12 +1203,10 @@ class TrainingTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, x, epochs=1)
if (testing_utils.should_run_eagerly() or
testing_utils.should_run_tf_function()):
if context.executing_eagerly():
expected_training_arg = True
else:
expected_training_arg = keras.backend.symbolic_learning_phase()
@ -1321,8 +1297,7 @@ class TestExceptionsAndWarnings(keras_parameterized.TestCase):
'dense_2': 'categorical_accuracy',
'dense_1': metrics_module.CategoricalAccuracy(),
},
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
@keras_parameterized.run_with_all_model_types
@keras_parameterized.run_all_keras_modes
@ -1358,8 +1333,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
metrics=['acc', metrics_module.CategoricalAccuracy()],
weighted_metrics=['mae', metrics_module.CategoricalAccuracy()],
optimizer=RMSPropOptimizer(learning_rate=learning_rate),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np.random.seed(1337)
(x_train, y_train), (x_test, y_test) = testing_utils.get_test_data(
@ -1427,8 +1401,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
metrics=['acc', metrics_module.CategoricalAccuracy()],
weighted_metrics=['mae', metrics_module.CategoricalAccuracy()],
loss='categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np.random.seed(43)
(x_train, y_train), (x_test, y_test) = testing_utils.get_test_data(
@ -1539,8 +1512,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
metrics=['acc', metrics_module.CategoricalAccuracy()],
weighted_metrics=['mae', metrics_module.CategoricalAccuracy()],
sample_weight_mode='temporal',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
temporal_x_train,
@ -1587,8 +1559,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
model.compile(
optimizer='adam',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((10, 3))
y = np.random.random((10, 2))
@ -1622,8 +1593,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode=[None],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
# sample_weight_mode is a list and mode value is `temporal`
@ -1631,8 +1601,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode=['temporal'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
# sample_weight_mode is a dict and mode value is None
@ -1640,8 +1609,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode={'time_distributed': None},
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
# sample_weight_mode is a dict and mode value is `temporal`
@ -1649,8 +1617,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode={'time_distributed': 'temporal'},
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
# sample_weight_mode is a not a list/dict and mode value is None
@ -1658,8 +1625,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode=None,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
# sample_weight_mode is a not a list/dict and mode value is `temporal`
@ -1667,8 +1633,7 @@ class LossWeightingTest(keras_parameterized.TestCase):
optimizer,
loss='mse',
sample_weight_mode='temporal',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=10)
def test_sample_weight_tensor(self):
@ -1714,8 +1679,7 @@ class MaskingTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(learning_rate=0.001),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
@keras_parameterized.run_with_all_model_types
@ -1760,8 +1724,7 @@ class MaskingTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(learning_rate=0.001),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y = np.random.random((5, 3))
model.train_on_batch(x, y)
@ -1779,8 +1742,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.trainable = True
model.train_on_batch(x, y)
self.assertRaises(Warning)
@ -1795,8 +1757,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out = model.predict(x)
model.train_on_batch(x, y)
out_2 = model.predict(x)
@ -1809,8 +1770,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out = model.predict(x)
model.train_on_batch(x, y)
out_2 = model.predict(x)
@ -1927,8 +1887,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model1.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs2 = keras.Input(10)
outputs2 = shared_layer(inputs2)
@ -1937,8 +1896,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model2.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x, y = np.ones((10, 10)), np.ones((10, 10))
@ -1964,8 +1922,7 @@ class TestDynamicTrainability(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((10, 1))
y = 5 * x + 2
@ -2521,8 +2478,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
optimizer,
loss='mae',
metrics=metrics,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
mse_metric = 'mse' if context.executing_eagerly() else 'mean_squared_error'
reference_metric_names = [
@ -2552,8 +2508,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
loss='mae',
metrics=[acc_obj],
optimizer=RMSPropOptimizer(learning_rate=0.001),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x_train = np.random.random((100, 4))
y_train = np.random.random((100, 1))
@ -2586,8 +2541,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
loss='mse',
metrics=[keras.metrics.MeanSquaredError()],
weighted_metrics=[keras.metrics.MeanSquaredError()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# list of list of metrics.
model.compile(
@ -2603,8 +2557,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
[keras.metrics.MeanSquaredError(),
keras.metrics.Accuracy()]
],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# dict of metrics.
model.compile(
@ -2626,8 +2579,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
keras.metrics.Accuracy()
],
},
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
@keras_parameterized.run_all_keras_modes
def test_metrics_masking(self):
@ -2641,8 +2593,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
RMSPropOptimizer(learning_rate=0.001),
loss='mse',
weighted_metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# verify that masking is applied.
x = np.array([[[1], [1]], [[1], [1]], [[0], [0]]])
@ -2678,8 +2629,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
'sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.ones(shape=(10, 1))
targets = np.ones(shape=(10, 1))
@ -2721,8 +2671,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -2764,8 +2713,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -2823,8 +2771,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
'sgd',
loss='mse',
metrics=[metrics_module.Accuracy('metric_4')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(np.ones((10, 1)), np.ones((10, 1)), batch_size=10)
@ -2852,8 +2799,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
loss='mse',
optimizer=RMSPropOptimizer(0.01),
metrics=[metrics_module.Accuracy('acc')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
model.fit(x, y, epochs=2, batch_size=5, validation_data=(x, y))
@ -2883,8 +2829,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -2919,8 +2864,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -2947,8 +2891,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=RMSPropOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones(shape=(10, 1))
y = np.ones(shape=(10, 2))
@ -2985,8 +2928,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
loss='mae',
optimizer=keras.optimizer_v2.gradient_descent.SGD(0.1),
metrics=[metrics_module.MeanAbsoluteError(name='mae_3')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.array([[0.], [1.], [2.]])
y = np.array([[0.5], [2.], [3.5]])
@ -3028,8 +2970,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(dataset_train, epochs=3)
self.assertDictEqual(
history.history, {
@ -3065,8 +3006,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
'sgd',
loss='mse',
metrics=[metrics_module.Accuracy('acc')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inner_model.fit(np.ones((10, 1)), np.ones((10, 1)), batch_size=10)
self.assertEqual([m.name for m in inner_model.metrics],
@ -3082,8 +3022,7 @@ class TestTrainingWithMetrics(keras_parameterized.TestCase):
'sgd',
loss='mse',
metrics=[metrics_module.Accuracy('acc2')],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
outer_model.fit(np.ones((10, 1)), np.ones((10, 1)), batch_size=10)
self.assertEqual([m.name for m in outer_model.metrics],
['loss', 'acc2', 'mean', 'mean1', 'mean2'])
@ -3169,8 +3108,7 @@ class TestAutoUpdates(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=1)
self.assertEqual(self.evaluate(layer.counter), 5)
@ -3183,16 +3121,14 @@ class TestAutoUpdates(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=1)
self.assertEqual(self.evaluate(layer.counter), 5)
layer.trainable = False
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=1)
self.assertEqual(self.evaluate(layer.counter), 5)
@ -3205,8 +3141,7 @@ class TestAutoUpdates(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=1)
self.assertEqual(self.evaluate(layer.counter), 5)
@ -3241,8 +3176,7 @@ class TestAutoUpdates(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x, y = np.ones((10, 10)), np.ones((10, 1))
model.fit(x, y, batch_size=2, epochs=1)
self.assertAllEqual(self.evaluate(bn.moving_mean), np.zeros((10,)))

View File

@ -97,8 +97,7 @@ class AdvancedActivationsTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(np.ones((10, 10)), np.ones((10, 1)), batch_size=2)

View File

@ -223,8 +223,7 @@ class ConvLSTMTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd', loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x_1 = np.random.rand(num_samples, sequence_len, 32, 32, 3)
x_2 = np.random.rand(num_samples, sequence_len, 32, 32, 4)
y = np.random.rand(num_samples, 32, 32, 1)

View File

@ -296,8 +296,7 @@ class TestStatefulLambda(keras_parameterized.TestCase):
model.compile(
keras.optimizer_v2.gradient_descent.SGD(0.1),
'mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x, y = np.ones((10, 10), 'float32'), 2 * np.ones((10, 10), 'float32')
model.fit(x, y, batch_size=2, epochs=2, validation_data=(x, y))
self.assertLen(model.trainable_weights, 1)

View File

@ -89,7 +89,6 @@ class CuDNNTest(keras_parameterized.TestCase):
self.assertEqual(len(state), num_states)
model = keras.models.Model(inputs, state[0])
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
inputs = np.random.random((num_samples, timesteps, input_size))
state = model.predict(inputs)
@ -149,8 +148,7 @@ class CuDNNTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer=RMSprop(learning_rate=0.001),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.random.random((num_samples, timesteps, input_size))
initial_state = [

View File

@ -82,7 +82,6 @@ class EmbeddingTest(keras_parameterized.TestCase):
layer.set_weights([np.array([[1, 1], [2, 2]])])
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
outputs = model.predict(np.array([[0, 1, 0]], dtype='int32'))
self.assertAllClose(outputs, [[[1, 1], [2, 2], [1, 1]]])
@ -113,7 +112,6 @@ class EmbeddingTest(keras_parameterized.TestCase):
outputs = layer(outputs)
model = keras.Model(inputs, outputs)
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model.run_eagerly = testing_utils.should_run_eagerly()
outputs = model.predict(
ragged_factory_ops.constant([[1., 2., 2.], [0.], [1., 2.]],

View File

@ -72,8 +72,7 @@ class GRULayerTest(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((num_samples, timesteps, embedding_dim))
y = np.random.random((num_samples, units))
model.train_on_batch(x, y)
@ -128,8 +127,7 @@ class GRULayerTest(keras_parameterized.TestCase):
gru_model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
gru_model.fit(x_train, y_train)
gru_model.predict(x_train)
@ -146,8 +144,7 @@ class GRULayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(inputs, targets, epochs=1, batch_size=2, verbose=1)
def test_statefulness_GRU(self):
@ -173,8 +170,7 @@ class GRULayerTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out1 = model.predict(np.ones((num_samples, timesteps)))
self.assertEqual(out1.shape, (num_samples, units))

View File

@ -490,8 +490,7 @@ class GRUV2Test(keras_parameterized.TestCase):
model.compile(
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out1 = model.predict(np.ones((num_samples, timesteps)))
self.assertEqual(out1.shape, (num_samples, units))
@ -563,8 +562,7 @@ class GRUV2Test(keras_parameterized.TestCase):
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, shuffle=False)
@test_util.run_v2_only
@ -662,8 +660,7 @@ class GRUGraphRewriteTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss=['categorical_crossentropy', None],
experimental_run_tf_function=testing_utils.should_run_tf_function())
loss=['categorical_crossentropy', None])
existing_loss = 0
for _ in range(self.epoch):
@ -727,8 +724,7 @@ class GRUGraphRewriteTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss=['categorical_crossentropy', None],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x_train, y_train)

View File

@ -87,8 +87,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.random.random((num_samples, timesteps, embedding_dim))
y = np.random.random((num_samples, units))
@ -157,8 +156,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(inputs, targets, epochs=1, batch_size=2, verbose=1)
@parameterized.parameters([True, False])
@ -174,8 +172,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(inputs, targets, epochs=1, batch_size=2, verbose=1)
def test_from_config_LSTM(self):
@ -208,8 +205,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer=adam.AdamOptimizer(),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.random.random((num_samples, timesteps, embedding_dim))
initial_state = [np.random.random((num_samples, units))
@ -236,8 +232,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer=adam.AdamOptimizer(),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.random.random((num_samples, timesteps, embedding_dim))
targets = np.random.random((num_samples, units))
@ -289,8 +284,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
inputs = np.random.random((num_samples, timesteps, embedding_dim))
initial_state = [np.random.random((num_samples, units))
@ -355,8 +349,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
loss='categorical_crossentropy',
optimizer=adam.AdamOptimizer(),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
main_inputs = np.random.random((num_samples, timesteps, embedding_dim))
initial_state = [np.random.random((num_samples, units))
@ -408,8 +401,7 @@ class LSTMLayerTest(keras_parameterized.TestCase):
model.compile(
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out1 = model.predict(np.ones((num_samples, timesteps)))
self.assertEqual(out1.shape, (num_samples, units))

View File

@ -655,8 +655,7 @@ class LSTMV2Test(keras_parameterized.TestCase):
model.compile(
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out1 = model.predict(np.ones((num_samples, timesteps)))
self.assertEqual(out1.shape, (num_samples, units))
@ -728,8 +727,7 @@ class LSTMV2Test(keras_parameterized.TestCase):
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, shuffle=False)
def test_dropout_LSTM(self):
@ -838,8 +836,7 @@ class LSTMGraphRewriteTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss=['categorical_crossentropy', None],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
existing_loss = 0
for _ in range(self.epoch):
@ -903,8 +900,7 @@ class LSTMGraphRewriteTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss=['categorical_crossentropy', None],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x_train, y_train)

View File

@ -44,7 +44,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2, i3], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -78,7 +77,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -112,7 +110,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2, i3], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -128,7 +125,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -143,7 +139,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -158,7 +153,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 4, 5])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -174,7 +168,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 8, 5])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
x1 = np.random.random((2, 4, 5))
x2 = np.random.random((2, 4, 5))
@ -206,7 +199,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 1])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
_ = keras.layers.Dot(axes=1).get_config()
x1 = np.random.random((2, 4))
@ -223,7 +215,6 @@ class MergeLayersTest(keras_parameterized.TestCase):
self.assertListEqual(o.shape.as_list(), [None, 1])
model = keras.models.Model([i1, i2], o)
model.run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
out = model.predict([x1, x2])
self.assertEqual(out.shape, (2, 1))
self.assertAllClose(out, expected, atol=1e-4)

View File

@ -106,8 +106,7 @@ class BatchNormalizationTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# centered on 5.0, variance 10.0
x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 3, 4, 4))
@ -128,8 +127,7 @@ class BatchNormalizationTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# centered on 5.0, variance 10.0
x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 4, 4, 3))
@ -178,8 +176,7 @@ class BatchNormalizationTest(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(np.random.random((100, 3)), np.random.random((100, 3)))
test_data = np.random.random((10, 3))
@ -190,8 +187,7 @@ class BatchNormalizationTest(keras_parameterized.TestCase):
model.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
train_loss = model.train_on_batch(test_data, test_targets)
self.assertAlmostEqual(test_loss, train_loss)
@ -369,8 +365,7 @@ def _run_batchnorm_correctness_test(layer, dtype='float32', fused=False):
model.compile(
loss='mse',
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# centered on 5.0, variance 10.0
x = (np.random.normal(loc=5.0, scale=10.0, size=(1000, 2, 2, 2))
@ -505,8 +500,7 @@ def _run_layernorm_correctness_test(layer, dtype='float32'):
model.compile(
loss='mse',
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# centered on 5.0, variance 10.0
x = (np.random.normal(loc=5.0, scale=10.0, size=(1000, 2, 2, 2))
@ -596,8 +590,7 @@ class LayerNormalizationTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# centered on 5.0, variance 10.0
x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 4, 4, 3))

View File

@ -203,7 +203,6 @@ class NormalizationTest(keras_parameterized.TestCase,
output = layer(input_data)
model = keras.Model(input_data, output)
model._run_eagerly = testing_utils.should_run_eagerly()
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
output_data = model.predict(test_data)
self.assertAllClose(expected, output_data)

View File

@ -85,8 +85,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacking.
@ -99,8 +98,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
def test_minimal_rnn_cell_non_layer_multiple_states(self):
@ -130,8 +128,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacking.
@ -146,8 +143,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
def test_minimal_rnn_cell_layer(self):
@ -189,8 +185,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test basic case serialization.
@ -216,8 +211,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacked RNN serialization.
@ -273,8 +267,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer="rmsprop",
loss="mse",
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacking.
@ -287,8 +280,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
def test_rnn_with_time_major(self):
@ -316,8 +308,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, embedding_dim)),
np.zeros((batch, time_step, units)))
@ -337,8 +328,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, embedding_dim)),
np.zeros((batch, time_step, cell_units[-1])))
@ -355,8 +345,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, embedding_dim)),
np.zeros((batch, time_step, units)))
@ -370,8 +359,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, embedding_dim)),
np.zeros((batch, time_step, units)))
@ -405,8 +393,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((6, 5, 5)), np.zeros((6, 3))],
np.zeros((6, 32))
@ -446,8 +433,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((6, 5, 5)), np.zeros((6, 3))],
np.zeros((6, 32))
@ -463,8 +449,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((6, 5, 5)), np.zeros((6, 3))],
np.zeros((6, 32))
@ -496,8 +481,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacking.
@ -510,8 +494,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
def test_rnn_cell_with_constants_layer_passing_initial_state(self):
@ -526,8 +509,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((6, 5, 5)), np.zeros((6, 32)), np.zeros((6, 3))],
np.zeros((6, 32))
@ -576,8 +558,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
# Test stacking.
@ -593,8 +574,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 32)))
def test_stacked_rnn_attributes(self):
@ -705,8 +685,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Test basic case serialization.
x_np = np.random.random((6, 5, 5))
@ -730,8 +709,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Test stacked RNN serialization.
x_np = np.random.random((6, 5, 5))
@ -761,8 +739,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x_np = np.random.random((6, 5, 5))
y_np = np.random.random((6, 3))
model.train_on_batch(x_np, y_np)
@ -786,8 +763,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x_np = np.random.random((6, 5, 5))
y_np = np.random.random((6, 3))
model.train_on_batch(x_np, y_np)
@ -924,8 +900,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, batch_size=1)
# check whether the model variables are present in the
@ -959,8 +934,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, input_a, input_b)),
np.zeros((batch, unit_a, unit_b)))
@ -978,8 +952,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, input_a, input_b)),
np.zeros((batch, unit_a * 4, unit_b * 4)))
@ -1004,8 +977,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch([
np.zeros((batch, time_step, input_a, input_b)),
np.zeros((batch, unit_a, unit_b))
@ -1043,8 +1015,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, time_step, input_size)),
np.zeros((batch, input_size)))
@ -1103,8 +1074,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)), np.zeros((batch, t, i2, i3))],
[np.zeros((batch, o1)), np.zeros((batch, o2, o3))])
@ -1128,8 +1098,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)),
np.zeros((batch, t, i2, i3))],
@ -1160,8 +1129,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)),
np.zeros((batch, t, i2, i3))],
@ -1187,8 +1155,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)),
np.zeros((batch, t, i2, i3))],
@ -1223,8 +1190,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)),
np.zeros((batch, t, i2, i3)),
@ -1257,8 +1223,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
[np.zeros((batch, t, i1)),
np.zeros((batch, t, i2, i3)),
@ -1335,8 +1300,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# last time step masked
x_np = np.array([[[1.], [2.], [0.]]])
@ -1362,8 +1326,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np_x = np.ones((6, 5, 5))
result_1 = model.predict(np_x)
@ -1387,8 +1350,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np_x = np.ones((6, 1, 5))
result = model.predict(np_x)
@ -1443,8 +1405,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, timesteps, input_dim)),
np.zeros((batch, output_dim)))
@ -1479,8 +1440,7 @@ class RNNTest(keras_parameterized.TestCase):
model = keras.Model(input_layer, rnn_output)
model.compile(
optimizer='rmsprop', loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
# Define a model with a constant state initialization
@ -1557,8 +1517,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(
np.zeros((batch, timesteps, input_dim)),
np.zeros((batch, output_dim)))
@ -1626,8 +1585,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(ragged_data, label_data)
# Test stateful and full shape specification
@ -1639,8 +1597,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(ragged_data, label_data)
# Must raise error when unroll is set to True
@ -1695,8 +1652,7 @@ class RNNTest(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch(np.zeros((6, 5, 5)), np.zeros((6, 5)))
@parameterized.parameters(

View File

@ -61,8 +61,7 @@ class RNNV2Test(keras_parameterized.TestCase):
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, epochs=1, shuffle=False)
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])

View File

@ -174,8 +174,7 @@ class SimpleRNNLayerTest(keras_parameterized.TestCase):
model.compile(
optimizer=gradient_descent.GradientDescentOptimizer(0.01),
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
out1 = model.predict(np.ones((num_samples, timesteps)))
self.assertEqual(out1.shape, (num_samples, units))

View File

@ -211,8 +211,7 @@ class AutoLambdaTest(keras_parameterized.TestCase):
model.compile(
adam.Adam(0.001),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np_inputs = nest.map_structure(
lambda x: np.ones((10,) + tuple(x.shape[1:]), 'float32'), model.inputs)
@ -230,8 +229,7 @@ class AutoLambdaTest(keras_parameterized.TestCase):
new_model.compile(
adam.Adam(0.001),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.fit(np_inputs, np_outputs, batch_size=2)
new_model(np_inputs) # Test calling the new model directly on inputs.
# Assert that metrics are preserved and in the right order.

View File

@ -371,8 +371,7 @@ class TimeDistributedTest(keras_parameterized.TestCase):
model_1.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
output_with_mask = model_1.predict(data, steps=1)
y = keras.layers.TimeDistributed(rnn_layer)(x)
@ -380,8 +379,7 @@ class TimeDistributedTest(keras_parameterized.TestCase):
model_2.compile(
'rmsprop',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
output = model_2.predict(data, steps=1)
self.assertNotAllClose(output_with_mask, output, atol=1e-7)
@ -392,7 +390,7 @@ class TimeDistributedTest(keras_parameterized.TestCase):
layer=[keras.layers.LSTM,
keras.layers.Dense]))
def test_TimeDistributed_with_ragged_input(self, layer):
if testing_utils.should_run_tf_function():
if context.executing_eagerly():
self.skipTest('b/143103634')
np.random.seed(100)
layer = layer(4)
@ -405,8 +403,6 @@ class TimeDistributedTest(keras_parameterized.TestCase):
x_ragged = keras.Input(shape=(None, 2, 1), dtype='float32', ragged=True)
y_ragged = keras.layers.TimeDistributed(layer)(x_ragged)
model_1 = keras.models.Model(x_ragged, y_ragged)
model_1._experimental_run_tf_function = (
testing_utils.should_run_tf_function())
model_1._run_eagerly = testing_utils.should_run_eagerly()
output_ragged = model_1.predict(ragged_data, steps=1)
@ -415,8 +411,6 @@ class TimeDistributedTest(keras_parameterized.TestCase):
y_dense = keras.layers.TimeDistributed(layer)(masking)
model_2 = keras.models.Model(x_dense, y_dense)
dense_data = ragged_data.to_tensor()
model_2._experimental_run_tf_function = (
testing_utils.should_run_tf_function())
model_2._run_eagerly = testing_utils.should_run_eagerly()
output_dense = model_2.predict(dense_data, steps=1)

View File

@ -79,8 +79,7 @@ class TestMetricsCorrectnessMultiIO(keras_parameterized.TestCase):
weighted_metrics=[
metrics.MeanSquaredError(name='mean_squared_error_2')
],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def setUp(self):
@ -354,8 +353,7 @@ class TestMetricsCorrectnessSingleIO(keras_parameterized.TestCase):
weighted_metrics=[
metrics.MeanSquaredError(name='mean_squared_error_2')
],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def _custom_generator(self, sample_weight=None):
@ -564,8 +562,7 @@ class TestOutputLossMetrics(keras_parameterized.TestCase):
model.compile(
optimizer='rmsprop',
loss=loss,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model
def setUp(self):

View File

@ -1991,8 +1991,7 @@ def _get_model(compile_metrics):
loss='mae',
metrics=compile_metrics,
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model

View File

@ -211,7 +211,7 @@ cuda_py_test(
size = "medium",
srcs = ["keras_test.py"],
python_version = "PY3",
shard_count = 4,
shard_count = 10,
tags = ["no_windows"], # b/139083295: bfloat16 tests fail on Windows
deps = [
":test_util",

View File

@ -496,10 +496,6 @@ class KerasModelTest(keras_parameterized.TestCase):
'strategy_fn': create_central_storage_strategy,
'use_regularizer': True,
'save_format': 'tf'
}, {
'testcase_name': 'norun_distributed',
'strategy_fn': create_mirrored_strategy,
'experimental_run_tf_function': False
})
def test_model(self,
strategy_fn,
@ -508,8 +504,7 @@ class KerasModelTest(keras_parameterized.TestCase):
policy_name='mixed_float16',
get_config=False,
save_format=None,
use_input_spec=False,
experimental_run_tf_function=True):
use_input_spec=False):
self._skip_if_strategy_unsupported(strategy_fn)
self._skip_if_save_format_unsupported(save_format)
regularizer = (mp_test_util.IdentityRegularizer() if use_regularizer
@ -546,8 +541,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
opt,
loss=loss_fn,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((2, 1))
y = np.ones((2, 1))
@ -606,14 +600,9 @@ class KerasModelTest(keras_parameterized.TestCase):
}, {
'testcase_name': 'distribute',
'strategy_fn': create_mirrored_strategy,
}, {
'testcase_name': 'norun_distributed',
'strategy_fn': create_mirrored_strategy,
'experimental_run_tf_function': False,
})
def test_fixed_loss_scaling(self,
strategy_fn,
experimental_run_tf_function=True):
strategy_fn):
# Note: We do not test mixed precision in this method, only loss scaling.
loss_scale = 8.
batch_size = 4
@ -640,8 +629,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
opt,
loss=loss_fn,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(backend.eval(layer.v), 1)
x = np.ones((batch_size, 1))
@ -720,8 +708,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
opt,
loss=loss_fn,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((2, 1))
y = np.ones((2, 1))
@ -760,16 +747,11 @@ class KerasModelTest(keras_parameterized.TestCase):
'testcase_name': 'central_storage',
'strategy_fn': create_central_storage_strategy,
'get_config': True,
}, {
'testcase_name': 'norun_distributed',
'strategy_fn': create_mirrored_strategy,
'experimental_run_tf_function': False,
})
def test_dynamic_loss_scaling(self,
strategy_fn,
pass_loss_scale_to_policy=False,
get_config=False,
experimental_run_tf_function=True):
get_config=False):
strategy = strategy_fn()
initial_loss_scale = 2.
batch_size = 4
@ -816,8 +798,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
opt,
loss=loss_fn,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(backend.eval(layer.v), 1)
x = np.ones((batch_size, 1))
@ -959,8 +940,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
optimizer=opt,
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(np.ones((2, 2)), np.zeros((2, 2)), batch_size=2)
weights_file = os.path.join(self.get_temp_dir(), 'weights')
@ -997,8 +977,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
optimizer=opt,
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Run for 3 steps (6 examples with a batch size of 2)
model.fit(np.zeros((6, 2)), np.zeros((6, 2)), batch_size=2)
self.assertEqual(backend.get_value(loss_scale()), 2)
@ -1057,8 +1036,7 @@ class KerasModelTest(keras_parameterized.TestCase):
model.compile(
optimizer=opt,
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Run for 3 steps (6 examples with a batch size of 2)
model.fit(np.ones((6, 2)), np.zeros((6, 2)), batch_size=2)
self.assertEqual(backend.get_value(loss_scale()), 2)

View File

@ -177,8 +177,7 @@ class TestModelCloning(keras_parameterized.TestCase):
new_model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.train_on_batch([val_a, val_b], val_out)
# On top of new tensors
@ -190,8 +189,7 @@ class TestModelCloning(keras_parameterized.TestCase):
new_model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.train_on_batch([val_a, val_b], val_out)
# On top of new, non-Keras tensors
@ -205,8 +203,7 @@ class TestModelCloning(keras_parameterized.TestCase):
new_model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.train_on_batch(None, val_out)
@keras_parameterized.run_all_keras_modes
@ -232,8 +229,7 @@ class TestModelCloning(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer=testing_utils.get_v2_optimizer('adam'),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y = np.array([[[1], [1]], [[1], [1]]])
loss = model.train_on_batch(x, y)
self.assertEqual(float(loss), 0.)
@ -322,8 +318,7 @@ class CheckpointingTests(keras_parameterized.TestCase):
model.compile(
optimizer=opt,
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
x=np.array([[1., 2., 3., 4.]]),
@ -352,8 +347,7 @@ class TestModelBackend(keras_parameterized.TestCase):
model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
keras.backend.set_floatx(floatx)
@ -382,8 +376,7 @@ class TestCloneAndBuildModel(keras_parameterized.TestCase):
new_model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.train_on_batch(inp, out)
# Create new tensors for inputs.
@ -400,8 +393,7 @@ class TestCloneAndBuildModel(keras_parameterized.TestCase):
new_model.compile(
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
new_model.train_on_batch(inp, out)
def _assert_same_compile_params(self, model):
@ -454,8 +446,7 @@ class TestCloneAndBuildModel(keras_parameterized.TestCase):
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
metrics=['acc', metrics.categorical_accuracy],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self._clone_and_build_test_helper(model, testing_utils.get_model_type())
@ -466,8 +457,7 @@ class TestCloneAndBuildModel(keras_parameterized.TestCase):
testing_utils.get_v2_optimizer('rmsprop'),
'mse',
metrics=['acc', metrics.categorical_accuracy],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self._clone_and_build_test_helper(model, 'sequential')
inp = np.random.random((10, 4))
@ -481,8 +471,7 @@ class TestCloneAndBuildModel(keras_parameterized.TestCase):
optimizer,
'mse',
metrics=['acc', metrics.categorical_accuracy],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
global_step = keras.backend.variable(123, dtype=dtypes.int64)
clone_model = models.clone_and_build_model(

View File

@ -655,13 +655,10 @@ class OptimizerTest(test.TestCase):
@keras_parameterized.run_all_keras_modes
class OptimizersCompatibilityTest(keras_parameterized.TestCase):
# After experimental_run_tf_function is turned on, optimizer v1 can no longer
# work in eager mode, skipping the test if so.
def _testOptimizersCompatibility(self, opt_v1, opt_v2, test_weights=True):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
np.random.seed(1331)
with test_util.use_gpu():
train_samples = 20
@ -681,8 +678,7 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
opt_v1,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_v1.fit(x, y, batch_size=5, epochs=1)
model_v2 = testing_utils.get_small_sequential_mlp(
@ -692,8 +688,7 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
opt_v2,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_v2._make_train_function()
if test_weights:
opt_v2.set_weights(opt_v1.get_weights())
@ -746,10 +741,9 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
self._testOptimizersCompatibility(opt_v1, opt_v2, False)
def testNumericEquivalenceForNesterovMomentum(self):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
np.random.seed(1331)
with test_util.use_gpu():
train_samples = 20
@ -781,20 +775,17 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
opt_k_v1,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_k_v2.compile(
opt_k_v2,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_tf.compile(
opt_tf,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
hist_k_v1 = model_k_v1.fit(x, y, batch_size=5, epochs=10, shuffle=False)
hist_k_v2 = model_k_v2.fit(x, y, batch_size=5, epochs=10, shuffle=False)
@ -808,10 +799,9 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
def testNumericEquivalenceForAmsgrad(self):
self.skipTest('b/150382655')
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
np.random.seed(1331)
with test_util.use_gpu():
train_samples = 20
@ -838,14 +828,12 @@ class OptimizersCompatibilityTest(keras_parameterized.TestCase):
opt_k_v1,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model_k_v2.compile(
opt_k_v2,
loss='categorical_crossentropy',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
hist_k_v1 = model_k_v1.fit(x, y, batch_size=5, epochs=10, shuffle=False)
hist_k_v2 = model_k_v2.fit(x, y, batch_size=5, epochs=10, shuffle=False)

View File

@ -45,13 +45,10 @@ def _get_model(input_dim, num_hidden, output_dim):
@keras_parameterized.run_all_keras_modes
class KerasOptimizersTest(keras_parameterized.TestCase):
# After experimental_run_tf_function is turned on, optimizer v1 can no longer
# work in eager mode, skipping the test if so.
def _test_optimizer(self, optimizer, target=0.75):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
np.random.seed(1337)
(x_train, y_train), _ = testing_utils.get_test_data(
train_samples=1000, test_samples=200, input_shape=(10,), num_classes=2)
@ -61,8 +58,7 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np.testing.assert_equal(
keras.backend.get_value(model.optimizer.iterations), 0)
history = model.fit(x_train, y_train, epochs=2, batch_size=16, verbose=0)
@ -99,8 +95,7 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
np.testing.assert_equal(
keras.backend.get_value(model.optimizer.iterations),
126) # Using same optimizer from before
@ -166,10 +161,9 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
keras.optimizers.SGD(lr=0.01, momentum=0.9, clipvalue=0.5))
def test_tf_optimizer(self):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
optimizer = keras.optimizers.TFOptimizer(AdamOptimizer(0.01))
model = keras.models.Sequential()
model.add(keras.layers.Dense(
@ -178,8 +172,7 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
model.compile(
loss='mean_squared_error',
optimizer=optimizer,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
keras.backend.track_tf_optimizer(optimizer)
model.fit(np.random.random((5, 3)),
np.random.random((5, 2)),
@ -195,10 +188,9 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
optimizer.from_config(None)
def test_optimizer_garbage_collection(self):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
graph = ops.Graph()
with graph.as_default():
optimizer = keras.optimizers.TFOptimizer(AdamOptimizer(0.01))
@ -212,10 +204,9 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
self.assertIs(optimizer_weak(), None)
def test_tf_optimizer_iterations(self):
if testing_utils.should_run_tf_function() or context.executing_eagerly():
if context.executing_eagerly():
self.skipTest(
'v1 optimizer does not run in experimental_run_tf_function mode or '
'eager mode')
'v1 optimizer does not run in eager mode')
with self.cached_session():
optimizer = keras.optimizers.TFOptimizer(AdamOptimizer(0.01))
model = keras.models.Sequential()
@ -224,8 +215,7 @@ class KerasOptimizersTest(keras_parameterized.TestCase):
model.compile(
loss='mean_squared_error',
optimizer=optimizer,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
keras.backend.track_tf_optimizer(optimizer)
self.assertEqual(keras.backend.get_value(model.optimizer.iterations), 0)

View File

@ -52,8 +52,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer=['sgd', 'adam'],
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
wide_deep_model.fit(inputs, output, epochs=5)
self.assertTrue(wide_deep_model.built)
@ -73,8 +72,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer=[linear_opt, dnn_opt],
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.evaluate(variables.global_variables_initializer())
wide_deep_model.fit(inputs, output, epochs=1)
self.assertAllClose(
@ -94,8 +92,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer=['sgd', 'adam'],
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
wide_deep_model.fit(inputs, output, epochs=5)
def test_wide_deep_model_with_multi_outputs(self):
@ -135,8 +132,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer='sgd',
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
wide_deep_model.fit(inputs, output, epochs=5)
self.assertTrue(wide_deep_model.built)
@ -160,8 +156,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer='sgd',
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit([linear_input_np, dnn_input_np, input_b_np], output_np, epochs=5)
def test_wide_deep_model_with_sub_model_trained(self):
@ -178,22 +173,19 @@ class WideDeepModelTest(keras_parameterized.TestCase):
optimizer='sgd',
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
dnn_model.compile(
optimizer='adam',
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
linear_model.fit(linear_inp, output, epochs=50)
dnn_model.fit(dnn_inp, output, epochs=50)
wide_deep_model.compile(
optimizer=['sgd', 'adam'],
loss='mse',
metrics=[],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
wide_deep_model.fit(inputs, output, epochs=50)
# This test is an example for cases where linear and dnn model accepts
@ -221,8 +213,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
combined.compile(
opt,
'mse', [],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
combined.fit(x={'symbol': data}, y=y, batch_size=32, epochs=10)
# This test is an example for cases where linear and dnn model accepts
@ -255,8 +246,7 @@ class WideDeepModelTest(keras_parameterized.TestCase):
wide_deep_model.compile(
opt,
'mse', [],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
wide_deep_model.fit(x={'symbol': data}, y=y, batch_size=32, epochs=10)
def test_config(self):

View File

@ -79,8 +79,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
loss='categorical_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(len(model.losses), 1)
model.fit(x_train, y_train, batch_size=10, epochs=1, verbose=0)
@ -97,8 +96,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
loss='categorical_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertEqual(len(model.losses), 1 if context.executing_eagerly() else 1)
model.fit(x_train, y_train, batch_size=10, epochs=1, verbose=0)
@ -113,8 +111,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=5, epochs=1)
def test_custom_regularizer_saving(self):
@ -144,8 +141,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
loss='categorical_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertLen(model.losses, 5)
@keras_parameterized.run_all_keras_modes
@ -167,8 +163,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
loss='categorical_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
self.assertLen(model.losses, 6)
@keras_parameterized.run_all_keras_modes
@ -195,8 +190,7 @@ class KerasRegularizersTest(keras_parameterized.TestCase,
model.compile(
loss='categorical_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# We expect to see 9 losses on the model:
# - 2 from the 2 add_loss calls on the outer model.

View File

@ -135,8 +135,7 @@ class LossesSerialization(keras_parameterized.TestCase):
model.compile(
optimizer_v2.gradient_descent.SGD(0.1),
loss=value,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.x], [self.y, self.y],
batch_size=3,
epochs=3,
@ -163,8 +162,7 @@ class LossesSerialization(keras_parameterized.TestCase):
model.compile(
optimizer_v2.gradient_descent.SGD(0.1),
loss=value,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.x], [self.y, self.y],
batch_size=3,
epochs=3,

View File

@ -181,8 +181,7 @@ class MetricsSerialization(keras_parameterized.TestCase):
'mae',
metrics=metric_input,
weighted_metrics=weighted_metric_input,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.x], [self.y, self.y],
batch_size=3,
epochs=3,
@ -222,8 +221,7 @@ class MetricsSerialization(keras_parameterized.TestCase):
'mae',
metrics=metric_input,
weighted_metrics=weighted_metric_input,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.x], [self.y, self.y],
batch_size=3,
epochs=3,

View File

@ -91,8 +91,7 @@ class TraceModelCallTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(
x=np.random.random((8, 5)).astype(np.float32),
y=np.random.random((8, 3)).astype(np.float32),
@ -137,8 +136,7 @@ class TraceModelCallTest(keras_parameterized.TestCase):
model.compile(
optimizer='sgd',
loss='mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x=[np.random.random((8, input_dim)).astype(np.float32),
np.random.random((8, input_dim)).astype(np.float32)],
y=[np.random.random((8, num_classes)).astype(np.float32),

View File

@ -79,8 +79,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.add_loss(math_ops.reduce_mean(mae(targets, outputs)))
model.compile(
optimizer_v2.gradient_descent.SGD(0.05),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.y], batch_size=3, epochs=5)
self.assertAllClose(history.history['loss'], [2., 1.8, 1.6, 1.4, 1.2], 1e-3)
@ -97,8 +96,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.add_loss(callable_loss)
model.compile(
optimizer_v2.gradient_descent.SGD(0.1),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(self.x, batch_size=3, epochs=5)
self.assertAllClose(history.history['loss'], [0., -.1, -.2, -.3, -.4], 1e-3)
@ -157,8 +155,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.add_loss(3 * math_ops.reduce_mean(sw * mae(targets, outputs)))
model.compile(
optimizer_v2.gradient_descent.SGD(0.025),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.y, self.w], batch_size=3, epochs=5)
self.assertAllClose(history.history['loss'], [4., 3.6, 3.2, 2.8, 2.4], 1e-3)
@ -203,8 +200,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.predict([self.x, self.y, self.w])
model.compile(
optimizer_v2.gradient_descent.SGD(0.05),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.y, self.w], batch_size=3, epochs=5)
self.assertEqual(len(model.losses), 2)
@ -237,8 +233,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.predict([self.x, self.y, self.w])
model.compile(
optimizer_v2.gradient_descent.SGD(0.05),
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit([self.x, self.y, self.w], batch_size=3, epochs=5)
self.assertAllClose(history.history['loss'], [2., 1.8, 1.6, 1.4, 1.2], 1e-3)
@ -266,8 +261,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.train_on_batch(np.ones((2, 3)), np.ones((2, 3)))
self.assertEqual(loss, 2 * 3)
@ -300,8 +294,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
model.compile(
optimizer,
'binary_crossentropy',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x, y, batch_size=2, epochs=5)
loss[reg] = model.evaluate(x, y)
self.assertLess(loss[None], loss['l2'])
@ -321,8 +314,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
optimizer = RMSPropOptimizer(learning_rate=0.001)
model.compile(
optimizer,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.test_on_batch(x)
self.assertAlmostEqual(0.01, loss, places=4)
@ -336,8 +328,7 @@ class TestAddLossCorrectness(keras_parameterized.TestCase):
optimizer = RMSPropOptimizer(learning_rate=0.001)
model.compile(
optimizer,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss_small_batch = model.test_on_batch(np.ones((10, 10), 'float32'))
loss_big_batch = model.test_on_batch(np.ones((20, 10), 'float32'))

View File

@ -75,8 +75,7 @@ class VectorClassificationIntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x_train, y_train, epochs=10, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)
@ -112,8 +111,7 @@ class VectorClassificationIntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
if not testing_utils.should_run_eagerly():
self.assertEqual(len(model.get_losses_for(None)), 2)
self.assertEqual(len(model.get_updates_for(x)), 2)
@ -153,8 +151,7 @@ class SequentialIntegrationTest(KerasIntegrationTest):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x_train, y_train, epochs=1, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)
@ -176,8 +173,7 @@ class SequentialIntegrationTest(KerasIntegrationTest):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x_train, y_train, epochs=10, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)
@ -213,8 +209,7 @@ class TimeseriesClassificationIntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x_train, y_train, epochs=15, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)
@ -244,8 +239,7 @@ class TimeseriesClassificationIntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x_train, y_train, epochs=15, batch_size=10,
validation_data=(x_train, y_train),
@ -284,8 +278,7 @@ class ImageClassificationIntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
history = model.fit(x_train, y_train, epochs=10, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)
@ -329,8 +322,7 @@ class ActivationV2IntegrationTest(keras_parameterized.TestCase):
loss='categorical_crossentropy',
optimizer=keras.optimizer_v2.adam.Adam(0.005),
metrics=['accuracy'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(x_train, y_train, epochs=2, batch_size=10,
validation_data=(x_train, y_train),
verbose=2)

View File

@ -49,8 +49,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc', keras.metrics.CategoricalAccuracy()],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim))
y = np.zeros((num_samples, num_classes))
@ -69,8 +68,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x1 = np.ones((num_samples, input_dim))
x2 = np.ones((num_samples, input_dim))
@ -91,8 +89,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim), dtype=np.float32)
y = np.zeros((num_samples, num_classes), dtype=np.float32)
@ -125,8 +122,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch([x1, x2], [y1, y2])
self.assertEqual(model.built, True)
@ -157,8 +153,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
y_ref = model.predict(x)
model.train_on_batch(x, y)
@ -191,8 +186,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.train_on_batch(x, y)
self.assertGreater(loss, 0.1)
@ -214,8 +208,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit([x1, x2], [y1, y2], epochs=2, batch_size=32, verbose=0)
model.fit({'input_1': x1, 'input_2': x2},
{'output_1': y1, 'output_2': y2},
@ -228,8 +221,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.train_on_batch([x1, x2], [y1, y2])
model.train_on_batch({'input_1': x1, 'input_2': x2},
{'output_1': y1, 'output_2': y2})
@ -251,8 +243,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.evaluate([x1, x2], [y1, y2])
model.test_on_batch([x1, x2], [y1, y2])
@ -279,8 +270,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit([x1, x2], [y1, y2], epochs=2, batch_size=32, verbose=0)
y_ref_1, y_ref_2 = model.predict([x1, x2])
@ -320,8 +310,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim))
y = np.zeros((num_samples, num_classes))
@ -345,8 +334,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim))
y = np.zeros((num_samples, num_classes))
@ -371,8 +359,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim))
y = np.zeros((num_samples, num_classes))
@ -407,8 +394,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
loss='mse',
optimizer='rmsprop',
metrics=['acc'],
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
x = np.ones((num_samples, input_dim))
y = np.zeros((num_samples, num_classes))
@ -447,8 +433,7 @@ class ModelSubclassCompiledTest(keras_parameterized.TestCase):
model.compile(
loss='mse',
optimizer='rmsprop',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
loss = model.train_on_batch(x, y)
self.assertGreater(loss, 0.1)

View File

@ -99,8 +99,7 @@ class ModelSubclassingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
model.fit(np.ones((10, 10)), np.ones((10, 1)), batch_size=2, epochs=2)
self.assertLen(model.layers, 2)
self.assertLen(model.trainable_variables, 4)
@ -122,8 +121,7 @@ class ModelSubclassingTest(keras_parameterized.TestCase):
model.compile(
'sgd',
'mse',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
data = dataset_ops.DatasetV2.from_tensor_slices(({
'a': np.ones((32, 10)),

View File

@ -63,8 +63,7 @@ def get_compiled_multi_io_model_temporal(sample_weight_mode):
metrics=[metrics.MeanAbsoluteError(name='mae')],
weighted_metrics=[metrics.MeanAbsoluteError(name='mae_2')],
sample_weight_mode=sample_weight_mode,
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
return model

View File

@ -164,15 +164,8 @@ def get_model_from_layers_with_input(layers,
def get_test_mode_kwargs():
run_eagerly = testing_utils.should_run_eagerly()
# Certain things weren't supported correctly in the old path, therefore
# with these changes, some tests now only pass in the single code path in V2.
if run_eagerly or context.executing_eagerly():
experimental_run_tf_function = True
else:
experimental_run_tf_function = testing_utils.should_run_tf_function()
return {
"run_eagerly": run_eagerly,
"experimental_run_tf_function": experimental_run_tf_function
}
@ -232,7 +225,6 @@ class CompositeTensorOutputTest(keras_parameterized.TestCase):
# converts the ragged tensor back to a dense tensor.
layers = [ToRagged(padding=0)]
model = testing_utils.get_model_from_layers(layers, input_shape=(None,))
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model._run_eagerly = testing_utils.should_run_eagerly()
# Define some input data with additional padding.
@ -247,7 +239,6 @@ class CompositeTensorOutputTest(keras_parameterized.TestCase):
# converts the ragged tensor back to a dense tensor.
layers = [ToRagged(padding=0)]
model = testing_utils.get_model_from_layers(layers, input_shape=(None,))
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model._run_eagerly = testing_utils.should_run_eagerly()
# Define some input data with additional padding.
@ -262,7 +253,6 @@ class CompositeTensorOutputTest(keras_parameterized.TestCase):
# converts the ragged tensor back to a dense tensor.
layers = [ToSparse()]
model = testing_utils.get_model_from_layers(layers, input_shape=(None,))
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model._run_eagerly = testing_utils.should_run_eagerly()
# Define some input data with additional padding.
@ -282,7 +272,6 @@ class CompositeTensorOutputTest(keras_parameterized.TestCase):
# converts the ragged tensor back to a dense tensor.
layers = [ToSparse()]
model = testing_utils.get_model_from_layers(layers, input_shape=(None,))
model._experimental_run_tf_function = testing_utils.should_run_tf_function()
model._run_eagerly = testing_utils.should_run_eagerly()
# Define some input data with additional padding.
@ -418,8 +407,7 @@ class ScipySparseTensorInputTest(keras_parameterized.TestCase,
model.compile(
optimizer="sgd",
loss="mse",
metrics=["accuracy"],
experimental_run_tf_function=testing_utils.should_run_tf_function())
metrics=["accuracy"])
input_data = scipy.sparse.coo_matrix(([1, 2, 3], ([0, 1, 1], [0, 0, 1])),
shape=[2, 3])
@ -480,8 +468,7 @@ class ScipySparseTensorInputTest(keras_parameterized.TestCase,
model.compile(
optimizer="sgd",
loss="mse",
metrics=["accuracy"],
experimental_run_tf_function=testing_utils.should_run_tf_function())
metrics=["accuracy"])
input_data = {
input_name:

View File

@ -86,8 +86,7 @@ class TestIOUtils(keras_parameterized.TestCase):
model.compile(
loss='binary_crossentropy',
optimizer='sgd',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
run_eagerly=testing_utils.should_run_eagerly())
# Note: you have to use shuffle='batch' or False with HDF5Matrix
model.fit(x_train, y_train, batch_size=32, shuffle='batch', verbose=False)

View File

@ -1859,8 +1859,7 @@ class KerasLoadTest(test.TestCase, parameterized.TestCase):
[feature_column_lib.DenseFeatures(columns),
core.Dense(1)])
model_input = {"x": constant_op.constant([[1.]])}
model.compile(optimizer="adam", loss="mse", run_eagerly=True,
experimental_run_tf_function=True)
model.compile(optimizer="adam", loss="mse", run_eagerly=True)
model.fit(model_input, constant_op.constant([[3.]]))
loaded = cycle(model, cycles)
loaded._default_save_signature(model_input)