120

I just installed tensorflow v2.3 on anaconda python. I tried to test out the installation using the python command below;

$ python -c "import tensorflow as tf; x = [[2.]]; print('tensorflow version', tf.__version__); print('hello, {}'.format(tf.matmul(x, x)))"

I got the following message;

2020-12-15 07:59:12.411952: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
hello, [[4.]]

From the message, it seems that the installation was installed successfully. But what does This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX AVX2 mean exactly?

Am I using a tensorflow version with some limited features? Any side effects?

I am using Windows 10.

user1315789
  • 3,069
  • 6
  • 18
  • 41

8 Answers8

240

An important part of Tensorflow is that it is supposed to be fast. With a suitable installation, it works with CPUs, GPUs, or TPUs. Part of going fast means that it uses different code depending on your hardware. Some CPUs support operations that other CPUs do not, such as vectorized addition (adding multiple variables at once). Tensorflow is simply telling you that the version you have installed can use the AVX and AVX2 operations and is set to do so by default in certain situations (say inside a forward or back-prop matrix multiply), which can speed things up. This is not an error, it is just telling you that it can and will take advantage of your CPU to get that extra speed out.

Note: AVX stands for Advanced Vector Extensions.

mCoding
  • 4,059
  • 1
  • 5
  • 11
  • 24
    Thanks. Sounds like this is a good thing. Not a warning to be worried about. Actually, if it is a good thing, there is no need to output a message to inform users. Some of us can get worried. – user3848207 Dec 17 '20 at 00:36
  • 7
    Yes, I had this exact complaint when I first tried as well. No news is good news in my world. – mCoding Dec 21 '20 at 19:20
  • 9
    Is there a way to hid this message without hiding potential errors in the rest of the code? – TheQuantumMan Feb 26 '21 at 10:25
  • 11
    @TheQuantumMan `import os; os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'` see: https://stackoverflow.com/a/42121886/2547724 – Riebeckite Feb 24 '22 at 21:56
  • 7
    Just to be sure, is it already optimized? Or do I need to actively enable it somehow? – Andre Goulart Mar 04 '22 at 01:40
  • 2
    This meat that your Tensorflow library is made without these printed flags and should be recompiled with these flags to take full speed of the Tensorflow library. – Leszek Kosinkiewicz Aug 09 '22 at 13:59
  • I am getting the same message in Nodejs. Is it possible to hide the message in NodeJS ? I tried tf.env().set('PROD', true); but to no avail. – S M Sep 06 '22 at 12:28
17

The message

This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)
to use the following CPU instructions in performance-critical operations:  AVX AVX2

means that in places where performance matters (eg matrix multiplication in deep neural networks), certain optimized compiler instructions will be used. Installation seems to be successful.

The oneDNN GitHub repository says:

oneAPI Deep Neural Network Library (oneDNN) is an open-source cross-platform performance library of basic building blocks for deep learning applications. The library is optimized for Intel Architecture Processors, Intel Processor Graphics and Xe architecture-based Graphics. oneDNN has experimental support for the following architectures:

  • Arm* 64-bit Architecture (AArch64)
  • NVIDIA* GPU
  • OpenPOWER* Power ISA (PPC64)
  • IBMz* (s390x)
jkr
  • 17,119
  • 2
  • 42
  • 68
6

I have compiled the Tensorflow library a few times and if you have got something like the following:

kosinkie_l@Fedora ~/project/build $ python -c "import tensorflow as tf; x = [[2.]]; print('tensorflow version', tf.__version__); print('hello, {}'.format(tf.matmul(x, x)))"

2022-08-09 15:31:03.414926: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tensorflow version 2.10.0-rc0
hello, Tensor("MatMul:0", shape=(1, 1), dtype=float32)
kosinkie_l@Fedora ~/project/build $

this meant that the cpu can use, but Tensorflow library does not used these.

The messages might be confused - so I have picked to source code (tensorflow/core/platform/cpu_feature_guard.cc:193) and there are the following:

131 #ifndef __AVX__
132     CheckIfFeatureUnused(CPUFeature::AVX, "AVX", missing_instructions);
133 #endif  // __AVX__
134 #ifndef __AVX2__
135     CheckIfFeatureUnused(CPUFeature::AVX2, "AVX2", missing_instructions);
136 #endif  // __AVX2__
...
192     if (!missing_instructions.empty()) {
193       LOG(INFO) << "This TensorFlow binary is optimized with "
194                 << "oneAPI Deep Neural Network Library (oneDNN) "
195                 << "to use the following CPU instructions in performance-"
196                 << "critical operations: " << missing_instructions << std::endl
197                 << "To enable them in other operations, rebuild TensorFlow "
198                 << "with the appropriate compiler flags.";
199     }

The method "CheckIfFeatureUnused(CPUFeature::AVX, "AVX", missing_instructions)" checks if the CPU can execute AVX and puts the "AVX" to missing_instructions collection, what is printed out.

  • Thanks for your useful answer. You went deeper in the code I'm scared to go to. I got the same message but I use an Nvidia GPU. Does this message indicate that Tensorflow might not be doing its best with my GPU by using these CPU instructions? – Maurício Collaça Jan 17 '23 at 19:09
4

This message typically appears when you are using a pre-built TensorFlow binary that does not include support for the AVX2 and FMA CPU instructions, which can significantly accelerate certain operations. To take advantage of these instructions, you need to build TensorFlow from source with the appropriate compiler flags.

To fix this issue, you can follow these steps:

  1. Install the necessary software dependencies, such as Python, TensorFlow's build dependencies, and a C++ compiler.

  2. Download the TensorFlow source code from the official repository.

  3. Configure the build with the appropriate flags to enable support for AVX2 and FMA instructions. You can do this by passing the --config=opt flag to the ./configure script.

  4. Build TensorFlow from source by running the bazel build //tensorflow/tools/pip_package:build_pip_package command.

  5. Finally, install the newly-built TensorFlow pip package by running pip install /path/to/tensorflow_pkg.whl.

After completing these steps, you should have a version of TensorFlow that is optimized for your CPU and includes support for AVX2 and FMA instructions.

3

You have to create new environment or else try to install tensorflow in gpu on currrent base environment, for that use following commands...

creating new environment:

conda create --name py36 python==3.6.13 or any latest version

installing tensorflow in CPU:

conda install tensorflow
conda install keras

installing tensorflow in GPU:

conda install tensorflow-gpu
conda install tensorflow-estimator==2.1.0 or any latest version

I Hope it will help you, Thank You...

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
2

You can disable these messages using:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' 

import tensorflow as tf

Source: https://stackoverflow.com/a/42121886

Freeman
  • 5,810
  • 3
  • 47
  • 48
-2

when I used "verbose=0" in Model.fit() it occurred then I remove that and it solved

  • 3
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 14 '22 at 21:52
-12

I did below commands to install keras and tensorflow on CPU and GPU:

conda create --name py36 python==3.6.13
conda install tensorflow
conda install keras
conda install tensorflow-gpu
conda install tensorflow-estimator==2.1.0
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Reza
  • 9
  • 2