如何用编译器标志重建tensorflow ?



我试图用tensorflow后端运行二进制分类,但我一直收到一个错误,我相信这要求我用正确的编译器标志重建tensorflow。我知道我的代码和数据是功能性的,所以我认为问题在于虚拟环境。我试着在tensorflow的网站、ibm的网站和堆栈溢出上找到解决方案,但我没有成功。我也试过重新安装tensorflow和python。

完整回溯:

I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set

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: AVX2 FMA

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

Virtual Environment Info:

-使用蟒蛇环境

python 3.7.9

-tensorflow 2.4.1

我隐藏了这些警告:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

注意,这不会重建TensorFlow,而只是隐藏警告。

你的CPU支持指令,这个TensorFlow二进制文件没有编译使用:AVX AVX2

要用编译器标志重新构建TensorFlow,您需要遵循以下步骤:

  1. Install required dependencies你需要安装必要的软件和库来构建TensorFlow。这包括一个Python环境、Bazel构建系统和Visual Studio构建工具。

  2. 克隆TensorFlow存储库:将TensorFlow存储库从GitHub克隆到本地机器上。这将使您能够访问TensorFlow的源代码。

  3. 配置构建:导航到您在第2步中克隆的TensorFlow存储库,并运行configure.py脚本来配置构建。您可以在配置过程中使用--copt标志来指定编译器标志。

  4. 构建TensorFlow:使用Bazel构建系统构建TensorFlow。您可以使用bazel build命令来构建TensorFlow库及其依赖项。

以下是我在Windows 10机器上使用编译器标志构建TensorFlow的方法:

# Clone the TensorFlow repository
git clone https://github.com/tensorflow/tensorflow.git

# Navigate to the TensorFlow repository
cd tensorflow

# Configure the build
python configure.py --copt=-march=native

# Build TensorFlow
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

最新更新