Skip to content

CNTK 2.0 Setup from Sources

sayanpa edited this page Oct 25, 2016 · 13 revisions

This page will walk through the manual installation steps to build CNTK V2 from sources. This is intended for individuals interested in contributing to CNTK shall choose this option.

These steps are intended for contributors and developers. Jump to specific platforms of interest:

Steps for Windows

Step 1: Install pre-requisites and build dependencies

  • If you do not have CNTK development environment already setup on your machine, follow the instructions on CNTK github (Setting up CNTK on Windows).
  • Please follow the instructions for Steps 4 here to clone the repository.

Step 2: Build CNTK

  • Build CNTK (Release version).

Step 3: Build Python

  • Install SWIG 3.0.10:

  • Install Anaconda recommended (Anaconda Python 3.4) or create a Python 3.4.3 environment within your existing Python Anaconda or miniconda installation using the following commands:

conda create --name cntk-py34 python=3.4.3 numpy scipy jupyter matplotlib

activate cntk-py34

[Note: Make sure that the python version installed above is what you use for the remainder of the instructions.]

Step 4: Uninstall previous CNTK 2.0 package

  • If you previously installed any version of the CNTK 2.0 pip-package on your machine, uninstall it by running: pip uninstall cntk-py34

Step 5: Building python package We are going to build the Python module using the CNTK Visual Studio solution, CNTK.sln.

(a) Set up build environment variables

setx SWIG_PATH [path to the folder containing swig.exe]
setx CNTK_PY34_PATH [paths for your Python 3.4 environment]
-Note: the value for the CNTK_PY34_PATH environment variable can be determined by running

conda ..activate cmd.exe [name-or-path-of-your-environment] For example, run conda ..activate cmd.exe cntk-py34, if you have set up the Python environment as suggested above.

(b) Build the binaries

  • Make sure that Visual Studio sees the updated environment variables.

  • Build a Release configuration in the CNTK Visual Studio solution, CNTK.sln. This will build the CNTK Python module inside bindings/python/cntk and also produce a package (.whl) in a subfolder Python of your build output folder (e.g., x64\Release\Python).

  • Make sure your path includes the build output folder (e.g., x64\Release), and that PYTHONPATH includes the bindings/python directory:

(c) Set python code/ build paths

setx PYTHONPATH [CNTK repo root]\bindings\python\;%PYTHONPATH%
setx PATH [CNTK repo root][build output directory];%PATH%
  • Note: in contrast to the setup shown for the Pip package installation, here we will load the CNTK module from the CNTK repository clone, not as an installed package in your Python environment.

Step 6: Verify setup

Python

  • Run the examples from inside the [CNTK clone root]/bindings/python directory, to verify your installation. Run python examples/NumpyInterop/feedforwardNet.py. You should following output on the console:
Minibatch: 0, Train Loss: 0.7915553283691407, Train Evaluation Criterion: 0.48

Minibatch: 20, Train Loss: 0.6266774368286133, Train Evaluation Criterion: 0.48

Minibatch: 40, Train Loss: 1.0378565979003906, Train Evaluation Criterion: 0.64

Minibatch: 60, Train Loss: 0.6558118438720704, Train Evaluation Criterion: 0.56

Brainscript (optional)

  • Please run the following self contained example:
cd C:\repos\CNTK\Examples\Other\Simple2d

CNTK configFile=Config/Simple.cntk currentDirectory=Data

You should be able to see the results getting printed on the console.

Note: If you see an error saying "RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9", your numpy version is outdated and needs to be updated, run: pip install --upgrade numpy

Steps for Linux

Step 1: Install pre-requisites and build dependencies

  • If you do not have CNTK development environment already setup on your machine, follow the instructions on (Setting up CNTK on Linux).
  • Please follow the instructions for Steps 4 here to clone the repository.

Step 2: Build CNTK

  • Build of CNTK (Release flavor) with the GPU SKU.

Step 3: Build Python APIs

  • Install SWIG by running the script: [CNTK clone root]/bindings/python/swig_install.sh. This creates the installed version into a $HOME/swig-3.0.10/root folder

  • Install Anaconda python 3.5

  • Create a Python 3.4.3 environment in your existing Python 3.5 anaconda or miniconda installation using the following commands:

conda create --name cntk-py34 python=3.4.3 numpy scipy jupyter matplotlib

activate cntk-py34

[Note: Make sure that the python version installed above is what you use for the remainder of the instructions.]

Step 4: Uninstall previous CNTK 2.0 package

  • If you previously installed any version of the CNTK 2.0 pip-package on your machine, uninstall it by running: pip uninstall cntk-py34

Step 5: Build Python Package

  • To configure a build with Python, include these two option when running configure:
--with-swig[=directory]
--with-py34-path[=directory]
  • Only Release builds are supported at this stage. For example, if you installed SWIG to $HOME/swig-3.0.10 and your Python 3.4 environment is located at $HOME/anaconda3/envs/cntk-py34 provide these additional parameters to configure:
--with-swig=$HOME/swig-3.0.10 --with-py34-path=$HOME/anaconda3/envs/cntk-py34
  • Afterwards, run make as you normally would, which will build the CNTK Python module inside bindings/python/cntk and also produce a package (.whl) in a subfolder python of your build output folder (e.g., build/gpu/release/python).
cd bindings/python
export PYTHONPATH=$PWD/bindings/python:$PYTHONPATH
export LD_LIBRARY_PATH=$PWD/cntk/libs:$LD_LIBRARY_PATH

Note: in contrast to the setup shown for the Pip package installation, here we will load the CNTK module from the CNTK repository clone, not as an installed package in your Python environment.

Step 6: Verify setup

Python

  • You may run the Python test included in the CNTK module
pip install pytest

python -c "import cntk, os; print(os.path.dirname(os.path.abspath(cntk.__file__)))"

pytest [the directory output by the previous command]
  • Run the examples from inside the [CNTK clone root]/bindings/python directory, to verify your installation. Run python examples/NumpyInterop/feedforwardNet.py. You should following output on the console:
Minibatch: 0, Train Loss: 0.7915553283691407, Train Evaluation Criterion: 0.48

Minibatch: 20, Train Loss: 0.6266774368286133, Train Evaluation Criterion: 0.48

Minibatch: 40, Train Loss: 1.0378565979003906, Train Evaluation Criterion: 0.64

Minibatch: 60, Train Loss: 0.6558118438720704, Train Evaluation Criterion: 0.56

Brainscript (optional)

  • Please run the following self contained example:
cd /home/username/repos/CNTK/Examples/Other/Simple2d

CNTK configFile=Config/Simple.cntk currentDirectory=Data

You should be able to see the results getting printed on the console.

Note: If you see an error saying "RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9", your numpy version is outdated and needs to be updated, run: pip install --upgrade numpy

Clone this wiki locally