Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (69 sloc) 3.45 KB

Building nGraph and nGraph-ONNX


Python 3.4 or higher is required.

Protocol Buffers

You will need Protocol Buffers v.2.6.1 or higher installed on your system to use ONNX.

On Ubuntu, for example you can install protobuf using:

# apt update
# apt install protobuf-compiler libprotobuf-dev

And on Mac OS you can install protobuf using Homebrew:

$ brew install protobuf

You can verify whether you have version >=2.6.1 installed using the command:

$ protoc --version
libprotoc 3.4.0


The other requirement is of course nGraph and nGraph's Python bindings. You can follow these instructions to build an nGraph Python wheel containing both.

nGraph build process on Ubuntu 18.04

Prepare System:

# apt update
# apt install python3 python3-pip python3-dev python-virtualenv
# apt install build-essential cmake curl clang-3.9 git zlib1g zlib1g-dev libtinfo-dev unzip autoconf automake libtool

Clone nGraph's master branch, build and install it into $HOME/ngraph_dist:

$ cd # Change directory to where you would like to clone nGraph sources
$ git clone -b master --single-branch --depth 1
$ mkdir ngraph/build && cd ngraph/build
$ make
$ make install

Prepare a Python virtual environment for nGraph (recommended):

$ mkdir -p ~/.virtualenvs && cd ~/.virtualenvs
$ virtualenv -p $(which python3) nGraph
$ source nGraph/bin/activate
(nGraph) $ 

Build Python package (Binary wheel) for nGraph:

(nGraph) $ cd # Change directory to where you have cloned nGraph sources
(nGraph) $ cd ngraph/python
(nGraph) $ git clone --recursive
(nGraph) $ export PYBIND_HEADERS_PATH=$PWD/pybind11
(nGraph) $ export NGRAPH_CPP_BUILD_PATH=$HOME/ngraph_dist
(nGraph) $ pip install numpy
(nGraph) $ python bdist_wheel

For additional information how to build nGraph Python bindings see:

Once the Python binary wheel file (ngraph-*.whl) is prepared you can install it using pip.

For example:

(nGraph) $ pip install -U dist/ngraph_core-0.0.0.dev0-cp36-cp36m-linux_x86_64.whl

You can check that nGraph is properly installed in your Python shell:

>>> import ngraph as ng
>>> ng.abs([[1, 2, 3], [4, 5, 6]])
<Abs: 'Abs_1' ([2, 3])>

Additionally check that nGraph and nGraph's Python wheel were both build with the NGRAPH_ONNX_IMPORT_ENABLE option:

from ngraph.impl import onnx_import

If you don't see any errors, nGraph should be installed correctly.

Installing ngraph-onnx

You can install ngraph-onnx using the following commands. Clone ngraph-onnx sources to the same directory where you cloned ngraph sources.

(nGraph) $ cd # Change directory to where you have cloned nGraph sources
(nGraph) $ git clone -b master --single-branch --depth 1
(nGraph) $ cd ngraph-onnx
(nGraph) $ pip install -r requirements.txt
(nGraph) $ pip install -r requirements_test.txt
(nGraph) $ pip install -e .

Running tests

(nGraph) $ pytest tests/ --backend=CPU -v
(nGraph) $ NGRAPH_BACKEND=CPU TOX_INSTALL_NGRAPH_FROM=../ngraph/python tox
You can’t perform that action at this time.