labs.beatcraft.com Deep Learning

Overview

This article explains how to install Pylearn2 on CUDA. Pylearn2 is a machine learning library for Python. Since most of functionality of Pylearn2 is built upon the top of Theano, the models and algorithms written in Pylearn2 are expressed in mathematical expressions. Theano compiles these models and algorithms to CUDA.

This article uses the same hardware, which is used for explaining how to install CUDA on Ubuntu in the article of CUDA6.5/Ubuntu 14.04. The system is equipped with Tesla K20c, and CUDA tools 6.5 is installed on Ubuntu 14.04. This article shows how to set up Pylearn2 on CUDA 6.5.

Setting up Pylearn2

Installing Ubuntu 14.04 and Configuring CUDA

To enable Pylearn2 to work on GPU at backend correctly, you have to set up CUDA correctly on the OS of the system. Please check this article for installing CUDA Toolkit 6.5 on Ubuntu 14.04.

Python Modules

If the Python modules, which are requred for installing Pylearn2 and Theano, are available at repository, please use the command line apt-get install. Otherwise use pip to install the modules.

Installing Theano

First, the required libraries, which are needed for installing Theano, are installed. The list of requirements is shown is shown below.

To install BLAS, use OpenBLAS. The instructions of how to install openBLAS are listed at the URL below. Please follow the instructions listed there. (The package of OpenBLAS for Ubuntu puts a limit on the number of threads at two. Therefore, please build and install OpenBLAS from the scratch.)

$ sudo apt-get install gfortran
$ git clone git://github.com/xianyi/OpenBLAS
$ cd OpenBLAS
$ make FC=gfortran
$ sudo make PREFIX = /usr/local install
$ sudo idconfig

Before installing libgpuarray, please install the requirements for libgpuarray, first. For the instructions of how to install these requirements, please visit the URL below.
URL

$ sudo apt-get install cmake check python-mako cython 

Obtaining the source code of libbgpuarray from git.

$ git clone https://github.com/Theano/libgpuarray.git
$ cd libgpuarray

If you try to execute the build command of Cmake, an error will occur at the link to pthread.
To avoid this error to happen, CMakeLists.text will be modified in the way as it is shown below.

$ cd src
$ vim CMakeLists.text


Before modifying the CMakeLists.text
if(CUDA_FOUND)
target_link_libraries(pthread $ {CUDADRV_LIBRARY} $ {CUDA_CUBLAS_LIBRARIES})
target_link_libraries(gpuarray-static $ {CUDADRV_LIBRARY} $ {CUDA_CUBLAS_LIBRARY})
endif()

 ↓

After modifying the CMakeLists.text
if(CUDA_FOUND)
target_link_libraries(gpuarrat pthread $ {CUDADRV_LIBRARY} $ {CUDA_CUBLAS_LIBRARIES})
target_link_libraries(gpuarray-static pthread $ {CUDADRV_LIBRARY} $ {CUDA_CUBLAS_LIBRARY})
endif()

After the modification is completed, going back to the directory below libgpuarray. To follow the instructions below, build and install libgpuarray.

$ cd ..
$ mkdir Build
$ cd Build
$ cmake.. -DCMAKE_BUILD_TYPE=Release
$ make
$ sudo make install
$ sudo idconfig
$ cd .. 

pygpu, which is included in libgpuarray, is installed by setup.py. To install pygpu, please aply the command lines listed below.

$ python setup.py build
$ sudo python setup.py install

This is basically the end of installing the pre-requirements for the installation of Theano. Since Pylearn2 recommends to install a newer version of Theano (please look at this page), download and instal bleeding-edge version of Theano. To follow the instructions listed at the URL shown below, please git the newest version of Theano.
URL

$ pip install -- update -- no-deps git + git://github.com/Theano/Theano.git

Adjusting the configuration of Theano

As the installation of Theano is succeed, Theano works at the CPU backend. As the article at the URL shown below suggests, Theano is needed to be configured for using GPU.
URL

Create .theanorc at the home directory, write down the contents listed below.

[global]
floatX=float32
device=gpu
[mode]=FAST_RUN)
[nvcc]
fastmath = True
[cuda]
root=/usr/local/cuda
[blas]
Idflags= -Iopenblas

Executing Theano, .theanorc is read. To examine whether GPU is effective or not, please execute an example, which is listed at this page. The other example of how to check the effectiveness of GPU is to execute check_blas.py changing the setting at device option Then, the outputs and the durations of executions are compared among different values at device option. This is how to execute check_blas.py.

Not using Tesla K20c

Code>

Using Tesla K20c

Code>

Installing Pylearn2

To install Pylearn2, PyYAML and PIL are required besides installing Theano.
(Because PIL is a dependent of CUDA, PIL is installed when CUDA is introduced to the system.)

$ sudo apt-get install python-yamal pyathon-pil

As the pre-requirements for Pylearn2 are installed, finally the source code of Pylearn2 is downloaded. To download the code, do git clone for the source code. Then, install the code.

$ git clone git://github.com/lisa-lab/paylearn2.git
$ cd pylearn2
sudo python setup.py.develop

After the installation process is completed, please add the configuration of Data Path, which is required for executing Pylearn2, to .bashrc.
Please create the Data directory for store the data. Basically, you can create this directory anywhere as long as where your write permission is effective. In this example the Data directory is created under the Home directory and specified it to .bashrc.

$ makedir -p pylearn2data
$ exho 'exporet PYLEARN2_DATA_PATH=/home/beat/pylearn2data >> .bashrc
$ .~/bashrc

Then, install matplotlib. This is required for executing a tutorial of Pylearn2.

$ sudo apt-get install

Checking the Operation of Pylearn2

To check whether Pylearn2 is set up correctly or not, execute Quick-start example. The details of this example is listed at this page.

<Code>

Before executing the example, please download the dataset. Otherwise, warnings will appear.

Code>

As the download is completed, the example is re-executed.

Code>

To use the script, which is located at the directory of pylearn2/scripts/, set PATH to this directory.

$ export PATH=/home/beat/work/pylearn2/pylearn2/scripts:$PATH

Execute train.py

<Code ~long>

cifar_grbm is output.

To check the results, apply show_weights.py and cifar_grbm_smd.pkl. If you execute it without any configuration, you will receive a warning for asking the configuration. To follow the

$ export PYLERN2_VIEWER_COMMAND=”Eog--new-instance”

Then, try to execute the example, again.

$  show_weights.py cifar_grbm_smd.pkl

As the command line above is executed, a Gabor filter, which is generated from the learning experience of pylearn2, is displayed on Eye of Gnome.

Picture>

Using --out, set up the options. Then, output the results on the image file. The command lines below indicate how to apply the options and show the outcomes.


Front page   New List of pages Search Recent changes   RSS of recent changes