Skip to content

Commit 0d30670

Browse files
authored
Fix Dockerfile and some minor updates (#97)
* Fix formatting of `scripts/entrypoint.sh` * 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 * Fix formatting in `MANIFEST.in`, `pyproject.toml` and `setup.py` * Update `.dockerignore` to include `.git` and `Makefile` (rename) * 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 * Fix `FromAsCasing` warning on `Dockerfile` * Rollback to `ppa:fkrull/deadsnakes` (poor error interpretation / missread)
1 parent 902c268 commit 0d30670

File tree

7 files changed

+48
-51
lines changed

7 files changed

+48
-51
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
.git
12
.github
23
.pytest_cache
34
.ruff_cache
45
.tox
56
.venv
67
.gitignore
7-
makefile
8+
Makefile
89
__pycache__
910
tests
1011
.vscode

MANIFEST.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
include LICENSE
32
include README.md
43

54
recursive-exclude * __pycache__
6-
recursive-exclude * *.py[co]
5+
recursive-exclude * *.py[co]

makefile renamed to Makefile

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
1-
.PHONY: quality style unit-test integ-test
1+
.PHONY: quality style unit-test integ-test inference-pytorch-gpu inference-pytorch-cpu inference-pytorch-inf2 stop-all
22

3-
check_dirs := src tests
3+
check_dirs := src tests
44

5-
# run tests
5+
# Check that source code meets quality standards
6+
quality:
7+
ruff check $(check_dirs)
8+
9+
# Format source code automatically
10+
style:
11+
ruff check $(check_dirs) --fix
612

13+
# Run unit tests
714
unit-test:
815
RUN_SLOW=True python3 -m pytest -s -v tests/unit -n 10 --log-cli-level='ERROR'
916

17+
# Run integration tests
1018
integ-test:
1119
python3 -m pytest -s -v tests/integ/
1220

13-
# Check that source code meets quality standards
14-
15-
quality:
16-
ruff check $(check_dirs)
17-
18-
# Format source code automatically
19-
20-
style:
21-
ruff check $(check_dirs) --fix
22-
21+
# Build Docker image for PyTorch on GPU
2322
inference-pytorch-gpu:
2423
docker build -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:gpu .
2524

25+
# Build Docker image for PyTorch on CPU
2626
inference-pytorch-cpu:
2727
docker build --build-arg="BASE_IMAGE=ubuntu:22.04" -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:cpu .
2828

29+
# Build Docker image for PyTorch on AWS Inferentia2
2930
inference-pytorch-inf2:
3031
docker build -f dockerfiles/pytorch/Dockerfile.inf2 -t integration-test-pytorch:inf2 .
3132

32-
vertex-pytorch-gpu:
33-
docker build -t vertex -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:gpu .
34-
35-
vertex-pytorch-cpu:
36-
docker build -t vertex --build-arg="BASE_IMAGE=ubuntu:22.04" -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:cpu .
37-
33+
# Stop all and prune/clean the Docker Containers
3834
stop-all:
39-
docker stop $$(docker ps -a -q) && docker container prune --force
35+
docker stop $$(docker ps -a -q) && docker container prune --force

dockerfiles/pytorch/Dockerfile

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG BASE_IMAGE=nvidia/cuda:12.1.0-devel-ubuntu22.04
22

3-
FROM $BASE_IMAGE as base
3+
FROM $BASE_IMAGE AS base
44
SHELL ["/bin/bash", "-c"]
55

66
LABEL maintainer="Hugging Face"
@@ -25,9 +25,8 @@ RUN apt-get update && \
2525
cmake \
2626
libprotobuf-dev \
2727
protobuf-compiler \
28-
python3-dev \
29-
python3-pip \
3028
python3.11 \
29+
python3.11-dev \
3130
libsndfile1-dev \
3231
ffmpeg \
3332
&& apt-get clean autoremove --yes \
@@ -36,6 +35,15 @@ RUN apt-get update && \
3635
# Copying only necessary files as filtered by .dockerignore
3736
COPY . .
3837

38+
# Set Python 3.11 as the default python version
39+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
40+
ln -sf /usr/bin/python3.11 /usr/bin/python
41+
42+
# Install pip from source
43+
RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
44+
python get-pip.py && \
45+
rm get-pip.py
46+
3947
# install wheel and setuptools
4048
RUN pip install --no-cache-dir --upgrade pip ".[torch,st,diffusers]"
4149

@@ -44,11 +52,6 @@ COPY src/huggingface_inference_toolkit huggingface_inference_toolkit
4452
COPY src/huggingface_inference_toolkit/webservice_starlette.py webservice_starlette.py
4553

4654
# copy entrypoint and change permissions
47-
COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh
55+
COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh
4856

4957
ENTRYPOINT ["bash", "-c", "./entrypoint.sh"]
50-
51-
FROM base AS vertex
52-
53-
# Install `google` extra for Vertex AI compatibility
54-
RUN pip install --no-cache-dir --upgrade ".[google]"

pyproject.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ scripts_are_modules = true
55

66
[tool.ruff]
77
select = [
8-
"E", # pycodestyle errors
9-
"W", # pycodestyle warnings
10-
"F", # pyflakes
11-
"I", # isort
12-
"C", # flake8-comprehensions
13-
"B", # flake8-bugbear
8+
"E", # pycodestyle errors
9+
"W", # pycodestyle warnings
10+
"F", # pyflakes
11+
"I", # isort
12+
"C", # flake8-comprehensions
13+
"B", # flake8-bugbear
1414
]
1515
ignore = [
16-
"E501", # Line length (handled by ruff-format)
17-
"B008", # do not perform function calls in argument defaults
18-
"C901", # too complex
16+
"E501", # Line length (handled by ruff-format)
17+
"B008", # do not perform function calls in argument defaults
18+
"C901", # too complex
1919
]
2020
# Same as Black.
2121
line-length = 119
2222

2323
# Allow unused variables when underscore-prefixed.
2424
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
2525

26-
# Assume Python 3.11.
26+
# Assume Python 3.11
2727
target-version = "py311"
2828

2929
per-file-ignores = { "__init__.py" = ["F401"] }

scripts/entrypoint.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ PORT=5000
55

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

1111
# Check if HF_MODEL_DIR is set and if not skip installing custom dependencies
1212
if [[ ! -z "${HF_MODEL_DIR}" ]]; then
13-
# Check if requirements.txt exists and if so install dependencies
14-
if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then
15-
echo "Installing custom dependencies from ${HF_MODEL_DIR}/requirements.txt"
16-
pip install -r ${HF_MODEL_DIR}/requirements.txt --no-cache-dir;
17-
fi
13+
# Check if requirements.txt exists and if so install dependencies
14+
if [ -f "${HF_MODEL_DIR}/requirements.txt" ]; then
15+
echo "Installing custom dependencies from ${HF_MODEL_DIR}/requirements.txt"
16+
pip install -r ${HF_MODEL_DIR}/requirements.txt --no-cache-dir
17+
fi
1818
fi
1919

2020
# Start the server

setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@
6262
packages=find_packages(where="src"),
6363
install_requires=install_requires,
6464
extras_require=extras,
65-
entry_points={
66-
"console_scripts": "serve=sagemaker_huggingface_inference_toolkit.serving:main"
67-
},
65+
entry_points={"console_scripts": "serve=sagemaker_huggingface_inference_toolkit.serving:main"},
6866
python_requires=">=3.8",
6967
license="Apache License 2.0",
7068
classifiers=[

0 commit comments

Comments
 (0)