From e5f7809040876d5a42485615d271be6af23c6357 Mon Sep 17 00:00:00 2001 From: chenyang <583695898@qq.com> Date: Mon, 25 Dec 2023 11:56:05 +0800 Subject: [PATCH] add pipeline component sample with primitive output (#2904) * add pipeline component sample with primitive output * add pipeline component sample with primitive output * add pipeline component sample with primitive output * add pipeline component sample with primitive output * upgrade mldesigner version to fix bug with not support string output * modify notebook * modify notebook * modify notebook * modify notebook * update component * update component * update component --- ...pipeline_with_python_function_components.ipynb | 7 +++++-- .../src/components.py | 15 ++++++++++++--- .../src/env.yaml | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/pipeline_with_python_function_components.ipynb b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/pipeline_with_python_function_components.ipynb index 04d49b6404b..e934848f810 100644 --- a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/pipeline_with_python_function_components.ipynb +++ b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/pipeline_with_python_function_components.ipynb @@ -196,7 +196,9 @@ " training_data=input_data, max_epochs=5, learning_rate=learning_rate\n", " )\n", " score_with_sample_data = score_data(\n", - " model_input=train_with_sample_data.outputs.model_output, test_data=test_data\n", + " model_input=train_with_sample_data.outputs.model_output,\n", + " test_data=test_data,\n", + " model_file=train_with_sample_data.outputs.output,\n", " )\n", " # example how to change path of output on step level,\n", " # please note if the output is promoted to pipeline level you need to change path in pipeline job level\n", @@ -204,7 +206,8 @@ " type=\"uri_folder\", mode=\"rw_mount\", path=custom_path\n", " )\n", " eval_with_sample_data = eval_model(\n", - " scoring_result=score_with_sample_data.outputs.score_output\n", + " scoring_result=score_with_sample_data.outputs.score_output,\n", + " scoring_file=score_with_sample_data.outputs.output,\n", " )\n", "\n", " # Return: pipeline outputs\n", diff --git a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/components.py b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/components.py index 4b6e2345f23..3214dc84746 100644 --- a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/components.py +++ b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/components.py @@ -12,7 +12,7 @@ def train_model( max_epochs: int, model_output: Output(type="uri_folder"), learning_rate=0.02, -): +) -> str: """A dummy train component. Args: @@ -37,6 +37,8 @@ def train_model( model = str(uuid4()) (Path(model_output) / "model").write_text(model) + return str((Path(model_output) / "model")) + @command_component( display_name="Score", @@ -50,11 +52,13 @@ def score_data( model_input: Input(type="uri_folder"), test_data: Input(type="uri_file"), score_output: Output(type="uri_folder"), -): + model_file: str = None, +) -> str: """A dummy score component.""" lines = [ f"Model path: {model_input}", + f"Model file: {model_file}", f"Test data path: {test_data}", f"Scoring output path: {score_output}", ] @@ -71,15 +75,20 @@ def score_data( # Here only print text to output file as demo (Path(score_output) / "score").write_text("scored with {}".format(model)) + return str(Path(score_output) / "score") + @command_component(display_name="Evaluate", environment="./env.yaml") def eval_model( - scoring_result: Input(type="uri_folder"), eval_output: Output(type="uri_folder") + scoring_result: Input(type="uri_folder"), + eval_output: Output(type="uri_folder"), + scoring_file: str = None, ): """A dummy evaluate component.""" lines = [ f"Scoring result path: {scoring_result}", + f"Scoring file: {scoring_file}", f"Evaluation output path: {eval_output}", ] diff --git a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/env.yaml b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/env.yaml index cabcd394989..af04ef35bba 100644 --- a/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/env.yaml +++ b/sdk/python/jobs/pipelines/1b_pipeline_with_python_function_components/src/env.yaml @@ -11,4 +11,4 @@ conda_file: - python=3.8.12 - pip=21.2.2 - pip: - - mldesigner==0.1.0b4 \ No newline at end of file + - mldesigner==0.1.0b17 \ No newline at end of file