Skip to content

Commit

Permalink
Fix for Cuda 10.1 /Cuda 10.2 related torch package installation issue…
Browse files Browse the repository at this point in the history
… in Docker. (#642)

* added cuda version specific package installation

* updated readme

* made cuda version check more generic to support multiple OS versions

* fixed posix expression

* Added support for multiple cuda versions.

Co-authored-by: jeremiahschung <70922646+jeremiahschung@users.noreply.github.com>

* Update docker/README.md

Co-authored-by: Aaqib <maaquib@gmail.com>
Co-authored-by: Geeta Chauhan <4461127+chauhang@users.noreply.github.com>
Co-authored-by: jeremiahschung <70922646+jeremiahschung@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 19, 2020
1 parent cc6d892 commit 48a1f46
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
28 changes: 21 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ARG BASE_IMAGE=ubuntu:18.04

FROM ${BASE_IMAGE} AS compile-image

ARG BASE_IMAGE=ubuntu:18.04
ENV PYTHONUNBUFFERED TRUE

RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
Expand All @@ -41,15 +41,29 @@ RUN python3 -m venv /home/venv

ENV PATH="/home/venv/bin:$PATH"

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN update-alternatives --install /usr/local/bin/pip pip /usr/local/bin/pip3 1
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& update-alternatives --install /usr/local/bin/pip pip /usr/local/bin/pip3 1

# This is only useful for cuda env
# This is only useful for cuda env
RUN export USE_CUDA=1

RUN pip install -U pip setuptools

RUN pip install --no-cache-dir torch torchvision torchtext torchserve torch-model-archiver
ARG CUDA_VERSION=""

RUN TORCH_VER=$(curl --silent --location https://pypi.org/pypi/torch/json | python -c "import sys, json, pkg_resources; releases = json.load(sys.stdin)['releases']; print(sorted(releases, key=pkg_resources.parse_version)[-1])") && \
TORCH_VISION_VER=$(curl --silent --location https://pypi.org/pypi/torchvision/json | python -c "import sys, json, pkg_resources; releases = json.load(sys.stdin)['releases']; print(sorted(releases, key=pkg_resources.parse_version)[-1])") && \
if echo "$BASE_IMAGE" | grep -q "cuda:"; then \
# Install CUDA version specific binary when CUDA version is specified as a build arg
if [ "$CUDA_VERSION" ]; then \
pip install --no-cache-dir torch==$TORCH_VER+$CUDA_VERSION torchvision==$TORCH_VISION_VER+$CUDA_VERSION -f https://download.pytorch.org/whl/torch_stable.html; \
# Install the binary with the latest CUDA version support
else \
pip install --no-cache-dir torch torchvision; \
fi \
# Install the CPU binary
else \
pip install --no-cache-dir torch==$TORCH_VER+cpu torchvision==$TORCH_VISION_VER+cpu -f https://download.pytorch.org/whl/torch_stable.html; \
fi
RUN pip install --no-cache-dir torchtext torchserve torch-model-archiver

# Final image for production
FROM ${BASE_IMAGE} AS runtime-image
Expand Down
10 changes: 8 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ For creating CPU based image :
DOCKER_BUILDKIT=1 docker build --file Dockerfile -t torchserve:latest .
```

For creating GPU based image :
For creating GPU based image with the latest CUDA version PyTorch supports (ex. CUDA 10.2 as of Oct 2020):

```bash
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE=nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 -t torchserve:latest .
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE=nvidia/cuda:10.2-cudnn7-runtime-ubuntu18.04 -t torchserve:latest .
```

For creating GPU based image with older CUDA versions (ex. CUDA 10.1), make sure that the `--build-arg CUDA_VERSION=<version>` is specified. The version is in the format "cuda92", "cuda101":

```bash
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE=nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 --build-arg CUDA_VERSION=cu101 -t torchserve:latest .
```

## Start a container with a TorchServe image
Expand Down

0 comments on commit 48a1f46

Please sign in to comment.