xadahiya / gcm-tensorflow-udacity

Tutorial to use Google cloud compute instances with tensorflow. Thanks John graves (https://github.com/jg1141) for such an awesome presentation!

Home Page:http://xadahiya.me/revealjs_with_speech/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google cloud engine VM instance setup to train deep neural networks.

Server Configuration

After you sign up to Google Cloud Platform, there are three basic steps to complete:

  • Create a Linux-based VM instance with the required hardware specs. Tutorial here
  • Install Software: Anaconda Python, Tensorflow and Julia.
  • Set up Jupyter (IPython), so that you can do your MachineLearning/DataScience magic remotely via a browser.

1. Create a Linux VM Instance

GCE_CreateInstanceFollow the Quickstart guide to create a new VM instance, but note the following:

  • Machine type: a micro instance isn’t going to cut it for compute intensive tasks. I created a 16 vCPU machine; select what works for you. Note: if you need a machine with more than 24 cores, you’ll need to increase your quota.
  • Boot Disk: I’m more familiar with Ubuntu so, that’s what I picked (14.04 LTS). The setup instructions below assume you’re using Ubuntu.
  • Firewall: Allow HTTPS traffic.
  • Take note of the Zone and instance Name. You’ll need those them later in our final step. In this example, the zone is us-central1-f and the name is awesomeness

google-console-image

The SSH Browser-based Terminal

Google’s Compute Engine has a sweet browser-based SSH terminal you can use to connect to your machine. We’ll be using it for additional setup below. gcm-image2

2. Install Required Software

We’ll install two major software packages: Anaconda Python and Google Tensorflow. Bring up your SSH terminal and enter

wget http://repo.continuum.io/archive/Anaconda3-4.0.0-Linux-x86_64.sh
bash Anaconda3-4.0.0-Linux-x86_64.sh

and follow the on-screen instructions. The defaults usually work fine, but answer yes to the last question about prepending the install location to PATH:

Do you wish the installer to prepend the 
Anaconda3 install location to PATH 
in your /home/haroldsoh/.bashrc ? 
[yes|no][no] >>> yes

To make use of Anaconda right away, source your bashrc

source ~/.bashrc

Install Tensorflow and tqdm modules

conda install -c conda-forge tensorflow
conda install -c conda-forge tqdm

3. Set up Jupyter (IPython)

In our final step, we’ll need to set up the Jupyter server and connect to it. The following instructions come mainly from here, with some tweaks.

Open up a SSH session to your VM and generate the Jupyter configuration file

jupyter notebook --generate-config

We’re going to add a few lines to your Jupyter configuration file; the file is plain text so, you can do this via your favorite editor (e.g., vim, emacs), I used nano:

nano ~/.jupyter/jupyter_notebook_config.py

Add the following lines to config file

c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8123

Once that’s done we can start the server using screen.

Install screen:

sudo apt-get install screen

and start a screen session with the name jupyter:

screen -S jupyter

The -S option names our session (else, screen will assign a numeric ID). I’ve chosen “jupyter” but the name can be anything you want.

Create a notebooks directory and start the jupyter notebook server:

cd ~/
mkdir notebooks
cd notebooks
jupyter notebook

Press CTRL-A, D to detach from the screen and take you back to the main command line. If you want to re-attach to this screen session in the future, type:

screen -r jupyter

You can now close your SSH session if you like and Jupyter will keep running.

Client Configuration

Now that we have the server side up and running, we need to set up a SSH tunnel so that you can securely access your notebooks.

For this, you’ll need to install the Google Cloud SDK on your local machine. Come back after it’s installed.

Now, authenticate yourself:

gcloud --init

and initiate a SSH tunnel from your machine to the server:

gcloud compute ssh  --zone=<host-zone> --ssh-flag="-D" --ssh-flag="1080" --ssh-flag="-N" --ssh-flag="-n" <host-name>

You’ll need to replace the host-zone and host-name with the appropriate zone and host-name of your VM (that you took note of in the first step). You’ll also find the relevant info on your VM Instances page.

Finally, start up your favorite browser with the right configuration:

<browser executable path> --proxy-server="socks5://localhost:1080" --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" --user-data-dir=/tmp/

Replace browser executable path with your full browser path on your system. See here for some common executable paths on different operating systems.

Finally, using the browser that you just launched, head to your server’s main notebook page:

http://<host-name>:8123

Tip : Use instance name not IP (awesomeness in my case).

and if everything went according to plan, you should see something like this: image-3

That’s it! Congratulations!

I just made some changes to make it compatible with dlnd projects.

About

Tutorial to use Google cloud compute instances with tensorflow. Thanks John graves (https://github.com/jg1141) for such an awesome presentation!

http://xadahiya.me/revealjs_with_speech/