Better performance with tf.function
If you would like to execute Python code during each invocation of a Function, tf.py_function is an exit hatch. The drawback of tf.py_function is that it's not portable or particularly performant, cannot be saved with SavedModel, and does not work well in distributed (multi-GPU, TPU) setups. Also, since tf.py_function has to be wired into the graph, it casts all inputs/outputs to tensors. Changing Python global and free variables counts as a Python side effect, so it only happens during tracing. Sometimes unexpected behaviors are very hard to notice.
Jul-28-2022, 01:26:19 GMT
- Technology: