


If you see a change in convergence behavior for your models, check the default learning rates. Some Keras optimizers have different learning rates in TF2. Adjust the default learning rate for some tf.keras.optimizers For inference use cases, it might be a single model forward pass.

Depending on your use case, this could be multiple training steps or even your whole training loop. For best performance, you should try to decorate the largest blocks of computation that you can in a tf.function (note that the nested python functions called by a tf.function do not require their own separate decorations, unless you want to use different jit_compile settings for the tf.function). Recommendations for idiomatic TensorFlow 2 Refactor your code into smaller modulesĪ good practice is to refactor your code into smaller functions that are called as needed. Import TensorFlow and other dependencies for the examples in this guide. Refer to the migrate section of the guide for more info on migrating your TF1.x code to TF2. This guide provides a list of best practices for writing code using TensorFlow 2 (TF2).
