3. TensorFlow 2 setup
The versions of TensorFlow included in Poplar SDK 2.5 and earlier are not compatible with
protobuf version 4 (see TensorFlow issue #56077).
When you install a TensorFlow wheel from the Poplar SDK, you must ensure you have a compatible version of
protobuf, downgrading if necessary.
For TensorFlow 2:
$ python -m pip install "protobuf>=3.8.0,<3.20" --force-reinstall
You can do this before or after installing the Graphcore TensorFlow wheel.
You should activate the Python virtual environment you created for TensorFlow 2 (Section 2.6, Create a Python virtual environment) before performing the setup in this section.
3.1. Install TensorFlow 2 wheel
This section describes how to install the wheel file containing the Graphcore distribution of TensorFlow 2.
There are two TensorFlow 2 wheels, one for AMD processors and one for Intel processors. Check which processor is used on your system by running:
$ lscpu | grep name
Install the Graphcore TensorFlow 2 distribution for the processor you found in the previous step using a command similar to the following:
$ python -m pip install $SDK_DIR/tensorflow-[ver]+[platform].whl where `$SDK_DIR` is the location of the Poplar SDK (:numref:`sdk_location`), ``[ver]`` is the version of the Graphcore port of TensorFlow 2 and ``[platform]`` defines the host processor and operating system for the TensorFlow build.
An example of the TensorFlow 2 wheel file for an AMD processor is:
To confirm that
tensorflow has been installed, you can use
list, which should include the
tensorflow package in the output, for
$ python3 -c "from tensorflow.python import ipu"
If you get an “illegal instruction” or similar error, then you may have installed the wrong version of TensorFlow for your processor.
3.2. Install Keras wheel
In the TensorFlow 2.6 release, Keras was moved into a separate
pip package. In the Poplar SDK 2.6 release, which includes the Graphcore distribution of TensorFlow 2.6, there is a Graphcore distribution of Keras which includes IPU-specific extensions.
This section describes how to install the wheel file containing the Graphcore distribution of Keras.
The Keras wheel must be installed after the TensorFlow wheel, but before the TensorFlow Addons wheel.
To install the Keras wheel, use a command similar to:
$ python -m pip install --force-reinstall --no-deps $SDK_DIR/keras-<tf-ver>*.whl
<tf-ver> is the TensorFlow 2 version.
An example of the Keras wheel file for for TensorFlow 2.6 for the IPU for Poplar SDK 2.6 is:
You can confirm that the
keraspackage has been installed by importing it in Python, for example:$ python3 -c "import keras"
If you get an “illegal instruction” or similar error, then try to install the Keras wheel again.
3.3. Install TensorFlow 2 Addons wheel
This section describes how to install the wheel file containing a collection of add-ons for the Graphcore distribution of TensorFlow 2.
IPU TensorFlow Addons is a collection of add-ons created for the Graphcore port of TensorFlow. These include layers and optimizers for Keras, as well as legacy TensorFlow layers. For more information, refer to the section on :ref:`IPU TensorFlow Addons <tensorflow2:ipu tensorflow addons python api>`_ in the TensorFlow 2 user guide.
The IPU TensorFlow 2 Addons wheel file is only available in Poplar SDK 2.4 and later.
There are separate Addons wheel files for TensorFlow 1 and TensorFlow 2.
Install the IPU TensorFlow 2 Addons wheel using a command similar to the following:
$ python -m pip install $SDK_DIR/ipu_tensorflow_addons-[ver]+X+X+X-X-X-X.whl
$SDK_DIR is the location of the Poplar SDK (Section 2.4, Define environment variables),
[ver] is the version of the Graphcore port of TensorFlow 2.
An example of the IPU TensorFlow 2 Addons wheel file is:
You can confirm that the Addons module has been installed correctly by importing it in Python. For example:
$ python3 -c "ipu_tensorflow_addons.keras import layers"
If you get an “illegal instruction” or similar error, confirm that you have installed the Addons wheel file for TensorFlow 2.