It’s a common problem which people get when they are installing Tensorflow using pip3.
sudo pip3 install tensorflow
After running the command, I have received the following warning message:
I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Advanced Vector Extensions (AVX) are the extension to the x86 instruction set architecture for microprocessors which are from Intel and AMD proposed by Intel in March 2008 and intel first support with the Sandy Bridge processor shipping in Q1 2011 and after on by AMD with the Bulldozer processor shipping in Q3 2011. AVX provides us with new features, new instructions, and a new coding scheme.
AVX introduces fused multiply-accumulate (FMA) operations to speed up linear algebra computation, namely dot-product, matrix multiply, convolution, etc. We can say Almost every machine-learning training involves a great deal of these operations, however, it will be faster on a CPU that supports AVX and FMA (up to 300%).
We won’t ignore the message which we got while installing Tensorflow. Firstly, we will start with uninstalling the default version of Tensorflow.
sudo pip3 uninstall protobuf
sudo pip3 uninstall tensorflow
In a temp folder, clone Tensorflow:
git clone https://github.com/tensorflow/tensorflow
git checkout r2.0
Now Install the TensorFlow pip package dependencies:
pip3 install -U --user pip six numpy wheel setuptools mock future>=0.17.1
pip3 install -U --user keras_applications==1.0.6 --no-deps
pip3 install -U --user keras_preprocessing==1.0.5 --no-deps
We need to Install Bazel, the build tool which is used to compile TensorFlow. In my case, after downloading bazel-0.26.0-installer-darwin-x86_64.sh:
chmod +x bazel-0.26.0-installer-darwin-x86_64.sh ./bazel-0.26.0-installer-darwin-x86_64.sh --user export PATH="$PATH:$HOME/bin" bazel version
Now Configure your system build by running the following at the root of your TensorFlow source tree:
Well, The Tensorflow build options expose flags to enable building for platform-specific CPU instruction sets:
|All supported by processor||–copt=-march=native|
We need to Use
bazel to make the TensorFlow package builder with CPU-only support:
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package
The command of
bazel build creates an executable named
build_pip_package —this is the program that builds the pip package. Then run the executable as shown below to build
a .whl package in the
Want to build from a release branch:
The Output wheel file is in:
If you want to install it directly, then you can download the file from here.
pip3 install /tmp/tensorflow_pkg/tensorflow-2.0.0b1-cp37-cp37m-macosx_10_14_x86_64.whl
We need to cd out of that directory, and now running should not produce any warning:
python3 -c "import tensorflow as