TensorFlow is an open source framework for running machine learning (ML), deep learning, and various statistical and predictive analytics workloads. Data scientists, predictive modelers, and statisticians use TensorFlow to streamline the development and execution of advanced analytics applications.
Docker is an open source platform for creating, deploying, and managing virtualized application containers on a shared operating system using an ecosystem of tools. You can use Docker containers to create a virtual environment that isolates a TensorFlow installation and replicate it to train and run models from any location.
In this article:
The Docker platform enables you to build, deliver, and operate applications. You can use it to decouple applications from the infrastructure to quickly release software and manage the infrastructure like you manage applications. Docker's approach for shipping, testing, and deploying code can help minimize the time-to-release.
To start using Docker and TensorFlow, you need to install Docker on your local host machine and install NVIDIA Docker Support for GPU Support on Linux. You can leverage the NVIDIA Container Toolkit to create and execute GPU-accelerated Docker containers. The toolkit includes a container runtime library and utilities.
There is no need to install the CUDA Toolkit on the host system. However, you must install the NVIDIA driver on the host. Once the NVIDIA driver and Docker engine are installed on your Linux distribution, you can get started.
You can find additional installation instructions on the Docker website:
Once you’ve installed Docker, you can continue with the following steps:
To use TensorFlow with a CPU-only image, you can pull the TensorFlow Docker image from the Docker Hub using the following command:
docker pull tensorflow/tensorflow:latest
This will download the latest version of the TensorFlow Docker image that is optimized for use with CPUs. Once the image has been downloaded, you can start a new container instance using the docker run command:
docker run -it --rm -p 8888:8888 tensorflow/tensorflow:latest
This will start a new container in interactive mode (-i), remove it when it exits (-t), and expose the Jupyter notebook server on port 8888 (-p 8888:8888). You can then access the Jupyter notebook server by going to the URL http://localhost:8888 in a web browser.
To use TensorFlow with a GPU-enabled image, you will need to have a GPU available on your system and install the appropriate drivers and libraries. You can then pull the TensorFlow Docker image with GPU support using the following command:
docker pull tensorflow/tensorflow:latest-gpu
This will download the latest version of the TensorFlow Docker image that is optimized for use with GPUs. You can then start a new container instance using the docker run command:
docker run -it --rm -p 8888:8888 tensorflow/tensorflow:latest-gpu
This will start a new container in interactive mode (-i), remove it when it exits (-t), and expose the Jupyter notebook server on port 8888 (-p 8888:8888). You can then access the Jupyter notebook server by going to the URL http://localhost:8888 in a web browser.
To use TensorFlow with GPU support, you will need to use a GPU-enabled image and ensure that your TensorFlow code is written to take advantage of the GPU. You can use the TensorFlow device function to specify which device (CPU or GPU) you want to use for a particular operation. For example:
import tensorflow as tf
with tf.device('/cpu:0'):
# Code to run on the CPU
with tf.device('/gpu:0'):
# Code to run on the GPU
You can also use the tf.config.experimental.set_visible_devices function to specify which GPUs are available to TensorFlow:
import tensorflow as tf
# Make GPU 0 visible to TensorFlow
tf.config.experimental.set_visible_devices(['/gpu:0'], 'GPU')
TensorFlow Serving is a tool that allows you to serve machine learning models in a production environment. It is designed to be flexible, scalable, and easy to use, and it can be used with a variety of platforms and architectures, including Docker.
Now you can do the following:
To use the GPU in your serving code, you will need to ensure that your code is written to take advantage of the GPU. This may include using GPU-accelerated libraries and frameworks, such as TensorFlow or PyTorch, and specifying which device (CPU or GPU) you want to use for particular operations.
For example, in TensorFlow you can use the device function to specify which device you want to use for a particular operation:
import tensorflow as tf
with tf.device('/cpu:0'):
# Code to run on the CPU
with tf.device('/gpu:0'):
# Code to run on the GPU
You can also use the tf.config.experimental.set_visible_devices function to specify which GPUs are available to TensorFlow:
import tensorflow as tf
# Make GPU 0 visible to T
Run:ai automates resource management and workload orchestration for machine learning infrastructure. With Run:ai, you can automatically run as many compute intensive experiments as needed in TensorFlow and other deep learning frameworks.
Here are some of the capabilities you gain when using Run:ai:
Run:ai simplifies machine learning infrastructure pipelines, helping data scientists accelerate their productivity and the quality of their models.