Hacker News new | ask | show | jobs
by brilee 2122 days ago
Disclaimer: I worked on AutoGraph @ google.

Your first two paragraphs describe TF 1 perfectly, and you also correctly point out that TF 2 has eager mode, which executes op by op.

The part you missed is that @tf.function lets users tell TensorFlow that TF should execute the entire function, inspect the graph that it produces, and optimize it. On top of this JIT functionality that tf.function provides, AutoGraph will inspect the source code of your program and see that there's a for loop. If the for loop executes over a Python object, then it acts as a preprocessor macro. If it executes over a tensor, then AutoGraph transforms it into a tf.while_loop. So you can have both Eager-style convenience and graph-style optimizations.

Of course, some caveats apply; check out https://www.tensorflow.org/guide/function for the full guide.

1 comments

Ah wow, that is interesting. I didn't know about tf.function, thank you for the correction