Launch aws ec2 p2 instance (use spot instance for lower price).
Note: this guide tested on Ubuntu Server 16.04 LTS (HVM) - ami-6f587e1c, Ireland.

Connect to your instance.

ssh -i aws-spot.pem ubuntu@

Note: you need to replace aws-spot.pem and with your values.

Install some nvidia stuff.


sudo apt-get update && \
sudo apt-get install -y build-essential linux-image-extra-`uname -r`

chmod +x ./
# This command should open interactive menu. You need to accept license and press few times [Enter].
sudo ./

chmod +x cuda_8.0.44_linux-run
./cuda_8.0.44_linux-run --extract=`pwd`/extracts

# another interactive installation
sudo ./extracts/
# 1. press **q**
# 2. enter **accept**
# 3. use defaul install path
# 4. don't add desktop menu shortcuts
# 5. yes, create a symbolic link

echo -e "export CUDA_HOME=/usr/local/cuda\nexport PATH=\$PATH:\$CUDA_HOME/bin\nexport LD_LIBRARY_PATH=\$LD_LINKER_PATH:\$CUDA_HOME/lib64" >> ~/.bashrc
source ~/.bashrc
tar xf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/

Optimizing GPU Settings official aws docs.

sudo nvidia-smi -pm 1
sudo nvidia-smi --auto-boost-default=0
sudo nvidia-smi -ac 2505,875

Install python with tensorflow.

sudo apt-get install -y python-pip python-dev
sudo pip install --upgrade $TF_BINARY_URL

Done! Let’s check simple tensorflow gpu example.

import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.

Create AMI for further fast launching.
That’s all.