Your CPU Supports Instructions That This Tensorflow Binary Was Not Compiled to Use: Avx Avx2

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

What is this warning about?

Modern CPUs provide a lot of low-level instructions, besides the usual arithmetic and logic, known as extensions, e.g. SSE2, SSE4, AVX, etc. From the Wikipedia:

Advanced Vector Extensions (AVX) are extensions to the x86 instruction
set architecture for microprocessors from Intel and AMD proposed by
Intel in March 2008 and first supported by Intel with the Sandy
Bridge processor shipping in Q1 2011 and later on by AMD with the
Bulldozer processor shipping in Q3 2011. AVX provides new features,
new instructions and a new coding scheme.

In particular, AVX introduces fused multiply-accumulate (FMA) operations, which speed up linear algebra computation, namely dot-product, matrix multiply, convolution, etc. Almost every machine-learning training involves a great deal of these operations, hence will be faster on a CPU that supports AVX and FMA (up to 300%). The warning states that your CPU does support AVX (hooray!).

I'd like to stress here: it's all about CPU only.

Why isn't it used then?

Because tensorflow default distribution is built without CPU extensions, such as SSE4.1, SSE4.2, AVX, AVX2, FMA, etc. The default builds (ones from pip install tensorflow) are intended to be compatible with as many CPUs as possible. Another argument is that even with these extensions CPU is a lot slower than a GPU, and it's expected for medium- and large-scale machine-learning training to be performed on a GPU.

What should you do?

If you have a GPU, you shouldn't care about AVX support, because most expensive ops will be dispatched on a GPU device (unless explicitly set not to). In this case, you can simply ignore this warning by

# Just disables the warning, doesn't take advantage of AVX/FMA to run faster
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

... or by setting export TF_CPP_MIN_LOG_LEVEL=2 if you're on Unix. Tensorflow is working fine anyway, but you won't see these annoying warnings.


If you don't have a GPU and want to utilize CPU as much as possible, you should build tensorflow from the source optimized for your CPU with AVX, AVX2, and FMA enabled if your CPU supports them. It's been discussed in this question and also this GitHub issue. Tensorflow uses an ad-hoc build system called bazel and building it is not that trivial, but is certainly doable. After this, not only will the warning disappear, tensorflow performance should also improve.

Java: Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

It is because you are using TensorFlow pre-built libraries, which were built on AVX CPU. But now your CPU supports AVX2 so you get this warning.

You can build TensorFlow from source on your PC, by selecting AVX2 while configuring.

Note: it is just a warning, you can ignore it.

Issue Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

If when forcing the os.environ["CUDA_VISIBLE_DEVICES"]="0" doesn't work, then this means that your tensorflow gpu installation did not succeed. You must ensure you have the right combination of TensorFlow + CUDA + CUDNN. That is why you get the error, because due to improper versions/installation TF falls back on CPU.

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 error

I have also been wondering what this warning means. After making a quick tour, here is what i ve found:
Adveance Vector Extensions are the instructions that extends integer operations to floating points numbers.
Eg: FUSE MULTIPLY ADD.

citing from the above source
"A fused multiply–add (sometimes known as FMA or fmadd) is a floating-point multiply–add operation performed in one step, with a single rounding.
That is, where an unfused multiply–add would compute the product b×c, round it to N significant bits, add the result to a, and round back to N significant bits, a fused multiply–add would compute the entire expression a+b×c to its full precision before rounding the final result down to N significant bits."

if AVX is not enabled in your compiler, the operation a+bxc would be done sequential steps wheras avx instructions executes it into one operation unit.

It seems by default, the build flags of tensorflow, doesn't include the support for AVX instructions as the configuration section states in on install from source page.

To be able to suppress this warning, you have to build tensorflow from source and on the configuration part, use additional these additional flags

bazel build -c opt --copt=-mavx --copt=-mavx2

I suspect that these flags are omitted by default because not all cpus supports these instructions.

For more details, see this answer and this github issue.

EDIT

Here is an exaustive list of of build you can use depending on which warnings you are getting, including this one.

TensorFlow binary was not compiled

If you have a GPU, you should not care about it. You can ignore the warning using this

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf

If you want more information about it, you can read:

  • A similar post: Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
  • A similar issue on github: https://github.com/tensorflow/tensorflow/issues/7778


Related Topics



Leave a reply



Submit