Series on Deep Learning

Setting up GPU Learning on EC2

We will be putting together a series of practical tutorials on deep learning techniques and tools.  This first post will focus on getting the GPU environment set up on EC2. 

Step 1: Launching a GPU instance

Launch an Amazon EC2 g2.2xlarge GPU instance which has a Nvidia GRID K520 with 3,072 cores.  If you are just testing and playing around, you can start with a EC2 spot instance and save yourself some money.  

Recommended Settings

  • Amazon Linux 64bit (based on Red Hat)
  • 300GB+ of EBS backed storage

After a few minutes of waiting (assuming you bid high enough) you'll see your spot instance show up.  Connect to the instance via ssh.

Step 2: Configuring the Instance

Update System

sudo yum update -y
sudo reboot #yes it is necessary
sudo yum groupinstall -y "Development tools"

Load Nvidia Drivers


sudo /bin/bash ./
sudo /bin/bash ./

# ignore the message about an unsupported environment.  It's because of the Amazon Linux flavor. 

Verify Nvidia Drivers/Hardware

# you should see GRID K520 in the output
nvidia-smi -q | head

Step 3: Loading Deep Learning Software

Install Python Libraries

sudo yum install python-devel python-nose python-setuptools gcc gcc-gfortran gcc-c++ blas-devel lapack-devel atlas-devel
sudo easy_install pip
sudo easy_install ipython
sudo pip install numpy==1.6.1
sudo pip install scipy==0.10.1
sudo pip install Theano

Configure Environment

# add to .bash_profile
export PATH=$PATH:$HOME/bin:/usr/local/cuda-7.0/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-7.0/lib64
export THEANO_FLAGS='cuda.root=/path/to/cuda/root,device=gpu,floatX=float32'

Select and Install Deep Learning Library (choose one)

# Keras
git clone
sudo python install

# Lasagne
git clone
pip install -r requirements.txt
python install

# Pylearn2
git clone git://
python develop

Step 4: Verifying Training on GPU

cd keras/examples

# output should show: Using gpu device 0: GRID K520