Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify sample pipeline input parameters #611

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions config/internal/apiserver/sample-pipeline/sample-pipeline.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ data:
# PIPELINE DEFINITION
# Name: iris-training-pipeline
# Inputs:
# min_max_scaler: bool
# neighbors: int
# standard_scaler: bool
# neighbors: int [Default: 3.0]
# standard_scaler: bool [Default: True]
# Outputs:
# train-model-metrics: system.ClassificationMetrics
components:
Expand All @@ -35,8 +34,6 @@ data:
schemaTitle: system.Dataset
schemaVersion: 0.0.1
parameters:
min_max_scaler:
parameterType: BOOLEAN
standard_scaler:
parameterType: BOOLEAN
outputDefinitions:
Expand Down Expand Up @@ -80,15 +77,18 @@ data:
- -c
- "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\
\ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.0.1'\
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.7.0'\
\ '--no-deps' 'typing-extensions>=3.7.4,<5; python_version<\"3.9\"' &&\
\ python3 -m pip install --quiet --no-warn-script-location 'pandas==2.2.0'\
\ && \"$0\" \"$@\"\n"
- sh
- -ec
- 'program_path=$(mktemp -d)


printf "%s" "$0" > "$program_path/ephemeral_component.py"

python3 -m kfp.components.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"
_KFP_RUNTIME=true python3 -m kfp.dsl.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"

'
- "\nimport kfp\nfrom kfp import dsl\nfrom kfp.dsl import *\nfrom typing import\
Expand All @@ -97,7 +97,7 @@ data:
\ col_names = [\n 'Sepal_Length', 'Sepal_Width', 'Petal_Length',\
\ 'Petal_Width', 'Labels'\n ]\n df = pd.read_csv(csv_url, names=col_names)\n\
\n with open(iris_dataset.path, 'w') as f:\n df.to_csv(f)\n\n"
image: quay.io/hukhan/iris-base:1
image: quay.io/opendatahub/ds-pipelines-sample-base:v1.0
gmfrasca marked this conversation as resolved.
Show resolved Hide resolved
exec-normalize-dataset:
container:
args:
Expand All @@ -110,32 +110,31 @@ data:
- -c
- "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\
\ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.0.1'\
\ && \"$0\" \"$@\"\n"
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.7.0'\
\ '--no-deps' 'typing-extensions>=3.7.4,<5; python_version<\"3.9\"' &&\
\ python3 -m pip install --quiet --no-warn-script-location 'pandas==2.2.0'\
\ 'scikit-learn==1.4.0' && \"$0\" \"$@\"\n"
- sh
- -ec
- 'program_path=$(mktemp -d)


printf "%s" "$0" > "$program_path/ephemeral_component.py"

python3 -m kfp.components.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"
_KFP_RUNTIME=true python3 -m kfp.dsl.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"

'
- "\nimport kfp\nfrom kfp import dsl\nfrom kfp.dsl import *\nfrom typing import\
\ *\n\ndef normalize_dataset(\n input_iris_dataset: Input[Dataset],\n\
\ normalized_iris_dataset: Output[Dataset],\n standard_scaler: bool,\n\
\ min_max_scaler: bool,\n):\n if standard_scaler is min_max_scaler:\n\
\ raise ValueError(\n 'Exactly one of standard_scaler\
\ or min_max_scaler must be True.')\n\n import pandas as pd\n from\
\ sklearn.preprocessing import MinMaxScaler\n from sklearn.preprocessing\
\ import StandardScaler\n\n with open(input_iris_dataset.path) as f:\n\
\ df = pd.read_csv(f)\n labels = df.pop('Labels')\n\n if standard_scaler:\n\
\ scaler = StandardScaler()\n if min_max_scaler:\n scaler\
\ = MinMaxScaler()\n\n df = pd.DataFrame(scaler.fit_transform(df))\n\
\ df['Labels'] = labels\n normalized_iris_dataset.metadata['state']\
\ = \"Normalized\"\n with open(normalized_iris_dataset.path, 'w') as\
\ f:\n df.to_csv(f)\n\n"
image: quay.io/hukhan/iris-base:1
):\n\n import pandas as pd\n from sklearn.preprocessing import MinMaxScaler\n\
\ from sklearn.preprocessing import StandardScaler\n\n with open(input_iris_dataset.path)\
\ as f:\n df = pd.read_csv(f)\n labels = df.pop('Labels')\n\n\
\ scaler = StandardScaler() if standard_scaler else MinMaxScaler()\n\n\
\ df = pd.DataFrame(scaler.fit_transform(df))\n df['Labels'] = labels\n\
\ normalized_iris_dataset.metadata['state'] = \"Normalized\"\n with\
\ open(normalized_iris_dataset.path, 'w') as f:\n df.to_csv(f)\n\n"
image: quay.io/opendatahub/ds-pipelines-sample-base:v1.0
exec-train-model:
container:
args:
Expand All @@ -148,35 +147,39 @@ data:
- -c
- "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\
\ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.0.1'\
\ && \"$0\" \"$@\"\n"
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.7.0'\
\ '--no-deps' 'typing-extensions>=3.7.4,<5; python_version<\"3.9\"' &&\
\ python3 -m pip install --quiet --no-warn-script-location 'pandas==2.2.0'\
\ 'scikit-learn==1.4.0' && \"$0\" \"$@\"\n"
- sh
- -ec
- 'program_path=$(mktemp -d)


printf "%s" "$0" > "$program_path/ephemeral_component.py"

python3 -m kfp.components.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"
_KFP_RUNTIME=true python3 -m kfp.dsl.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@"

'
- "\nimport kfp\nfrom kfp import dsl\nfrom kfp.dsl import *\nfrom typing import\
\ *\n\ndef train_model(\n normalized_iris_dataset: Input[Dataset],\n\
\ model: Output[Model],\n metrics: Output[ClassificationMetrics],\n\
\ n_neighbors: int,\n):\n import pickle\n\n import pandas as pd\n\
\ from sklearn.neighbors import KNeighborsClassifier\n\n from sklearn.metrics\
\ import roc_curve\n from sklearn.model_selection import train_test_split,\
\ cross_val_predict\n from sklearn.metrics import confusion_matrix\n\n\
\n with open(normalized_iris_dataset.path) as f:\n df = pd.read_csv(f)\n\
\n y = df.pop('Labels')\n X = df\n\n X_train, X_test, y_train,\
\ y_test = train_test_split(X, y, random_state=0)\n\n clf = KNeighborsClassifier(n_neighbors=n_neighbors)\n\
\ from sklearn.model_selection import train_test_split\n from sklearn.neighbors\
\ import KNeighborsClassifier\n\n from sklearn.metrics import roc_curve\n\
\ from sklearn.model_selection import train_test_split, cross_val_predict\n\
\ from sklearn.metrics import confusion_matrix\n\n\n with open(normalized_iris_dataset.path)\
\ as f:\n df = pd.read_csv(f)\n\n y = df.pop('Labels')\n X\
\ = df\n\n X_train, X_test, y_train, y_test = train_test_split(X, y,\
\ random_state=0)\n\n clf = KNeighborsClassifier(n_neighbors=n_neighbors)\n\
\ clf.fit(X_train, y_train)\n\n predictions = cross_val_predict(\n\
\ clf, X_train, y_train, cv=3)\n metrics.log_confusion_matrix(\n\
\ ['Iris-Setosa', 'Iris-Versicolour', 'Iris-Virginica'],\n \
\ confusion_matrix(\n y_train,\n predictions).tolist()\
\ # .tolist() to convert np array to list.\n )\n\n model.metadata['framework']\
\ = 'scikit-learn'\n with open(model.path, 'wb') as f:\n pickle.dump(clf,\
\ f)\n\n"
image: quay.io/hukhan/iris-base:1
image: quay.io/opendatahub/ds-pipelines-sample-base:v1.0
pipelineInfo:
name: iris-training-pipeline
root:
Expand Down Expand Up @@ -209,9 +212,6 @@ data:
outputArtifactKey: iris_dataset
producerTask: create-dataset
parameters:
min_max_scaler:
runtimeValue:
constant: false
standard_scaler:
runtimeValue:
constant: true
Expand All @@ -237,14 +237,13 @@ data:
name: train-model
inputDefinitions:
parameters:
min_max_scaler:
defaultValue: true
parameterType: BOOLEAN
neighbors:
defaultValue: 3
defaultValue: 3.0
isOptional: true
parameterType: NUMBER_INTEGER
standard_scaler:
defaultValue: false
defaultValue: true
isOptional: true
parameterType: BOOLEAN
outputDefinitions:
artifacts:
Expand All @@ -253,7 +252,7 @@ data:
schemaTitle: system.ClassificationMetrics
schemaVersion: 0.0.1
schemaVersion: 2.1.0
sdkVersion: kfp-2.0.1
sdkVersion: kfp-2.7.0
{{ else }}
apiVersion: v1
kind: ConfigMap
Expand Down
Loading
Loading