From 00b28a5d6873374d54c4dd9c2e3176dfce5099ad Mon Sep 17 00:00:00 2001 From: nsosio Date: Fri, 3 Nov 2023 16:40:31 +0100 Subject: [PATCH 1/5] added configurable port --- ebd-all-minilm/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ebd-all-minilm/main.py b/ebd-all-minilm/main.py index a624f51..8fb43df 100644 --- a/ebd-all-minilm/main.py +++ b/ebd-all-minilm/main.py @@ -1,3 +1,4 @@ +import argparse import logging import uvicorn @@ -41,4 +42,7 @@ def get_application() -> FastAPI: if __name__ == "__main__": - uvicorn.run("main:app", host="0.0.0.0", port=8000) + parser = argparse.ArgumentParser() + parser.add_argument("--port", help="Port to run model server on", type=int, default=8444) + args = parser.parse_args() + uvicorn.run("main:app", host="0.0.0.0", port=args.port) From 0f310d6cef5a465c148d71409728e2bd3400676a Mon Sep 17 00:00:00 2001 From: nsosio Date: Fri, 3 Nov 2023 17:37:17 +0100 Subject: [PATCH 2/5] added loading model from path --- ebd-all-minilm/main.py | 15 +++++++++++---- ebd-all-minilm/models.py | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ebd-all-minilm/main.py b/ebd-all-minilm/main.py index 8fb43df..7e68642 100644 --- a/ebd-all-minilm/main.py +++ b/ebd-all-minilm/main.py @@ -1,5 +1,6 @@ import argparse import logging +import os import uvicorn from dotenv import load_dotenv @@ -10,6 +11,15 @@ load_dotenv() +MODEL_PATH = f"./ml/models/{os.getenv('MODEL_ID', 'all-MiniLM-L6-v2')}" + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--port", help="Port to run model server on", type=int, default=8444) + parser.add_argument("--model-path", help="Path to model", default=MODEL_PATH) + args = parser.parse_args() + MODEL_PATH = args.model_path + logging.basicConfig( format="%(asctime)s %(levelname)-8s %(message)s", level=logging.INFO, @@ -19,7 +29,7 @@ def create_start_app_handler(app: FastAPI): def start_app() -> None: - SentenceTransformerBasedModel.get_model() + SentenceTransformerBasedModel.get_model(MODEL_PATH) return start_app @@ -42,7 +52,4 @@ def get_application() -> FastAPI: if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("--port", help="Port to run model server on", type=int, default=8444) - args = parser.parse_args() uvicorn.run("main:app", host="0.0.0.0", port=args.port) diff --git a/ebd-all-minilm/models.py b/ebd-all-minilm/models.py index 7ed2ed9..115ab95 100644 --- a/ebd-all-minilm/models.py +++ b/ebd-all-minilm/models.py @@ -12,10 +12,12 @@ def embeddings(cls, texts): return values.tolist() @classmethod - def get_model(cls): + def get_model(cls, model=None): if cls.model is None: + if model is None or not os.path.exists(model): + model = os.getenv("MODEL_ID", "all-MiniLM-L6-v2") cls.model = SentenceTransformer( - os.getenv("MODEL_ID", "all-MiniLM-L6-v2"), + model, device=os.getenv("DEVICE", "cpu"), ) return cls.model From a8e4707b9a59752299c02acba9cc6a9d10b518be Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 3 Nov 2023 19:46:52 +0000 Subject: [PATCH 3/5] sync with cht-llama-cpp --- ebd-all-minilm/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ebd-all-minilm/models.py b/ebd-all-minilm/models.py index 115ab95..184ad6d 100644 --- a/ebd-all-minilm/models.py +++ b/ebd-all-minilm/models.py @@ -12,12 +12,10 @@ def embeddings(cls, texts): return values.tolist() @classmethod - def get_model(cls, model=None): + def get_model(cls, model_path): if cls.model is None: - if model is None or not os.path.exists(model): - model = os.getenv("MODEL_ID", "all-MiniLM-L6-v2") cls.model = SentenceTransformer( - model, + model_path, device=os.getenv("DEVICE", "cpu"), ) return cls.model From 1142ace3758377c2e3620e856780db9c93a57db6 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 3 Nov 2023 19:49:11 +0000 Subject: [PATCH 4/5] bump versions --- ebd-all-minilm/build-aarch64-apple-darwin.sh | 2 +- ebd-all-minilm/build.sh | 2 +- ebd-all-minilm/models.py | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ebd-all-minilm/build-aarch64-apple-darwin.sh b/ebd-all-minilm/build-aarch64-apple-darwin.sh index 072befa..10ae98a 100755 --- a/ebd-all-minilm/build-aarch64-apple-darwin.sh +++ b/ebd-all-minilm/build-aarch64-apple-darwin.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -e -export VERSION=1.0.4 +export VERSION=1.0.5 test -f venv/bin/activate || python -m venv venv source venv/bin/activate diff --git a/ebd-all-minilm/build.sh b/ebd-all-minilm/build.sh index c112287..4c84146 100755 --- a/ebd-all-minilm/build.sh +++ b/ebd-all-minilm/build.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -export VERSION=1.0.4 +export VERSION=1.0.5 source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh" build_cpu ghcr.io/premai-io/embeddings-all-minilm-l6-v2-cpu all-MiniLM-L6-v2 ${@:1} diff --git a/ebd-all-minilm/models.py b/ebd-all-minilm/models.py index 184ad6d..afade91 100644 --- a/ebd-all-minilm/models.py +++ b/ebd-all-minilm/models.py @@ -14,8 +14,5 @@ def embeddings(cls, texts): @classmethod def get_model(cls, model_path): if cls.model is None: - cls.model = SentenceTransformer( - model_path, - device=os.getenv("DEVICE", "cpu"), - ) + cls.model = SentenceTransformer(model_path, device=os.getenv("DEVICE", "cpu")) return cls.model From 52c5969caf0b3dbed07483551843b4409e2c29f3 Mon Sep 17 00:00:00 2001 From: nsosio Date: Sat, 4 Nov 2023 13:46:34 +0100 Subject: [PATCH 5/5] change to model dir --- ebd-all-minilm/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ebd-all-minilm/main.py b/ebd-all-minilm/main.py index 7e68642..71bbead 100644 --- a/ebd-all-minilm/main.py +++ b/ebd-all-minilm/main.py @@ -11,14 +11,14 @@ load_dotenv() -MODEL_PATH = f"./ml/models/{os.getenv('MODEL_ID', 'all-MiniLM-L6-v2')}" +MODEL_DIR = os.getenv("MODEL_ID", "all-MiniLM-L6-v2") if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--port", help="Port to run model server on", type=int, default=8444) - parser.add_argument("--model-path", help="Path to model", default=MODEL_PATH) + parser.add_argument("--model-dir", help="Path to model dir", default=MODEL_DIR) args = parser.parse_args() - MODEL_PATH = args.model_path + MODEL_DIR = args.model_dir logging.basicConfig( format="%(asctime)s %(levelname)-8s %(message)s", @@ -29,7 +29,7 @@ def create_start_app_handler(app: FastAPI): def start_app() -> None: - SentenceTransformerBasedModel.get_model(MODEL_PATH) + SentenceTransformerBasedModel.get_model(MODEL_DIR) return start_app