Compile tensorflow CPU on small RAM devices

Nicola Landro
2 min readMar 1, 2021

I just write how to compile tensorflow with GPU support in a older post, but recently I have to apply it on a device that have less power and the pip version of tensorflow does not work out of the box. In particular I am on a teclast x4 with linux but this guide can be used also from a raspberry pi user or fot other similar devices.

This guide is build as a note after testing it in a linux environment (Linux Mint 20.1) but I think that the same can be done also with other operating system.

The problems

The motivation to compile tensorflow from source is because the pip version of version 2.3 on python 3.8.5 on intel N4100 does not work, it return error on import. I think that this problem arrive from intel atom problems with tensorflow and N4100 is in the middle between Celeron and Intel Atom architecture. But you can want to compile tensorflow also for other reason, this is mine.

The officila tensorflow guide does not work and get errors, but watching the swap during the compilation say me that it is used. Also in a more economic or arm architecture you can not have enought memory to compile it.

The problem is that I do not have enought ram (8GB) to compile it. So I follow the guide but I try to solve this problem by adding some paramiters.

The solution

To reduce the use of ram I add the parmaiter --local_ram_resources=4000

If you ave also problem with cpus you can also add the paramiter --jobs=5

So you can follow the officila tensorflow guide and when you arrive to the build add these paramiters. In particular if you need only the pip package you can do the following:

bazel build --local_ram_resources=512 --jobs=3 --verbose_failures //tensorflow/tools/pip_package:build_pip_package

Now I have a version of tensorflow compiled on my personal CPU and I can use the tensorflow code.

Intel N4100 problem

But I have also another problem trying to compile:

….
tensorflow/python/lib/core/bfloat16.cc:608:60: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘PyUFuncGenericFunction {aka void (*)(char**, const long int*, const long int*, void*)}’
Target //tensorflow/tools/pip_package:build_pip_package failed to build
….

like in this issue but the solution seams does not work for me.

So if less ram is enoght you can try the proposed solution or create a swap partition. For the N4100 I wandering for the solution.

Conclusions

Too much time tensorflow get problems. It is the only not painfull way to use TPU that get a very great boost on training, but for meny other reason (debug firt) i think that it is very worse. So if I can I use Pytorch that now can be bring in production also with caffee to speed up (and pain).

For too meny existing trained model tensorflow it usefull, but I prefer to start my new project with pytorch.

If you have some comments about tensorflow and reason to use it again today write in the comment in order to the best of our nowledge.

--

--

Nicola Landro

Linux user and Open Source fun. Deep learning PhD. , Full stack web developer, Mobile developer, cloud engineer and Musitian.