From df30014c5d8e55f85ec16bc1d5bf747d0e4e5dda Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Tue, 16 Apr 2024 23:39:12 -0700 Subject: [PATCH] Build models and all downloads directly into docker containers --- backend/Dockerfile | 6 ++++++ backend/Dockerfile.model_server | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/backend/Dockerfile b/backend/Dockerfile index a61864fa2c0..09114aa4598 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -42,6 +42,12 @@ RUN apt-get remove -y --allow-remove-essential perl-base xserver-common xvfb cma rm -rf /var/lib/apt/lists/* && \ rm /usr/local/lib/python3.11/site-packages/tornado/test/test.key +# Pre-downloading NLTK for setups with limited egress +RUN python -c "import nltk; \ +nltk.download('stopwords', quiet=True); \ +nltk.download('wordnet', quiet=True); \ +nltk.download('punkt', quiet=True);" + # Set up application files WORKDIR /app COPY ./danswer /app/danswer diff --git a/backend/Dockerfile.model_server b/backend/Dockerfile.model_server index 365a553c9f1..89f24e2ac26 100644 --- a/backend/Dockerfile.model_server +++ b/backend/Dockerfile.model_server @@ -17,6 +17,16 @@ RUN pip install --no-cache-dir --upgrade -r /tmp/requirements.txt RUN apt-get remove -y --allow-remove-essential perl-base && \ apt-get autoremove -y +# Pre-downloading models for setups with limited egress +RUN python -c "from transformers import AutoModel, AutoTokenizer, TFDistilBertForSequenceClassification; \ +from huggingface_hub import snapshot_download; \ +AutoTokenizer.from_pretrained('danswer/intent-model'); \ +AutoTokenizer.from_pretrained('intfloat/e5-base-v2'); \ +AutoTokenizer.from_pretrained('mixedbread-ai/mxbai-rerank-xsmall-v1'); \ +snapshot_download('danswer/intent-model'); \ +snapshot_download('intfloat/e5-base-v2'); \ +snapshot_download('mixedbread-ai/mxbai-rerank-xsmall-v1')" + WORKDIR /app # Utils used by model server