The installation is available at The Microsoft Cognitive Toolkit page. Manual installation is recommended because the user can build the desired CNTK binary for the specific architecture. It enriches the CNTK with a better system compatibility and it will run much faster. Manual installation is available at Setup CNTK on your machine link. The official CNTK explanations are concise and to the point. However. few things might become important as we go through the installation. We try to project the step by step process to avoid any confusion. The following sections must be considered in the written order.
The assumption is that installing CNTK 2.0
in the Ubuntu 14.04
using GPU support
is desired. Python2.7
is chosen for installation. It has not been tested on Ubuntu 16.04
but it should works as is.
The following should be done in order:
- CNTK system dependencies installation
- CNTK Python dependencies installation
- GPU prerequisites setup
- C++ Compiler
- Open MPI Installation
sudo apt-get install autoconf automake libtool curl make g++ unzip
For installation of the required dependencies, the following command must be executed in the terminal:
sudo apt-get install python-numpy python-dev python-pip python-wheel python-virtualenv
The following requirements must be satisfied:
- NVIDIA's Cuda Toolkit and its associated drivers (version 8.0 is recommended). The installation is explained at CUDA Installation.
- The cuDNN library (version 5.1 or higher is recommended). Please refer to NIDIA documentation for further details.
- Installing the
libcupti-dev
using the following command:sudo apt-get install libcupti-dev
The main goal is to make sure the latest NVIDIA driver is installed.
You can refer to the NVIDIA CUDA Download page. Installation instructions in available at CUDA official online documentation.
CUDNN can be downloaded and installed as follows:
wget http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz
tar -xzvf ./cudnn-8.0-linux-x64-v5.1.tgz
sudo mkdir /usr/local/cudnn-5.1
sudo cp -r cuda /usr/local/cudnn-5.1
Alternatively, you can refer to NVIDIA CUDA Deep Neural Network library (cuDNN) official documentation.
Finally, the environment must be added to the .bashrc
profile by adding the following line:
export LD_LIBRARY_PATH=/usr/local/cudnn-5.1/cuda/lib64:$LD_LIBRARY_PATH
NVIDIA CUB must be installed too as one of the dependencies.
wget https://github.com/NVlabs/cub/archive/1.4.1.zip
unzip ./1.4.1.zip
sudo cp -r cub-1.4.1 /usr/local
Assume the installation of CNTK in a python virtual environment
is desired. First, we need to create a directory to contain all the environments. It can be done by executing the following in the terminal:
sudo mkdir ~/virtualenvs
Now by using the virtualenv
command, the virtual environment can be created:
sudo virtualenv --system-site-packages ~/virtualenvs/CNTK
or the following for python3:
sudo virtualenv --p python3 ~/virtualenvs/CNTK
Environment Activation
Up to now, the virtual environment named CNTK has been created. For environment activation, the following must be done:
source ~/virtualenvs/CNTK/bin/activate
However, the command is too verbose!
Alias
The solution is to use an alias to make life easy! Let's execute the following command:
echo 'alias CNTK="source $HOME/virtualenvs/CNTK/bin/activate" ' >> ~/.bash_aliases
bash
After running the previous command, please close and open terminal again. Now by running the following simple script, the CNTK environment will be activated.
CNTK
check the ``~/.bash_aliases``
To double check let's check the ~/.bash_aliases
from the terminal using the sudo gedit ~/.bash_aliases
command. The file should contain the following script:
alias CNTK="source $HO~/virtualenvs/CNTK/bin/activate"
check the ``.bashrc``
Also, let's check the .bashrc
shell script using the sudo gedit ~/.bashrc
command. It should contain the following:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
The C++ compiler might be naively installed. In the Ubuntu, you can check it as follows:
dpkg --list | grep compiler
Please refer to the C++ Compiler documentation.
Intel Math Kernel Library (Intel MKL) is the default CNTK math library is the.
As Microsoft says: "You can NOT directly build CNTK using a regular installed Intel MKL SDK, the build is configured to work with a custom generated CNTK custom MKL library (This way you don't need to go through the process of installing the complete Intel MKL SDK).
The installation process is as follows:
Create a directory to hold CNTK custom MKL:
sudo mkdir /usr/local/CNTKCustomMKL
Download the required CNTK custom MKL from Cognitive Toolkit Custom MKL Package page.
Unpack it in the created directory:
sudo tar -xzf CNTKCustomMKL-Linux-3.tgz -C /usr/local/CNTKCustomMKL
For configuration of CNTK
, --with-mkl=<directory>
option must be used. In
our case, --with-mkl=/usr/local/CNTKCustomMKL
is the correct flag.
Open MPI is a High Performance Message Passing Library. It is an important part of the manual installation of CNTK for having a better performance and make the most of it.
The procedure for Open MPI installation is as below:
Getting the source of installation:
wget https://www.open-mpi.org/software/ompi/v1.10/downloads/openmpi-1.10.3.tar.gz
Unpack it:
tar -xzvf ./openmpi-1.10.3.tar.gz cd openmpi-1.10.3
Configuration:
./configure --prefix=/usr/local/mpi
Build & Install:
make -j all && sudo make install
Add the environment variable to
.bashrc
profile:export PATH=/usr/local/mpi/bin:$PATH export LD_LIBRARY_PATH=/usr/local/mpi/lib:$LD_LIBRARY_PATH
In CNTK Protocol Buffers is used for serialization. It should be installed by the following procedure:
Installing the required packages:
sudo apt-get install autoconf automake libtool curl make g++ unzip
Get the Protobuf from the source:
wget https://github.com/google/protobuf/archive/v3.1.0.tar.gz && tar -xzf v3.1.0.tar.gz
Compiling Protobuf && Installation:
cd protobuf-3.1.0 && ./autogen.sh && ./configure CFLAGS=-fPIC CXXFLAGS=-fPIC --disable-shared --prefix=/usr/local/protobuf-3.1.0 && make -j $(nproc) && sudo make install
You can get the latest version from zlib offical website. Alternatively, it can be installed in Ubuntu using the following command:
sudo apt-get install zlib1g-dev
LIBZIP is a C library for reading, creating, and modifying zip archives. It is recommended
to install LIBZIP
from the source. The procedure is as follows:
Get and unpack the source file:
wget http://nih.at/libzip/libzip-1.1.2.tar.gz && tar -xzvf ./libzip-1.1.2.tar.gz
Configuration & Installation:
cd libzip-1.1.2 && ./configure && make -j all && sudo make install
Now the environment variable must be added to .bashrc
profile:
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
Boost Library is an important prerequisite for CNTK setup. The installation process is as follows:
Installing dependencies:
sudo apt-get install libbz2-dev && sudo apt-get install python-dev
Getting the source files:
wget -q -O - https://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz/download | tar -xzf -
Installation:
cd boost_1_60_0 && ./bootstrap.sh --prefix=/usr/local/boost-1.60.0 && sudo ./b2 -d0 -j"$(nproc)" install
NVIDIA's NCCL library can be installed for optimized multi-GPU communication on Linux which CNTK can take advantage from it.
Please follow build instructions as follows:
Clone the NCCL repository:
git clone https://github.com/NVIDIA/nccl.git $$ cd nccl
Build $$ Test:
make CUDA_HOME=<cuda install path> test
In which <cuda install path>
is usually /usr/local/cuda
.
Add to path:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./build/lib
Build tests:
./build/test/single/all_reduce_test
You may get the error of Error: must specify at least data size in bytes!
. Then
run the following:
./build/test/single/all_reduce_test 10000000
WARNING: In configuration of CNTK, --with-nccl=<path>
option must be used
to enable NVIDIA NCCL
. In our example $HOME/nccl/build
in the path argument
.
SWIG is required if Python is desired to be the interface for CNTK. The process is as follows:
sudo [CNTK clone root]/Tools/devInstall/Linux/install-swig.sh
This is expected to install SWIG in /usr/local/swig-3.0.10
.
WARNING: It is very important to use sudo
for SWIG installation.
The step-by-step procedure is as follows:
Make sure
SWIG
is installed.Make sure Anaconda, Miniconda or any other environment (which contains conda environment) is installed.
Create the conda environment as follows (for a Python X-based version in which X can be
27
,34
,35
,36
equivalent to2.7
,3.4
,3.5
,3.6
):conda env create --file [CNTK clone root]/Scripts/install/linux/conda-linux-cntk-pyX-environment.yml
Now, since we have the environment, the packages can be updated to latest versions as below:
conda env update --file [CNTK clone root]/Scripts/install/linux/conda-linux-cntk-pyX-environment.yml --name cntk-pyX
Now, the conda environment can be activated as below:
source activate cntk-pyX
NOTE: Remember to set X
according to the desired version and existing files.
Parameter server is a framework which is of great importance in distributed machine learning.
Asynchronous parallel training with many workers is one of the key advantages. before
configuration of CNTK
we are determined to build CNTK with Multiverso supported.
Multiverso is a parameter server framework developed by Microsoft Research Asia team. It enables the Asynchronous SGD.
The installation process is as follows:
cd the root folder of CNTK.
Clone the
Multiverso
code under the root folder of CNTK:git submodule update --init Source/Multiverso
In
CNTK
configuration, use the--asgd=yes
flag (Linux).
Configuration is as follows as the user is the directory of CNTK clone root
.
./configure --with-swig=/usr/local/swig-3.0.10 --with-py35-path=$HOME/anaconda/envs/cntk-py35 --with-nccl=$HOME/GITHUB/nccl/build --with-mkl=/usr/local/CNTKCustomMKL --asgd=yes --cuda=yes --with-cuda=/usr/local/cuda
Now, the .whl
file has been created. Installation of CNTK
is as follows:
cd to the folder that
.whl
file is located.cd [CNTK clone root]/python
Activate virtual environment.
source activate cntk-py35
Install the created package using
pip
.pip install file_name.whl
In the terminal, the following script must be run (in the home directory
) correctly without any error and preferably any warning:
python
>> import cntk
In this tutorial, we described how to install CNTK from the source which has the advantage of more compatibility with the system configuration. Python virtual environment installation has been investigated as well to separate the CNTK environment from other environments. Conda environments can be used as well as Python virtual environments which will be explained in a separated post. In any case, the CNTK installed from the source can be run much faster than the pre-build binary packages provided by the Microsoft CNTK although it adds the complexity to the installation process.