Skip to content
forked from cs231n/gcloud

Google Cloud tutorial and setup

Notifications You must be signed in to change notification settings

asadovnik/gcloud

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Cloud Setup and Tutorial

BEFORE WE BEGIN

BIG REMINDER: Make sure you stop your instances!

(We know you won't read until the very bottom once your assignment is running, so we are printing this at the top too since it is super important)

Don't forget to stop your instance when you are done (by clicking on the stop button at the top of the page showing your instances), otherwise you will run out of credits and that will be very sad. :(

If you follow our instructions below correctly, you should be able to restart your instance and the downloaded software will still be available.

Create and Configure Your Account

For the class final project, we offer an option to use Google Compute Engine for developing and testing your implementations. This tutorial lists the necessary steps of working on the assignments using Google Cloud. We expect this tutorial to take a little while. Don't get intimidated by the steps, we tried to make the tutorial detailed so that you are less likely to get stuck on a particular step. I will open a discussion section on Canvas for students who are having problem setting up their account.

You will receive an email from me with a link to redeem your $50 credit (If $50 ends up not being enough, I will try to adjust this number as the semester goes on). When clicking that link you will be sent to a webpage where you will be requuired to enter your full name and email. You must use your UTK email. Note that the domain name is already placed there for you (can change between @utk.edu and @vols.utk.edu.)

This email should be sent relatively quickly. If you do not find it in your main inbox look for it in your spam folder. Once you recieve this email you will be asked to click an additional link to verify your email. This in turn will send you an additional email with your $50 credit. Simply click on this link and you will be sent to a webpage where you simply have to agree to the terms and conditions. That's it. You've created your Google Cloud Platform (GCP) account.

Note that at some point you will see a bar on the top allowing you to actiave $300 of credit since you are a new user. Feel free to do so, alothugh that requires you to insert a credit card (They say it will not be charged but I'm not 100% sure how it works). More details about that can be found in te bottom of this page.

You should now be able to go to the main dashboard by clicking on the "Google Cloud Platform" banner. Notice that through this tutorial all the menu options can be reached through the hamurger button on the top left.

Request an increase in GPU quota

Your account typically does not come with GPU quota. Please request the quota increase ASAP, because they will take up to a week to process! If you don't have GPU quota, you will have to create a CPU-only VM first and create another GPU VM later, explained in the next section.

Before you request a GPU you check that you have a default zone and region set under Compute Engine > Settings > Region / Zone. Please set these to be us-east1 and one of the zones, and then try again.

You have to explicitly request for it under IAM Admin >Quotas. Follow the instructions at:

Google Cloud VM Image

  1. Go to this gcloud marketplace. You may (or may not) be taken to a page where you have to click on "Launch in Compute Engine", and then you should see a configuration sheet with the title "New Deep Learning VM deployment".
  2. Fill in Deployment name field with your preferred VM name.
  3. In Machine type field, change 2 vCPUs to 1 vCPU. You can always add more CPUs later if necessary.
  4. In GPUs field, you can follow one of the two paths:
    • (a) If you have successfully requested GPU quota, you should set Number of GPUs to 1. GPU drivers and CUDA will be automatically installed only if you select at least 1 GPU. It's better to do it this way, so wait for this step until you have receievd an your quota.
    • (b) If you don't have GPU quota yet, you must set Number of GPUs to None. WARNING: GPU drivers and CUDA will NOT be installed. All libraries will be CPU only. Once your GPU quota increase request is approved, you can follow path (a) to deploy a GPU-enabled image.
  5. In Frameworks field, make sure TensorFlow Enterprise 2.1 (Intel optimized ...) is selected.
  6. Check the box Install NVIDIA GPU driver automatically on first startup?.
  7. Check the box Enable access to JupyterLab via URL instead of SSH. (Beta) if you would like to try and set that up.
  8. Leave all other options as default.
  9. Click the blue botton Deploy at the end of the page.

Your configuration sheet should look similar to below:

Once you click deploy you will have to wait a while till everything gets set up (a few minutes). In the meantime you will see a screen saying that it is being deplyed. Once it has completed you will see a message that it was deployed successfullly(do not worry about the warnings). Note that this may fail due to not having enough resources. You may be able to change your zone to a different one to fix that.

Your virtual machine is now running. You can always see all of your runnning virtual machines at: Compute Engine > VM Instances. This screen allows you to start and stop your instance. It also allows you to open a browser window to directly ssh into yout machine.

Change VM hardware (only if needed)

You can always change number of CPUs, number of GPUs, CPU memory, and GPU type after your VM has been created.

  1. You must stop the instance first.
  2. Go to your VM instance's details at Compute Engine > VM instances > [click on instance name]. Click "edit" on your VM's page.
  3. In Machine type box, click Customize.
  4. Set Number of GPUs to None if you don't need GPUs.
  5. For GPU type, NVIDIA Tesla K80 is typically enough for most of our assignments. P100 and V100 are way more expensive, but also faster.
  6. Scroll all the way down and click Save button.
  7. Start your instance again.

Access your newly created VM

Now that you have created your virtual GCE, you want to be able to connect to it from your computer. The rest of this tutorial goes over how to do that using the command line. First, download the Google Cloud SDK that is appropriate for your platform from here and follow their installation instructions. NOTE: this tutorial assumes that you have performed step #4 on the website which they list as optional.

If gcloud command is not in system path, you can also reference it by its full path /<DIRECTORY-WHERE-GOOGLE-CLOUD-IS-INSTALLED>/bin/gcloud. See this page for more detailed instructions.

To ssh into your VM, go to your VM instance details page by clicking on its name. Under Remote access at the top of the page, you may either click directly on SSH which will launch a new browser window with the SSH session, or click on the drop-down arrow and select View gcloud command instead to retrieve the terminal command. It should look like

gcloud compute --project "<YOUR_PROJECT_ID>" ssh --zone "us-west1-b" "<YOUR_VM_NAME>"

Transferring Files From Your Instance To Your Computer

You can transfer the files from GCP instance to your local laptop. There is an easy command for this purpose:

gcloud compute scp <user>@<instance-name>:/path/to/assignment1.zip /local/path

For example, to download files from our instance to the current folder:

gcloud compute scp tonystark@cs231:/home/shared/assignment1.zip .

The transfer works in both directions. To upload a file to GCE:

gcloud compute scp /my/local/file tonystark@cs231:/home/shared/

BIG REMINDER: Make sure you stop your instances!

Don't forget to stop your instance when you are done (by clicking on the stop button at the top of the page showing your instances). You can restart your instance and the downloaded software will still be available.

We have seen students who left their instances running for many days and ran out of credits. This includes code development time. We encourage you to read up on Google Cloud, regularly keep track of your credits and not solely rely on our tutorials.

Appendecies

The follwing describes some extra constumization information from Stanford's CS231n: Convolutional Neural Networks for Visual Recognition. I have not tried any of this and will only be able to offer minimal assistance. It mostly relates to actiavting your $300 credit and activating jupyter notebooks. If you are not worried about that then you are basically done.

Activating your $300 credit

Enter the requested information (your name, billing address and credit card information). Remember to select "Individual" as "Account Type":

Once you have entered the required information, press the blue Start my free trial button. You will be greeted by a page like this:

Click the "Google Cloud Platform" (in red circle), and it will take you to the main dashboard:

To change the name of your project, click on Go to project settings under the Project info section.

Configure networking

  1. You must stop the instance first.
  2. Go to your VM instance's details at Compute Engine > VM instances > [click on instance name]. Click "edit" on your VM's page.
  3. Select "Allow HTTP traffic" and "Allow HTTPS traffic".
  4. Scroll all the way down and click the blue button "save".
  5. Go to Firewall config page.
  6. Click "CREATE FIREWALL RULE"
  7. Give it an arbitrary name, such as cs231n.
  8. In Targets field, select All instances in the network.
  9. In Source IP ranges, enter 0.0.0.0/0.
  10. In Protocols and ports field, select "Specified protocols and ports". Then check tcp and enter 7000-9000.
  11. Click the blue button Create.
  12. Restart your instance on the Compute Engine page.

Your configuration sheets should look similar to below:

Firewall Rules:

First-time Setup Script

After you SSH into the VM for the first time, you need to run a few commands in your home directory. You will be asked to set up a password for your Jupyter notebook.

git clone https://github.com/cs231n/gcloud.git
cd gcloud/
chmod +x ./setup.sh
./setup.sh

Verification

If you have GPU enabled, you should be able to:

  • run nvidia-smi and see the list of attached GPUs and their usage statistics. Run watch nvidia-smi to monitor your GPU usage in real time.
  • inside the gcloud/ folder, run python verify_gpu.py. If your GPU is attached and CUDA is correctly installed, you shouldn't see any error.
  • If you want to use Tensorflow 2.0, run python test_tf.py. The script will show you the installed Tensorflow version (2.0.0-alpha) and then run a sample MNIST training. You should see around 97% accuracy at the end.

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 connect to it with your local browser.

Getting a Static IP Address

Change the External IP address of your Google Cloud Engine instance to be static (see screenshot below).

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 VPC network > External IP addresses (see screenshot below).

To have a static IP address, change Type from Ephemeral to Static. Enter your prefered name for your static IP, ours is cs231n-ip (see screenshot below). And click on Reserve.

NOTE: At the end of CS 231N when you don't need your instance anymore, release the static IP address because Google charges a small fee for unused static IPs (according to this page).

Take note of your Static IP address (circled on the screenshot below). We use 35.185.240.182 for this tutorial.

Launching and connecting to Jupyter Notebook

After you ssh into your VM using the prior instructions, run Jupyter notebook from the folder with your assignment files.

jupyter notebook

The default port is 8888, specified in ~/.jupyter/jupyter_notebook_config.py.

You can connect to your Jupyter session from your personal laptop. Open any browser and visit 35.185.240.182:8888. The login password is the one you set with the setup script above.

About

Google Cloud tutorial and setup

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.0%
  • Shell 1.0%