shubham goel
shubham goel

Reputation: 63

Cannot see Tensorflow logs in google colab notebook

I was playing around with tensorflow apis on google colab virtual notebook. I want to see device mapping of my colab virtual machine.

As mentioned on tensorflow developer guide, I can set the flag (log_device_placement=True) to enable logging. https://www.tensorflow.org/guide/using_gpu

Below is my code running on colab notebook -

import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)

tf.logging.set_verbosity(tf.logging.INFO)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

But it doesn't seems to work on colab notebook. However it is working with local jupyter notebook terminal console.

Any idea how to enable logging on google colab platform ?

Upvotes: 3

Views: 2889

Answers (1)

Bob Smith
Bob Smith

Reputation: 38619

Looks like a TensorFlow issue: https://github.com/tensorflow/tensorflow/issues/3047

Or, a jupyter issue: https://github.com/ipython/ipython/issues/1230

Here's a work-around using a third-party library:

!pip install wurlitzer

import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)

tf.logging.set_verbosity(tf.logging.INFO)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

# Runs the op.
from wurlitzer import pipes

with pipes() as (out, err):
  print(sess.run(c))

print (out.read())

Full notebook: https://colab.research.google.com/drive/1Z5FVCD_z8EMmyd31PsjQffQV_K7dDLfj

Upvotes: 1

Related Questions