TensorFlow with support for GPU and python on NVIDIA GTX 950 in Debian Stretch

Why is there a need for this recipe at all; why doesn't TensorFlow and CUDA just work together?

There are two underlying problems:

  1. TensorFlow is not packaged by Debian, and the versions of TensorFlow provided by google assume that the CUDA libraries (in particular the cuDNN library and the header file for the cupti library) are located in non-standard locations. Yes, non-standard, not just where Debian happens to put libraries and include files. Since TensorFlow is free software, we can fix it.
  2. The deep-learning part of CUDA, cuDNN, is proprietary software, and is outdated in that it requires outdated versions of gcc. And since it is proprietary, the free software community cannot fix it. Instead, we have to install obsolete versions of gcc, however, different versions of gcc can be installed simultaneously, and we don't have to make the obsolete version (4.9) the system default, so other things relying on gcc will unaffected.

We will first build TensorFlow with support for

Then we will build a python-package which uses our custom build of TensorFlow.

  1. Install the Debian base system, and add contrib non-free to /etc/apt/sources.list
  2. Install the nvidia kernel modules and the nvidia-cuda-toolkit from debian non-free
  3. Install nvidias deeplearning library cuDNN. You have to get these packages directly from nvidia here. You will have to register as a nvidia developer to get access to these packages. The registration is free. The packages needed are available at "Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 8.0":
sudo dpkg -i libcudnn7-dev_7.0.5.15-1+cuda8.0_amd64.deb libcudnn7_7.0.5.15-1+cuda8.0_amd64.deb
sudo apt-get install git curl python-numpy python-dev python-pip python-wheel python-setuptools openjdk-8-jdk
  1. Get the source code for tensorflow: git clone https://github.com/tensorflow/tensorflow
  2. Install bazel (from googles repository, I don't know why bazel is not packaged by debian yet)
  3. cd tensorflow
  4. git checkout r1.5
  5. Install obsolete version of gcc, gcc 4.9 (improved version of https://github.com/dasGringuen/debian9-install)

:/usr/local/cuda# ls -l
total 0
lrwxrwxrwx 1 root staff 25 feb  9 23:55 lib64 -> /usr/lib/x86_64-linux-gnu
/usr/local/cuda# ls -l include
lrwxrwxrwx 1 root staff 12 feb 10 00:16 include -> /usr/include
:/usr/local/cuda/extras/CUPTI# ln -s /usr/lib/x86_64-linux-gnu include
bazel build --local_resources 2048,.5,1.0 --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

16. Build and install a wheel

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.5.0-cp35-cp35m-linux_x86_64.whl
sudo apt-get install musescore
sudo apt-get install python-matplotlib python-scipy
$ python

Once inside, issue the following:

import music21
us=music21.environment.UserSettings()
us['musicxmlPath']='/usr/bin/musescore'
us['warnings'] = 0
exit()

The last line:

us['warnings'] = 0

Is optional, and only relevant if you run python 2. If you run python 3, it is pointless (but also harmless).

What does this do? It creates a file .music21rc with among other things has this element:

<preference name="musicxmlPath" value="/usr/bin/musescore" />

Back to the dependencies of DeepBach, we are done with musescore, next is support for Hierarchical Data Format library, version 5, aka HDF5, packaged in Debian as python-h5py:

sudo apt-get install python-h5py

    sudo pip install keras
    
sudo apt-get install python-mako
sudo apt-get install python-nose
sudo apt-get install libprotobuf-c1
sudo apt-get install python-setuptools python-tqdm python-werkzeug python-sqlite python-wheel python-lzma (xz) python-appdirs python-click python-flask python-packaging
cp ~/DeepBach/deepBachMuseScore.qml .local/share/data/MuseScore/MuseScore2/plugins/
model_name = 'deepbach'
# model_name = 'skip_new'
cd /home/hans/DeepBach/DeepBach
export FLASK_APP=/home/hans/DeepBach/plugin_flask_server.py
python -m flask run --host=0.0.0.0
            /* text: "http://localhost:5000/" */
            text: "http://foo.bar.com:5000/"

Python 3

sudo apt-get install python3-pip python3-setuptools python3-matplotlib python3-scipy python3-numpy python3-h5py python3-mako python3-nose libprotobuf-c1 python3-tqdm python3-werkzeug python3-wheel python3-xopen python3-appdirs python3-click python3-flask python3-packaging
sudo pip3 install keras music21 tensorflow
python3
import music21
us=music21.environment.UserSettings()
us['musicxmlPath']='/usr/bin/musescore'
exit()
cd /home/hans/DeepBach/DeepBach
export FLASK_APP=/home/hans/DeepBach/plugin_flask_server.py
python3 -m flask run --host=0.0.0.0
[14:45:11]hans@Haleno:~>sudo pip3 install tensorflow
Collecting tensorflow
  Using cached tensorflow-1.6.0-cp35-cp35m-manylinux1_x86_64.whl
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading termcolor-1.1.0.tar.gz
Requirement already satisfied: wheel>=0.26 in /usr/lib/python3/dist-packages (from tensorflow)
Collecting protobuf>=3.4.0 (from tensorflow)
  Using cached protobuf-3.5.2-cp35-cp35m-manylinux1_x86_64.whl
Collecting numpy>=1.13.3 (from tensorflow)
  Downloading numpy-1.14.2-cp35-cp35m-manylinux1_x86_64.whl (12.1MB)
Collecting gast>=0.2.0 (from tensorflow)
  Downloading gast-0.2.0.tar.gz
Collecting absl-py>=0.1.6 (from tensorflow)
  Using cached absl-py-0.1.11.tar.gz
Collecting grpcio>=1.8.6 (from tensorflow)
  Using cached grpcio-1.10.0-cp35-cp35m-manylinux1_x86_64.whl
Collecting tensorboard<1.7.0,>=1.6.0 (from tensorflow)
  Using cached tensorboard-1.6.0-py3-none-any.whl
Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from tensorflow)
Collecting astor>=0.6.0 (from tensorflow)
  Using cached astor-0.6.2-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from protobuf>=3.4.0->tensorflow)
Collecting bleach==1.5.0 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading bleach-1.5.0-py2.py3-none-any.whl
Requirement already satisfied: werkzeug>=0.11.10 in /usr/lib/python3/dist-packages (from tensorboard<1.7.0,>=1.6.0->tensorflow)
Collecting markdown>=2.6.8 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading Markdown-2.6.11-py2.py3-none-any.whl (78kB)
Collecting html5lib==0.9999999 (from tensorboard<1.7.0,>=1.6.0->tensorflow)
  Downloading html5lib-0.9999999.tar.gz (889kB)
Building wheels for collected packages: termcolor, gast, absl-py, html5lib
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: /root/.cache/pip/wheels/de/f7/bf/1bcac7bf30549e6a4957382e2ecab04c88e513117207067b03
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: /root/.cache/pip/wheels/8e/fa/d6/77dd17d18ea23fd7b860e02623d27c1be451521af40dd4a13e
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: /root/.cache/pip/wheels/3c/0f/0a/6c94612a8c26070755559045612ca3645fea91c11f2148363e
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: /root/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
Successfully built termcolor gast absl-py html5lib
Installing collected packages: termcolor, protobuf, numpy, gast, absl-py, grpcio, html5lib, bleach, markdown, tensorboard, astor, tensorflow
  Found existing installation: numpy 1.12.1
    Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed absl-py-0.1.11 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-1.10.0 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.2 protobuf-3.5.2 tensorboard-1.6.0 tensorflow-1.6.0 termcolor-1.1.0

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: mars 25, 2018