Skip to content

Commit

Permalink
Issues/fix docker dependencies (#2340)
Browse files Browse the repository at this point in the history
* re-run kserve build because of runner issue

* Fixes missing dependencies

* added depth 1 to reduce clone size by 50 MB
  • Loading branch information
agunapal authored May 11, 2023
1 parent 8ea1dab commit 35fb574
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
python$PYTHON_VERSION-venv \
openjdk-17-jdk \
curl \
git \
&& rm -rf /var/lib/apt/lists/*

# Make the virtual environment and "activating" it by adding it first to the path.
Expand All @@ -62,26 +63,29 @@ RUN export USE_CUDA=1

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])") && \
RUN git clone --depth 1 https://github.com/pytorch/serve.git

WORKDIR "serve"

RUN \
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 \
python -m 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
python ./ts_scripts/install_dependencies.py --cuda $CUDA_VERSION; \
# Install the binary with the latest CPU image on a CUDA base image
else \
python -m pip install --no-cache-dir torch torchvision; \
python ./ts_scripts/install_dependencies.py; \
fi; \
python -m pip install --no-cache-dir -r https://raw.githubusercontent.com/pytorch/serve/master/requirements/common.txt; \
# Install the CPU binary
else \
python -m pip install --no-cache-dir torch==$TORCH_VER+cpu torchvision==$TORCH_VISION_VER+cpu -f https://download.pytorch.org/whl/torch_stable.html; \
python ./ts_scripts/install_dependencies.py; \
fi

RUN python -m pip install --no-cache-dir captum torchtext torchserve torch-model-archiver pyyaml
# Make sure latest version of torchserve is uploaded before running this
RUN python -m pip install --no-cache-dir torchserve torch-model-archiver torch-workflow-archiver

# Final image for production
FROM ${BASE_IMAGE} AS runtime-image
FROM ${BASE_IMAGE} AS runtime-image
# Re-state ARG PYTHON_VERSION to make it active in this build-stage (uses default define at the top)
ARG PYTHON_VERSION
ENV PYTHONUNBUFFERED TRUE
Expand Down

0 comments on commit 35fb574

Please sign in to comment.