-
Notifications
You must be signed in to change notification settings - Fork 16
Old style "Option 2": Build nGraph bridge from source using TensorFlow source
Recommended for developers only. If you don't need to do this, use pip install ngraph-tensorflow-bridge
(see main README). Note this option is slowly being phased out and being replaced by "build_ngtf.py" style build
To run unit tests, or if you are planning to contribute, install the nGraph bridge using the TensorFlow source tree as follows:
The installation prerequisites are the same as described in the TensorFlow [prepare environment] for linux.
-
We use the standard build process which is a system called "bazel". These instructions were tested with [bazel version 0.16.0].
wget https://github.com/bazelbuild/bazel/releases/download/0.16.0/bazel-0.16.0-installer-linux-x86_64.sh chmod +x bazel-0.16.0-installer-linux-x86_64.sh ./bazel-0.16.0-installer-linux-x86_64.sh --user
-
Add and source the
bin
path to your~/.bashrc
file in order to be able to call bazel from the user's installation we set up:export PATH=$PATH:~/bin source ~/.bashrc
-
Once TensorFlow's dependencies are installed, clone the source of the [tensorflow] repo to your machine.
⚠️ You need the following version of TensorFlow:v1.12.0-rc2
git clone https://github.com/tensorflow/tensorflow.git cd tensorflow git checkout v1.12.0-rc2 git status HEAD detached at v1.12.0-rc2
-
You must instantiate a specific kind of
virtualenv
to be able to proceed with thengraph-tf
bridge installation. For systems with Python 3.n or Python 2.7, these commands arevirtualenv --system-site-packages -p python3 your_virtualenv virtualenv --system-site-packages -p /usr/bin/python2 your_virtualenv source your_virtualenv/bin/activate # bash, sh, ksh, or zsh
Note: Depending on specific version of the Python and components already installed on your system - the list of dependent Python components vary. You may need to install one or more of the following Python packages:
numpy mock keras keras_applications protobuf keras_preprocessing
. -
Now run
./configure
and chooseno
for the following when prompted to build TensorFlow.XLA support:
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n No XLA JIT support will be enabled for TensorFlow.
CUDA support:
Do you wish to build TensorFlow with CUDA support? [y/N]: N No CUDA support will be enabled for TensorFlow.
Note that if you are running TensorFlow on a Skylake family processor then select
-march=broadwell
when prompted to specify the optimization flags:Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=broadwell
This is due to an issue in TensorFlow tracked in this issue: https://github.com/tensorflow/tensorflow/issues/17273
-
Prepare the pip package and the TensorFlow C++ library:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package bazel-bin/tensorflow/tools/pip_package/build_pip_package ./
-
Install the pip package, replacing the
tensorflow-1.*
with your version of TensorFlow:pip install -U ./tensorflow-1.*whl
-
Now clone the
ngraph-tf
repo one level above -- in the parent directory of thetensorflow
repo cloned in step 1:cd .. git clone https://github.com/NervanaSystems/ngraph-tf.git cd ngraph-tf git checkout v0.7.0
-
Next, build and install nGraph bridge. :warning: Run the ngraph-tf build from within the
virtualenv
.mkdir build cd build cmake -DUNIT_TEST_ENABLE=TRUE -DTF_SRC_DIR=<path to TensorFlow source directory> .. make -j <your_processor_cores> make install pip install -U python/dist/<ngraph-0.7.0-py2.py3-none-linux_x86_64.whl>
This final step automatically downloads the necessary version of ngraph
and
the dependencies.
-
Test the installation by running the following command:
python -c "import tensorflow as tf; print('TensorFlow version: r',tf.__version__);import ngraph_config; print(ngraph_config.__version__)"
Once the build and installation steps are complete, you can start using TensorFlow with nGraph backends.
Please add the following line to enable nGraph: import ngraph_config
Note: The actual filename for the pip package may be different as it's version
dependent. Please check the build/python/dist
directory for the actual pip wheel.