TensorFlow未编译CPU指令

6

MacBook Air: OSX El Capitan

当我在终端中运行TensorFlow代码(python 3 tfpractice.py)时,我需要等待比正常更长的时间才能得到输出,接着会出现以下错误信息:

W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

我不知道该如何解决这个问题。我希望通过pip3安装让TensorFlow正常工作。所以我按照路径找到了:tensorflow/core/platform/cpu_feature_guard

我需要在这里编辑代码吗?还是有其他方法可以使TensorFlow编译使用这些指令?

我使用sudo pip3 install tensorflow安装了TensorFlow。


其他人讨论了这个问题:https://dev59.com/x1gR5IYBdhLWcg3wd9G5 - xxi
4个回答

9

注意:这些不是错误消息,而只是警告消息。

除了编写良好的代码之外,最大化TensorFlow性能的最佳方法是从代码进行编译。

在那时,TF会要求您提供各种选项,其中也涉及这些指令的选项。

根据我的经验,从源代码编译的平均性能更好。

如果您正在进行一些可在GPU上完成的密集处理,则可能会解释您的等待时间。 要使用GPU支持,您需要执行pip3 install tensorflow-gpu


谢谢。我会尝试您的建议并更新。 - Fizics

4

这些是警告,意味着在您的计算机上从源代码构建tensorflow可能更快。

然而,如果您想禁用它们,可以使用下面的代码。

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

这应该会消除警告。'TF_CPP_MIN_LOG_LEVEL'代表着Tensorflow环境变量的日志记录级别。如果你在Ubuntu上,你可以使用下面的代码:

export TF_CPP_MIN_LOG_LEVEL=2 

我希望这可以帮到你。

2

你也可以使用 bazel 编译,并使用优化参数:

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package

我认为你可以在这个讨论中找到有用的内容:如何使用SSE4.2和AVX指令编译Tensorflow?

祝好运!


我建议使用 bazel build -c opt --copt=-march=native //tensorflow/tools/pip_package:build_pip_package-march=native 将选择当前机器上支持的所有 CPU 功能。要查看 CPU 功能,请使用 gcc -march=native -Q --help=target | grep enabled - RedEyed

-3
这些只是警告。它们只是告诉您,如果您从源代码构建TensorFlow,则可以在您的计算机上更快。我认为这些指令在可用的构建版本中默认情况下未启用,以便与尽可能多的CPU兼容。
如果您对此有任何其他疑问,请随时提出,否则可以关闭。
尝试导出TF_CPP_MIN_LOG_LEVEL=2。

https://github.com/tensorflow/tensorflow/issues/7778


1
这并不会让它运行得更快,只是消除了警告。 - Peter Cordes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接