From dd9b268226f9348943fdc192bf030b9d9550b8d6 Mon Sep 17 00:00:00 2001 From: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:56:50 +0100 Subject: [PATCH 1/2] Add imagespec Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> --- .gitignore | 1 + .../{{cookiecutter.project_name}}/Dockerfile | 26 ------------------- .../image-requirements.txt | 2 ++ .../local-requirements.txt | 3 +++ .../requirements.txt | 3 --- .../workflows/wine_classification_example.py | 18 ++++++++----- 6 files changed, 17 insertions(+), 36 deletions(-) delete mode 100644 wine-classification/{{cookiecutter.project_name}}/Dockerfile create mode 100644 wine-classification/{{cookiecutter.project_name}}/image-requirements.txt create mode 100644 wine-classification/{{cookiecutter.project_name}}/local-requirements.txt delete mode 100644 wine-classification/{{cookiecutter.project_name}}/requirements.txt diff --git a/.gitignore b/.gitignore index 3228387..a26c2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea .venv +.DS_Store diff --git a/wine-classification/{{cookiecutter.project_name}}/Dockerfile b/wine-classification/{{cookiecutter.project_name}}/Dockerfile deleted file mode 100644 index c848bb8..0000000 --- a/wine-classification/{{cookiecutter.project_name}}/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM python:3.10-slim-buster - -WORKDIR /root -ENV VENV /opt/venv -ENV LANG C.UTF-8 -ENV LC_ALL C.UTF-8 -ENV PYTHONPATH /root - -RUN apt-get update && apt-get install -y build-essential - -ENV VENV /opt/venv -# Virtual environment -RUN python3 -m venv ${VENV} -ENV PATH="${VENV}/bin:$PATH" - -# Install Python dependencies -COPY requirements.txt /root -RUN pip install -r /root/requirements.txt - -# Copy the actual code -COPY . /root - -# This tag is supplied by the build script and will be used to determine the version -# when registering tasks, workflows, and launch plans -ARG tag -ENV FLYTE_INTERNAL_IMAGE $tag diff --git a/wine-classification/{{cookiecutter.project_name}}/image-requirements.txt b/wine-classification/{{cookiecutter.project_name}}/image-requirements.txt new file mode 100644 index 0000000..fda4dd6 --- /dev/null +++ b/wine-classification/{{cookiecutter.project_name}}/image-requirements.txt @@ -0,0 +1,2 @@ +pandas +scikit-learn diff --git a/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt b/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt new file mode 100644 index 0000000..d2267f5 --- /dev/null +++ b/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt @@ -0,0 +1,3 @@ +flytekit +flytekitplugins-envd +-r image-requirements.txt diff --git a/wine-classification/{{cookiecutter.project_name}}/requirements.txt b/wine-classification/{{cookiecutter.project_name}}/requirements.txt deleted file mode 100644 index bcdd339..0000000 --- a/wine-classification/{{cookiecutter.project_name}}/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -flytekit>=1.5.0 -pandas==1.5.3 -scikit-learn==1.2.2 diff --git a/wine-classification/{{cookiecutter.project_name}}/workflows/wine_classification_example.py b/wine-classification/{{cookiecutter.project_name}}/workflows/wine_classification_example.py index 607930e..a08b144 100644 --- a/wine-classification/{{cookiecutter.project_name}}/workflows/wine_classification_example.py +++ b/wine-classification/{{cookiecutter.project_name}}/workflows/wine_classification_example.py @@ -2,19 +2,26 @@ from sklearn.datasets import load_wine from sklearn.linear_model import LogisticRegression -from flytekit import task, workflow +from flytekit import ImageSpec, task, workflow -@task +image_spec = ImageSpec( + registry="ghcr.io/", + name="wine-classification-image", + base_image="ghcr.io/flyteorg/flytekit:py3.11-latest", + requirements="image-requirements.txt" +) + +@task(container_image=image_spec) def get_data() -> pd.DataFrame: """Get the wine dataset.""" return load_wine(as_frame=True).frame -@task +@task(container_image=image_spec) def process_data(data: pd.DataFrame) -> pd.DataFrame: """Simplify the task from a 3-class to a binary classification problem.""" return data.assign(target=lambda x: x["target"].where(x["target"] == 0, 1)) -@task +@task(container_image=image_spec) def train_model(data: pd.DataFrame, hyperparameters: dict) -> LogisticRegression: """Train a model on the wine dataset.""" features = data.drop("target", axis="columns") @@ -30,6 +37,3 @@ def training_workflow(hyperparameters: dict = {"C": 0.1}) -> LogisticRegression: data=processed_data, hyperparameters=hyperparameters, ) - -if __name__ == "__main__": - training_workflow(hyperparameters={"C": 0.1}) From 97b76c433fd7ccd85722c1a5accd4d878c696c7e Mon Sep 17 00:00:00 2001 From: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> Date: Wed, 29 May 2024 18:13:49 +0200 Subject: [PATCH 2/2] change package flytekit to unionai Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> --- .../{{cookiecutter.project_name}}/local-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt b/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt index d2267f5..80fa69f 100644 --- a/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt +++ b/wine-classification/{{cookiecutter.project_name}}/local-requirements.txt @@ -1,3 +1,3 @@ -flytekit +unionai flytekitplugins-envd -r image-requirements.txt