Python 未使用 TensorFlow 编译的 CPU 指令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42463594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CPU instructions not compiled with TensorFlow
提问by Fizics
MacBook Air: OSX El Capitan
MacBook Air:OSX El Capitan
When I run TensorFlow code in terminal (python 3 tfpractice.py
), I get a longer than normal waiting time to get back output followed by these error messages:
当我在终端 ( 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.
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.
I have no clue how to fix this. I would like to get TensorFlow to just work on this pip3 install. So I followed the path to: tensorflow/core/platform/cpu_feature_guard
我不知道如何解决这个问题。我想让 TensorFlow 只在这个 pip3 安装上工作。所以我遵循了以下路径:tensorflow/core/platform/cpu_feature_guard
Do I need to edit the code here? Or is there an alternate way to get TensorFlow to compile with these instructions?
我需要在这里编辑代码吗?或者是否有其他方法可以让 TensorFlow 使用这些指令进行编译?
I installed TensorFlow using sudo pip3 install tensorflow
.
我使用sudo pip3 install tensorflow
.
回答by Ujjwal
NOTE: These are not error messages but mere warning messages.
注意:这些不是错误消息,而只是警告消息。
The best way to maximise TF performance (apart from writing good code !!), is to compile it from the sources
最大化 TF 性能的最佳方法(除了编写好的代码!!),是从源代码编译它
When you do that, TF would ask you for a variety of options which will also involve options for these instructions.
当您这样做时,TF 会要求您提供各种选项,其中也将涉及这些说明的选项。
In my own experience, compilation from the source is better in performance on an average.
根据我自己的经验,从源代码编译的平均性能更好。
If you are doing some intensive processing that could be done on a GPU then that might also explain your waiting time.
For GPU support you would need to do pip3 install tensorflow-gpu
如果您正在进行一些可以在 GPU 上完成的密集处理,那么这也可能解释了您的等待时间。对于 GPU 支持,您需要执行以下操作pip3 install tensorflow-gpu
回答by Fizics
These are warning which mean it may be faster to build tensorflow on your pc from source.
这些是警告,这意味着从源代码在您的 PC 上构建 tensorflow 可能会更快。
However if you want to disable them, you may use the code below
但是如果你想禁用它们,你可以使用下面的代码
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
this should silence the warnings. 'TF_CPP_MIN_LOG_LEVEL' represents the Tensorflow environment variable responsible for logging. Also if you are on Ubuntu you may use this code below
这应该使警告静音。'TF_CPP_MIN_LOG_LEVEL' 代表负责日志记录的 Tensorflow 环境变量。此外,如果您使用的是 Ubuntu,则可以使用下面的代码
export TF_CPP_MIN_LOG_LEVEL=2
I hope this helps.
我希望这有帮助。
回答by Tai Christian
You can also compile using bazel with opt arguments:
您还可以使用带有 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
I think you can find something in this discussion: How to compile Tensorflow with SSE4.2 and AVX instructions?
我想你可以在这个讨论中找到一些东西:如何使用 SSE4.2 和 AVX 指令编译 Tensorflow?
Good luck!
祝你好运!
回答by Ajay Singh
Those are simply warnings. They are just informing you if you build TensorFlow from source it can be faster on your machine. Those instructions are not enabled by default on the builds available I think to be compatible with more CPUs as possible. If you have any other doubts regarding this please feel free to ask, otherwise this can be closed.
这些只是警告。他们只是告诉你,如果你从源代码构建 TensorFlow,它在你的机器上会更快。默认情况下,这些指令在可用的构建中不启用,我认为尽可能与更多的 CPU 兼容。如果您对此有任何其他疑问,请随时提问,否则可以关闭。
Try export TF_CPP_MIN_LOG_LEVEL=2
Try export TF_CPP_MIN_LOG_LEVEL=2