Machine Learning Environment with AWS
-
Go to http://console.aws.com and login using your AWS Credentials
-
Under Compute, select EC2 to visit the EC2 Dashboard
-
Select Launch Instance and create an instance with a GPU graphics card. I selected g3.8xlarge. Follow the configuration pages to setup. Add 20 GiB of storage, and make sure to select your existing key pair or create one.
-
Your EC2 instance will launch after completing setup and the indicator will turn green once it is running.
- Launch your instance using SSH and your terminal of choice
Example:
$ ssh -i "MyKeyPair.pem" [email protected]
- Run the follow commands to update and upgrade the instance
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt install gcc
- Install Nvidia Drivers using the following commands:
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt-get install nvidia-384
Make sure to restart your server after installing.
- Next, install Cuda. Go here for the official documentation and choose the correct installation:https://developer.nvidia.com/rdp/cudnn-download.
$ wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
$ cd cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
$ sudo apt-get update
$ sudo apt-get install -y cuda
$ sudo apt-get upgrade cuda
Make sure it works:
$ nvidia-smi
CudaNN is a GPU-accelerated library of primitives for deep neural networks. This library provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers.
-
You must first visit https://developer.nvidia.com/rdp/cudnn-download and create a NVIDIA Developer Program account. This is necessary to download cudaNN
-
An easy way to install this library is to download it from Chrome inside your EC2 Instance. Install Google Chrome using the following commands:
#Add Key:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
#Set repository:
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
#Install package:
sudo apt-get update
sudo apt-get install google-chrome-stable
Test Chrome is working by running google-chrome
in the command line.
- Next, download the Linux library for Cuda 8.0 in your newly installed Chrome browser from this website: https://developer.nvidia.com/rdp/cudnn-download
You must sign in using the credentials you created in Part 1.
- After downloading completes, return to the terminal and unzip the file.
$ cd ~
$ cd Downloads
$ tar -zxf cudnn-8.0-linux-x64-v7.tgz
- Copy the following files into the Cuda Toolkit Directory
$ ubuntu@ip-172-31-33-60:~/Downloads$ cd cuda
$ ubuntu@ip-172-31-33-60:~/Downloads/cuda$ sudo cp lib64/* /usr/local/cuda/lib64/
$ ubuntu@ip-172-31-33-60:~/Downloads/cuda$ sudo cp include/* /usr/local/cuda/include/
- Test the installation:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
- Install Python 3
$ sudo apt-get install python3-pip
Test if Python 3 is installed: python3 --version
.
- Install the following python libraries:
$ sudo pip3 install --upgrade pip
$ sudo apt-get install python3-tk
$ sudo pip3 install numpy
$ sudo pip3 install seaborn
$ sudo pip3 install pandas
$ sudo pip3 install sklearn
$ sudo pip3 install matplotlib
$ sudo pip3 install keras
$ sudo pip3 install theano
$ sudo pip3 install tensorflow
Run a short TensorFlow program to see if it's working:
vim tftest.py
# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
python3 tftest.py
The system should output the following:
Hello, TensorFlow!
This instructions are based on this helpful resource: https://github.com/BVLC/caffe/wiki/Install-Caffe-on-EC2-from-scratch-(Ubuntu,-CUDA-7,-cuDNN-3)
- Install the dependencies with all of these installs:
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev git python-dev libgoogle-glog-dev libbz2-dev libxml2-dev libxslt-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev python-yaml
Then run:
$ sudo easy_install pillow
- Clone Caffe.git
$ cd ~
$ git clone https://github.com/BVLC/caffe.git
- Cd to Caffe folder and run the follwing:
$ cat python/requirements.txt | xargs -L 1 sudo pip install
- Next, copy the Makefile.config.example to create our own Makefile.config
$ cp Makefile.config.example Makefile.config
$ vi Makefile.config
Uncomment the line: USE_CUDNN := 1 Make sure the CUDA_DIR correctly points to our CUDA installation.
- Now we build Caffe. Set X to the number of CPU threads (or cores) on your machine. For me, this was 8.
$ sudo apt-get install htop
$ make pycaffe -jX
$ make all -jX
$ make test -jX
Now test Caffe:
$ ./data/mnist/get_mnist.sh
This instructions are based on this helpful resource: http://torch.ch/docs/getting-started.html
Run the following in the terminal:
$ git clone https://github.com/torch/distro.git ~/torch --recursive
$ cd ~/torch; bash install-deps;
$ ./install.sh
The last command will take some time to install.
Then run:
source ~/.bashrc
Test if it's working:
$ th
If successful, Torch will start:
______ __ | Torch7
/_ __/__ ________/ / | Scientific computing for Lua.
/ / / _ \/ __/ __/ _ \ |
/_/ \___/_/ \__/_//_/ | https://github.com/torch
| http://torch.ch
-
Run
google-chrome
to open the Chrome browser -
Navigate to https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=linux&code=PCC and download the Linux version of PyCharm Community
-
Cd to Downloads folder in the terminal and unzip:
$ cd ~
$ cd Downloads
$ tar -zxf pycharm-community-2017.2.tar.gz
- To open PyCharm community:
$ cd pycharm-community-2017.2
$ cd bin
$ cd ./pycharm.sh