In this section, some frequently asked questions about the migration from TF 1.x to TF 2.0 will be addressed.
Does code written in TF 2.0 have the same speed as graph-based TF 1.x code?
Yes, code written in TF 2.0 using tf.function or tf.keras will have the same speed and optimality as it does in TF 1.x. As we mentioned earlier in this chapter, using tf.function to annotate major functions allows the model to be run in graph mode, and all the computations and logic in the function will be compiled into a computational graph. The same goes for using tf.keras to define and train TensorFlow models. Using the model.fit method will also train the model in graph mode and has all of the benefits and optimizations that come with this. When writing eager executed code, there is a slight performance drop, something which is more than compensated for by the other...