Path: blob/master/Custom and Distributed Training with Tensorflow/Week 3 - Graph Mode/C2_W3_Lab_1_autograph-basics.ipynb
15840 views
Kernel: Python 3
Autograph: Basic
In this ungraded lab, you will go through some of the basics of autograph so you can explore what the generated code looks like.
Imports
In [ ]:
Addition in autograph
You can use the @tf.function
decorator to automatically generate the graph-style code as shown below:
In [ ]:
if-statements in autograph
Control flow statements which are very intuitive to write in eager mode can look very complex in graph mode. You can see that in the next examples: first a simple function, then a more complicated one that involves lots of ops and conditionals (fizzbuzz).
In [ ]:
Fizzbuzz in autograph
You may remember implementing fizzbuzz in preparation for a coding interview.
Imagine how much fun it would be if you were asked to impement the graph mode version of that code!
Fortunately, you can just use @tf.function
and then call tf.autograph.to_code
!
In [ ]: