From ee5e0d076cee1e5145aba9b2e87409b655dfa154 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:10:27 +0100 Subject: [PATCH 1/7] Fix formatting of `scripts/entrypoint.sh` --- scripts/entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 4cec7345..f89d83c7 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -5,16 +5,16 @@ PORT=5000 # Check if AIP_MODE is set and adjust the port for Vertex AI if [[ ! -z "${AIP_MODE}" ]]; then - PORT=${AIP_HTTP_PORT} + PORT=${AIP_HTTP_PORT} fi # Check if HF_MODEL_DIR is set and if not skip installing custom dependencies if [[ ! -z "${HF_MODEL_DIR}" ]]; then - # Check if requirements.txt exists and if so install dependencies - if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then - echo "Installing custom dependencies from ${HF_MODEL_DIR}/requirements.txt" - pip install -r ${HF_MODEL_DIR}/requirements.txt --no-cache-dir; - fi + # Check if requirements.txt exists and if so install dependencies + if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then + echo "Installing custom dependencies from ${HF_MODEL_DIR}/requirements.txt" + pip install -r ${HF_MODEL_DIR}/requirements.txt --no-cache-dir + fi fi # Start the server From 49678da8bd67039d6d9120937082aaf83933141c Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:12:57 +0100 Subject: [PATCH 2/7] Update and rename `Makefile` - Remove Vertex-related stuff since there's already a dedicated repository for building, pushing and testing the Vertex AI compatible images i.e. https://github.com/huggingface/Google-Cloud-Containers - Add missing PHONY targets - Add some in-line comments on each target --- makefile => Makefile | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) rename makefile => Makefile (63%) diff --git a/makefile b/Makefile similarity index 63% rename from makefile rename to Makefile index ef45c469..a8f38091 100644 --- a/makefile +++ b/Makefile @@ -1,39 +1,35 @@ -.PHONY: quality style unit-test integ-test +.PHONY: quality style unit-test integ-test inference-pytorch-gpu inference-pytorch-cpu inference-pytorch-inf2 stop-all -check_dirs := src tests +check_dirs := src tests -# run tests +# Check that source code meets quality standards +quality: + ruff check $(check_dirs) + +# Format source code automatically +style: + ruff check $(check_dirs) --fix +# Run unit tests unit-test: RUN_SLOW=True python3 -m pytest -s -v tests/unit -n 10 --log-cli-level='ERROR' +# Run integration tests integ-test: python3 -m pytest -s -v tests/integ/ -# Check that source code meets quality standards - -quality: - ruff check $(check_dirs) - -# Format source code automatically - -style: - ruff check $(check_dirs) --fix - +# Build Docker image for PyTorch on GPU inference-pytorch-gpu: docker build -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:gpu . +# Build Docker image for PyTorch on CPU inference-pytorch-cpu: docker build --build-arg="BASE_IMAGE=ubuntu:22.04" -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:cpu . +# Build Docker image for PyTorch on AWS Inferentia2 inference-pytorch-inf2: docker build -f dockerfiles/pytorch/Dockerfile.inf2 -t integration-test-pytorch:inf2 . -vertex-pytorch-gpu: - docker build -t vertex -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:gpu . - -vertex-pytorch-cpu: - docker build -t vertex --build-arg="BASE_IMAGE=ubuntu:22.04" -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:cpu . - +# Stop all and prune/clean the Docker Containers stop-all: - docker stop $$(docker ps -a -q) && docker container prune --force \ No newline at end of file + docker stop $$(docker ps -a -q) && docker container prune --force From e10027450cce394229efd970638f552a26417583 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:13:43 +0100 Subject: [PATCH 3/7] Fix formatting in `MANIFEST.in`, `pyproject.toml` and `setup.py` --- MANIFEST.in | 3 +-- pyproject.toml | 20 ++++++++++---------- setup.py | 4 +--- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 2f05587a..f3155af7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ - include LICENSE include README.md recursive-exclude * __pycache__ -recursive-exclude * *.py[co] \ No newline at end of file +recursive-exclude * *.py[co] diff --git a/pyproject.toml b/pyproject.toml index 29746fe6..96be591c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,17 +5,17 @@ scripts_are_modules = true [tool.ruff] select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "I", # isort - "C", # flake8-comprehensions - "B", # flake8-bugbear + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "C", # flake8-comprehensions + "B", # flake8-bugbear ] ignore = [ - "E501", # Line length (handled by ruff-format) - "B008", # do not perform function calls in argument defaults - "C901", # too complex + "E501", # Line length (handled by ruff-format) + "B008", # do not perform function calls in argument defaults + "C901", # too complex ] # Same as Black. line-length = 119 @@ -23,7 +23,7 @@ line-length = 119 # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -# Assume Python 3.11. +# Assume Python 3.11 target-version = "py311" per-file-ignores = { "__init__.py" = ["F401"] } diff --git a/setup.py b/setup.py index 4d3265e2..92b37ddb 100644 --- a/setup.py +++ b/setup.py @@ -62,9 +62,7 @@ packages=find_packages(where="src"), install_requires=install_requires, extras_require=extras, - entry_points={ - "console_scripts": "serve=sagemaker_huggingface_inference_toolkit.serving:main" - }, + entry_points={"console_scripts": "serve=sagemaker_huggingface_inference_toolkit.serving:main"}, python_requires=">=3.8", license="Apache License 2.0", classifiers=[ From e5af3f916387b989fe2f853976174f9ec00a175f Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:14:22 +0100 Subject: [PATCH 4/7] Update `.dockerignore` to include `.git` and `Makefile` (rename) --- .dockerignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 2cb0b490..d3de8edf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,11 @@ +.git .github .pytest_cache .ruff_cache .tox .venv .gitignore -makefile +Makefile __pycache__ tests .vscode From 18ae9a048efe977421a4899188b09436de7b65e1 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:16:42 +0100 Subject: [PATCH 5/7] Fix `Dockerfile` to use `ppa:fkrull/deadsnakes` and Python 3.11 - Python 3.11 was being installed, but Python 3.10 was used instead; both via `python` and when installing with `pip` - Fix `pip` installation to use recommended installation path as per https://pip.pypa.io/en/stable/installation/ - Remove `vertex` build stage since there's already a dedicated repository for the Google Cloud Containers, including the Vertex AI compatible ones, i.e. https://github.com/huggingface/Google-Cloud-Containers --- dockerfiles/pytorch/Dockerfile | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dockerfiles/pytorch/Dockerfile b/dockerfiles/pytorch/Dockerfile index 324001df..b3a4909d 100644 --- a/dockerfiles/pytorch/Dockerfile +++ b/dockerfiles/pytorch/Dockerfile @@ -1,6 +1,6 @@ ARG BASE_IMAGE=nvidia/cuda:12.1.0-devel-ubuntu22.04 -FROM $BASE_IMAGE as base +FROM $BASE_IMAGE as base SHELL ["/bin/bash", "-c"] LABEL maintainer="Hugging Face" @@ -11,7 +11,7 @@ WORKDIR /app RUN apt-get update && \ apt-get install software-properties-common -y && \ - add-apt-repository ppa:deadsnakes/ppa && \ + add-apt-repository ppa:fkrull/deadsnakes && \ apt-get -y upgrade --only-upgrade systemd openssl cryptsetup && \ apt-get install -y \ build-essential \ @@ -25,9 +25,8 @@ RUN apt-get update && \ cmake \ libprotobuf-dev \ protobuf-compiler \ - python3-dev \ - python3-pip \ python3.11 \ + python3.11-dev \ libsndfile1-dev \ ffmpeg \ && apt-get clean autoremove --yes \ @@ -36,6 +35,15 @@ RUN apt-get update && \ # Copying only necessary files as filtered by .dockerignore COPY . . +# Set Python 3.11 as the default python version +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \ + ln -sf /usr/bin/python3.11 /usr/bin/python + +# Install pip from source +RUN curl -O https://bootstrap.pypa.io/get-pip.py && \ + python get-pip.py && \ + rm get-pip.py + # install wheel and setuptools RUN pip install --no-cache-dir --upgrade pip ".[torch,st,diffusers]" @@ -44,11 +52,6 @@ COPY src/huggingface_inference_toolkit huggingface_inference_toolkit COPY src/huggingface_inference_toolkit/webservice_starlette.py webservice_starlette.py # copy entrypoint and change permissions -COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh +COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh ENTRYPOINT ["bash", "-c", "./entrypoint.sh"] - -FROM base AS vertex - -# Install `google` extra for Vertex AI compatibility -RUN pip install --no-cache-dir --upgrade ".[google]" From cd3311373cf8e57e90311d2d9fdbacbb75e1f383 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:28:32 +0100 Subject: [PATCH 6/7] Fix `FromAsCasing` warning on `Dockerfile` --- dockerfiles/pytorch/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/pytorch/Dockerfile b/dockerfiles/pytorch/Dockerfile index b3a4909d..cf5c6769 100644 --- a/dockerfiles/pytorch/Dockerfile +++ b/dockerfiles/pytorch/Dockerfile @@ -1,6 +1,6 @@ ARG BASE_IMAGE=nvidia/cuda:12.1.0-devel-ubuntu22.04 -FROM $BASE_IMAGE as base +FROM $BASE_IMAGE AS base SHELL ["/bin/bash", "-c"] LABEL maintainer="Hugging Face" From a5f9c91801f493ce7441c0b1655b05c8b49b3055 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:33:56 +0100 Subject: [PATCH 7/7] Rollback to `ppa:fkrull/deadsnakes` (poor error interpretation / missread) --- dockerfiles/pytorch/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/pytorch/Dockerfile b/dockerfiles/pytorch/Dockerfile index cf5c6769..4ca98a86 100644 --- a/dockerfiles/pytorch/Dockerfile +++ b/dockerfiles/pytorch/Dockerfile @@ -11,7 +11,7 @@ WORKDIR /app RUN apt-get update && \ apt-get install software-properties-common -y && \ - add-apt-repository ppa:fkrull/deadsnakes && \ + add-apt-repository ppa:deadsnakes/ppa && \ apt-get -y upgrade --only-upgrade systemd openssl cryptsetup && \ apt-get install -y \ build-essential \