【问题标题】:CPU instructions not compiled with TensorFlow未使用 TensorFlow 编译的 CPU 指令
【发布时间】:2017-02-26 01:11:34
【问题描述】:

MacBook Air:OSX El Capitan

当我在终端 (python 3 tfpractice.py) 中运行 TensorFlow 代码时,我得到比正常情况更长的等待时间来取回输出,然后出现以下错误消息:

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.

我不知道如何解决这个问题。我想让 TensorFlow 只在这个 pip3 安装上工作。于是我就跟着路径去了:tensorflow/core/platform/cpu_feature_guard

我需要在这里编辑代码吗?或者是否有其他方法可以让 TensorFlow 使用这些指令进行编译?

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

【问题讨论】:

标签: python machine-learning terminal tensorflow cpu


【解决方案1】:

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

最大化 TF 性能的最佳方法(除了编写好的代码!!)是从 sources 编译它

当您这样做时,TF 会要求您提供各种选项,其中还涉及这些说明的选项。

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

如果您正在进行一些可以在 GPU 上完成的密集处理,那么这也可以解释您的等待时间。 对于 GPU 支持,您需要执行 pip3 install tensorflow-gpu

【讨论】:

  • 谢谢。我会尝试您的建议并提供更新
【解决方案2】:

这些是警告,这意味着在您的电脑上从源代码构建 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 

我希望这会有所帮助。

【讨论】:

    【解决方案3】:

    您也可以使用带有 opt 参数的 bazel 进行编译:

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

    我想你可以在这个讨论中找到一些东西:How to compile Tensorflow with SSE4.2 and AVX instructions?

    祝你好运!

    【讨论】:

    • 我建议使用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
    【解决方案4】:

    这些只是警告。他们只是告诉你,如果你从源代码构建 TensorFlow,它可以在你的机器上更快。这些指令在我认为尽可能与更多 CPU 兼容的可用版本上默认不启用。 如果您对此有任何其他疑问,请随时询问,否则可以关闭。

    Try export TF_CPP_MIN_LOG_LEVEL=2

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

    【讨论】:

    • 这不会让它运行得更快,它只会让警告静音。
    猜你喜欢
    • 1970-01-01
    • 2017-08-25
    • 2018-04-14
    • 2018-12-28
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    相关资源
    最近更新 更多