Skip to content

Commit 893de39

Browse files
authored
Merge branch 'main' into bump-versions-and-release
2 parents dfc1ed3 + 8c3562d commit 893de39

File tree

7 files changed

+337
-81
lines changed

7 files changed

+337
-81
lines changed

.github/workflows/docker-build-action.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828

2929
jobs:
3030
buildx:
31-
runs-on:
31+
runs-on:
3232
group: aws-highmemory-32-plus-priv
3333
steps:
3434
- name: Check out
@@ -56,6 +56,6 @@ jobs:
5656
context: ${{ inputs.context }}
5757
build-args: ${{ inputs.build_args }}
5858
target: base
59-
file: ${{ inputs.context }}/${{ inputs.dockerfile }}
59+
outputs: type=image,compression=zstd,force-compression=true,push=true
60+
file: ${{ inputs.context }}/${{ inputs.dockerfile }}
6061
tags: ${{ inputs.repository }}/${{ inputs.image }}:sha-${{ env.GITHUB_SHA_SHORT }},${{ inputs.repository }}/${{ inputs.image }}:latest
61-

dockerfiles/pytorch/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ RUN apt-get update && \
1616
apt-get install -y \
1717
build-essential \
1818
bzip2 \
19+
cmake \
1920
curl \
2021
git \
2122
git-lfs \
2223
tar \
2324
gcc \
2425
g++ \
25-
cmake \
2626
libprotobuf-dev \
2727
protobuf-compiler \
2828
python3.11 \
@@ -44,14 +44,17 @@ RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
4444
python get-pip.py && \
4545
rm get-pip.py
4646

47-
# install wheel and setuptools
47+
# Upgrade pip
48+
RUN pip install --no-cache-dir --upgrade pip
49+
50+
# Install wheel and setuptools
4851
RUN pip install --no-cache-dir --upgrade pip ".[torch,st,diffusers]"
4952

50-
# copy application
53+
# Copy application
5154
COPY src/huggingface_inference_toolkit huggingface_inference_toolkit
5255
COPY src/huggingface_inference_toolkit/webservice_starlette.py webservice_starlette.py
5356

54-
# copy entrypoint and change permissions
57+
# Copy entrypoint and change permissions
5558
COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh
5659

5760
ENTRYPOINT ["bash", "-c", "./entrypoint.sh"]
Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,69 @@
11
# Build based on https://github.com/aws/deep-learning-containers/blob/master/huggingface/pytorch/inference/docker/2.1/py3/sdk2.18.0/Dockerfile.neuronx
2-
FROM ubuntu:20.04 as base
2+
FROM ubuntu:22.04 AS base
33

44
LABEL maintainer="Hugging Face"
55

6-
ARG PYTHON=python3.10
7-
ARG PYTHON_VERSION=3.10.12
8-
ARG MAMBA_VERSION=23.1.0-4
9-
10-
# Neuron SDK components version numbers
11-
ARG NEURONX_FRAMEWORK_VERSION=2.1.2.2.1.0
12-
ARG NEURONX_DISTRIBUTED_VERSION=0.7.0
13-
ARG NEURONX_CC_VERSION=2.13.66.0
14-
ARG NEURONX_TRANSFORMERS_VERSION=0.10.0.21
15-
ARG NEURONX_COLLECTIVES_LIB_VERSION=2.20.22.0-c101c322e
16-
ARG NEURONX_RUNTIME_LIB_VERSION=2.20.22.0-1b3ca6425
17-
ARG NEURONX_TOOLS_VERSION=2.17.1.0
6+
ARG NEURONX_COLLECTIVES_LIB_VERSION=2.22.33.0-d2128d1aa
7+
ARG NEURONX_RUNTIME_LIB_VERSION=2.22.19.0-5856c0b42
8+
ARG NEURONX_TOOLS_VERSION=2.19.0.0
189

1910
# HF ARGS
20-
ARG OPTIMUM_NEURON_VERSION=0.0.23
11+
ARG OPTIMUM_NEURON_VERSION=0.0.28
2112

2213
# See http://bugs.python.org/issue19846
23-
ENV LANG C.UTF-8
24-
ENV LD_LIBRARY_PATH /opt/aws/neuron/lib:/lib/x86_64-linux-gnu:/opt/conda/lib/:$LD_LIBRARY_PATH
25-
ENV PATH /opt/conda/bin:/opt/aws/neuron/bin:$PATH
14+
ENV LANG=C.UTF-8
15+
ENV LD_LIBRARY_PATH=/opt/aws/neuron/lib:/lib/x86_64-linux-gnu:/opt/conda/lib/:$LD_LIBRARY_PATH
16+
ENV PATH=/opt/aws/neuron/bin:$PATH
2617

2718
RUN apt-get update \
2819
&& apt-get upgrade -y \
2920
&& apt-get install -y --no-install-recommends software-properties-common \
30-
&& add-apt-repository ppa:openjdk-r/ppa \
3121
&& apt-get update \
3222
&& apt-get install -y --no-install-recommends \
3323
build-essential \
3424
apt-transport-https \
3525
ca-certificates \
3626
cmake \
3727
curl \
38-
emacs \
3928
git \
4029
jq \
41-
libgl1-mesa-glx \
42-
libsm6 \
43-
libxext6 \
44-
libxrender-dev \
45-
openjdk-11-jdk \
46-
vim \
4730
wget \
4831
unzip \
4932
zlib1g-dev \
50-
libcap-dev \
51-
gpg-agent \
52-
&& rm -rf /var/lib/apt/lists/* \
53-
&& rm -rf /tmp/tmp* \
54-
&& apt-get clean
33+
gpg-agent
5534

56-
RUN echo "deb https://apt.repos.neuron.amazonaws.com focal main" > /etc/apt/sources.list.d/neuron.list
35+
RUN echo "deb https://apt.repos.neuron.amazonaws.com jammy main" > /etc/apt/sources.list.d/neuron.list
5736
RUN wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | apt-key add -
5837

5938
# Install Neuronx tools
6039
RUN apt-get update \
6140
&& apt-get install -y \
6241
aws-neuronx-tools=$NEURONX_TOOLS_VERSION \
6342
aws-neuronx-collectives=$NEURONX_COLLECTIVES_LIB_VERSION \
64-
aws-neuronx-runtime-lib=$NEURONX_RUNTIME_LIB_VERSION \
65-
&& rm -rf /var/lib/apt/lists/* \
43+
aws-neuronx-runtime-lib=$NEURONX_RUNTIME_LIB_VERSION
44+
45+
RUN apt-get install -y \
46+
python3 \
47+
python3-pip \
48+
python-is-python3
49+
50+
RUN rm -rf /var/lib/apt/lists/* \
6651
&& rm -rf /tmp/tmp* \
6752
&& apt-get clean
6853

69-
# https://github.com/docker-library/openjdk/issues/261 https://github.com/docker-library/openjdk/pull/263/files
70-
RUN keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt; \
71-
mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts; \
72-
/var/lib/dpkg/info/ca-certificates-java.postinst configure;
73-
74-
RUN curl -L -o ~/mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-x86_64.sh \
75-
&& chmod +x ~/mambaforge.sh \
76-
&& ~/mambaforge.sh -b -p /opt/conda \
77-
&& rm ~/mambaforge.sh \
78-
&& /opt/conda/bin/conda update -y conda \
79-
&& /opt/conda/bin/conda install -c conda-forge -y \
80-
python=$PYTHON_VERSION \
81-
pyopenssl \
82-
cython \
83-
mkl-include \
84-
mkl \
85-
botocore \
86-
parso \
87-
scipy \
88-
typing \
89-
# Below 2 are included in miniconda base, but not mamba so need to install
90-
conda-content-trust \
91-
charset-normalizer \
92-
&& /opt/conda/bin/conda update -y conda \
93-
&& /opt/conda/bin/conda clean -ya
94-
95-
RUN conda install -c conda-forge \
96-
scikit-learn \
97-
h5py \
98-
requests \
99-
&& conda clean -ya \
100-
&& pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org \
101-
&& ln -s /opt/conda/bin/pip /usr/local/bin/pip3 \
102-
&& pip install --no-cache-dir "protobuf>=3.18.3,<4" setuptools==69.5.1 packaging
103-
54+
RUN pip install --no-cache-dir "protobuf>=3.18.3,<4" setuptools==69.5.1 packaging
55+
10456
WORKDIR /
10557

10658
# install Hugging Face libraries and its dependencies
107-
RUN pip install --extra-index-url https://pip.repos.neuron.amazonaws.com --no-cache-dir optimum-neuron[neuronx]==${OPTIMUM_NEURON_VERSION} \
59+
RUN pip install --extra-index-url https://pip.repos.neuron.amazonaws.com --no-cache-dir optimum-neuron[neuronx]==${OPTIMUM_NEURON_VERSION} \
10860
&& pip install --no-deps --no-cache-dir -U torchvision==0.16.*
10961

62+
# FIXME
63+
RUN pip install --extra-index-url https://pip.repos.neuron.amazonaws.com git+https://github.com/huggingface/optimum-neuron.git@5237fb0ada643ba471f60ed3a5d2eef3b66e8e59
11064

11165
COPY . .
112-
# install wheel and setuptools
66+
11367
RUN pip install --no-cache-dir -U pip ".[st]"
11468

11569
# copy application
@@ -118,5 +72,7 @@ COPY src/huggingface_inference_toolkit/webservice_starlette.py webservice_starle
11872

11973
# copy entrypoint and change permissions
12074
COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh
75+
COPY --chmod=0755 scripts/inf2_env.py inf2_env.py
76+
COPY --chmod=0755 scripts/inf2_entrypoint.sh inf2_entrypoint.sh
12177

122-
ENTRYPOINT ["bash", "-c", "./entrypoint.sh"]
78+
ENTRYPOINT ["bash", "-c", "./inf2_entrypoint.sh"]

scripts/entrypoint.sh

100644100755
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
11
#!/bin/bash
22

3-
# Define the default port
3+
# Set the default port
44
PORT=5000
55

66
# Check if AIP_MODE is set and adjust the port for Vertex AI
77
if [[ ! -z "${AIP_MODE}" ]]; then
88
PORT=${AIP_HTTP_PORT}
99
fi
1010

11-
# Check if HF_MODEL_DIR is set and if not skip installing custom dependencies
11+
# Check that only one of HF_MODEL_ID or HF_MODEL_DIR is provided
12+
if [[ ! -z "${HF_MODEL_ID}" && ! -z "${HF_MODEL_DIR}" ]]; then
13+
echo "Error: Both HF_MODEL_ID and HF_MODEL_DIR are set. Please provide only one."
14+
exit 1
15+
elif [[ -z "${HF_MODEL_ID}" && -z "${HF_MODEL_DIR}" ]]; then
16+
echo "Error: Neither HF_MODEL_ID nor HF_MODEL_DIR is set. Please provide one of them."
17+
exit 1
18+
fi
19+
20+
# If HF_MODEL_ID is provided, download handler.py and requirements.txt if available
21+
if [[ ! -z "${HF_MODEL_ID}" ]]; then
22+
filename=${HF_DEFAULT_PIPELINE_NAME:-handler.py}
23+
revision=${HF_REVISION:-main}
24+
25+
echo "Downloading $filename for model ${HF_MODEL_ID}"
26+
huggingface-cli download ${HF_MODEL_ID} "$filename" --revision "$revision" --local-dir /tmp
27+
28+
# Check if handler.py was downloaded successfully
29+
if [ -f "/tmp/$filename" ]; then
30+
echo "$filename downloaded successfully, checking if there's a requirements.txt file..."
31+
rm /tmp/$filename
32+
33+
# Attempt to download requirements.txt
34+
echo "Downloading requirements.txt for model ${HF_MODEL_ID}"
35+
huggingface-cli download "${HF_MODEL_ID}" requirements.txt --revision "$revision" --local-dir /tmp
36+
37+
# Check if requirements.txt was downloaded successfully
38+
if [ -f "/tmp/requirements.txt" ]; then
39+
echo "requirements.txt downloaded successfully, now installing the dependencies..."
40+
41+
# Install dependencies
42+
pip install -r /tmp/requirements.txt --no-cache-dir
43+
rm /tmp/requirements.txt
44+
else
45+
echo "${HF_MODEL_ID} with revision $revision contains a custom handler at $filename but doesn't contain a requirements.txt file, so skipping downloading and installing extra requirements from it."
46+
fi
47+
else
48+
echo "${HF_MODEL_ID} with revision $revision doesn't contain a $filename file, so skipping download."
49+
fi
50+
fi
51+
52+
# If HF_MODEL_DIR is provided, check for requirements.txt and install dependencies if available
1253
if [[ ! -z "${HF_MODEL_DIR}" ]]; then
1354
# Check if requirements.txt exists and if so install dependencies
1455
if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then

scripts/inf2_entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e -o pipefail -u
3+
4+
export ENV_FILEPATH=$(mktemp)
5+
6+
trap "rm -f ${ENV_FILEPATH}" EXIT
7+
8+
touch $ENV_FILEPATH
9+
10+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
11+
12+
${SCRIPT_DIR}/inf2_env.py $@
13+
14+
source $ENV_FILEPATH
15+
16+
rm -f $ENV_FILEPATH
17+
18+
exec ${SCRIPT_DIR}/entrypoint.sh $@

0 commit comments

Comments
 (0)