英特尔: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 Vallesnode
谷歌:Andy Davis,Toby Boyd,Megan Kacholia,Rasmus Larsen,Rajat Monga,Thiru Palanisamy,Vijay Vasudevan,Yao Zhangpython
做为一款领先的深度学习和机器学习框架,TensorFlow* 对英特尔和谷歌发挥英特尔硬件产品的最佳性能相当重要。本文 向人工智能 (AI) 社区介绍了在基于英特尔® 至强和英特尔® 至强融核™ 处理器的平台上实施的 TensorFlow* 优化。在去年举办的首届英特尔人工智能日上,英特尔公司的柏安娜和谷歌的 Diane Green 共同宣布了双方的合做,这些优化是英特尔和谷歌工程师密切合做取得的成果。linux
咱们介绍了在优化实践中遇到的各类性能挑战以及采用的解决方法,还报告了对通用神经网络模型示例的性能改进。这些优化带来了多个数量级的性能提高。例如,根据咱们的测量,英特尔® 至强融核™ 处理器 7250 (KNL) 上的训练性能提高了高达 70 倍,推断性能提高了高达 85 倍。基于英特尔® 至强® 处理器 E5 v4 (BDW) 和英特尔至强融核处理器 7250 的平台为下一代英特尔产品奠基了基础。用户尤为但愿今年晚些时候推出的英特尔至强(代号为 Skylake)和英特尔至强融合(代号为 Knights Mill)处理器将提供显著的性能提高。git
在现代 CPU 上优化深度学习模型的性能面临众多挑战,和优化高性能计算 (HPC) 中其余性能敏感型应用所面临的挑战差异不大:github
为了知足这些要求,英特尔开发了众多优化型深度学习基元,计划应用于不一样的深度学习框架,以确保通用构建模块的高效实施。除了矩阵乘法和卷积之外,建立模块还包括:web
请参阅 本文,获取关于面向深度神经网络的英特尔® 数学核心函数(英特尔® 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:
cd ..