| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Ubuntu + PyTorch + CUDA (optional)
In order to use this image you must have Docker Engine installed. Instructions for setting up Docker Engine are available on the Docker website.
If you have a CUDA-compatible NVIDIA graphics card, you can use a CUDA-enabled version of the PyTorch image to enable hardware acceleration. I have only tested this in Ubuntu Linux.
Firstly, ensure that you install the appropriate NVIDIA drivers. On Ubuntu, I've found that the easiest way of ensuring that you have the right version of the drivers set up is by installing a version of CUDA at least as new as the image you intend to use via the official NVIDIA CUDA download page. As an example, if you intend on using the cuda-10.1 image then setting up CUDA 10.1 or CUDA 10.2 should ensure that you have the correct graphics drivers.
You will also need to install the NVIDIA Container Toolkit to enable GPU device access within Docker containers. This can be found at NVIDIA/nvidia-docker.
Prebuilt images are available on Docker Hub under the name anibali/pytorch.
For example, you can pull an image with PyTorch 2.0.1 and CUDA 11.8 using:
$ docker pull anibali/pytorch:2.0.1-cuda11.8It is possible to run PyTorch programs inside a container using the python3 command. For example, if you are within a directory containing some PyTorch project with entrypoint main.py, you could run it with the following command:
docker run --rm -it --init \
--gpus=all \
--ipc=host \
--user="$(id -u):$(id -g)" \
--volume="$PWD:/app" \
anibali/pytorch python3 main.pyHere's a description of the Docker command-line options shown above:
If you are running on a Linux host, you can get code running inside the Docker container to display graphics using the host X server (this allows you to use OpenCV's imshow, for example). Here we describe a quick-and-dirty (but INSECURE) way of doing this. For a more comprehensive guide on GUIs and Docker check out http://wiki.ros.org/docker/Tutorials/GUI.
On the host run:
sudo xhost +local:rootYou can revoke these access permissions later with sudo xhost -local:root. Now when you run a container make sure you add the options -e "DISPLAY" and --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw". This will provide the container with your X11 socket for communication and your display ID. Here's an example:
docker run --rm -it --init \
--gpus=all \
-e "DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
anibali/pytorch python3 -c "import tkinter; tkinter.Tk().mainloop()"The recommended way of adding additional dependencies to an image is to create your own Dockerfile using one of the PyTorch images from this project as a base.
For example, let's say that you require OpenCV and wish to work with PyTorch 2.0.1. You can create your own Dockerfile using anibali/pytorch:2.0.1-cuda11.8-ubuntu22.04 as the base image and install OpenCV using additional build steps:
FROM anibali/pytorch:2.0.1-cuda11.8-ubuntu22.04
# Set up time zone.
ENV TZ=UTC
RUN sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
# Install system libraries required by OpenCV.
RUN sudo apt-get update \
&& sudo apt-get install -y libgl1-mesa-glx libgtk2.0-0 libsm6 libxext6 \
&& sudo rm -rf /var/lib/apt/lists/*
# Install OpenCV from PyPI.
RUN pip install opencv-python==4.5.1.48The Dockerfiles in the dockerfiles/ directory are automatically generated by the manager.py script using details in images.yml and the templates in templates/.
Here's an example workflow illustrating how to create a new Dockerfile.
| Back | FazBrowse Home | New Git URL |