python - 您的 CPU 支持此 TensorFlow 二进制文件未编译为使用 : AVX AVX2 的指令

标签 python tensorflow cpu avx

我最近安装了tensorflow(Windows CPU版本)并收到以下消息:

Successfully installed tensorflow-1.4.0 tensorflow-tensorboard-0.4.0rc2

然后当我尝试运行时

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 找到的)

我收到以下消息:

2017-11-02 01:56:21.698935: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

但是当我运行的时候

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

它按预期运行并输出 Hello, TensorFlow!,这表明安装确实成功,但还有其他问题。

您知道问题是什么以及如何解决吗?

最佳答案

这个警告是关于什么的?

除了常见的算术和逻辑之外,现代 CPU 还提供许多低级指令,称为扩展,例如SSE2、SSE4、AVX 等来自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.

特别是,AVX 引入了 fused multiply-accumulate (FMA) 运算,可加速线性代数计算,即点积、矩阵乘法、卷积等。几乎每个机器学习训练都涉及大量这些运算,因此在支持 AVX 和 FMA 的 CPU 上速度会更快(高达 300%)。该警告表明您的 CPU 确实支持 AVX(万岁!)。

我想在此强调:这一切都与仅CPU有关。

为什么不使用它?

因为tensorflow默认发行版已构建without CPU extensions ,例如 SSE4.1、SSE4.2、AVX、AVX2、FMA 等。默认版本(来自 pip install tensorflow 的版本)旨在与尽可能多的 CPU 兼容。另一个论点是,即使有这些扩展,CPU 也比 GPU 慢很多,并且预计中大规模机器学习训练将在 GPU 上执行。

你应该做什么?

如果您有 GPU,则不必关心 AVX 支持,因为最昂贵的操作将在 GPU 设备上分派(dispatch)(除非明确设置为不这样做)。在这种情况下,您可以简单地忽略此警告

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

...或者如果您使用的是 Unix,则通过设置 export TF_CPP_MIN_LOG_LEVEL=2 。无论如何,Tensorflow 工作正常,但您不会看到这些烦人的警告。

<小时/>

如果您没有 GPU 并且希望尽可能多地利用 CPU,您应该从针对您的 CPU 优化的源代码构建 tensorflow 启用 AVX、AVX2 和 FMA(如果您的 CPU 支持)。 this question 中对此进行了讨论。还有this GitHub issue 。 Tensorflow 使用名为 bazel 的临时构建系统构建它并不是那么简单,但肯定是可行的。此后,不仅警告会消失,tensorflow 性能也会提高。

关于python - 您的 CPU 支持此 TensorFlow 二进制文件未编译为使用 : AVX AVX2 的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47068709/

相关文章:

python - joblib.Parallel() 比 skimage 的 single 慢

cpu - RAM提取16位或128位所需的时间相同吗?

Python 2.7 concurrent.futures.ThreadPoolExecutor 不并行化

python - 如何使用anaconda在window上安装tensorflow

python - 我可以使用数组作为索引对 numpy 数组进行切片吗?

tensorflow - .pb和.h5之间的区别

python - 列出语料库中通过卡方检验拒绝原假设的所有单词

python - tf.keras `predict()` 得到不同的结果

python - 如何拆分张量然后连接它?

assembly - 调用堆栈究竟是如何工作的?