You are on page 1of 14

Using Google Cloud Compute with

Jupyter Notebooks/Lab and Tensorflow


Deep Learning: Spring 2018
Patrick Aselin

With a Google account, users can set up VMs with up to 8CPUs 30GB of RAM. This is offered
for free for 365 days and with an initial balance of $300. Depending upon the VM setup you
choose, you will be charged a varying per hour rate. Once done with the VM, simply stop/delete
instance to terminate charging your balance.

1) Navigate to https://cloud.google.com/compute/, click “Try It Free” and navigate through the


setup. Note that you will need to enter a credit card, but you will not be billed as they will ask
before charging should you run out your account.
2) When you log in, you should see the following panel under the Compute Engine tab on the right
side. Click “Select”.
3) Click the “+” in the upper right hand corner.

4) In the screen that opens, enter a project name and click “Create”.
5) Click the three bars in the upper left hand corner, select “APIs & Services” and select
“Dashboard”.

6) Here you can enable the Compute Engine API by selecting the option.
7) Click the three bars in the upper left, select “Compute Engine” and click “VM Instances”.

8) We can now begin launching a VM instance by clicking “Create” on this page.


9) Technically the base settings are free, but we want to build a more powerful VM. Note
that the per hour cost is given in the green box and will update as you change parameters.

10) Under the machine type, you can choose a preset selection of CPU/RAM. Here, I select
8vCPUs for a more powerful system. Note that as you change these parameters, the per
hour charge will change (the more powerful, the higher per hour cost).
11) To the right of the “Machine Type” box, click “customize”. Here you can change the

number of cores and memory. Here I change the RAM to 30GB.

12) Scroll down to “Boot Disk” and click “Change” in the box. Here you can change the OS.
Here, I select “Ubuntu 16.04 LTS” and change the “Size” at the bottom to 25GB or
whatever you wish. Click “Select” to finish.
13) Scroll down and check the “Allow HTTP traffic” and “Allow HTTPS traffic” boxes.

14) Finally, click the “Create” button to launch the VM.

15) In the VM instance dashboard, you are now given this screen.
16) We now need to reserve a static IP address in order to open Jupyter from your browser.
Click the three bars in the upper left hand corner, scroll down and click “Network
Services”, and then click “External IP Addresses”.

17) Click the dropdown under Type where it says “Ephemeral” and select “Static”.
18) Here, type in a name for your IP address without spaces and click “Reserve”.

19) Now navigate back to the VM instance page. Next we need to set up the IP address to
connect to the VM through your browser. Click “instance-1” under the ‘Name” column.
20) Scroll down to the “Network Interfaces” section and click “default” under the “Network”
column.
21)

22) Next click the “Firewall rules” tab.

23) Here, scroll down, change Targets to “All instances in the network”, change Source Filter
to “IP Ranges”, in the Source IP Ranges field, type “0.0.0.0/0”, set the Second sources
filter to “None”, set Protocols and Ports to “Specified protocols and ports”, and in the
field below enter “tcp:8888; udp:8888”.

24) Navigate back to the VM instances dashboard and click “SSH” under the “Connect”
column. This will open the following terminal window.
25) In this terminal, enter the following commands to install Jupyer, Python 3, and
TensorFlow (should be able to copy/paste):
- sudo apt-get update
- sudo apt-get install python-pip
- cd /tmp
- curl -O https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
- sha256sum Anaconda3-5.0.1-Linux-x86_64.sh
- bash Anaconda3-5.0.1-Linux-x86_64.sh
- Go through the Anaconda installation process
- source ~/.bashrc
- conda update anaconda
- conda update –all
- sudo pip install tensorflow
- jupyter notebook --ip 0.0.0.0 --port 8888

26) In your browser, navigate to “[ip address reserved before]:8888/tree”


27) Copy the key highlighted below and paste into the token field in the Jupyter notebook.

28) You are now all set to use Jupyter Notebooks with TensorFlow! Note that you may be
disconnect from the SHH instance, shutting down your notebooks if your computer goes
to sleep or turns off. To persist, you can enter “nohup jupyter notebook --ip 0.0.0.0 --port
8888” to start a persistent Jupyter instance. Be sure to already have a notebook running
and in your browser before shutting down Jupyter from the terminal and then relaunching
with this command.

29) When finished, be sure to shutdown/delete your boot instance to ensure that you are not
being charged for use. Once this is removed, you must also navigate back to the External
IP Addresses page and remove the reserved IP address in order to not be charged for this.

You might also like