How to use free GPU/TPU with Pipcook on Google Colab

Alibaba Tech
2 min readOct 28, 2020

--

In order to reduce the cost of computing power for front-end engineers using Pipcook, we supported the use of Pipcook training models on Google Colab in August.

Google Colab is a Juypter Notebook service provided by Google, which can use free GPU/TPU resources.

Let’s start the Step by Step of this article!

Create a new Google Colab on Google Drive. Opening the link will create a new *.ipynb file on your Google Drive.

Next is environment preparation. Just execute the following code in the code block in Notebook:

!wget -P /tmp https://nodejs.org/dist/v12.18.1/node-v12.18.1-linux-x64.tar.xz
!rm -rf /usr/local/lib/nodejs
!mkdir -p /usr/local/lib/nodejs
!tar -xJf /tmp/node-v12.18.1-linux-x64.tar.xz -C /usr/local/lib/nodejs
!sh -c 'echo "export PATH=/usr/local/lib/nodejs/node-v12.18.1-linux-x64/bin:\$PATH" >> /etc/profile'
!rm -f /usr/bin/node
!rm -f /usr/bin/npm
!ln -s /usr/local/lib/nodejs/node-v12.18.1-linux-x64/bin/node /usr/bin/node
!ln -s /usr/local/lib/nodejs/node-v12.18.1-linux-x64/bin/npm /usr/bin/npm
!npm config delete registry
import os
PATH_ENV = os.environ['PATH']
%env PATH=/usr/local/lib/nodejs/node-v12.18.1-linux-x64/bin:${PATH_ENV}

Since Juypter Notebook generally only provides a specific Python environment, the above script is to install the Node.js environment.

After preparing the Node.js environment, you can install Pipcook Cli.

!npm install @pipcook/pipcook-cli -g
!rm -f /usr/bin/pipcook
!ln -s /usr/local/lib/nodejs/node-v12.18.1-linux-x64/bin/pipcook /usr/bin/pipcook

After the installation is successful, start the daemon:

!sudo pipcook init
!sudo pipcook daemon start

After the startup is successful, you can use Pipcook to train the model you want. We have prepared two sets of Google Colab tutorials for UI component recognition:

How to switch Google Colab to GPU/TPU?

In the process of using Google Colab, the CPU machine is used by default, so how to switch to GPU and TPU?

As shown in the figure above, after entering Google Colab, click Runtime> Change runtime type:

After switching to GPU or TPU in the pop-up prompt box, just save (SAVE).

End

We are convening volunteers to participate in Pipcook to create a Jupyter Notebook that is more suitable for Node.js/Web developers.

Alibaba Tech

First hand and in-depth information about Alibaba’s latest technology → Facebook: “Alibaba Tech”. Twitter: “AlibabaTech”.

--

--

Alibaba Tech

First-hand & in-depth information about Alibaba's tech innovation in Artificial Intelligence, Big Data & Computer Engineering. Follow us on Facebook!