Graph execution in TensorFlow 2
TensorFlow 2 is eager execution by default. However, as a Keras user, when I do NN training and predictions, TensorFlow is actually running in graph execution mode. Basically, graph execution still offers better performance and can be easily run in parallel. Useful documentation about graph execution can be found at the following:
- Introduction to graphs and tf.function
- Better performance with tf.function
- AutoGraph reference
Although Keras uses graphs by default, it is possible to configure it to run eagerly. See Model training APIs. It is also possible to turn off
tf.function everywhere in TensorFlow. See tf.config.run_functions_eagerly.
Note that while TensorFlow 1 was also using graphs, the graphs in TensorFlow 2 are very different compared to those in TensorFlow 1. There is no longer any
feed_dict, etc. See Migrate your TensorFlow 1 code to TensorFlow 2.