Setting up an AWS EC2 instance with RStudio Server and Tensorflow GPU
I bought Chollet and Allaire’s insanely good Deep Learning with R book and wanted to follow along with the example Neural Networks in R with Keras. However, my machine does not have a GPU that is powerful enough, let alone have CUDA capabilities 🙄.
Thus I set forth, as the authors suggest, to create an AWS EC2 instance. Since there can be many tiny obstacles to prevent you from having a smooth start, I wrote this post, so you can get a timely start on your deep learning endeavors.
Getting started
If you haven’t already, create an AWS account, which will be using your existing Amazon user information (if you like).
The actual set-up happens through the Amazon marketplace, where RStudio has a ready-made AMI set up that you can subscribe to.
If you’re not already logged in, you do that, then you click subscribe (it is completely free).
However, the application uses a p2.xlarge instance , which sets you back $0.90/hr. Now, this is not bad at all IFF you don’t forget to stop your instance after you’re done using it. Also, I have recently received my first bill and am happy to report that you only pay for the actual time used. So it seems you are not charged by the full hour.
Otherwise, it’s going to be $648/month (24hrs/30days).
The good news: RStudio’s AMI is free to use and AWS’ P2 instances come packed with power. They all have NVIDIA K80 GPUs with GPU drivers and CUDA toolkits pre-installed. The smallest (p2.xlarge) has 1 GPU, 4 vCPUs (4 virtual cores), and 61GiB (~61GB) RAM. Learn more about them here.
Set up
- Depending on where you are, select a U.S. region. Everything else can be left as is.
Click 'Continue to Launch.'
Make sure to select p2.xlarge under ‘EC2 Instance Type’
- Leave everything else as is except you can create your own security group and you will be asked to supply a Key-Pair, which you can create at this point by clicking on the link right below the text box.
- Then click 'Launch.'
Oh what holy hell is this? Yeah, you’ll not be able to launch a p2.xlarge instance if you haven’t gotten one approved from the AWS people (because, you know, don’t mess around with it as it costs a ton of money if not handled right).
You have to click on ‘Limits’ under your EC2 dashboard and request a limit increase for p2.xlarge. They ask you what you want to do with it and then you should be good to go within 10 minutes of the request or so.
Then go back to ‘Launch’ and try again. If successful, your brand new instance is going to show up under ‘Instances’. The Instance State tab shows you the state of your instance. Once running, the Public DNS tab shows you the connection. Right click on it and select Connect.
A window is going to pop up showing you the browser address. Copy and paste that in your browser and append :8787 at the end. This will take you to RStudio Server. You log in with ‘rstudio-user’ and the Instance ID. Before you do anything, change the password by going to the Terminal tab and punch in: ‘passwd’. This will prompt you to put in the current password (the Instance ID) and let you reset the password with your own.
After this, you are good to go. In order to build a neural network, load the keras-package with library(keras)
. However, do NOT run install_keras(tensorflow = "gpu")
because it is already installed and running this command will probably screw stuff up (like it did for me), resulting in error messages further down the road.
That’s it - happy deep learning! May your accuracy go 📈 and your loss 📉.