Installing TensorFlow r1.1 on an AWS P2 instance.
Following this with a few modifications
Built using Ubuntu 16.04 with p2.xlarge instance and 25GB of standard ssd storage.
# Update and upgrade installed packages
sudo apt-get update
sudo apt-get upgrade
############################################
# Install NVIDIA Driver
########################
# The best approach is to install the Ubuntu version of the driver. Do not
# install the driver included in the CUDA package unless necessary.
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update && sudo apt-get upgrade
# Check https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa to see the
# latest drivers available
# You can also use http://www.nvidia.com/Download/Find.aspx to find which driver you should install
sudo apt-get install nvidia-378
Reboot the machine and then check to ensure the nvidia driver has installed:
sudo reboot
# ssh back in
nvidia-smi
############################################
# Install basic packages needed for TensorFlow and generally needed
########################
sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python-matplotlib libblas-dev liblapack-dev libatlas-base-dev python-dev python-pydot linux-headers-generic linux-image-extra-virtual unzip python-numpy swig python-pandas python-sklearn unzip wget pkg-config zip g++ zlib1g-dev libcurl3-dev
sudo apt-get install libcupti-dev bc
# AWS EFS Driver (to mount drives from EFS)
sudo apt-get -y install nfs-common
# Install Python package manager
sudo pip install -U pip
sudo pip install --upgrade pip
sudo pip install wheel numpy
############################################
# Install CUDA using packages rather than the script install.
########################
# If a new version of CUDA is out, get the link from NVIDIA's site.
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
chmod +x cuda_8.0.61_375.26_linux-run
./cuda_8.0.61_375.26_linux-run --extract=/home/ubuntu/
sudo ./cuda-linux64-rel-8.0.61-21551265.run
############################################
# Install CuDNN
########################
# Download CuDNN from NVIDIA (get the Linux package not deb packages)
# scp to ec2 instance
# Cannot provide direct download due to needing to signup to get CuDNN.
tar -zxf cudnn-8.0-linux-x64-v5.1.tar.gz
# Copy files into CUDA directories
sudo cp -P cuda/include/cudnn.h /usr/local/cuda-8.0/include/
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64/
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
# Setup Profile with CUDA environment variables
Add to ~.bashrc
#CUDA Setup
export CUDA_HOME=/usr/local/cuda
export CUDA_ROOT=/usr/local/cuda
PATH=$PATH:$CUDA_ROOT/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64:$CUDA_ROOT/extras/CUPTI/lib64
# now source the file
source .bashrc
############################################
# Install Bazel
########################
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install bazel
sudo apt-get upgrade bazel
############################################
# Install TensorFlow
########################
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git checkout r1.1
./configure
# Defaults with exception of
# Y Cuda / 8.0 / 5.1.5 cudnn / Compute 3.7 for K80s.
# Compiles in AVX2 optimizations.
bazel build -c opt --copt=-march="native" --config=cuda //tensorflow/tools/pip_package:build_pip_package
# Build the pip package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# Install
sudo pip install --upgrade --force-reinstall /tmp/tensorflow_pkg/tensorflow-1.1.0rc2-cp27-cp27mu-linux_x86_64.whl
# Install any additional packages that you want the image to have
sudo pip install pyyaml
sudo pip install keras
sudo pip install ipython jupyter
You should now have a fully functional python environment and all of these should work:
import tensorflow as tf
import keras
import sklearn
from PIL import Image
import numpy as np
import scipy
from matplotlib import pyplot as plt