Some incomplete notes, which I'll later turn into a proper post.
I'm running on a 160-core Ampere Altra, but these instructions should work for any arm64 Ubuntu 20.04 system you have in mind. I'll try next on an 8GB Raspberry Pi for completeness.
In order, you need the following:
- Python 3.7 (and not the system Python which should be 3.8) from the
deadsnakes
PPA - a Python 3.7 virtual environment (venv)
- a prebuilt wheel for Tensorflow 2.0 from Linaro targeting Python 3.7
- the package libhdf5-dev so that you can build h5py from scratch
A little more detail on each.
deadsnakes
provides more recent Python versions packaged for Ubuntu, as well
as previous versions. The PPA does not promise that security problems will be
updated in a timely way, so be forewarned.
The PPA is at https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa , and you can install it with
sudo apt-add-repository ppa:deadsnakes/ppa
sudo apt-get update
Once it's in place, get the full set of Python 3.7 packages
sudo apt-get install python3.7 python3.7-dev python3.7-venv
Next, set up a virtual enviornment (venv) to hold Tensorflow and all of its dependencies under Python 3.7. We'll follow the official Tensorflow docs at https://www.tensorflow.org/install/pip for a little bit, adapted to use the python3.7 bits:
python3.7 -m venv --system-site-package ./venv-3.7
source ./venv-3.7/bin/activate
pip install --upgrade pip
With this venv ready, you can now grab a prebuilt Python "wheel" for arm64 from the Linaro repository at
https://snapshots.linaro.org/ldcg/python/tensorflow/12
Pick up just the "tensorflow_cpu" wheel or optionally additionally the "grpcio" and "h5py" wheels to speed up the install. Your installation will look something like this:
wget https://snapshots.linaro.org/ldcg/python/tensorflow/12/tensorflow_cpu/tensorflow_cpu-2.4.0-cp37-cp37m-linux_aarch64.whl
and then install with pip (still in that venv)
pip install tensorflow_cpu-2.4.0-cp37-cp37m-linux_aarch64.whl
pip will grind away for a while, then complain about h5py. You can deal with its complaints by installing the prebuilt h5py wheel from the Linaro site, or let pip built that wheel from scratch if you first do
apt-get install libhdf5-dev
and then restart the pip install.
If you are lucky - and if I haven't missed a step - you will have a working install of Tensorflow. I tested mine with the sample code at https://www.tensorflow.org/overview/ with the sample that uses the mnist dataset.
How this could be easier
The easy install process should be simply
pip install tensorflow
All of the other things I describe here should be obsoleted when a proper tensorflow wheel is eventually published.
A few things could make this easier. The Linaro wheels could be easier to find - if you want to locate them again, start from the https://github.com/tensorflow/tensorflow source code and look under "community supported builds".
There is an easy-to-find repo https://github.com/lhelontra/tensorflow-on-arm which also has a binary wheel for arm64 and some build instructions, but none of the issues raised in that repo for the last several months have been closed.
I could turn this into a script that did everything, and that had a test process to make sure it continued to do everything.
If you really want to build Tensorflow from sources, you need the Bazel build system and a whole lot of patience. I'm not documenting that here, focusing instead on getting running copy of Tensorflow based on someone else's build.