IMPORTANT: Thank you for all the support for this article! Colab is now supports TPU out of the BOX! https://colab.research.google.com/notebooks/tpu.ipynb

Turns out there is no, due to the different reasons, support of TPUs in the Google Colab. Here is where we can use Google Compute Engine DeepLearning images to solve this problem. This is possible since recently we have announced that images are now can be used as a Google Colab backend. So with this functionality, there are only a few steps that we need to be done in order to start using TPUs with Colab:

start cheap CPU instance with GCE DeepLearning image

connect the VM to the Colab

create TPU

Profit!

Start Cheap CPU Instance

In order to do so with the latest image you can run the following command:

Please keep in mind that you DO need to set scopes to “cloud-platform”, otherwise the instance will NOT be able to talk to the instance.

If you want to use exact image that I have used you can run the following command:

This image has TF 1.9 and is exact image that I’m using while writing this.

Connect The VM to The Colab

SSH to the instance with port mapping(gssh command is from here):

Open your browser once at localhost:8080

Go to the Colab and create the new notebook:

Connect it to the localhost. Click on the dropdown next to the “Connected”

Click on “Connect to local runtime…”

Press “connect”

Done:)

Create TPU

Now it is time to open Google Cloud Console on the TPU Page:

If used by the firs time you might need to enable the API:

From here you can click “Create TPU Node”:

Now you need to:

fill the name

set the zone ( should be the same as the instance zone )

) set ip range

press “create”:

Now you have to wait until it goes from this state:

To this:

Now when you have an IP address (10.0.101.1)you can go back to your notebook and start using it!

Use Your TPU From The Colab

Create a cell and run something like:

Done! We now have a working TPU session in the Colab: