Skip to content

Instantly share code, notes, and snippets.

@navinpai
Last active May 24, 2017 07:03
Show Gist options
  • Save navinpai/34942eabe6324633e9f4570fd32fb545 to your computer and use it in GitHub Desktop.
Save navinpai/34942eabe6324633e9f4570fd32fb545 to your computer and use it in GitHub Desktop.
Boostrap Scripts to Install and Test Setup for Deep Learning Applications

Boostrap Scripts to Install and Test Setup for Deep Learning Applications

This gist is simply a set of scripts to install and test everything you need to get started with Deep Learning. This includes:

  • TensorFlow
  • Theano
  • Keras
  • CUDNN
  • CUDA Toolkit
  • Misc. linux Tools like tmux.

How to use

  • Assuming you already have a newly created EC2 GPU instance, and are able to SSH into it.

  • Copy deep_learning_bootstrap.sh, test_install.sh and theano_test.py on the machine.

  • Run chmod +x *.sh to make the .sh files executable

  • Run sudo ./deep_learning_bootstrap.sh and go have a cup of tea while it installs everything for you

    • If a pink screen pops up mentioning "A new version of /boot/grub/menu.lst is available", choose "Keep local version" and select OK.
  • When the message to restart system comes up, just restart with sudo shutdown -r 0

  • After restart, run ./test_install.sh

    • If everything has gone correct, then you will see output matching the expected output (in green). You are all set to get started!
    • In case of errors, please ping me at @navinpai on twitter or email at navin[at]fiftheye[dot]in

Version

1.0b

Thanks and Have Fun!

Navin "M@dMAx" Pai (@navinpai)

#!/bin/bash
apt-get update
apt-get -y dist-upgrade
apt-get install -y gcc g++ gfortran build-essential git wget tmux linux-image-extra-`uname -r` linux-generic linux-image-generic libopenblas-dev python-dev python-pip python-nose python-numpy python-scipy
# Bleeding edge Theano
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
# Install Tensorflow
sudo pip install six --upgrade --target="/usr/lib/python2.7/dist-packages"
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl
# Keras v.1.0.7
pip install --upgrade --no-deps keras==1.0.7
# Scikit-Learn
pip install -U scikit-learn
# CUDA
curl -fsSL http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb -O
dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb
apt-get update
apt-get install -y cuda
echo -e "\nexport PATH=/usr/local/cuda/bin:$PATH\n\nexport LD_LIBRARY_PATH=/usr/local/cuda/lib64\n\nexport CUDA_HOME=/usr/local/cuda\n\nexport PS1='\[\033[0;32m\]\u@\[\033[0;33m\]D33P_L34RN:\[\033[36m\]\W\[\033[0m\] \$ '" >> .bashrc
# CUDNN
curl -fsSL http://developer.download.nvidia.com/compute/redist/cudnn/v4/cudnn-7.0-linux-x64-v4.0-prod.tgz -O
tar xvzf cudnn-7.0-linux-x64-v4.0-prod.tgz
cp cuda/include/cudnn.h /usr/local/cuda/include
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# Make Theano use GPU by default
echo -e "\n[global]\nfloatX=float32\ndevice=gpu\n[mode]=FAST_RUN\n\n[nvcc]\nfastmath=True\n\n[cuda]\nroot=/usr/local/cuda" >> ~/.theanorc
# Reboot system and run test_install.sh
echo -e '\E[33;92m'"Reboot System (sudo shutdown -r 0) and run ./test_install.sh"; tput sgr0
#!/bin/bash
# Test CUDA install
echo -e '\E[33;92m'"TEST CUDA INSTALL"; tput sgr0
cuda-install-samples-7.5.sh ~
cd NVIDIA_CUDA-7.5_Samples/1_Utilities/deviceQuery
make
./deviceQuery
echo -e '\E[33;92m'"SHOULD PRINT Result = PASS ABOVE THIS LINE"; tput sgr0
# Test Theano GPU usage
echo -e '\E[33;92m'""; tput sgr0
cd ~
python theano_test.py
echo -e '\E[33;92m'"SHOULD PRINT Used the gpu ABOVE THIS LINE"; tput sgr0
# Test Theano CDNN usage
echo -e '\E[33;92m'"TEST Theano CDNN USAGE"; tput sgr0
python -c 'from theano.sandbox.cuda.dnn import version; print(version())'
echo -e '\E[33;92m'"SHOULD PRINT (4007, 4007) ABOVE THIS LINE"; tput sgr0
# Run MNIST on TensorFlow
echo -e '\E[33;92m'"TEST TENSORFLOW (Might take a while...)"; tput sgr0
python -m tensorflow.models.image.mnist.convolutional
echo -e '\E[33;92m'"Should Print Validation and Test Error numbers ABOVE THIS LINE"; tput sgr0
echo -e '\E[1;33;92m'"If No errors Seen, then you are done! Have fun! :) - M@dMAx"; tput sgr0
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
@navinpai
Copy link
Author

If you get the following error on running python -m tensorflow.models.image.mnist.convolutional:

Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main mod_name, loader, code, fname = _get_module_details(mod_name) File "/usr/lib/python2.7/runpy.py", line 101, in _get_module_details loader = get_loader(mod_name) File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader return find_loader(fullname) File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader for importer in iter_importers(fullname): File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers __import__(pkg) File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module> from tensorflow.python import * File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 98, in <module> from tensorflow.python.platform import test File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/test.py", line 63, in <module> from tensorflow.python.framework import test_util File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/test_util.py", line 43, in <module> from tensorflow.python.platform import googletest File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/googletest.py", line 32, in <module> from tensorflow.python.platform import benchmark # pylint: disable=unused-import File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 112, in <module> class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)): File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass return meta("NewBase", bases, {}) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 107, in __new__ if not newclass.is_abstract(): AttributeError: type object 'NewBase' has no attribute 'is_abstract'

run

sudo pip install six --upgrade --target="/usr/lib/python2.7/dist-packages"
and then try again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment