在 PyCharm 的虚拟环境中更新 Tensorflow 二进制文件以使用 AVX2

Sta*_*ian 5 python pycharm avx2 tensorflow

我的问题与此处有关,但我使用的是 PyCharm,并根据本指南第 5 页使用 Python 解释器设置了我的虚拟环境。

当我运行我的 tensorflow 代码时,我收到警告:

您的 CPU 支持此 TensorFlow 二进制文件未编译使用的指令:AVX2

我可以忽略它,但由于我的模型拟合很慢,我想利用它。但是,我不知道如何在此虚拟环境 PyCharm 设置中更新我的系统以使用 AVX2?

Cha*_* Gm 2

Anaconda/conda 作为包管理工具:

假设您已在计算机上安装了 anaconda/conda,如果未安装,请按照此操作 - https://docs.anaconda.com/anaconda/install/windows/

conda create --name tensorflow_optimized python=3.7
conda activate tensorflow_optimized

# you need intel's tensorflow version that's optimized to use SSE4.1 SSE4.2 AVX AVX2 FMA
conda install tensorflow-mkl -c anaconda

#run this to check if the installed version is using MKL, 
#which in turns uses all the optimizations that your system provide. 
python -c "import tensorflow as tf; tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)"

# you should see something like this as the output.
2020-07-14 19:19:43.059486: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations:  SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
Run Code Online (Sandbox Code Playgroud)

pip3 作为包管理工具:

py -m venv tensorflow_optimized
.\tensorflow_optimized\Scripts\activate

#once the env is activated, you need intel's tensorflow version 
#that's optimized to use SSE4.1 SSE4.2 AVX AVX2 FMA
pip install intel-tensorflow

#run this to check if the installed version is using MKL, 
#which in turns uses all the optimizations that your system provide. 
py -c "import tensorflow as tf; tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)"

# you should see something like this as the output.
2020-07-14 19:19:43.059486: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations:  SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
Run Code Online (Sandbox Code Playgroud)

一旦你有了这个,你就可以在 pycharm 中设置使用这个环境。

where python在此之前,在 Windows、Linux 和 Mac 上运行 which python,当环境被激活时,应该会为您提供解释器的路径。在 Pycharm 中,转到首选项 -> 项目:您的项目名称 -> 项目解释器 -> 单击设置符号 -> 单击添加。

在此输入图像描述

选择系统解释器 -> 单击 ... -> 这将打开一个弹出窗口,询问 python 解释器的位置。

在此输入图像描述

在位置路径中,粘贴路径where python-> 单击确定 在此输入图像描述

现在您应该看到该环境中安装的所有软件包。 在此输入图像描述

从下次开始,如果您想为您的项目选择该解释器,请单击右下半部分显示 python3/python2(您的解释器名称)的位置,然后选择您需要的解释器。

在此输入图像描述

我建议你安装 Anaconda 作为你的默认包管理器,因为它使你在 Windows 机器上使用 python 的开发生活更轻松,但你也可以使用 pip。