Selected from hackernoon

Heart of the machine compiles

Participation: Huang Xiaotian, Lu Xue



Docker has many advantages, but in data science and deep learning, there are some obstacles to using Docker. With an introduction to Docker utilities and gPU-ready boilerplate, let’s see what Docker Compose + GPU + TensorFlow can do for you.
Docker is great — more and more people are using it for development and distribution. Docker has many advantages: instant environment Settings, platform-independent apps, off-the-shelf solutions, better version control, simplified maintenance.

But there are some obstacles when it comes to data science and deep learning. You have to remember all the Docker flags to share ports and files between hosts and containers, create unnecessary run.sh scripts, and deal with CUDA versions and GPU sharing. If you’ve ever seen this mistake, you know the pain:

Our goal

The purpose of this article is to introduce you to a series of Docker utilities and the GPU-ready boilerplate that we often use in our company.

Therefore, the following results will not occur:

Instead, this result:

Cool!

What we actually want to achieve:

  • Manage our application state (run, stop, Remove) with a single command
  • Save all run flags to a single configuration file that we can commit to git repo
  • Forget GPU driver version mismatch and sharing
  • Use gPU-ready containers in production tools such as Kubernetes or Rancher
So here’s a list of tools we highly recommend for every deep learner:

1. CUDA

First, you’ll need the CUDA toolkit, which is a must if you’re going to train the model yourself. We recommend using the RunFile installer type instead of deb because it does not confuse dependencies in future updates.

(Optional) How to check if it works:

2. Docker

You don’t want to contaminate your computer with massive libraries, and you also fear version problems. Again, you don’t have to build and install it yourself — usually, the software is already created for you and packaged in images. Installing Docker is simple:

3. Nvidia Docker

If you use the Docker, there must be from the nvidia utility (https://github.com/NVIDIA/nvidia-docker), it simplifies the use of GPU in the Docker container real steps.

Installation is very simple:

Now, don’t share nvidia devices every time:

You can use the nvidia-docker command:

Again, you don’t have to worry about driver versions mismatching: Nvidia’s Docker plugin will take care of that for you.



4. Docker Compose

Super useful utility that allows you to store Docker Run configuration in files and manage application state more easily. Although docker Compose is designed to combine multiple Docker containers, docker Compose is still very useful when you only have one service. There is a stable version (https://github.com/docker/compose/releases) :

5. Nvidia Docker Compose

Unfortunately, Docker Compose is not aware of Nvidia Docker’s existence. Fortunately, there is a solution: there is a small Python script that generates the configuration using the Nvidia-Docker driver. Install Nvidia Docker Compose via PIP:

Now you can use the nvidia-Docker-compose command instead of docker-compose.

alternative

If you don’t want to use Nvidia-Docker-compose, you can manually pass the volume driver, just add these options to docker-comemess.yml:

6. Bash alias

But Nvidia-Docker-compose requires 21 characters, which is too much.

Fortunately, we can use the bash alias. Open ~/.bashrc (sometimes ~/.bash_profile) in your favorite editor and type the following line:

Update your Settings by running source ~/.bashrc.

The TensorFlow service is started

Now we’re ready to take advantage of all of these tools. For example, we run a Tensorflow GPU-enabled Docker container.

Create a docker-comemage.yml file in your project directory with the following contents:

Now we can start TensorFlow Jupiter with a single command:

Doc is an alias for Nvidia-Docker-compose — it will use the correct volume-driver to generate the modified configuration file nvidia-Docker-comemess.yml and then run docker-compose.

You can use the same command to manage your service:

conclusion

But is it worth it? Let’s take a look at the pros and cons.

advantages

  • Don’t worry about GPU device sharing
  • Don’t worry about nvidia driver versions anymore
  • Get rid of command flags that favor clean, simple configurations
  • The –name flag is no longer needed to manage container state
  • Well-known documented and widely used utilities
  • Your configuration is ready for an authoring tool, such as Kubernetes, which understands the docker-compose file
disadvantages

  • You have to install more tools
Is it production-ready

Yes. For Movix, we use the GPU-accelerated TensorFlow network to compute real-time movie selections based on user input.

We have three machines with Nvidia Titan X in the Proxy API Rancher cluster. The configuration is stored in the regular docker-comemater.yml file: it makes it easy to deploy the application or set up the development environment on a new server. So far it has performed flawlessly.

Get ready for the future of machine learning!

The original link: https://hackernoon.com/docker-compose-gpu-tensorflow-%EF%B8%8F-a0e2011d36