Skip to content

Commit

Permalink
Download embedding model in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Feb 11, 2024
1 parent 9b2ba00 commit 7883b2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ RUN mkdir /tmp/vespa-cli \
&& cp -r /tmp/vespa-cli/share/* /usr/local/share/ \
&& rm -rf /tmp/vespa-cli.tar.gz /tmp/vespa-cli

# Download embedding model, which gets deployed by setup_vespa.py
ADD "https://github.com/vespa-engine/sample-apps/raw/master/simple-semantic-search/model/e5-small-v2-int8.onnx" /opt/models/model.onnx
ADD "https://raw.githubusercontent.com/vespa-engine/sample-apps/master/simple-semantic-search/model/tokenizer.json" /opt/models/tokenizer.json


# `builder-base` stage is used to build deps + create our virtual environment
FROM python-base as builder-base
Expand Down
6 changes: 6 additions & 0 deletions radis/vespa/management/commands/setup_vespa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import subprocess
import tempfile
from pathlib import Path
Expand Down Expand Up @@ -85,6 +86,11 @@ def handle(self, *args, **options):
configurator = VespaConfigurator(app_folder)
configurator.apply()

models_folder = app_folder / "files" / "models"
models_folder.mkdir()
shutil.copy("/opt/models/model.onnx", models_folder)
shutil.copy("/opt/models/tokenizer.json", models_folder)

if options["deploy"]:
vespa_host: str
if options["host"]:
Expand Down
8 changes: 2 additions & 6 deletions radis/vespa/vespa_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
)

REPORT_SCHEMA_NAME = "report"
EMBEDDER_MODEL_URL = "https://github.com/vespa-engine/sample-apps/raw/master/\
simple-semantic-search/model/e5-small-v2-int8.onnx"
TOKENIZER_MODEL_URL = "https://raw.githubusercontent.com/vespa-engine/sample-apps/master/\
simple-semantic-search/model/tokenizer.json"


def _create_report_schema():
Expand Down Expand Up @@ -128,11 +124,11 @@ def _create_app_package(schemas: list[Schema]):
parameters=[
Parameter(
"transformer-model",
{"url": EMBEDDER_MODEL_URL},
{"path": "files/models/model.onnx"},
),
Parameter(
"tokenizer-model",
{"url": TOKENIZER_MODEL_URL},
{"path": "files/models/tokenizer.json"},
),
],
)
Expand Down

0 comments on commit 7883b2e

Please sign in to comment.