Collaborating Authors

#003 TF 2.0 Eager Execution- A Pythonic way of using TensorFlow Master Data Science 24.12.2018


TensorFlow uses Eager execution, which is a more convenient way to execute the code, and also more "Pythonic". It is a default choice in the latest version TensorFlow 2.0. In TensorFlow 1.x, we first need to write a Python program that constructs a graph for our computation, the program then invokes, which hands the graph off for execution to the C runtime. This type of programming is called declarative programming (specification of the computation is separated from the execution of it). So, Sessions provide one way to execute these compositions.

TensorFlow meets PyTorch with Eager execution. – Yaroslav Bulatov – Medium


Relaxing this requirement was one of my projects when I was at Google Brain, eventually open-sourced as imperative mode. However it relied on private/unstable APIs which became too costly to maintain over time. Luckily, PyTorch coming out crystallized researcher needs/wants, and there has been a concerted effort to support this kind of mode as a first-class citizen. It's still under active development but the version available in nightly release is quite usable, to try it out: Note that there's no longer need to deal with graph or session and execution happens immediately. So what can you do with it?

Deep Reinforcement Learning with TensorFlow 2.0


In this tutorial, I will showcase the upcoming TensorFlow 2.0 features through the lens of deep reinforcement learning (DRL) by implementing an advantage actor-critic (A2C) agent to solve the classic CartPole-v0 environment. While the goal is to showcase TensorFlow 2.0, I will do my best to make the DRL aspect approachable as well, including a brief overview of the field. In fact, since the main focus of the 2.0 release is making developers' lives easier, it's a great time to get into DRL with TensorFlow -- our full agent source is under 150 lines! The code is available as a notebook here and online on Google Colab here. As TensorFlow 2.0 is still in an experimental stage, I recommend installing it in a separate (virtual) environment.

TensorFlow 1.x vs 2.x. – summary of changes


In 2019, Google announced TensorFlow 2.0, it is a major leap from the existing TensorFlow 1.0. Ease of use: Many old libraries (example tf.contrib) were removed, and some consolidated. For example, in TensorFlow1.x the model could be made using Contrib, layers, Keras or estimators, so many options for the same task confused many new users. TensorFlow 2.0 promotes TensorFlow Keras for model experimentation and Estimators for scaled serving, and the two APIs are very convenient to use. The writing of code was divided into two parts: building the computational graph and later creating a session to execute it.