Skip to content

Setup Linux Binary Manual

Mark Hillebrand edited this page Feb 1, 2017 · 29 revisions

Linux binary manual installation

This page will walk you through the process of installing the Microsoft Cognitive Toolkit (CNTK) based on a binary distribution we have prepared and you can download from our website.

These instructions apply to release 2.0.beta10.0.

Note: You can find an overview about all the available installation options for CNTK on [this page] (./Setup-CNTK-on-your-machine).

We will install the CNTK binaries, the CNTK prerequisites, and create (or update) a Python 2.7, 3.4, or 3.5 environment on your computer. The changes are as much localized as possible to not impact any other installed software.

Note: If you previously installed an earlier version of the CNTK Python package, you can skip steps 1 through 3 below and directly jump to step 4 to update your existing CNTK package installation from your Python 2.7, 3.4, 3.5 environment

Step 1: Download and install pre-requisites

Docker users please follow the instructions here. Others please continue reading.

CNTK V2 on Linux requires the following prerequisites to be installed from the links below:

  • C++ Compiler
  • Open MPI IMPORTANT! We strongly recommend to follow Open MPI installation procedure described by the link above to ensure the correct work of CNTK.
  • For GPU systems ensure that you have the latest NVIDIA driver

Download the required binary package from CNTK Releases page and extract it to your machine.

Step 2: Python setup

  • If you do not have Anaconda environment: install Anaconda Python 3.5 for Linux

  • If you already have a CNTK Python environment (called cntk-py35, cntk-py34, or cntk-py27) you can update it with the latest required packages with the following commands:

# For cntk-py35:
conda env update --file ./Scripts/install/linux/conda-linux-cntk-py35-environment.yml --name cntk-py35
# For cntk-py34:
conda env update --file ./Scripts/install/linux/conda-linux-cntk-py34-environment.yml --name cntk-py34
# For cntk-py27:
conda env update --file ./Scripts/install/linux/conda-linux-cntk-py27-environment.yml --name cntk-py27
  • In your Anaconda installation, create a conda environment (called cntk-py35 here) and activate it by running the following commands:
conda env create --file ./Scripts/install/linux/conda-linux-cntk-py35-environment.yml
source activate cntk-py35
python -m pip install --upgrade pip

Note: Make sure that the Python environment updated or created above is activated for the remainder of the instructions. For example, if you have Python 3.5 based environment called cntk-py35 run this command:

source activate cntk-py35

Similarly, for a Python 3.4 or 2.7 based environment.

Step 3: Install CNTK

Python

  • Run one of the following commands, depending on your Python version:
# For a Python 3.5 based version:
pip install --upgrade ./cntk/python/cntk-2.0.beta10.0-cp35-cp35m-linux_x86_64.whl
# For a Python 3.4 based version:
pip install --upgrade ./cntk/python/cntk-2.0.beta10.0-cp34-cp34m-linux_x86_64.whl
# For a Python 2.7 based version:
pip install --upgrade ./cntk/python/cntk-2.0.beta10.0-cp27-cp27mu-linux_x86_64.whl

Brainscript

  • Set the following environment variables (we assume that the CNTK archive is extracted to /home/username/cntkbin):
export PATH=/home/username/cntkbin/cntk/bin:$PATH
export LD_LIBRARY_PATH=/home/username/cntkbin/cntk/lib:/home/username/cntkbin/cntk/dependencies/lib:$LD_LIBRARY_PATH

Note: If you've built openmpi yourself (for example, on Ubuntu 14), make sure to add its library directory to LD_LIBRARY_PATH as well:

export LD_LIBRARY_PATH=[path-to-your-openmpi-installation]/lib:$LD_LIBRARY_PATH

Step 4: Verify the setup (Python)

  • Run an example from Tutorials directory to verify your installation. Run python NumpyInterop/FeedForwardNet.py. You should see the following output on the console:

    Minibatch[   1- 128]: loss = 0.564038 * 3200
    Minibatch[ 129- 256]: loss = 0.308571 * 3200
    Minibatch[ 257- 384]: loss = 0.295577 * 3200
    Minibatch[ 385- 512]: loss = 0.270765 * 3200
    Minibatch[ 513- 640]: loss = 0.252143 * 3200
    Minibatch[ 641- 768]: loss = 0.234520 * 3200
    Minibatch[ 769- 896]: loss = 0.231275 * 3200
    Minibatch[ 897-1024]: loss = 0.215522 * 3200
    Finished Epoch [1]: loss = 0.296552 * 25600
    error rate on an unseen minibatch 0.040000
    
  • Run the Jupyter notebooks, which contain several tutorials, by executing the following commands:

    cd /home/username/cntk/Tutorials
    jupyter notebook
    

This will spawn a browser with all available notebooks ready to be run. Should the notebooks fail to execute, run conda install jupyter from your activated CNTK environment (e.g., cntk-py35).

Step 5 (Optional): Verify the setup (BrainScript)

Perform the following command in the CNTK environment command prompt (see previous step):

cd /home/username/cntk/Tutorials/HelloWorld-LogisticRegression
cntk configFile=lr_bs.cntk makeMode=false command=Train

The last lines of the CNTK output on the console should look similar to this:

Finished Epoch[42 of 50]: [Training] lr = 0.04287672 * 1000; err = 0.01152817 * 1000; totalSamplesSeen = 42000; learningRatePerSample = 0.039999999; epochTime=0.050296s
Finished Epoch[43 of 50]: [Training] lr = 0.04388479 * 1000; err = 0.01206375 * 1000; totalSamplesSeen = 43000; learningRatePerSample = 0.039999999; epochTime=0.052143s
Finished Epoch[44 of 50]: [Training] lr = 0.04223433 * 1000; err = 0.01105073 * 1000; totalSamplesSeen = 44000; learningRatePerSample = 0.039999999; epochTime=0.057235s
Finished Epoch[45 of 50]: [Training] lr = 0.04208072 * 1000; err = 0.01140516 * 1000; totalSamplesSeen = 45000; learningRatePerSample = 0.039999999; epochTime=0.051414s
Finished Epoch[46 of 50]: [Training] lr = 0.04261674 * 1000; err = 0.01158323 * 1000; totalSamplesSeen = 46000; learningRatePerSample = 0.039999999; epochTime=0.051115s
Finished Epoch[47 of 50]: [Training] lr = 0.04326523 * 1000; err = 0.01164283 * 1000; totalSamplesSeen = 47000; learningRatePerSample = 0.039999999; epochTime=0.051611s
Finished Epoch[48 of 50]: [Training] lr = 0.04225255 * 1000; err = 0.01148774 * 1000; totalSamplesSeen = 48000; learningRatePerSample = 0.039999999; epochTime=0.0509s
Finished Epoch[49 of 50]: [Training] lr = 0.04173276 * 1000; err = 0.01124948 * 1000; totalSamplesSeen = 49000; learningRatePerSample = 0.039999999; epochTime=0.049659s
Finished Epoch[50 of 50]: [Training] lr = 0.04399402 * 1000; err = 0.01202178 * 1000; totalSamplesSeen = 50000; learningRatePerSample = 0.039999999; epochTime=0.052725s

COMPLETED.

If you have an NVidia GPU and installed a GPU build, you can also try this command:

cntk configFile=lr_bs.cntk makeMode=false command=Train deviceId=auto

To validate that the GPU was being used, look for the following line in your output:

Model has 9 nodes. Using GPU 0.
Clone this wiki locally