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

wget http://us.download.nvidia.com/XFree86/Linux-x86_64/352.21/NVIDIA-Linux-x86_64-352.21.run
wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run

sudo /bin/bash ./NVIDIA-Linux-x86_64-352.21.run
sudo /bin/bash ./cuda_7.0.28_linux.run

# 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 https://github.com/fchollet/keras
sudo python setup.py install

# Lasagne
git clone https://github.com/Lasagne/Lasagne.git
pip install -r requirements.txt
python setup.py install

# Pylearn2
git clone git://github.com/lisa-lab/pylearn2.git
python setup.py develop

Step 4: Verifying Training on GPU

cd keras/examples
python lstm_text_generation.py 

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

Resources