这个tensorflow消息是什么意思?有副作用吗?安装成功吗



我刚刚在anaconda python上安装了tensorflow v2.3。我尝试使用下面的python命令来测试安装;

$ python -c "import tensorflow as tf; x = [[2.]]; print('tensorflow version', tf.__version__); print('hello, {}'.format(tf.matmul(x, x)))"

我收到以下信息;

2020-12-15 07:59:12.411952: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
hello, [[4.]]

从消息中可以看出,安装似乎已成功安装。但是This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX AVX2到底是什么意思呢?

我使用的是功能有限的tensorflow版本吗?有副作用吗?

我正在使用Windows 10。

Tensorflow的一个重要部分是它应该很快。通过适当的安装,它可以与CPU、GPU或TPU配合使用。快速的一部分意味着它根据您的硬件使用不同的代码。有些CPU支持其他CPU不支持的操作,例如矢量化加法(一次添加多个变量(。Tensorflow只是告诉你,你安装的版本可以使用AVX和AVX2操作,并且在某些情况下默认设置为这样做(比如在前向或后向道具矩阵乘法中(,这可以加快速度。这不是一个错误,它只是告诉你,它可以而且将利用你的CPU来获得额外的速度。

注:AVX代表高级矢量扩展。

消息

This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)
to use the following CPU instructions in performance-critical operations:  AVX AVX2

意味着在性能重要的地方(例如深度神经网络中的矩阵乘法(,将使用某些优化的编译器指令。安装似乎很成功。

oneDNN GitHub存储库显示:

oneAPI深度神经网络库(oneDNN(是一个用于深度学习应用程序的基础构建块的开源跨平台性能库。该库针对英特尔体系结构处理器、英特尔处理器图形和基于Xe体系结构的图形进行了优化。oneDNN在实验上支持以下架构:

  • Arm*64位体系结构(AArch64(
  • NVIDIA*GPU
  • OpenPOWER*电源ISA(PPC64(
  • IBMz*(s390x(

我已经编译了几次Tensorflow库,如果您得到了以下内容:

kosinkie_l@Fedora ~/project/build $ python -c "import tensorflow as tf; x = [[2.]]; print('tensorflow version', tf.__version__); print('hello, {}'.format(tf.matmul(x, x)))"
2022-08-09 15:31:03.414926: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tensorflow version 2.10.0-rc0
hello, Tensor("MatMul:0", shape=(1, 1), dtype=float32)
kosinkie_l@Fedora ~/project/build $

这意味着cpu可以使用,但Tensorflow库不使用这些

这些消息可能会混淆——所以我选择了源代码(tensorflow/core/platform/cpu_feature_guard.cc:193(,其中有以下内容:

131 #ifndef __AVX__
132     CheckIfFeatureUnused(CPUFeature::AVX, "AVX", missing_instructions);
133 #endif  // __AVX__
134 #ifndef __AVX2__
135     CheckIfFeatureUnused(CPUFeature::AVX2, "AVX2", missing_instructions);
136 #endif  // __AVX2__
...
192     if (!missing_instructions.empty()) {
193       LOG(INFO) << "This TensorFlow binary is optimized with "
194                 << "oneAPI Deep Neural Network Library (oneDNN) "
195                 << "to use the following CPU instructions in performance-"
196                 << "critical operations: " << missing_instructions << std::endl
197                 << "To enable them in other operations, rebuild TensorFlow "
198                 << "with the appropriate compiler flags.";
199     }

方法";CheckIfFeatureUnused(CPUFeature::AVX,"AVX",missing_instructions(;检查CPU是否可以执行AVX;AVX";到missinginstructions集合,打印出什么。

您必须创建新的环境,或者尝试在当前基本环境的gpu中安装tensorflow,为此请使用以下命令。。。

创建新环境:

conda create --name py36 python==3.6.13 or any latest version

在CPU:中安装tensorflow

conda install tensorflow
conda install keras

在GPU:中安装tensorflow

conda install tensorflow-gpu
conda install tensorflow-estimator==2.1.0 or any latest version

我希望它能帮助你,谢谢。。。

当您使用预构建的TensorFlow二进制文件时,通常会出现此消息,该二进制文件不支持AVX2和FMA CPU指令,这会显著加快某些操作。为了利用这些指令,您需要使用适当的编译器标志从源代码构建TensorFlow。

要解决此问题,您可以按照以下步骤操作:

  1. 安装必要的软件依赖项,如Python,TensorFlow的构建依赖项,以及一个C++编译器。

  2. 从官方存储库下载TensorFlow源代码。

  3. 使用适当的标志配置构建,以启用对AVX2和FMA指令的支持。你可以通过--config=的opt标志/配置脚本。

  4. 通过运行bazelbuild //tensorflow/tools/pip_package:build_pip_package命令从源代码构建TensorFlow。

  5. 最后,通过运行安装新建的TensorFlow pip包pip install /path/to/tensorflow_pkg.whl

完成这些步骤后,您应该有一个针对CPU进行优化的TensorFlow版本,该版本包括对AVX2和FMA指令的支持。

您可以使用以下命令禁用这些消息:

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

来源:https://stackoverflow.com/a/42121886

当我使用"verbose=0">在Model.fit((中发生然后我删除它,它解决了

我执行了以下命令,在CPUGPU上安装keras和tensorflow:

conda create --name py36 python==3.6.13
conda install tensorflow
conda install keras
conda install tensorflow-gpu
conda install tensorflow-estimator==2.1.0

最新更新