Skip to content

Commit

Permalink
add pipeline component sample with primitive output (#2904)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Stephen1993 authored Dec 25, 2023
1 parent 342e602 commit e5f7809
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,18 @@
" 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",
" score_with_sample_data.outputs.score_output = Output(\n",
" 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
Expand All @@ -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}",
]
Expand All @@ -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}",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ conda_file:
- python=3.8.12
- pip=21.2.2
- pip:
- mldesigner==0.1.0b4
- mldesigner==0.1.0b17

0 comments on commit e5f7809

Please sign in to comment.