profile
viewpoint

Ask questionsSimple keras model, Model.fit() does not learn unless experimental_run_tf_function=False at compile

System information

  • Windos 10, 64 Bit
  • TensorFlow installed from pip
  • TensorFlow version: v2.1.0-rc2-17-ge5bf8de410 2.1.0
  • Python version: 3.7

Describe the current behavior

Simple Model (see below), compiles without error. It is used in a reinforcement scenario, i.e. iterations of predict() and fit() calls to iteratively train the model. Currently the model does not seem to improve with calls to fit() unless compile() was called with compile(..., experimental_run_tf_function = False).

Describe the expected behavior

Model should train equally well whether experimental_run_tf_function = False was passed to model.compile() or not.

Code to reproduce the issue

Example code can be found at https://github.com/fcarsten/tic-tac-toe/blob/tf-2.1-issue/test_nn_q_tf2.py - need to check out the whole branch as it uses other code from this repository.

Either run as is run_test(True) to see failing, or run_test(False) to see how it should run.

When running as expected "Player 1 win %" should increase and end up over 80%, usually somewhere around 90%. When not running as expected, "Player 1 win %" will randomly meander up and down.

The model is defined in File SimpleNNQPlayerTF2.py line 29 ff:

input_layer = tf.keras.Input(shape=(BOARD_SIZE * 3,))
x = tf.keras.layers.Dense(BOARD_SIZE * 3 * 9, activation='relu')(input_layer)
x = tf.keras.layers.Dense(BOARD_SIZE * 3 * 100, activation='relu')(x)
x = tf.keras.layers.Dense(BOARD_SIZE * 3 * 9, activation='relu')(x)
q_values = tf.keras.layers.Dense(BOARD_SIZE, activation=None, name='q_values')(x)
probabilities = tf.keras.layers.Softmax(name='probabilities')(q_values)

self.model = tf.keras.Model(inputs=input_layer, outputs=[probabilities, q_values])
if run_tf_function:
    self.model.compile(optimizer='adam', loss = [None, tf.keras.losses.MeanSquaredError()])
else:
    self.model.compile(optimizer='adam', loss = [None, tf.keras.losses.MeanSquaredError()], experimental_run_tf_function = False)

Other info / logs

While the model is a very simple sequential model, note that it has 2 output layers and the training target layer is not the final layer in the model. Not sure this makes any difference,

tensorflow/tensorflow

Answer questions pavithrasv

Thank you @fcarsten for taking a look. We are doing a bunch of code refactoring internally and i think this use case in eager will be fixed as part of that. Will update this thread after I know when it is fixed in a tf-nightly release.

useful!

Related questions

ModuleNotFoundError: No module named 'tensorflow.contrib'
Error occurred when finalizing GeneratorDataset iterator
ModuleNotFoundError: No module named 'tensorflow.contrib'
When importing TensorFlow, error loading Hadoop hot 4
The flag 'log_dir' is defined twice. hot 3
[TF 2.0] Dataset has no attribute 'make_one_shot_iterator' hot 3
Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. hot 3
TF2.0 AutoGraph issue hot 3
Error loading tensorflow hot 3
AttributeError: module 'tensorflow' has no attribute 'set_random_seed' hot 3
AttributeError: module 'tensorflow' has no attribute 'Session' hot 3
No tf.lite.experimental.nn.bidirectional_dynamic_rnn ops is finded hot 3
AttributeError: module 'tensorflow' has no attribute 'app' hot 3
Incorrect Error TypeError: padded_batch() missing 1 required positional argument: 'padded_shapes' hot 3
tensorflow2.0 detected 'xla_gpu' , but 'gpu' expected hot 2
Github User Rank List