TL;DR:
- Each student in the class will receive a $50 coupon for GCP. This amount isn't a lot, but it can be extended if you need more -- just let us know.
- This amount can be used together with the $300 credits you get when signing up for GCP. Since Stanford accounts do not have GCP project privileges, you should use a personal Google account to manage your Cloud instance(s) for this course.
- Although you will use your Stanford email to receive the credits, you should NOT apply the coupon to your Stanford email or Stanford account on GCP. Instead, apply the coupon to your GCP account registered with Personal GMail.
- TURN OFF YOUR INSTANCE WHEN NOT IN USE.
- You should have one group member set up GCP for your project, and add the other group members as project collaborators.
- To avoid having many Billing accounts is to have the other group members forward the email containing Coupon code to the member responsible for setting up GCP project. This will allow CS329S credit be accumulated into one single account.
- Google Cloud Free Tier does not come with GPU support or quota. You need to upgrade your account in order to use GPUs.
- TURN OFF YOUR INSTANCE WHEN NOT IN USE.
- Don't use GPUs unless you have to since GPUs are much more expensive! Start with CPUs only, and if that's too slow, switch to GPUs.
- TURN OFF YOUR INSTANCE WHEN NOT IN USE.
- The link to claim your GCP credits is on Ed.
- Google Cloud Platform (GCP) Setup Tutorial
This tutorial lists the necessary steps of setting up a VM instance on Google Cloud Platform.
For your class project, we recommend setting up an instance on GCP (Google Cloud Platform). $50 GCP credits will be given to each student for the class project. When you first sign up on GCP, you will have $300 free credits.
You should receive $300 credits from Google when you first sign up with Personal GMail and also UPGRADE it into a full account. Since Stanford accounts do not have GCP project privileges, you should use a personal Google account to manage your Cloud instance(s) for this course.
- Create Google Cloud account by going to the Google Cloud homepage. Click on the blue Get Started for free button. Sign into your Gmail account.
This should bring you to a registration page. Fill in the necessary information and click continue.
- Verify that your phone number is correct.
- Choose Account type to be Individual. You will then fill in your name, address and credit card information.
After that, this should bring you to the GCP Console.
- Click the "Google Cloud Platform" on the top left corner, to take you to the main project dashboard.
- To add project collaborators, click ADD PEOPLE TO THIS PROJECT. Add their email and make their role Owner.
Google Cloud Free Tier does not come with GPU support or quota. You need to upgrade your account in order to use GPUs.
- Click the navigation icon in the top right corner, and goto Billing.
- Click this link or MANAGE BILLING ACCOUNTS.
- Click into the account to go to BILLING ACCOUNT OVERVIEW. In the overview page, click UPGRADE.
- If the Cloud Billing account is upgraded to a paid account, you will see a Credits info card. The Google Cloud Free Program gives more details.
You should have created and logged in your GCP account registered with your personal gmail account by now.
- We will release the link to Google Cloud Education Grants page you will need to access in order to request a $50 Google Cloud Platform coupon on Ed. 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. Although you will use your Stanford email to receive the credits, you should NOT apply the coupon to your Stanford email or Stanford account on GCP. Instead, apply the coupon to your GCP account registered with Personal GMail.
- After submission, you should receive a email from GCP with a link to confirm your email address. Click the link to verify your Stanford email.
- You will soon receive another email from GCP with a link that applys the $50 credits to your account. Click on the link and enter your coupon code to redeem the $50 credit.
- After that, you will jump to the Billing Overview page where you should see the $50 promotional credit linked to CS 329S account.
- You should set a billing account to link to your project if your project does not have a billing account linked. (Click the navigation icon -> Billing).
Google Cloud does not support combining the $300 Free Tier credits with the $50 CS329S credits. Hence you will see 2 accounts in your Billing page. You will need to switch billing account if you want to use 2 sources of gcloud credits.
You should have one group member set up GCP for your project, and add the other group members as project collaborators.
Each group member may be able to claim $50. A tip to avoid having many Billing accounts is to have the other group members forward the email containing Coupon code to the member responsible for setting up GCP project. This will allow CS329S credit be accumulated into one single account.
This section describes the steps necessary to set up a GPU instance. Navigate to the Compute Engine page from Compute Engine -> VM Instances.
Click Enable to enable Compute Engine API.
Your account typically does not come with GPU quota. You have to explicitly request for it under IAM & Admin > Quotas.
Please request the quota increase ASAP, because they will take up between couple minutes to a week to process!
- On the Quotas page, filter for Metric: compute.googleapis.com/gpus_all_regions.
- Click EDIT QUOTA, and set a new limit.
- After setting a new global quota limit, filter for Metric again with the specific type of GPUs you wish to use (e.g. Metric: compute.googleapis.com/nvidia_a100_gpus) and your location (e.g. Dimensions (e.g. location): us-west1-a). Make sure that you have enough quota limit for the specific GPUs you wish to request, otherwise adjust the quota limit like before.
Wait until GCP send you a second email to confirm your quota request. (It could take couple minutes to couple days for them to approve.)
If you need more help, check out the official documentation for Requesting Additional Quota, or escalate any issues to us via a private Ed post (this has been an issue for students in other courses in the past, and we'd like to make sure that this isn't a major blocker for you!).
- Go to the Getting Started tab in your Dashboard.
- Click VIEW ALL next to Top products, and search for Deep Learning VM. Click into it and click LAUNCH. Make sure you enable all required APIs on the next page.
You should see a configuration sheet with the title "New Deep Learning VM deployment".
-
Fill in
Deployment name
field with your preferred VM name. -
Choose your desired number of
CPUs
andmemory
. -
Set
Number of GPUs
toNone
if you don't need GPUs.
For
GPU type
,NVIDIA Tesla K80
is typically enough.P100
andV100
are way more expensive (check the price on the right), but also faster and have larger memory. Check pricing and spec for GCP GPUs. GPU drivers and CUDA will be automatically installed only if you select at least 1 GPU.
Alternatively, you can choose None if you are not in need of GPU resources yet (you can always add on later) to save cost, and in this case GPU drivers and CUDA will not be installed.
-
In
Frameworks
field, changeTensorFlow Enterprise 2.7 (CUDA 11.3)
toPyTorch 1.10 (CUDA 11.0)
. If you wish to use Tensorflow, our setup script will help you set it up later in this tutorial. -
Check the box
Install NVIDIA GPU driver automatically on first startup?
. -
Check the box
Enable access to JupyterLab via URL instead of SSH. (Beta)
.
-
Leave all other options as default.
-
Click the blue botton
Deploy
at the end of the page. It will Automatically Start your Instance, so if you don't need to use it now, Stop it Immediately.
Once the deployment is finished. You should see a running VM with a green checkmark next to it in your Compute Engine -> VM Instances page.
While you can connect to your VM via a browser window, you may be more comfortable connecting to it in your local terminal via the gcloud
CLI. Follow the instructions here to install the Google Cloud SDK.
Note The gcloud
CLI (version 369.0.0) is not compatible with Python 3.10. If you run into this issue, you can resolve it by pointing the CLI to an earlier Python version.
export CLOUDSDK_PYTHON=/path/to/python-less-than-3.10
Once you have installed gcloud
, go to your VM instance details page by clicking on its name. Start the VM instance first. Once it has a green check mark on, click on the drop-down arrow and select View gcloud command instead to retrieve the terminal command.
This should give you a command like the following
gcloud beta compute ssh --zone "us-west1-b" "cs329s-vm" --project "secret-primacy-302223"
Copy and run the command in your terminal to SSH into your VM.
If you follow the instructions in Set Up Google Cloud VM Image, your VM should already come with PyTorch installed.
If you want to use TensorFlow without GPU, you can install the latest version.
pip install tensorflow
If you want to use TensorFlow with GPU, make sure that your TensorFlow version and your CUDA version are compatible. The current TensorFlow>=2.5.0 uses CUDA 11.2, TensorFlow==2.4 uses CUDA 11, and TensorFlow<=2.3 uses CUDA 10.1.
To install TensorFlow to use with CUDA 11.0, run the following command
pip install tensorflow-gpu==2.4.0
To install JAX without GPU, run the following command:
pip install --upgrade pip
pip install --upgrade "jax[cpu]"
To install JAX with GPU, run the following command
pip install --upgrade pip
# Installs the wheel compatible with CUDA 11 and cuDNN 8.2 or newer.
pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html # Note: wheels only available on linux.
You may have to install JAX in a virtual environment in order to avoid package conflicts (if you see /lib/x86_64-linux-gnu/libstdc++.so.6: version 'GLIBCXX_3.4.26' not found
):
python -m venv env
source env/bin/activate
pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html
You can use the scripts in this repo to check if PyTorch/TensorFlow/JAX is sucessfully installed and can be used with GPU on the server.
git clone https://github.com/stanford-cs329s/gcp-tutorials
cd gcp-tutorials
python check_pytorch.py
python check_tf.py
python check_jax.py
To see a list of attached GPUs and their usage statistics, run
nvidia-smi
To monitor your GPU usage in real time, run
watch nvidia-smi
To verify that PyTorch is installed correctly, run python check_pytorch.py
To verify that TensorFlow is installed correctly, run python check_tf.py
To verify that JAX is installed correctly, run python check_jax.py
We recommend using git
for your project. You can develop locally, push your change to Github, and pull on remote server to run.
You can also transfer files from your local computer to the remote server via gcloud compute scp
.
For example, to download files from your instance to our local computer, use:
gcloud compute scp <user>@<instance-name>:/path/to/file.zip /local/path
You can also scp
the other way around. To upload a file to your instance:
gcloud compute scp /local/path/file <user>@<instance-name>:/home/shared/
Please remember to STOP YOUR INSTANCE when you are done (by clicking on the stop button at the top of the page). If you fail to do so, and leave your instance running for additional days (or weeks) beyond that which you need, you run the risk of exhausting your CS329S credits and incurring personal billing charges. In order to avoid this, please be diligent about stopping your instance(s) when you are done using them.
Restarting your instance does not reset the machine's state: you can restart your instance and any downloaded software will still be available to you.
You will be charged per hour when your instance is running. This includes code development time. We encourage you regularly check your Cloud Billing so that you know how many credits you have left!
- This tutorial is based on https://github.com/cs231n/gcloud
- Official Documentation on Creating a Deep Learning VM Instance From the Google Cloud Marketplace
- Please remember to keep track of your compute credits, check VM instances pricing
- Google Cloud SDK provides tools and libraries for interacting with Google Cloud