TensorFlow in Anaconda
TensorFlow is a Python library for high-performance numerical calculations that allows users to create sophisticated deep learning and machine learning applications. Released as open source software in 2015, TensorFlow has seen tremendous growth and popularity in the data science community.
There are a number of methods that can be used to install TensorFlow, such as using pip to install the wheels available on PyPI. Installing TensorFlow using conda packages offers a number of benefits, including a complete package management system, wider platform support, a more streamlined GPU experience, and better CPU performance. These packages are available via the Anaconda Repository, and installing them is as easy as running “conda install tensorflow” or “conda install tensorflow-gpu” from a command line interface.
One key benefit of installing TensorFlow using conda rather than pip is a result of the conda package management system. When TensorFlow is installed using conda, conda installs all the necessary and compatible dependencies for the packages as well. This is done automatically; users do not need to install any additional software via system packages managers or other means. Additionally, any of the 1,400+ professionally built packages in the Anaconda repository can be installed alongside TensorFlow to provide a complete data science environment. These packages are installed into an isolated conda environment whose contents do not impact other environments.
Like other packages in the Anaconda repository, TensorFlow is supported on a number of platforms. TensorFlow conda packages are available for Windows, Linux, and macOS. The Linux packages for the 1.10.0 release support a number of Linux distributions including older distributions such as CentOS 6. This is a further benefit of the conda packages: in spite of being labeled as manylinux1-compatible (works on many versions of linux), the wheels available on PyPI support only a minimum of Ubuntu 16.04, which is much newer than many enterprise Linux installations.
Many of the functions in TensorFlow can be accelerated using NVIDIA GPUs. The gain in acceleration can be especially large when running computationally demanding deep learning applications. When installing TensorFlow using pip, the CUDA and CuDNN libraries needed for GPU support must be installed separately, adding a burden on getting started. When the GPU accelerated version of TensorFlow is installed using conda, by the command “conda install tensorflow-gpu”, these libraries are installed automatically, with versions known to be compatible with the tensorflow-gpu package. Furthermore, conda installs these libraries into a location where they will not interfere with other instances of these libraries that may have been installed via another method. Regardless of using pip or conda-installed tensorflow-gpu, the NVIDIA driver must be installed separately.
For many versions of TensorFlow, conda packages are available for multiple CUDA versions. For example, packages for CUDA 8.0, 9.0, and 9.2 are available for the latest release at this time, version 1.10.0. The pip packages only supports the CUDA 9.0 library. This can be important when working on systems which do not support the newer version of the CUDA libraries. Finally, because these libraries are installed via conda, users can easily create multiple environments and compare the performance of different CUDA versions.
The conda TensorFlow packages are also designed for better performance on CPUs through the use of the Intel® Math Kernel Library for Deep Neural Networks (Intel® MKL-DNN). Starting with version 1.9.0, the conda TensorFlow packages are built using the Intel® MKL-DNN library, which demonstrates considerable performance improvements. For example, Figure 1 compares the performance of training and inference on two different image classification models using TensorFlow installed using conda verses the same version installed using pip. The performance of the conda installed version is over eight times the speed of the pip installed package in many of the benchmarks.
Figure 1: Training performance of TensorFlow on a number of common deep learning models using synthetic data. Benchmarks were performed on an Intel® Xeon® Gold 6130.
Anaconda is proud of our efforts to deliver a simpler, faster experience using the excellent TensorFlow library. It takes significant time and effort to add support for the many platforms used in production, and to ensure that the accelerated code is still stable and mathematically correct. As a result, our TensorFlow packages may not be available concurrently with the official TensorFlow wheels. We are, however, committed to maintaining our TensorFlow packages, and work to have updates available as soon as we can.
conda create -n tensorflow_env tensorflow conda activate tensorflow_env
Or for the GPU version
conda create -n tensorflow_gpuenv tensorflow-gpu conda activate tensorflow_gpuenv
TensorFlow is now installed and ready for use. For those new to TensorFlow, the tutorials offer a great place to get started.