Ultimate guide to setting up a Google Cloud machine for fast.ai version 2
1. Sign up on Google Cloud Platform Free Tier.
2. Upgrade to a paid account (credit card required).
Note 1: Please note that some people have reported that Google Cloud does not accept debit cards.
Note 2: If you are unable to find an Upgrade button at this point, just continue with the next steps. The Upgrade button should appear at Step 5 below when you request for an increase in quota.
3. Create a new project for the fast.ai course
4. Set a default Compute Engine region
Compute Engine → Settings
5. Request for increase in quota for GPU
IAM & Admin → Quotas
6. Receive email approval of quota increase
7. Configure firewall for Jupyter notebook
VPC Network → Firewall rules
Create a firewall rule if your project does not already have one for tcp:8888.
You may choose some other unused port number but the typical number is 8888. It is permissible to specify a range of ports such as in the above case.
8. Create your virtual machine instance for fast.ai
Compute Engine → VM instances → Create
It is up to you to decide the number of cores and the amount of memory to allocate for your VM instance but if you have the budget for it, it is a good idea to go with 4 cores and 26 GB memory (ideally > 12 GB, as the Tesla K80 GPU comes with 12 GB memory).
Again, it is up to you to decide the type of persistent disk to use as the boot disk but SSD is recommended for its higher speed if you have the budget for it. (For the fast.ai version 2 course, you minimally need 20 GB.)
9. (Optional) Convert the IP address to static
VPC network → External IP addresses
**Following this step results in ongoing charges for the static IP address. Skip this step if you wish to save on the cost of a static IP address (US$0.01/hour at time of writing).
10. Connecting to the VM instance
There are a few methods of connecting to your Ubuntu VM according to Google Cloud Platform’s official documentation (which can be found here). Two of those methods will be mentioned briefly.
Method 1: SSH from the browser:
While this method is the most convenient, it comes with a list of known issues that are officially documented here, which is why I recommend using the Google Cloud SDK command line method below.
Method 2: Command line using Google Cloud SDK (recommended)
Step a. Download and install Cloud Tools for your OS to use the Cloud SDK. (Windows users: check the option to install Python during installation).
Step b. Run “gcloud init” to link your account, and select project and region.
Step c. Run “gcloud compute ssh <your instance name>”
Note: You should always stick to the same method of connecting to your VM because your login usernames for SSH from browser and for Cloud SDK may be different. This may result in confusion as you will end up in completely different home directories after connecting to your VM. If you intend to alternate between the two methods, first configure your SSH from browser and Cloud SDK login usernames to be identical.
*To switch users when connecting via Cloud SDK, use the command: “gcloud compute ssh <your user name>@<your instance name>”
Step 11: Run the bash setup script
curl https://raw.githubusercontent.com/howkhang/fastai-v2-setup/master/setup.sh | bash
You will be automatically disconnected after the script has finished running in order for the VM to do a reboot.
Step 12: Reconnect to the VM instance
Step 13: Connect to Jupyter notebook
Method 1: Connecting using your VM’s static IP address
Use this method only if you went through step 9 to obtain a static IP address.
Launch your browser and connect using your VM’s static IP address followed by the port number (in this case, “:8888”). For the token, copy the long string of characters shown after the “token=” .
Method 2: Connecting using ssh and port forwarding
Use this method if you skipped obtaining a static IP address in step 9 or if you encounter difficulties connecting to your Jupyter notebook using method 1.
Step a. Open another terminal (or Google Cloud SDK Shell) on your local machine and run the following command for port forwarding:
gcloud compute ssh <your instance name> --ssh-flag=“-L” --ssh-flag=“8888:localhost:8888”
You should see a new VM terminal pop up. You should now have a total of two local terminals (both showing your gcloud compute ssh commands) and two VM terminals (one showing the jupyter notebook server running and the other just showing the command line prompt).
Step b. Connect to Jupyter notebook using localhost:8888
Launch your browser and connect using “localhost” followed by the port number (in this case, “:8888”). For the token, copy the long string of characters shown after the “token=”.
Step 14: Get ready to do some serious learning!
And we are good to go! Let me know if you face any issues or have any feedback on this guide.
**Stopping your VM instance
Important: Remember to stop your VM instance when you are done with your notebooks or you will continue to incur charges.
Method 1: Online console
Compute Engine → VM instances