您的位置:首页 > 运维架构 > Linux

Linux Theano 安装教程

2016-07-01 19:36 746 查看
该文章来自Theano官网,http://deeplearning.net/software/theano/install.html

Easy Installation of an Optimized Theano on Current Ubuntu

For NVIDIA Jetson TX1 embedded platform:

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libblas-dev git
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git --user  # Need Theano 0.8(not yet released) or more recent


For Ubuntu 16.04 with cuda 7.5

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano

# cuda 7.5 don't support the default g++ version. Install an supported version and make it the default.
sudo apt-get install g++-4.9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

# Work around a glibc bug
echo -e "\n[nvcc]\nflags=-D_FORCE_INLINES\n" >> ~/.theanorc


For Ubuntu 11.10 through 14.04:

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano


On 14.04, this will install Python 2 by default. If you want to use Python 3:

sudo apt-get install python3-numpy python3-scipy python3-dev python3-pip python3-nose g++ libopenblas-dev git
sudo pip install Theano


For Ubuntu 11.04:

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git libatlas3gf-base libatlas-dev
sudo pip install Theano


Note
If you have error that contain “gfortran” in it, like this one:

ImportError: (‘/home/Nick/.theano/compiledir_Linux-2.6.35-31-generic-x86_64-with-Ubuntu-10.10-maverick–2.6.6/tmpIhWJaI/0c99c52c82f7ddc775109a06ca04b360.so: undefined symbol: _gfortran_st_write_done’

The problem is probably that NumPy is linked with a different blasthen then one currently available (probably ATLAS). There is 2possible fixes:

Uninstall ATLAS and install OpenBLAS.
Use the Theano flag “blas.ldflags=-lblas -lgfortran”
1) is better as OpenBLAS is faster then ATLAS and NumPy isprobably already linked with it. So you won’t need any otherchange in Theano files or Theano configuration.

Note
If you are behind a proxy, you must do some extra configuration stepsbefore starting the installation. You must set the environmentvariable
http_proxy
to the proxy address. Using bash this isaccomplished with the command
export
http_proxy="http://user:pass@my.site:port/"
You can also provide the
--proxy=[user:pass@]url:port
parameterto pip. The
[user:pass@]
portion is optional.

Note
We use
pip
for 2 reasons. First, it allows “
import
module;module.test()
” to work correctly. Second, the installation of NumPy1.6 or 1.6.1 with
easy_install
raises an ImportError at the end ofthe installation. To my knowledge we can ignore this error, butthis is not completely safe.
easy_install
with NumPy 1.5.1 does notraise this error.

Note
This page describes how to install Theano for Python 2. If you haveinstalled Python 3 on your system, maybe you need to change thecommand pip to
pip-2.7
to specify to install it for Python 2, assometimes the pip command refers to the Python 3 version.

The development version of Theano supports Python 3.3 andprobably supports Python 3.2, but we do not test on it.

Bleeding Edge Installs

If you would like, instead, to install the bleeding edge Theano (from github)such that you can edit and contribute to Theano, replace the
pip install Theanocommand with:

git clone git://github.com/Theano/Theano.git
cd Theano
python setup.py develop --user
cd ..


VirtualEnv

If you would like to install Theano in a VirtualEnv, you will want to pass the–system-site-packages flag when creating the VirtualEnv so that it will pick upthe system-provided
Numpy and SciPy.

virtualenv --system-site-packages -p python2.7 theano-env
source theano-env/bin/activate
pip install Theano


Test the newly installed packages

NumPy (~30s):
python
-c "import numpy;
numpy.test()"

SciPy (~1m):
python
-c "import scipy;
scipy.test()"

Theano (~30m):
python
-c "import theano;
theano.test()"


NumPy 1.6.2, 1.7.0 and 1.7.1, have a bug where it marks some ndarraysas not aligned. Theano does not support unaligned arrays, and raisesan Exception when that happens. This can cause one test to fail withan unaligned error with those versions of NumPy.
You can ignore thattest error as at worst, your code will crash. If this happens, you caninstall another NumPy version to fix this problem. NumPy 1.6.2 is usedin Ubuntu 12.10 and NumPy 1.7.1 is used in Ubuntu 13.04.

Speed test Theano/BLAS

It is recommended to test your Theano/BLAS integration. There are many versionsof BLAS that exist and there can be up to 10x speed difference between them.Also, having Theano link directly against BLAS instead of using NumPy/SciPy asan intermediate layer
reduces the computational overhead. This isimportant for BLAS calls to
ger
,
gemv
and small
gemm
operations(automatically called when needed when you use
dot()
). To run theTheano/BLAS speed test:

python `python -c "import os, theano; print(os.path.dirname(theano.__file__))"`/misc/check_blas.py


This will print a table with different versions of BLAS/numbers ofthreads on multiple CPUs and GPUs. It will also print some Theano/NumPyconfiguration information. Then, it will print the running time of the samebenchmarks for your installation. Try to find
a CPU similar to yours inthe table, and check that the single-threaded timings are roughly the same.

Theano should link to a parallel version of Blas and use all coreswhen possible. By default it should use all cores. Set the environmentvariable “OMP_NUM_THREADS=N” to specify to use N threads.

Note
It is possible to have a faster installation of Theano than the one theseinstructions provide, but this will make the installation morecomplicated and/or may require that you buy software. This is a simple setof installation instructions that
will leave you with a relativelywell-optimized version that uses only free software. With more work or byinvesting money (i.e. buying a license to a proprietary BLASimplementation), it is possible to gain further performance.

Updating Theano

If you followed these installation instructions, you can execute this commandto update only Theano:

sudo pip install --upgrade --no-deps theano


If you want to also installed NumPy/SciPy with pip instead of thesystem package, you can run this:

sudo pip install --upgrade theano


Updating Bleeding Edge Installs

Change to the Theano directory and run:

git pull


Manual Openblas instruction

The openblas included in some older Ubuntu version is limited to 2threads. Ubuntu 14.04 do not have this limit. If you want to use morecores at the same time, you will need to compile it yourself. Here issome code that will help you.

# remove openblas if you installed it
sudo apt-get remove libopenblas-base
# Download the development version of OpenBLAS
git clone git://github.com/xianyi/OpenBLAS
cd OpenBLAS
make FC=gfortran
sudo make PREFIX=/usr/local/ install
# Tell Theano to use OpenBLAS.
# This works only for the current user.
# Each Theano user on that computer should run that line.
echo -e "\n[blas]\nldflags = -lopenblas\n" >> ~/.theanorc


Contributed GPU instruction

Basic configuration for the GPU
Using the GPU.

Ubuntu 11.10/12.04 (probably work on 11.04 too):

sudo apt-add-repository ppa:ubuntu-x-swat/x-updates
sudo apt-get update
sudo apt-get install nvidia-current


Then you need to fetch latest CUDA tool kit (download ubuntu 11.04 32/64bit package)from

here.

Ubuntu 14.04:

sudo apt-get install nvidia-current
sudo apt-get install nvidia-cuda-toolkit # As of October 31th, 2014, provide cuda 5.5, not the latest cuda 6.5


If you want cuda 6.5, you can download packages from
nvidia for Ubuntu 14.04.

If you downloaded the run package (the only one available for CUDA 5.0 and older), you install it like this:

chmod a+x XXX.sh
sudo ./XXX.sh


Since CUDA 5.5, Nvidia provide a DEB package. If you don’t know how tointall it, just double click on it from the graphical interface. Itshould ask if you want to install it. On Ubuntu 14.04, you need to runthis in your terminal:

sudo apt-get update
sudo apt-get install cuda


You must reboot the computer after the driver installation. To testthat it was loaded correctly after the reboot, run the commandnvidia-smi from the command line.

You probably need to change the default version of gcc asexplained by Benjamin J. McCann if the package you downloaded is for another Ubuntu
version:

sudo apt-get install nvidia-cuda-toolkit g++-4.4 gcc-4.4
# On Ubuntu 11.10 and 12.04, you probably need to change gcc-4.5 to gcc-4.6 on the next line.
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4
sudo update-alternatives --config gcc


Test GPU configuration

THEANO_FLAGS=floatX=float32,device=gpu python /usr/lib/python2.*/site-packages/theano/misc/check_blas.py


Note
Ubuntu 10.04 LTS: default gcc version 4.4.3. gcc 4.1.2, 4.3.4 available.

Ubuntu 11.04: default gcc version 4.5.2. gcc 4.4.5 available.

Ubuntu 11.10: default gcc version 4.6.1. gcc 4.4.6 and 4.5.3 available.

Ubuntu 12.04 LTS: default gcc version 4.6.3. gcc 4.4.7 and 4.5.3 available.

Ubuntu 12.10: default gcc version 4.7.2. gcc 4.4.7, 4.5.4 and 4.6.3 available.

Ubuntu 13.10: default gcc version 4.8.1. gcc 4.4.7, 4.6.4 and 4.7.3 available.

Ubuntu 14.04: default gcc version 4.8.2, gcc 4.4.7,, 4.6.4, and 4.7.3 available.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: