diff --git a/.github/workflows/finetuning-service-test.yml b/.github/workflows/finetuning-service-test.yml index 899807ed..a97137ff 100644 --- a/.github/workflows/finetuning-service-test.yml +++ b/.github/workflows/finetuning-service-test.yml @@ -33,16 +33,18 @@ jobs: cd services/finetuning poetry self add "poetry-dynamic-versioning[plugin]" poetry install -n --with dev - - name: Test local server tsfmfinetuning service with pytest + # for not we're not really using the image + # for much, we just want to make sure + # that it continues to build until we + # do so + - name: image build run: | source .venv/bin/activate cd services/finetuning - make boilerplate - pytest tests - - name: Test image server tsfmfinetuning service with pytest + make image + - name: test local run: | source .venv/bin/activate cd services/finetuning - make image - make test_image + make test_local \ No newline at end of file diff --git a/.github/workflows/inference-services-test.yml b/.github/workflows/inference-services-test.yml index 443c5380..d4ac6561 100644 --- a/.github/workflows/inference-services-test.yml +++ b/.github/workflows/inference-services-test.yml @@ -33,16 +33,13 @@ jobs: cd services/inference poetry self add "poetry-dynamic-versioning[plugin]" poetry install -n --with dev - - name: Clone models directory + - name: Test local server run: | - git lfs install - git clone https://huggingface.co/ibm/test-tsfm /tmp/test-tsfm - - name: Test local server tsfminference service with pytest + source .venv/bin/activate + cd services/inference + make test_local + - name: Test image run: | source .venv/bin/activate cd services/inference - make boilerplate - TSFM_MODEL_DIR=/tmp/test-tsfm make start_service_local - sleep 20 - pytest tests - make stop_service_local || true + make test_image \ No newline at end of file diff --git a/services/finetuning/Dockerfile b/services/finetuning/Dockerfile index 64406230..6ac0585e 100644 --- a/services/finetuning/Dockerfile +++ b/services/finetuning/Dockerfile @@ -1,11 +1,17 @@ # based on https://github.com/opendatahub-io/caikit-tgis-serving/blob/main/Dockerfile -FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS builder +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest +ARG PYTHON_VERSION=3.12 RUN microdnf -y update && \ microdnf -y install \ - git shadow-utils python3.11-pip python-wheel && \ - pip3.11 install --no-cache-dir --upgrade pip wheel && \ + git \ + shadow-utils \ + python${PYTHON_VERSION} \ + python${PYTHON_VERSION}-pip \ + python$(PYTHON_VERSION)-wheel && \ + pip${PYTHON_VERSION} install --no-cache-dir --upgrade pip wheel && \ + microdnf remove python3.9 python-unversioned-command python3-setuptools python3-wheel -y && \ microdnf clean all ENV POETRY_VIRTUALENVS_IN_PROJECT=1 @@ -15,17 +21,8 @@ COPY tsfmfinetuning/* /finetuning/tsfmfinetuning/ COPY pyproject.toml /finetuning/ COPY poetry.lock /finetuning/ WORKDIR /finetuning -RUN pip3.11 install poetry && poetry install +RUN pip${PYTHON_VERSION} install poetry && poetry install -FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS deploy -RUN microdnf -y update && \ - microdnf -y install \ - shadow-utils python3.11 && \ - microdnf clean all - -WORKDIR /finetuning - -COPY --from=builder /finetuning /finetuning ENV VIRTUAL_ENV=/finetuning/.venv ENV PATH="$VIRTUAL_ENV/bin:$PATH" @@ -38,4 +35,5 @@ RUN groupadd --system tsfmfinetuning --gid 1001 && \ USER tsfmfinetuning -CMD ["python","-m","gunicorn","-w","4","-k","uvicorn.workers.UvicornWorker","--bind","0.0.0.0:8000","tsfmfinetuning.main:app"] \ No newline at end of file +# currently finetuning is not a service hosting platform +# CMD ["python","-m","gunicorn","-w","4","-k","uvicorn.workers.UvicornWorker","--bind","0.0.0.0:8000","tsfmfinetuning.main:app"] diff --git a/services/finetuning/Makefile b/services/finetuning/Makefile index c9cefa12..0688d4b2 100644 --- a/services/finetuning/Makefile +++ b/services/finetuning/Makefile @@ -8,32 +8,11 @@ boilerplate: cat $$f>>tsfmfinetuning/$$(basename $$f); \ done - -# starts the tsfmfinetuning service (used mainly for test cases) -start_service_local: - python -m tsfmfinetuning.ftservice & - sleep 10 -stop_service_local: - pkill -f 'python.*tsfmfinetuning.*' - sleep 10 - image: $(CONTAINER_BUILDER) build -t tsfmfinetuning -f Dockerfile . -start_service_image: image - $(CONTAINER_BUILDER) run -p 8000:8000 -d --rm --name tsfmserver tsfmfinetuning - sleep 10 -stop_service_image: - $(CONTAINER_BUILDER) stop tsfmserver - -test_local: start_service_local - pytest tests - $(MAKE) stop_service_local - -test_image: start_service_image +test_local: boilerplate pytest tests install_dev: boilerplate pip install poetry && poetry install --with dev - - diff --git a/services/inference/Dockerfile b/services/inference/Dockerfile index a09a6564..8dc86bfd 100644 --- a/services/inference/Dockerfile +++ b/services/inference/Dockerfile @@ -1,11 +1,17 @@ # based on https://github.com/opendatahub-io/caikit-tgis-serving/blob/main/Dockerfile -FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS builder +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest +ARG PYTHON_VERSION=3.12 RUN microdnf -y update && \ microdnf -y install \ - git shadow-utils python3.11-pip python-wheel && \ - pip3.11 install --no-cache-dir --upgrade pip wheel && \ + git \ + shadow-utils \ + python${PYTHON_VERSION} \ + python${PYTHON_VERSION}-pip \ + python$(PYTHON_VERSION)-wheel && \ + pip${PYTHON_VERSION} install --no-cache-dir --upgrade pip wheel && \ + microdnf remove python3.9 python-unversioned-command python3-setuptools python3-wheel -y && \ microdnf clean all ENV POETRY_VIRTUALENVS_IN_PROJECT=1 @@ -15,17 +21,8 @@ COPY tsfminference/* /inference/tsfminference/ COPY pyproject.toml /inference/ COPY poetry.lock /inference/ WORKDIR /inference -RUN pip3.11 install poetry && poetry install +RUN pip${PYTHON_VERSION} install poetry && poetry install -FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS deploy -RUN microdnf -y update && \ - microdnf -y install \ - shadow-utils python3.11 && \ - microdnf clean all - -WORKDIR /inference - -COPY --from=builder /inference /inference ENV VIRTUAL_ENV=/inference/.venv ENV PATH="$VIRTUAL_ENV/bin:$PATH" diff --git a/services/inference/Makefile b/services/inference/Makefile index c8d64c2f..914737ad 100644 --- a/services/inference/Makefile +++ b/services/inference/Makefile @@ -10,7 +10,7 @@ boilerplate: # starts the tsfminference service (used mainly for test cases) start_service_local: boilerplate - python -m gunicorn \ + TSFM_MODEL_DIR=./mytest-tsfm python -m gunicorn \ -w 1 \ -k uvicorn.workers.UvicornWorker \ --bind 127.0.0.1:8000 \ @@ -22,31 +22,39 @@ image: boilerplate $(CONTAINER_BUILDER) build -t tsfminference -f Dockerfile . start_service_image: image - $(CONTAINER_BUILDER) run -p 8000:8000 -d --rm --name tsfmserver tsfminference - sleep 10 - -start_service_image_no_hf: image $(CONTAINER_BUILDER) run -p 8000:8000 \ - -e "TSFM_ALLOW_LOAD_FROM_HF_HUB=0" \ - -e "TSFM_MODEL_DIR=/" \ - -v ./ibm:/ibm \ - --rm --name tsfmserver tsfminference - sleep 10 + -d \ + --rm \ + --name tsfmserver \ + -e TSFM_MODEL_DIR=/mytest-tsfm \ + -e TSFM_ALLOW_LOAD_FROM_HF_HUB=1 \ + -v ./mytest-tsfm:/mytest-tsfm \ + tsfminference + sleep 5 stop_service_image: $(CONTAINER_BUILDER) stop tsfmserver -test_local: boilerplate start_service_local - pytest tests +test_local: clone_models boilerplate start_service_local + TSFM_ALLOW_LOAD_FROM_HF_HUB=1 TSFM_MODEL_DIR=./mytest-tsfm \ + pytest tests $(MAKE) stop_service_local + $(MAKE) delete_models -test_image: start_service_image - pytest tests +test_image: clone_models start_service_image + TSFM_MODEL_DIR=./ pytest tests $(MAKE) stop_service_image + $(MAKE) delete_models install_dev: boilerplate pip install poetry && poetry install --with dev +clone_models: + git lfs install || true + git clone https://huggingface.co/ibm/test-tsfm mytest-tsfm || true + +delete_models: + rm -rf mytest-tsfm || true diff --git a/services/inference/tests/test_inference.py b/services/inference/tests/test_inference.py index 3b9e9de5..010ac0bc 100644 --- a/services/inference/tests/test_inference.py +++ b/services/inference/tests/test_inference.py @@ -1,5 +1,7 @@ # Copyright contributors to the TSFM project # +import os +import tempfile from pathlib import Path from typing import Any, Dict @@ -98,7 +100,10 @@ def test_zero_shot_forecast_inference(ts_data): prediction_length = params["prediction_length"] context_length = params["context_length"] model_id = params["model_id"] - model_id_path = str(Path("/tmp/test-tsfm") / model_id) + model_dir = ( + Path(os.getenv("TSFM_MODEL_DIR")) if os.getenv("TSFM_MODEL_DIR") else Path(tempfile.gettempdir()) / "test-tsfm" + ) + model_id_path: Path = (model_dir / model_id).as_posix() id_columns = params["id_columns"]