June 2017 version to build Tensorflow / Keras environment on GPU instance of AWS

Overview

Build an environment where Tensorflow and Keras run on GPU on AWS GPU instance.

I know that these articles are the nth room, but even so, there are scattered materials on the net that are written at each timing and I do not know whether they are the latest or not, so I will write the current situation by dividing it into such articles. .. It seems that it has been released from the manual installation of Nouveau and CUDA Toolkit, although there is still some manual work.

Reference material

Basically, refer to the contents of the following URL. Detailed versions etc. have been changed.

environment

work

GPU instance setup

The OS to be selected is Ubuntu 16.04, and the detailed settings will be omitted. The caveat here is that the CUDA Toolkit files are huge, so it's a good idea to set the storage size a bit larger than the default 8GB.

Install NVIDIA Driver

$ sudo add-apt-repository ppa:graphics-drivers/ppa -y
$ sudo apt-get update
$ sudo apt-get install -y nvidia-375 nvidia-settings

Install CUDA Toolkit

Install the CUDA Toolkit. This time I will use 8.0. Here, it is obtained by wget, but it is the same as the installer obtained by "Linux> x86_64> Ubuntu> 16.04> deb (local)" from the following URL.

CUDA Toolkit Download | NVIDIA Developer

$ 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
$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
$ sudo apt-get update
$ sudo apt-get install -y cuda nvidia-cuda-toolkit

Now make sure you have successfully installed with nvidia-smi and nvcc --version.

cuDNN installation

** Addition: It seems that you can download it directly from the URL below. ** ** $ wget http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz

~~ cuDNN must be downloaded from the NVIDIA site and transferred to your AWS instance. ~~

~~ Click the download button at the URL below to agree to the "cuDNN Software License Agreement", and then "Download cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0" "cuDNN v5.1 Library for Linux" (file name: Download cudnn-8.0-linux-x64-v5.1.tgz). Login required. ~~

NVIDIA cuDNN | NVIDIA Developer

~~ Copy the downloaded file to your AWS GPU instance. ~~

# local
$ scp cudnn-8.0-linux-x64-v5.1.tgz aws-gpu-instance:

Unzip and place the files inside.

$ tar zxvf cudnn-8.0-linux-x64-v5.1.tgz 
$ sudo mv cuda/lib64/* /usr/local/cuda/lib64/
$ sudo mv cuda/include/* /usr/local/cuda/include/

Setting environment variables

Add the following settings to the configuration file of the shell you are using. This time I added it to .bashrc.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda

Install Tensorflow and Keras

Now it's time to set up Tensorflow and Keras. I will omit building the Python environment, but if you follow this article, you can build a Python3 environment using pyenv / virtualenv.

$ pip install tensorflow-gpu
$ pip install keras

Test if GPU is available

I will download the Keras source code and run some examples inside.

$ git clone https://github.com/fchollet/keras.git
$ cd keras/examples
$ python mnist_cnn.py

If you try to move something appropriately, GPU-Util goes up with nvidia-smi, or it is obviously faster than the local or CPU usage version, it will be OK. Thank you for your hard work.

Reference: Error during trial and error

One of the reference URL If you install according to, an error will occur due to the version difference of cuDNN. Use v5.1 instead of v5.0.

Loaded runtime CuDNN library: 5005 (compatibility version 5000) but source was compiled with 5110 (compatibility version 5100)

Recommended Posts

June 2017 version to build Tensorflow / Keras environment on GPU instance of AWS
Build Keras environment on AWS E2 G2 instance February 2017 version
Run TensorFlow on a GPU instance on AWS
Building an environment to run ChainerMN on a GPU instance on AWS
Try Tensorflow with a GPU instance on AWS
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
[Environment construction] @anaconda that runs keras / tensorflow on GPU
Run GPU version tensorflow on AWS EC2 Spot Instances
Use jupyter on AWS GPU instance
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)
I installed TensorFlow (GPU version) on Ubuntu
Prepare the environment of Chainer on EC2 spot instance with AWS Lambda
[2020 version] How to install Python3 on AWS EC2
How to build an environment for using multiple versions of Python on Mac
Create an AWS GPU instance to train StyleNet
How to build Java environment on Ubuntu (Linux)
[TF] How to build Tensorflow in Proxy environment
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X
[AWS] Development environment version that tried to build a Python environment with eb [Elastic Beanstalk]
Allow Keras 2.0 and OpenCV 3.2 to work in GPU environment
Deployment procedure on AWS (2) Server (EC2 instance) environment settings
Building a TensorFlow environment that uses GPU on Windows 10
How to build a Django (python) environment on docker
How to build a development environment for TensorFlow (1.0.0) (Mac)
How to build a Python environment on amazon linux 2
Summary of Tensorflow / Keras
Build TensorFlow on Windows
How to manage Python minor version (build virtual environment) on Windows (without Pyenv or WSL)
If you think tensorflow doesn't recognize your GPU on AWS
Introducing Kaggle's Docker Image on Windows to build an environment
Building an environment to execute python programs on AWS EC2
I stumbled on TensorFlow (What is Out of GPU Memory)
[End of 2020] A memo to start using AWS CLI (Version 2)
[AWS] Flask application deployment version that tried to build a Python environment with eb [Elastic Beanstalk]
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Build Python environment on Windows
Build python environment on windows
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
I tried to create an environment of MkDocs on Amazon Linux
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Environment construction of Tensorflow and Chainer by Window with CUDA (with GPU)
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
The first artificial intelligence. How to check the version of Tensorflow installed.
How to update the python version of Cloud Shell on GCP
[AWS / Tello] Build a system to operate the drone on the cloud
How to set up the development environment of ev3dev [Windows version]
Shell script to build pyenv environment on ubuntu in one shot
[TensorFlow 2.x compatible version] How to train a large amount of data using TFRecord & DataSet in TensorFlow (Keras)