Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To solve common_gpu.txt installation, you only need ref
https://github.com/pytorch/serve/blob/master/docker/Dockerfile#L75

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lxning There is a problem with the CPU image too. It doesn't have pynvml , torchaudio, torchtext

# 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; \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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