From 1cc184ed107d6b3ca6ff449bd5d37cfa9cf3bab9 Mon Sep 17 00:00:00 2001 From: Zack Pollard <zackpollard@ymail.com> Date: Wed, 1 Mar 2023 17:48:35 +0000 Subject: [PATCH] Revert "feat(server): Machine learning's image optimisations (#1908)" (#1915) This reverts commit 977740045a6c1c29ea5edc4f22ad9377523c422d. --- machine-learning/Dockerfile | 27 ++++++++++--------------- machine-learning/gunicorn.conf.py | 29 --------------------------- machine-learning/requirements.txt | 33 ------------------------------- 3 files changed, 10 insertions(+), 79 deletions(-) delete mode 100644 machine-learning/gunicorn.conf.py delete mode 100644 machine-learning/requirements.txt diff --git a/machine-learning/Dockerfile b/machine-learning/Dockerfile index 80064c44bf..8e07778fe9 100644 --- a/machine-learning/Dockerfile +++ b/machine-learning/Dockerfile @@ -1,26 +1,19 @@ -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 +FROM python:3.10 ENV TRANSFORMERS_CACHE=/cache \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - PATH="/opt/venv/bin:$PATH" + PIP_NO_CACHE_DIR=true 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 ["gunicorn", "src.main:server"] +CMD ["python", "src/main.py"] diff --git a/machine-learning/gunicorn.conf.py b/machine-learning/gunicorn.conf.py deleted file mode 100644 index 0db0e8ee7d..0000000000 --- a/machine-learning/gunicorn.conf.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Gunicorn configuration options. -https://docs.gunicorn.org/en/stable/settings.html -""" -import os - - -# Set the bind address based on the env -port = os.getenv("MACHINE_LEARNING_PORT") or "3003" -listen_ip = os.getenv("MACHINE_LEARNING_IP") or "0.0.0.0" -bind = [f"{listen_ip}:{port}"] - -# Preload the Flask app / models etc. before starting the server -preload_app = True - -# Logging settings - log to stdout and set log level -accesslog = "-" -loglevel = os.getenv("MACHINE_LEARNING_LOG_LEVEL") or "info" - -# Worker settings -# ---------------------- -# It is important these are chosen carefully as per -# https://pythonspeed.com/articles/gunicorn-in-docker/ -# Otherwise we get workers failing to respond to heartbeat checks, -# especially as requests take a long time to complete. -workers = 2 -threads = 4 -worker_tmp_dir = "/dev/shm" -timeout = 60 diff --git a/machine-learning/requirements.txt b/machine-learning/requirements.txt deleted file mode 100644 index 4d0b78ec7f..0000000000 --- a/machine-learning/requirements.txt +++ /dev/null @@ -1,33 +0,0 @@ -certifi==2022.12.7 -charset-normalizer==3.0.1 -click==8.1.3 -filelock==3.9.0 -Flask==2.2.3 -gunicorn==20.1.0 -huggingface-hub==0.12.1 -idna==3.4 -importlib-metadata==6.0.0 -itsdangerous==2.1.2 -Jinja2==3.1.2 -joblib==1.2.0 -MarkupSafe==2.1.2 -nltk==3.8.1 -numpy==1.24.2 -packaging==23.0 -Pillow==9.4.0 -PyYAML==6.0 -regex==2022.10.31 -requests==2.28.2 -scikit-learn==1.2.1 -scipy==1.10.1 -sentence-transformers==2.2.2 -sentencepiece==0.1.97 -threadpoolctl==3.1.0 -tokenizers==0.13.2 -torch==1.13.1 -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html -tqdm==4.64.1 -transformers==4.26.1 -typing-extensions==4.5.0 -urllib3==1.26.14 -Werkzeug==2.2.3 -zipp==3.15.0