https://github.com/tillahoffmann/universal_tensorflow_image
Develop tensorflow models with or without a GPU accelerator using the same Docker image. 🥳
https://github.com/tillahoffmann/universal_tensorflow_image
cuda nvidia-docker tensorflow
Last synced: 11 months ago
JSON representation
Develop tensorflow models with or without a GPU accelerator using the same Docker image. 🥳
- Host: GitHub
- URL: https://github.com/tillahoffmann/universal_tensorflow_image
- Owner: tillahoffmann
- Created: 2018-05-18T20:29:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-21T21:00:42.000Z (almost 7 years ago)
- Last Synced: 2025-04-08T20:04:12.212Z (about 1 year ago)
- Topics: cuda, nvidia-docker, tensorflow
- Language: Dockerfile
- Homepage:
- Size: 2.93 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# universal_tensorflow_image
Develop tensorflow models with or without a GPU accelerator using the same Docker image. 🥳
Use
* `docker build -t universal-tensorflow-image .` to build the image
* `docker run --rm --runtime=nvidia universal-tensorflow-image python3 test_tensorflow.py` to test tensorflow using the GPU
* `docker run --rm universal-tensorflow-image python3 test_tensorflow.py` to test tensorflow using the CPU
Note that the only difference between the CPU and GPU run is the runtime.
## Background
Docker images for tensorflow commonly come in [two flavours](https://hub.docker.com/r/tensorflow/tensorflow/#optional-features):
* one to develop on machines without a GPU accelerator, e.g. [`cpu.Dockerfile`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/cpu.Dockerfile),
* and one to develop on machines with a GPU accelerator, e.g. [`gpu.Dockerfile`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/gpu.Dockerfile).
Maintaining two images in parallel is both cumbersome and increases the risk of discrepancies between different runtime environments.
The [`Dockerfile`](https://github.com/tillahoffmann/universal_tensorflow_image/blob/master/Dockerfile) provides a universal setup so you can use the same image irrespective of whether you're using a GPU or not. It installs [`tensorflow-gpu`](https://pypi.org/project/tensorflow-gpu/) and [symlinks](https://en.wikipedia.org/wiki/Symbolic_link) the required CUDA library stubs to the location where tensorflow expects to find them. That means `tensorflow-gpu` can be used even if you start a container based on the image without using the [nvidia runtime](https://github.com/NVIDIA/nvidia-docker). When you use the nvidia runtime, the stubs are overwritten by the real libraries and you can access the GPU seamlessly.
You may want to stick to a setup with two different images if you care about the size of your images: the universal tensorflow image has the same size as the GPU image. The CPU image is substantially smaller.