更新时间:2022-09-21 21:29:39
英特尔:Elmoustapha Ould-Ahmed-Vall,Mahmoud Abuzaina,Md Faijul Amin,Jayaram Bobba,Roman S Dubtsov,Evarist M Fomenko,Mukesh Gangadhar,Niranjan Hasabnis,Jing Huang,Deepthi Karkada,Young Jin Kim,Srihari Makineni,Dmitri Mishura,Karthik Raman,AG Ramesh,Vivek V Rane,Michael Riera,Dmitry Sergeev,Vamsi Sripathi,Bhavani Subramanian,Lakshay Tokas,Antonio C Valles
谷歌:Andy Davis,Toby Boyd,Megan Kacholia,Rasmus Larsen,Rajat Monga,Thiru Palanisamy,Vijay Vasudevan,Yao Zhang
作为一款领先的深度学习和机器学习框架,TensorFlow* 对英特尔和谷歌发挥英特尔硬件产品的***性能至关重要。本文 向人工智能 (AI) 社区介绍了在基于英特尔® 至强和英特尔® 至强融核™ 处理器的平台上实施的 TensorFlow* 优化。在去年举办的首届英特尔人工智能日上,英特尔公司的柏安娜和谷歌的 Diane Green 共同宣布了双方的合作,这些优化是英特尔和谷歌工程师密切合作取得的成果。
我们介绍了在优化实践中遇到的各种性能挑战以及采用的解决方法,还报告了对通用神经网络模型示例的性能改进。这些优化带来了多个数量级的性能提升。例如,根据我们的测量,英特尔® 至强融核™ 处理器 7250 (KNL) 上的训练性能提升了高达 70 倍,推断性能提升了高达 85 倍。基于英特尔® 至强® 处理器 E5 v4 (BDW) 和英特尔至强融核处理器 7250 的平台为下一代英特尔产品奠定了基础。用户尤其希望今年晚些时候推出的英特尔至强(代号为 Skylake)和英特尔至强融合(代号为 Knights Mill)处理器将提供显著的性能提升。
在现代 CPU 上优化深度学习模型的性能面临众多挑战,和优化高性能计算 (HPC) 中其他性能敏感型应用所面临的挑战差别不大:
为了满足这些要求,英特尔开发了众多优化型深度学习基元,计划应用于不同的深度学习框架,以确保通用构建模块的高效实施。除了矩阵乘法和卷积以外,创建模块还包括:
请参阅 本文,获取关于面向深度神经网络的英特尔® 数学核心函数(英特尔® MKL-DNN)的优化基元的更多详情。
在 TensorFlow 中,我们实施了英特尔优化版运算,以确保这些运算能在任何情况下利用英特尔 MKL-DNN 基元。同时,这也是支持英特尔® 架构可扩展性能的必要步骤,我们还需要实施大量其他优化。特别是,因为性能原因,英特尔 MKL 使用了不同于 TensorFlow 默认布局的另一种布局。我们需要最大限度地降低两种格式的转换开销。我们还想确保数据科学家和其他 TensorFlow 用户不需要改变现有的神经网络模型,便可使用这些优化。
我们推出了大量图形优化通道,以:
这些图形优化进一步提升了性能,没有为 TensorFlow 编程人员带来任何额外负担。数据布局优化是一项关键的性能优化。对于 CPU 上的某些张量运算而言,本地 TensorFlow 数据格式通常不是最高效的数据布局。在这种情况下,将来自 TensorFlow 本地格式的数据布局转换运算插入内部格式,在 CPU 上执行运算,并将运算输出转换回 TensorFlow 格式。但是,这些转换造成了性能开销,应尽力降低这些开销。我们的数据布局优化发现了能利用英特尔 MKL 优化运算完全执行的子图,并消除了子图运算中的转换。自动插入的转换节点在子图边界执行数据布局转换。融合通道是另一个关键优化,它将多个运算自动融合为高效运行的单个英特尔 MKL 运算。
我们还调整众多 TensorFlow 框架组件,以确保在各种深度学习模型上实现最高的 CPU 性能。 我们使用 TensorFlow 中现成的池分配器开发了一款自定义池分配器。 我们的自定义池分配器确保了 TensorFlow 和英特尔 MKL 共享相同的内存池(使用英特尔 MKL imalloc 功能),不必过早地将内存返回至操作系统,因此避免了昂贵的页面缺失和页面清除。 此外,我们还认真优化了多个线程库(TensorFlow 使用的 pthread 和英特尔 MKL 使用的 OpenMP),使它们能共存,而不是互相争夺 CPU 资源。
我们的优化(如上述优化)在英特尔至强和英特尔至强融核平台上实现了显著的性能提升。 为了更好地展示性能改进,我们提供了以下***方法(或 BKM)和 3 个通用 ConvNet 性能指标评测的基准和优化性能值。
按照“现已推出英特尔优化型 TensorFlow 系统” 中的指令安装包含 pip 或 conda 的预构建二进制软件包,或按照以下指令从源构建:
优化 TensorFlow 意味着高度可用、广泛应用的框架创建的深度学习应用现在能更快速地运行于英特尔处理器,以扩大灵活性、可访问性和规模。 例如,英特尔至强融核处理器能以近乎线性的方式跨内核和节点横向扩展,可显著减少训练机器学习模型的时间。 我们不断增强英特尔处理器的性能,以处理更大、更困难的人工智能工作负载,TensorFlow 也能随着性能的进步而升级。
英特尔和谷歌共同优化 TensorFlow 的合作体现了双方面向开发人员和数据科学家普及人工智能的不懈努力,力求在从边缘到云的所有设备上随时运行人工智能应用。 英特尔相信这是创建下一代人工智能算法和模型的关键,有助于解决最紧迫的业务、科学、工程、医学和社会问题。
本次合作已经在基于英特尔至强和英特尔至强融核处理器的领先平台上实现了显著的性能提升。 这些优化现已在谷歌的 TensorFlow GitHub 存储库中推出。 我们建议人工智能社区尝试这些优化,并期待获得基于优化的反馈与贡献。
转自:https://software.intel.com/zh-cn/articles/intel-optimized-tensorflow-wheel-now-available#
Intel's Tensorflow optimizations are now available for Linux as a wheel installable through pip.
For more information on the optimizations as well as performance data, see this blog post.
To install the wheel into an existing Python installation, simply run
# Python 2.7 |
pip install https://anaconda.org/intel/tensorflow/1.4.0/download/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl
|
# Python 3.5 |
pip install https://anaconda.org/intel/tensorflow/1.3.0/download/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl
|
# Python 3.6 |
Edit 10/12/17: Wheel paths have been updated to 1.3.0
Edit 11/22/17: Wheel paths have been updated to 1.4.0
To create a conda environment with Intel Tensorflow that also takes advantage of the Intel Distribution for Python’s optimized numpy, run
conda create -n tf -c intel python=<2|3> pip numpy |
. activate tf |
# Python 3.6 |
pip install https://anaconda.org/intel/tensorflow/1.4.0/download/tensorflow-1.4.0-cp36-cp36m-linux_x86_64.whl
|
# Python 2.7 |
A conda package of Intel's optimized Tensorflow comes with the new 2018 Intel Python distribution on Linux. You can also create a conda environment with Intel Optimized Tensorflow with the following commands:
conda create -n intel_tf -c intel --override-channels tensorflow |
source activate intel_tf
|
参考:https://software.intel.com/en-us/articles/build-and-install-tensorflow-on-intel-architecture
可以直接用谷歌官方的tf来编译支持Intel的mkl CPU。
If the program Git* is not currently installed on your system, issue the following command:
sudo apt install git
Clone the GitHub repository by issuing the following command:
git clone https://github.com/tensorflow/tensorflow
The tensorflow directory created during cloning contains a script named configure that must be executed prior to creating the pip package and installing TensorFlow. This script allows you to identify the pathname, dependencies, and other build configuration options. For TensorFlow optimized on Intel architecture, this script also allows you to set up Intel® Math Kernel Library (Intel® MKL) related environment settings. Execute the following commands:
cd tensorflow
./configure
Important: Select ‘Y’ to build TensorFlow with Intel MKL support, and ‘Y’ to download MKL LIB from the web. Select the default settings for the other configuration parameters. When the script has completed running, issue the following command to build the pip package:
bazel build --config=mkl --copt="-DEIGEN_USE_VML" -c opt //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
At this point in the process the newly created pip package will be located in tmp/tensorflow_pkg. The next step is to install TensorFlow, which can be done either as a native pip installation, or in an Anaconda* virtual environment as described in the next section. For a native pip installation simply enter the following command:
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.2.0rc1-cp27-cp27mu-linux_x86_64.whl
(Note: The name of the wheel, as shown above in italics, may be different for your particular build.)
Once these steps have been completed be sure to validate the installation before proceeding to the next section. Note: When running the Python validation script provided in the link, be sure to change to a different directory, for example:
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/8318282.html,如需转载请自行联系原作者
cd ..