Tutorial: Configuring a Virtual Instance for Deep Learning with GPUs
This tutorial will run through setting up an AWS EC2 Instance for Deep Learning from scratch - no ami or docker required. The tutorial can be used on Google Cloud's Virtual Machines as well, but it will only run through the initialization process on AWS.
After configuration, your instance will have Anaconda, Python 3.6, Jupyter Notebook, Tensorflow, and Keras running with a NVIDIA Graphics Driver, CUDA, and CUDNN.
I've run the tutorial on an instance with Ubuntu 16.04, but the configuration should work on other operating systems as well. Take care to download the appropriate links for your OS type.
Scroll down to the bottom if you want to test whether your GPUs are currently being utilized by Tensorflow.
Launch a new EC2 Instance.
Select Ubuntu Server 16.04.
Configure an instance type with GPUs. Currently Amazon's G2, G3, and P2 series offer graphics cards. Check out how the instance types differ here and their pricing here. You can also explore AWS' Elastic GPUs Service.
Give your instance the full 30 GBs of free storage.
Configure a custom security group that opens ports 22, 443, and 8888.
Launch your instance.
Establish access through your terminal window.
We'll start by installing Anaconda and Python 3.6.
Go to Anaconda's Download Page to find the appropriate download link for your system. Here I used the Python 3.6 Linux Installer. Copy the link.
Download the package from the link above.
Install the package.
Type 'yes' and press Return for everything - most importantly:
Run your .bashrc file.
Anaconda and Python 3.6 are installed!
Below, we launch ipython and change Jupyter Notebook's configuration file so that we can easily access it from our browser.
Copy output somewhere safe: 'sha1:98ff0e580111:12798c72623a6eecd54b51c006b1050f0ac1a62d'
There's no need to actually fill this in - just press Return.
Copy & paste the text below into the config file you just opened. Make sure to replace the ‘sha1:...’ password below with your own.
Press :wq to save and quit the text editor.
Remove the Anaconda Installer from your computer.
Congrats! You've configured Jupyter Notebook for easy use. Now when you type 'jupyter notebook' into your instance terminal, it will open at port 8888. You can access it from your browser at https://[instance IP address]:8888/.
Now we're going to install the graphics driver needed to utilize your GPUs.
First check the type of graphics cards you have on your instance.
Look at your GPU information and find the appropriate NVIDIA Driver to download for it here.
Copy the download link.
Download the installer.
Update apt-get and install a C++ compiler system.
Install downloaded package.
Check whether the installation worked. This will show you information on your GPU usage.
Now that the NVIDIA Driver is installed, we'll download a software package that let us interface with our GPUs.
First find the appropriate NVIDIA CUDA Package link for your OS system here.
For my Ubuntu 16.04, I configured the settings as such and chose to download the deb installer package.
Copy the link into your instance terminal and download it.
Install the package.
Update apt-get one more time. Now you should be able to install the CUDA software.
While CUDA is installing go to https://developer.nvidia.com/rdp/cudnn-download, make an account, and search for cuDNN's installation page.
cuDNN is a neural network library that optimizes your GPU usage for deep learning.
Once you've gotten access to the download page check the CUDA version you installed to find out which cuDNN package to get.
Because of the login requirement, you'll have to download the cuDNN package to your personal computer and scp it to your instance.
Copy & paste the text below into your .bashrc file.
Type :wq to save & quit the text editor.
You’re done installing the NVIDIA Graphics Card Driver, CUDA & cuDNN.
Now we can install Tensorflow and Keras!
Let's check if Tensorflow is utilizing our GPUs.
Check the output of the print statement to see if the GPUs are working.
Install Keras.
Congrats! You're EC2 is configured and ready to use for Deep Learning!