OR 750. Setting up G Cloud machine for deep learning

Here is the URL you will need to access in order to request a Google Cloud Platform coupon. You will be asked to provide your school email address and name. An email will be sent to you to confirm these details before a coupon is sent to you.

Student Coupon Retrieval Link

You will be asked for a name and email address, which needs to match the domain. A confirmation email will be sent to you with a coupon code.

Please contact me if you have any questions or issues.

Once you redeemed the coupon go to the Google cloud console.

Click on the top of the screen to select list of projects and click on + to create a new project.

Polaris Project 

I typically use Cloud Shel, which you can start by clicking on the terminal icon on the top right corner. You can also install gcloud on your local machine as described here.

Ask to increase you quota on GPUs, it is 0 be default. Go to Compute Engine -> Quotas

Polaris Project 

And check the Google Compute Engine API NVIDIA K80 GPUs for us-east1 region, then click Edit Quotas on the top

Polaris Project 

Now create a virtual machine by clicking Compute Engine -> VM Instances.

Polaris Project 

Make sure you choose zone us-east1-c.

Polaris Project 

Using the gcloud command

gcloud beta compute instances create dl-gpu \
	--machine-type n1-standard-2 --zone us-east1-c --accelerator \
	type=nvidia-tesla-k80,count=1 --image-family ubuntu-1604-lts --image-project \
	ubuntu-os-cloud --boot-disk-size 50GB --maintenance-policy TERMINATE \

ssh to your newly created machine by

gcloud compute ssh dl-gpu --zone us-east1-c

Install CUDA libraries by running the following script (with sudo)

echo "Checking for CUDA and installing."
# Check for CUDA and try to install.
if ! dpkg-query -W cuda-8-0; then
  # The 16.04 installer works with 16.10.
  curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  dpkg -i ./cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  apt-get update
  apt-get install cuda-8-0 -y

Verify coda installation


Install Anaconda

curl -O https://repo.continuum.io/archive/Anaconda2-
bash Anaconda2-
source ~/.bashrc

Install pytorch

conda install pytorch torchvision cuda80 -c soumith

Verify that pytroch has access to cuda

sokolov83@dl-gpu:~$ python
Python 2.7.13 |Anaconda, Inc.| (default, Sep 30 2017, 18:12:43)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()

Repeat the steps to create a CPU machine

gcloud beta compute instances create dl-cpu
	--machine-type n1-standard-2 --zone us-east1-c --image-family ubuntu-1604-lts
	--image-project ubuntu-os-cloud --boot-disk-size 50GB --maintenance-policy
	 TERMINATE --restart-on-failure

Then start the instance and ssh to the it

gcloud compute ssh dl-cpu --zone us-east1-c

Using Jupyter Notebook with Google Compute Engine

Many of the assignments will involve using Jupyter Notebook. Below, we discuss how to run Jupyter Notebook from your GCE instance and use it on your local browser.

Getting a Static IP Address

Change the Extenal IP address of your GCE instance to be static (see screenshot below).

Polaris Project 

To Do this, click on the 3 line icon next to the Google Cloud Platform button on the top left corner of your screen, go to Networking and External IP addresses (see screenshot below).

Polaris Project 

To have a static IP address, change Type from Ephemeral to Static. Enter your preffered name for your static IP, mine is assignment-1 (see screenshot below). And click on Reserve. Remember to release the static IP address when you are done because according to this page Google charges a small fee for unused static IPs. Type should now be set to Static.

Polaris Project 

Take note of your Static IP address (circled on the screenshot below). I used for this tutorial.

Polaris Project 

Adding a Firewall rule

One last thing you have to do is adding a new firewall rule allowing TCP acess to a particular <PORT-NUMBER>. I usually use 7000 or 8000 for <PORT-NUMBER>. Click on the 3 line icon at the top of the page next to Google Cloud Platform. On the menu that pops up on the left column, go to Networking and Firewall rules (see the screenshot below).

Polaris Project 

Click on the blue CREATE FIREWALL RULE button. Enter whatever name you want: I used assignment1-rules. Enter for Source IP ranges and tcp:<PORT-NUMBER> for Allowed protocols and ports where <PORT-NUMBER> is the number you used above. Click on the blue Create button. See the screen shot below.

Polaris Project 

NOTE: Some people are seeing a different screen where instead of Allowed protocols and ports there is a field titled Specified protocols and ports. You should enter tcp:<PORT-NUMBER> for this field if this is the page you see. Also, if you see a field titled Targets select All instances in the network.

Configuring Jupyter Notebook

The following instructions are excerpts from this page that has more detailed instructions.

On your GCE instance check where the Jupyter configuration file is located:

ls ~/.jupyter/jupyter_notebook_config.py

Mine was in hometimnitgebru.jupyterjupyternotebookconfig.py

If it doesn’t exist, create one:

# Remember to activate your virtualenv ('source .env/bin/activate') so you can actually run jupyter :)
jupyter notebook --generate-config

Using your favorite editor (vim, emacs etc…) add the following lines to the config file, (e.g.: hometimnitgebru.jupyterjupyternotebookconfig.py):

c = get_config()

c.NotebookApp.ip = '*'

c.NotebookApp.open_browser = False

c.NotebookApp.port = <PORT-NUMBER>

Where <PORT-NUMBER> is the same number you used in the prior section. Save your changes and close the file