Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Custom and Distributed Training with Tensorflow/Week 3 - Graph Mode/C2_W3_Lab_1_autograph-basics.ipynb
Views: 13370
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
Addition in autograph
You can use the @tf.function
decorator to automatically generate the graph-style code as shown below:
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).
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
!