|
| 1 | +--- |
| 2 | +title: How to use pipeline component in pipeline |
| 3 | +titleSuffix: Azure Machine Learning |
| 4 | +description: How to use pipeline component to build nested pipeline job in Azure Machine Learning pipeline using CLI v2 and Python SDK |
| 5 | +services: machine-learning |
| 6 | +ms.service: machine-learning |
| 7 | +ms.subservice: mlops |
| 8 | +ms.topic: how-to |
| 9 | +author: cloga |
| 10 | +ms.author: lochen |
| 11 | +ms.reviewer: lagayhar |
| 12 | +ms.date: 04/12/2023 |
| 13 | +ms.custom: sdkv2, cliv2, |
| 14 | +--- |
| 15 | + |
| 16 | +# How to use pipeline component to build nested pipeline job (V2) (preview) |
| 17 | + |
| 18 | +[!INCLUDE [dev v2](../../includes/machine-learning-dev-v2.md)] |
| 19 | + |
| 20 | +When developing a complex machine learning pipeline, it's common to have sub-pipelines that use multi-step to perform tasks such as data preprocessing and model training. These sub-pipelines can be developed and tested standalone. Pipeline component groups multi-step as a component that can be used as a single step to create complex pipelines. Which will help you share your work and better collaborate with team members. |
| 21 | + |
| 22 | +By using a pipeline component, the author can focus on developing sub-tasks and easily integrate them with the entire pipeline job. Furthermore, a pipeline component has a well-defined interface in terms of inputs and outputs, which means that user of the pipeline component doesn't need to know the implementation details of the component. |
| 23 | + |
| 24 | +In this article, you'll learn how to use pipeline component in Azure Machine Learning pipeline. |
| 25 | + |
| 26 | +[!INCLUDE [machine-learning-preview-generic-disclaimer](../../includes/machine-learning-preview-generic-disclaimer.md)] |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +- Understand how to use Azure Machine Learning pipeline with [CLI v2](how-to-create-component-pipelines-cli.md) and [SDK v2](how-to-create-component-pipeline-python.md). |
| 31 | +- Understand what is [component](concept-component.md) and how to use component in Azure Machine Learning pipeline. |
| 32 | +- Understand what is a [Azure Machine Learning pipeline](concept-ml-pipelines.md) |
| 33 | + |
| 34 | +## The difference between pipeline job and pipeline component |
| 35 | + |
| 36 | +In general, pipeline component is similar to pipeline job. They're both consist of a group of jobs/components. |
| 37 | + |
| 38 | +Here are some main differences you need aware when defining pipeline component: |
| 39 | + |
| 40 | +- Pipeline component only defines the interface of inputs/outputs, which means when defining a pipeline component you need to explicitly define the type of inputs/outputs instead of directly assigning values to them. |
| 41 | +- Pipeline component can't have runtime settings, you can't hard-code compute, or data node in the pipeline component. Instead you need to promote them as pipeline level inputs and assign values during runtime. |
| 42 | +- Pipeline level settings such as default_datastore and default_compute are also runtime settings. They aren't part of pipeline component definition. |
| 43 | + |
| 44 | +### CLI v2 |
| 45 | + |
| 46 | +The example used in this article can be found in [azureml-example repo](https://github.com/Azure/azureml-examples). Navigate to *azureml-examples/cli/jobs/pipelines-with-components/pipeline_with_pipeline_component* to check the example. |
| 47 | + |
| 48 | +You can use multi-components to build a pipeline component. Similar to how you built pipeline job with component. This is two step pipeline component. |
| 49 | + |
| 50 | +:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component/components/train_pipeline_component.yml" highlight="7-48"::: |
| 51 | + |
| 52 | +When reference pipeline component to define child job in a pipeline job, just like reference other type of component. You can provide runtime settings such as default_datastore, default_compute in pipeline job level, any parameter you want to change during run time need promote as pipeline job inputs, otherwise, they'll be hard-code in next pipeline component. We're support to promote compute as pipeline component input to support heterogenous pipeline, which may need different compute target in different steps. |
| 53 | + |
| 54 | +:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component/pipeline.yml" highlight="11-16,23-25,60"::: |
| 55 | + |
| 56 | +### Python SDK |
| 57 | + |
| 58 | +The python SDK example can be found in [azureml-example repo](https://github.com/Azure/azureml-examples). Navigate to *azureml-examples/sdk/python/jobs/pipelines/1j_pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component* to check the example. |
| 59 | + |
| 60 | +You can define a pipeline component using a Python function, which is similar to defining a pipeline job using a function. You can also promote the compute of some step to be used as inputs for the pipeline component. |
| 61 | + |
| 62 | +[!notebook-python[] (~/azureml-examples-main/sdk/python/jobs/pipelines/1j_pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component/pipeline_with_train_eval_pipeline_component.ipynb?name=pipeline-component)] |
| 63 | + |
| 64 | +You can use pipeline component as a step like other components in pipeline job. |
| 65 | + |
| 66 | +[!notebook-python[] (~/azureml-examples-main/sdk/python/jobs/pipelines/1j_pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component/pipeline_with_train_eval_pipeline_component.ipynb?name=pipeline-component-pipeline-job)] |
| 67 | + |
| 68 | +## Pipeline job with pipeline component in studio |
| 69 | + |
| 70 | +You can use `az ml component create` or `ml_client.components.create_or_update` to register pipeline component as a registered component. After that you can view the component in asset library and component list page. |
| 71 | + |
| 72 | +### Using pipeline component to build pipeline job |
| 73 | + |
| 74 | +After you register the pipeline component, you can drag and drop the pipeline component into the designer canvas and use the UI to build pipeline job. |
| 75 | + |
| 76 | +:::image type="content" source="./media/how-to-use-pipeline-component/pipeline-component-authoring.png" alt-text="Screenshot of the designer canvas page to build pipeline job with pipeline component." lightbox= "./media/how-to-use-pipeline-component/pipeline-component-authoring.png"::: |
| 77 | + |
| 78 | +### View pipeline job using pipeline component |
| 79 | + |
| 80 | +After submitted pipeline job, you can go to pipeline job detail page to change pipeline component status, you can also drill down to child component in pipeline component to debug specific component. |
| 81 | + |
| 82 | +:::image type="content" source="./media/how-to-use-pipeline-component/pipeline-component-right-panel.png" alt-text="Screenshot of view pipeline component on the pipeline job detail page." lightbox= "./media/how-to-use-pipeline-component/pipeline-component-right-panel.png"::: |
| 83 | + |
| 84 | +## Sample notebooks |
| 85 | + |
| 86 | +- [nyc_taxi_data_regression_with_pipeline_component](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/pipelines/1j_pipeline_with_pipeline_component/nyc_taxi_data_regression_with_pipeline_component/nyc_taxi_data_regression_with_pipeline_component.ipynb) |
| 87 | +- [pipeline_with_train_eval_pipeline_component](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/pipelines/1j_pipeline_with_pipeline_component/pipeline_with_train_eval_pipeline_component/pipeline_with_train_eval_pipeline_component.ipynb) |
| 88 | + |
| 89 | +## Next steps |
| 90 | +- [YAML reference for pipeline component](reference-yaml-component-pipeline.md) |
| 91 | +- [Track an experiment](how-to-log-view-metrics.md) |
| 92 | +- [Deploy a trained model](how-to-deploy-managed-online-endpoints.md) |
0 commit comments