feat(server): Machine learning's image optimisations (#1908)

* Use multi stage build to slim down ML image size

* Use gunicorn as WSGI server in ML image

* Configure gunicorn server for ML use case

* Use requirements.txt file to install python dependencies in ML image

* Make ML listen IP configurable
This commit is contained in:
Olly Welch
2023-03-01 15:37:12 +00:00
committed by GitHub
parent 2a1dcbc28b
commit 977740045a
3 changed files with 79 additions and 10 deletions

View File

@@ -1,19 +1,26 @@
FROM python:3.10
FROM python:3.10 as builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=true
COPY requirements.txt ./
RUN python -m venv /opt/venv && \
/opt/venv/bin/pip install --upgrade pip setuptools wheel && \
/opt/venv/bin/pip install --no-deps -r requirements.txt
FROM python:3.10-slim
COPY --from=builder /opt/venv /opt/venv
ENV TRANSFORMERS_CACHE=/cache \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=true
PATH="/opt/venv/bin:$PATH"
WORKDIR /usr/src/app
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
RUN pip install transformers tqdm numpy scikit-learn scipy nltk sentencepiece flask Pillow
RUN pip install --no-deps sentence-transformers
COPY . .
CMD ["python", "src/main.py"]
CMD ["gunicorn", "src.main:server"]