Skip to content

Commit

Permalink
Merge pull request #162 from ibm-granite/cve
Browse files Browse the repository at this point in the history
CVE
  • Loading branch information
ssiegel95 authored Oct 22, 2024
2 parents 0716938 + 7a8addc commit fb8238c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 79 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/finetuning-service-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 6 additions & 9 deletions .github/workflows/inference-services-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 12 additions & 14 deletions services/finetuning/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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"]
# 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"]
23 changes: 1 addition & 22 deletions services/finetuning/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


23 changes: 10 additions & 13 deletions services/inference/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
36 changes: 22 additions & 14 deletions services/inference/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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



7 changes: 6 additions & 1 deletion services/inference/tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright contributors to the TSFM project
#
import os
import tempfile
from pathlib import Path
from typing import Any, Dict

Expand Down Expand Up @@ -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"]

Expand Down

0 comments on commit fb8238c

Please sign in to comment.