Should I use @tf.function for all functions?
问题 An official tutorial on @tf.function says: To get peak performance and to make your model deployable anywhere, use tf.function to make graphs out of your programs. Thanks to AutoGraph, a surprising amount of Python code just works with tf.function, but there are still pitfalls to be wary of. The main takeaways and recommendations are: Don't rely on Python side effects like object mutation or list appends. tf.function works best with TensorFlow ops, rather than NumPy ops or Python primitives.