Running cloud TPU profiler in Google Colab environment

1.2k Views Asked by At

I am running a Google Colab notebook and am trying to capture TPU profiling data for use in TensorBoard, however I can't get capture_tpu_profile to run in the background while running my TensorFlow code.

So far I tried to run the capture process in the background with:

!capture_tpu_profile --logdir=gs://<my_logdir> --tpu=$COLAB_TPU_ADDR &

and

!bg capture_tpu_profile --logdir=gs://<my_logdir> --tpu=$COLAB_TPU_ADDR
2

There are 2 best solutions below

2
On BEST ANSWER

Turns out a way to do this is to start the process from python directly like this (I also had to modify the parameter from --tpu to --service_addr):

import subprocess
subprocess.Popen(["capture_tpu_profile","--logdir=gs://<my_logdir>", "--service_addr={}".format(os.environ['COLAB_TPU_ADDR'])])

the check=True makes the command raise an Exception if it fails.

0
On