PyCharm, Tensorflow-gpu-Docker container and Git integration

I had some trouble getting the GPU support work on the PyCharm-Docker combo, but it turned out I was only missing a runtime package. I won’t post all the steps here in detail, just links to the official documentation.

I’m using PyCharm professional edition 2019.3 and Docker 19.03 on Ubuntu 18.04 LTS.

1. Pull the Tensorflow container and install the nvidia toolkit and runtime:

https://www.tensorflow.org/install/docker

$ docker pull tensorflow/tensorflow:latest-gpu-py3

PyCharm doesn’t support all docker command line options (in this case –gpu all). In order for docker to use the nvidia-runtime on default, following file is needed in ‘/etc/docker’:

$ cat /etc/docker/daemon.json
{ "default-runtime":"nvidia",
    "runtimes": {
        "nvidia": {
            "path":"/usr/bin/nvidia-container-runtime",
            "runtimeArgs": [] }
    }
}

Toolkit installation: https://github.com/NVIDIA/nvidia-docker

$ sudo apt-get install nvidia-container-runtime

2. Install docker plugin for PyCharm:
https://www.jetbrains.com/help/pycharm/docker.html#

3. Make PyCharm to use a container-based python runtime:
https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html

If you are working in a Git repository, PyCharm recognizes it. The workflow isn’t as smooth and straightforward as from command line, but the powers of a good IDE are utilized.

To summarize: Tensorflow with GPU support runs in a container, and the PyCharm IDE uses the container runtime. Took some hours to set it up, but the process was not too complicated, and using Docker was really key here to achieve easy installation of a large set of dependencies.

Screenshot while working on our testing repository:

Screenshot from 2020-02-18 10-18-29

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s