Search code examples
pythontensorflowanacondaconda

Compile TensorFlow while installing by Conda


Error due to AVX

I have run into this error when importing TensorFlow by a simple Python statement:

>>> import tensorflow as tf
Illegal instruction (core dumped)

The lscpu command confirms that CPU lacks AVX instruction set. It looks like the error is due to my CPU not supporting the AVX instructions:

https://github.com/tensorflow/tensorflow/issues/62342#issuecomment-1801151769

Option 1

Compile TensorFlow

I'm using conda. How can I force conda to compile TensorFlow while installing it? Only TensorFlow needs to be compiled, not others.

This is my environment.yml file:

name: deep3d_pytorch
channels:
  - pytorch
  - conda-forge
  - defaults
dependencies:
  - python
  - pytorch
  - torchvision
  - numpy
  - scikit-image
  - scipy
  - pillow
  - pip
  - ipython
  - yaml
  - pip:
    - matplotlib
    - opencv-python
    - tensorboard
    - tensorflow
    - kornia
    - dominate
    - trimesh

Option 2

Install older TensorFlow

The other option might be forcing conda to install the latest TensorFlow version that doesn't require AVX. I wonder how I can force conda to do that.

Option 3

Get a virtual machine with proper CPU

I have contacted the virtual server provider to give me a CPU with AVX capability. Since they are creating and selling virtual machines, so maybe it's easy for them to just create another virtual CPU with AVX support. I'm not sure. Let's see.

Option 4

Wheel

The other option is to find a precompiled wheel of the TensorFlow which is compiled without AVX requirement.

Are there any other options?


Solution

  • Once I compiled tensorflow from source code (using 10 years old notebook without AVX)
    and it took me ~7.8 hours - so it can be long task. furas/tensorflow-no-avx


    There is place where people put precompiled whl for different systems, pythons, CPUs, GPUs

    yaroslavvb/tensorflow-community-wheels

    and sometimes it can be the fastest method.

    You may also ask (make Request) for some special version and maybe someone will compile it for it.