您的CPU支持该TensorFlow二进制文件未编译为使用的指令

您的CPU支持该TensorFlow二进制文件未编译为使用的指令

本文介绍了您的CPU支持该TensorFlow二进制文件未编译为使用的指令:AVX AVX2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是TensorFlow的新手.我最近安装了它(Windows CPU版本),并收到以下消息:

I am new to TensorFlow. I have recently installed it (Windows CPU version) and received the following message:

然后当我尝试跑步时

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
sess.run(hello)
'Hello, TensorFlow!'
a = tf.constant(10)
b = tf.constant(32)
sess.run(a + b)
42
sess.close()

(我通过 https://github.com/tensorflow/tensorflow 找到)

我收到以下消息:

但是当我跑步

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

它按预期运行,并输出Hello, TensorFlow!,这表明安装确实成功,但是还有其他错误.

it ran as it should and output Hello, TensorFlow!, which indicates that the installation was successful indeed but there is something else that is wrong.

您知道问题出在哪里以及如何解决吗?

Do you know what the problem is and how to fix it?

推荐答案

此警告是关于什么的?

现代CPU除了提供通常的算术和逻辑功能外,还提供了许多低级指令,这些功能称为扩展,例如SSE2,SSE4,AVX等.摘自维基百科:

尤其是,AVX引入了融合乘法累加(FMA)操作,可加快线性代数的计算速度,即点积,矩阵乘法,卷积等.几乎每个机器学习训练都涉及大量这些操作,因此在具有以下功能的CPU上速度会更快支持AVX和FMA(最高300%).该警告表明您的CPU确实支持AVX(万岁!).

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!).

我想在这里强调一下:这仅涉及 CPU .

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

因为构建了tensorflow默认分发没有CPU扩展,例如SSE4.1, SSE4.2,AVX,AVX2,FMA等.默认版本(pip install tensorflow中的版本)旨在与尽可能多的CPU兼容.另一个论点是,即使有了这些扩展,CPU仍然比GPU慢很多,并且期望在GPU上进行中型和大型的机器学习培训.

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.

如果您有GPU ,则不必在乎AVX的支持,因为大多数昂贵的操作都将在GPU设备上分发(除非明确设置为不这样做).在这种情况下,您可以通过以下方式简单地忽略此警告:

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 enable AVX/FMA
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

...或通过设置export TF_CPP_MIN_LOG_LEVEL=2(如果您使用的是Unix).无论如何,Tensorflow都运行良好,但是您不会看到这些烦人的警告.

... 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.

如果您没有GPU ,并且想尽可能多地利用CPU,则您应该从针对您的 CPU优化的源构建tensorflow./strong>,并且启用了AVX,AVX2和FMA(如果您的CPU支持).在此问题此GitHub问题. Tensorflow使用一个名为 bazel 的临时构建系统,构建它并不是那么简单,但是肯定是可行的.此后,不仅警告会消失,而且tensorflow性能也将得到改善.

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.

这篇关于您的CPU支持该TensorFlow二进制文件未编译为使用的指令:AVX AVX2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:11