Intel® Optimization for TensorFlow* Installation Guide

TensorFlow* is a predominantly-used machine learning framework in the deep learning arena, demanding efficient utilization of computational resources. In order to take full advantage of Intel® architecture and to extract maximum performance, the TensorFlow framework has been optimized using Intel® Math Kernel Library for Deep Neural Networks (Intel® MKL-DNN) primitives, a popular performance library for deep learning applications.

For more information on the optimizations as well as performance data, see this blog post TensorFlow* Optimizations on Modern Intel® Architecture .

Anaconda* has now made it convenient for the AI community to enable high-performance-computing in TensorFlow library. Starting from TensorFlow v1.9, Anaconda has and will continue to build TensorFlow using Intel® Math Kernel Library for Deep Neural Networks (Intel® MKL-DNN) primitives to deliver maximum performance in your CPU. If you are using conda package manager to manage your environments and packages, all you have to do is just install the TensorFlow package from Anaconda.org into your virtual environments.

Additionally, Intel® Optimization for latest TensorFlow* version is distributed as Wheels and Docker images for Python 2.7, 3.5 and 3.6.

Install the latest Intel® Optimization for TensorFlow* from Anaconda* Cloud

TensorFlow* version: 1.9

Installation instructions:

Open Anaconda prompt and use the following instruction

conda install tensorflow

In case your anaconda channel is not the highest priority channel by default(or you are not sure), use the following command to make sure you get the right TensorFlow with Intel optimizations

conda install -c anaconda tensorflow

Besides the install method described above, Intel Optimization for TensorFlow is distributed as wheels, docker images and conda package on Intel channel. Follow one of the installation procedures to get Intel-optimized TensorFlow.

Install the latest Intel® Optimization for TensorFlow* from Intel Channel

TensorFlow* version: 1.9

Installation instructions:

Open Anaconda prompt and use the following instruction. Available for Python 2.7 and 3.6.

conda install tensorflow -c intel

Install the Intel® Optimization for TensorFlow* Wheel Into an Existing Python* Installation Through PIP

Available for Linux* OS

TensorFlow version: 1.9.0

Installation instructions:

Run the below instructions to install the wheel into an existing Python* installation, preferably Intel® Distribution for Python*:

# Python 2.7
pip install https://storage.googleapis.com/intel-optimized-tensorflow/tensorflow-1.9.0-cp27-cp27mu-linux_x86_64.whl

# Python 3.5
pip install https://storage.googleapis.com/intel-optimized-tensorflow/tensorflow-1.9.0-cp35-cp35m-linux_x86_64.whl

# Python 3.6
pip install https://storage.googleapis.com/intel-optimized-tensorflow/tensorflow-1.9.0-cp36-cp36m-linux_x86_64.whl

Edit 08/07/18: Wheel paths have been updated to 1.9.0

Warning on ISA above AVX2:

"The TensorFlow library was not compiled to use <Instruction set> instructions, but these are available on your machine and could speed up CPU computations."

This warning can be ignored since Intel MKL-DNN library with which the TensorFlow is compiled utilizes the latest Instruction sets available in your processor to perform compute-intensive operations.

Older CPUs may not support this version of TensorFlow and may result in "Illegal instruction (core dumped)" error.

Install the Intel® Optimization for TensorFlow* Docker Images Into an Existing Python* Installation

Obtaining and Running the Containers

These docker images are all published at http://hub.docker.com in theintelaipg/intel-optimized-tensorflow namespace and can be pulled with the following command:

 

$ docker pull docker.io/intelaipg/intel-optimized-tensorflow:<tag>

 

For example, to run the python 2.7 data science container directly, simply

$ docker run -it -p 8888:8888 intelaipg/intel-optimized-tensorflow

And then go to your browser on http://localhost:8888/

Available Container Configurations 

The following tags/configurations are available:

Docker Container Configurations
ConfigurationTags
Python 2.7 with jupyter and sample notebooks

latest

latest-mkl

1.9.0-mkl

Python 3.5 with jupyter and sample notebooks

latest-py3

latest-mkl-py3

1.9.0-mkl-py3

Python 2.7 with TensorFlow development toolchain

latest-devel

latest-devel-mkl

1.9.0-devel-mkl

Python 2.7 with TensorFlow development toolchain

latest-devel-py3

latest-devel-mkl-py3

1.9.0-devel-mkl-py3

To get the latest Release Notes on Intel-optimized Tensorflow, please refer this article

Build TensorFlow from Source with Intel® MKL

Building TensorFlow from source is not recommended. However, if instructions provided above do not work due to unsupported ISA, you can always build from source.

Building TensorFlow from source code requires Bazel installation, refer to the instructions here, Installing Bazel.

Installation instructions:

  1. Run "./configure" from the TensorFlow source directory
  2. Execute the following commands to create a pip package that can be used to install the optimized TensorFlow build.
    • PATH can be changed to point to a specific version of GCC compiler:
      export PATH=/PATH//bin:$PATH
      
    • LD_LIBRARY_PATH can also be to new:
      export LD_LIBRARY_PATH=/PATH//lib64:$LD_LIBRARY_PATH
      
    • Set the flag to build TensorFlow with Intel® Math Kernel Library (Intel® MKL) and pass appropriate Instruction sets you want to compile the library with: 

Flags set in the command below will add AVX, AVX2 and AVX512 instructions which will result in "illegal instruction" errors when you use older CPUs. If you want to build on older CPUs, set the instruction flags accordingly

bazel build --config=mkl -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mavx512f --copt=-mavx512pf --copt=-mavx512cd --copt=-mavx512er //tensorflow/tools/pip_package:build_pip_package

        3. Install the optimized TensorFlow wheel

     bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/path_to_save_wheel
     pip install --upgrade --user ~/path_to_save_wheel /<wheel_name.whl>

Archived Wheels

Version

Wheels(2.7, 3.5, 3.6)

1.6

https://anaconda.org/intel/tensorflow/1.6.0/download/tensorflow-1.6.0-cp27-cp27mu-linux_x86_64.whl

(or)

*/tensorflow-1.6.0-cp35-cp35mu-linux_x86_64.whl

(or)

*/tensorflow-1.6.0-cp36-cp36mu-linux_x86_64.whl

For more complete information about compiler optimizations, see our Optimization Notice.

16 comments

Top
Sagalovsky, Benjamin's picture

Thank you, Preethi, but the original question still stands: will this speed up Tensorflow on my Core  i7-7500U CPU, or are those optimizations only effective for high-end Xeon processors? Thanks!

Preethi: Intel MKL-DNN, which is used to build the optimized TensorFlow supports Core processors. Refer the System Requirements section in the GitHub page here: https://github.com/intel/mkl-dnn

 

Sagalovsky, Benjamin's picture

Hello,

I have a humble laptop with an Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz, running Windows 10 (oh, what a shame!), Anaconda and Jupyter Lab. Would I benefit at all of installing tensorflow-mkl? If there are any benefits, are there some pre-requisites/pre-installs that I would need to do?

In more general terms, what are the processors that would benefit from this install and from the MKL-DNN library as such?

Preethi Venkatesh: Hi Benjamin, The new version of  default TensorFlow (1.9) from the Anaconda Channel is build using MKL-DNN optimizations and is available for download now. just do a "conda install tensorflow". No other prerequisites needed.

Thanks!

Ben

Cooksey, Robert (Intel)'s picture

Is this method still relevant? https://software.intel.com/en-us/articles/using-intel-distribution-for-python-with-anaconda

It avoids the pip <-> conda conflict.

 

 

Pradyumna's picture

Method 2 doesn't work for me on my MacBook. I get the following error:

Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - intelpython3_core
  - tbb4py
  - tensorflow
Use "conda info <package>" to see the dependencies for each package.

Can somebody please help?

 

Pradyumna's picture

I tried method 2, but I get the following error:

Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - intelpython3_core
  - tbb4py
  - tensorflow
Use "conda info <package>" to see the dependencies for each package.

Can somebody please help?

Cai, Jason's picture

Thanks for the update about details of compiling TF+MKL from source with TF r1.6.

I am confused when doing "bazel build ...". From https://www.tensorflow.org/performance/performance_guide#tensorflow_with_intel_mkl_dnn, it says:

./configure
# Pick the desired options
bazel build --config=mkl --config=opt //tensorflow/tools/pip_package:build_pip_package

It's quite different from the bazel build cmds here.

Could you please tell me the reason why '--copt="-DEIGEN_USE_VML"' is needed?

Thanks.

Ehsan T. (Intel)'s picture

I installed this wheel in my conda environment, but python crashes with this error when I import tensorflow:

./tensorflow/core/common_runtime/mkl_cpu_allocator.h:144] Non-OK-status: s status: Unimplemented: Unimplemented case for hooking MKL function.

Qiang L. (Intel)'s picture

It seems that AVX512F is not compiled into released tensorflow 1.6. (but other KNL specific AVX512 instructions are compiled!!!)

I run simple "hello world" test on KNL after install the tensorflow 1.6 by following the steps mentioned here!!

it give me the message as follows:

2018-03-08 13:08:26.924344: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX512F

BTW, i try to compile the tensorflow 1.6 from source code, and adding all of avxxxxx as -copt to bazel build cmd, after build tensorflow 1.6 package correctly, re-run above test program, it seems the "AVX512F" is compiled!!!!

Karczewski, Jakub Jan (Intel)'s picture

I've run into issue when running AlexNet (https://github.com/jakubkarczewski/AlexNetF/blob/master/alexnet.py) on all of above TF versions (model works just fine on TF distribution installed with pip install tensorflow).

Error code:  tensorflow/core/kernels/mkl_lrn_op.cc:595] Check failed: dnnConversionCreate_F32( &convert_input, static_cast<dnnLayout_t>(inimage_shape.GetCurLayout()), lt_internal_input) == E_SUCCESS (-1 vs. 0)

 

Craig R.'s picture

The "... TensorFlow library wasn't compiled to use ..." may not indicate an issue.  There's a discussion over at https://software.intel.com/en-us/forums/intel-distribution-for-python/topic/738132 which suggests that you'll still get SSE/AVX performance where it counts.  However, I would like a definitive answer and way to verify that I'm getting optimized versions.

Pages

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.