Skip to content

Commit 5a4b59d

Browse files
committed
changes
1 parent 4a39449 commit 5a4b59d

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

articles/machine-learning/how-to-use-sweep-in-pipeline.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
---
22
title: How to do hyperparameter sweep in pipelines
33
titleSuffix: Azure Machine Learning
4-
description: Learn how to use sweep to do hyperparameter tuning in Azure Machine Learning pipeline using CLI v2 and Python SDK.
4+
description: Learn how to use sweep to automate hyperparameter tuning in Azure Machine Learning pipelines with CLI v2 and Python SDK v2.
55
services: machine-learning
66
ms.service: azure-machine-learning
77
ms.subservice: mlops
88
ms.topic: how-to
99
author: lgayhardt
1010
ms.author: lagayhar
1111
ms.reviewer: zhanxia
12-
ms.date: 09/18/2024
12+
ms.date: 09/19/2024
1313
ms.custom: devx-track-python, sdkv2, cliv2, update-code2
1414
---
1515

1616
# How to do hyperparameter tuning in pipelines
1717

1818
[!INCLUDE [dev v2](includes/machine-learning-dev-v2.md)]
1919

20-
In this article, you learn how to do hyperparameter tuning in Azure Machine Learning pipelines by using Azure Machine Learning CLI v2 or Azure Machine Learning SDK for Python v2.
20+
In this article, you learn how to automate hyperparameter tuning in Azure Machine Learning pipelines by using Azure Machine Learning CLI v2 or Azure Machine Learning SDK for Python v2.
2121

22-
Hyperparameters are adjustable parameters that let you control the model training process. Hyperparameter tuning is the process of finding the configuration of hyperparameters that results in the best performance. Azure Machine Learning lets you automate hyperparameter tuning and run experiments in parallel to efficiently optimize hyperparameters.
22+
Hyperparameters are adjustable parameters that let you control the model training process. Hyperparameter tuning is the process of finding the configuration of hyperparameters that results in the best performance. Azure Machine Learning lets you automate hyperparameter tuning and [run experiments in parallel](how-to-use-parallel-job-in-pipeline.md) to efficiently optimize hyperparameters.
2323

2424
## Prerequisites
2525

2626
- Have an Azure Machine Learning account and workspace.
2727
- Understand [Azure Machine Learning pipelines](concept-ml-pipelines.md) and [hyperparameter tuning a model](how-to-tune-hyperparameters.md).
2828

29-
## Create a pipeline with a hyperparameter sweep step
29+
## Create and run a hyperparameter tuning pipeline
3030

3131
# [Azure CLI](#tab/cli)
3232

33-
The following Azure CLI examples come from [Run a pipeline job using sweep (hyperdrive) in pipeline](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep) in the [Azure Machine Learning examples](https://github.com/Azure/azureml-examples) repository. For more information about creating pipelines with components, see [Create and run machine learning pipelines using components with the Azure Machine Learning CLI](how-to-create-component-pipelines-cli.md).
33+
The following examples come from [Run a pipeline job using sweep (hyperdrive) in pipeline](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep) in the [Azure Machine Learning examples](https://github.com/Azure/azureml-examples) repository. For more information about creating pipelines with components, see [Create and run machine learning pipelines using components with the Azure Machine Learning CLI](how-to-create-component-pipelines-cli.md).
3434

3535
# [Python SDK](#tab/python)
3636

37-
The following Python SDK examples come from [Build pipeline with sweep node](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/pipelines/1c_pipeline_with_hyperparameter_sweep/pipeline_with_hyperparameter_sweep.ipynb) in the [Azure Machine Learning examples](https://github.com/Azure/azureml-examples) repository. For more information about creating pipelines with components, see [Create and run machine learning pipelines using components with the Azure Machine Learning SDK v2](how-to-create-component-pipeline-python.md).
37+
The following examples come from the [Build pipeline with sweep node](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/pipelines/1c_pipeline_with_hyperparameter_sweep/pipeline_with_hyperparameter_sweep.ipynb) notebook in the [Azure Machine Learning examples](https://github.com/Azure/azureml-examples) repository. For more information about creating pipelines with components, see [Create and run machine learning pipelines using components with the Azure Machine Learning SDK v2](how-to-create-component-pipeline-python.md).
38+
39+
For a related notebook, see [Run hyperparameter sweep on a command job](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/single-step/lightgbm/iris/lightgbm-iris-sweep.ipynb).
3840

3941
---
4042

4143
### Create a command component with hyperparameter inputs
4244

43-
The Azure Machine Learning pipeline must have a command component with hyperparameter inputs. The following *train.yml* file defines a `trial` component that has the `c_value`, `kernel`, and `coef` hyperparameter inputs and runs the source code that's located in the *./train-src* folder.
45+
The Azure Machine Learning pipeline must have a command component with hyperparameter inputs. The following *train.yml* file from the example projects defines a `trial` component that has the `c_value`, `kernel`, and `coef` hyperparameter inputs and runs the source code that's located in the *./train-src* folder.
4446

4547
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep/train.yml" highlight="11-16,23-25,60":::
4648

4749
### Create the trial component source code
4850

49-
The example source code for this example is a single *train.py* file. This code executes in every trial of the sweep job. The following code shows the trial component source code:
51+
The source code for this example is a single *train.py* file. This code executes in every trial of the sweep job.
5052

5153
:::code language="python" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep/train-src/train.py" highlight="15":::
5254

5355
>[!NOTE]
5456
>Make sure to log the metrics in the trial component source code with exactly the same name as the `primary_metric` value in the pipeline file. This example uses `mlflow.autolog()`, which is the recommended way to track machine learning experiments. For more information about MLflow, see [Track ML experiments and models with MLflow](./how-to-use-mlflow-cli-runs.md).
5557
56-
### Create the pipeline job with hyperparameter sweep step
58+
### Create a pipeline with a hyperparameter sweep step
5759

5860
# [Azure CLI](#tab/cli)
5961

60-
Given the command component defined in *train.yml*, the following code creates a two-step `train` and `predict` pipeline definition file. In the `sweep_step`, the required step type is `sweep`, and the `c_value`, `kernel`, and `coef` hyperparameter inputs for the `trial` component are added to the `search_space`. The following example highlights the hyperparameter tuning `sweep_step`.
62+
Given the command component defined in *train.yml*, the following code creates a two-step `train` and `predict` pipeline definition file. In the `sweep_step`, the required step type is `sweep`, and the `c_value`, `kernel`, and `coef` hyperparameter inputs for the `trial` component are added to the `search_space`.
63+
64+
The following example highlights the hyperparameter tuning `sweep_step`.
6165

6266
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep/pipeline.yml" highlight="8-48":::
6367

@@ -71,29 +75,28 @@ The example first loads the `train_component_func` defined in the *train.yml* fi
7175

7276
---
7377

74-
After you submit this pipeline job, Azure Machine Learning runs the `trial` component multiple times to sweep over hyperparameters, based on the search space and limits you defined in the `sweep_step`. For the full sweep job schema, see [CLI (v2) sweep job YAML schema](reference-yaml-job-sweep.md).
78+
For the full sweep job schema, see [CLI (v2) sweep job YAML schema](reference-yaml-job-sweep.md).
79+
80+
### Submit the hyperparameter tuning pipeline job
7581

76-
## Check a pipeline job with sweep step in studio
82+
After you submit this pipeline job, Azure Machine Learning runs the `trial` component multiple times to sweep over hyperparameters, based on the search space and limits you defined in the `sweep_step`.
83+
84+
## View hyperparameter tuning results in studio
7785

7886
After you submit a pipeline job, the SDK or CLI widget gives you a web URL link to the pipeline graph in the Azure Machine Learning studio UI.
7987

80-
To details of the sweep step, double click the sweep step in the pipeline graph, select the **Child jobs** tab in the details panel, and then select the child job.
88+
To view hyperparameter tuning results, double-click the sweep step in the pipeline graph, select the **Child jobs** tab in the details panel, and then select the child job.
8189

8290
:::image type="content" source="./media/how-to-use-sweep-in-pipeline/pipeline-view.png" alt-text="Screenshot of the pipeline with child job and the train_model node highlighted." lightbox= "./media/how-to-use-sweep-in-pipeline/pipeline-view.png":::
8391

8492
On the child job page, select the **Trials** tab to see and compare metrics for all the child runs. Select any of the child runs to see the details for that run.
8593

8694
:::image type="content" source="./media/how-to-use-sweep-in-pipeline/sweep-job.png" alt-text="Screenshot of the child job page with the Trials tab." lightbox= "./media/how-to-use-sweep-in-pipeline/sweep-job.png":::
8795

88-
If a child run failed, select the **Outputs + logs** tab on the child run page to see useful debug information.
96+
If a child run failed, you can select the **Outputs + logs** tab on the child run page to see useful debug information.
8997

9098
:::image type="content" source="./media/how-to-use-sweep-in-pipeline/child-run.png" alt-text="Screenshot of the output and logs tab of a child run." lightbox= "./media/how-to-use-sweep-in-pipeline/child-run.png":::
9199

92-
## Other example notebooks
93-
94-
- [Build pipeline with sweep node](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/pipelines/1c_pipeline_with_hyperparameter_sweep/pipeline_with_hyperparameter_sweep.ipynb)
95-
- [Run hyperparameter sweep on a command job](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/single-step/lightgbm/iris/lightgbm-iris-sweep.ipynb)
96-
97100
## Related content
98101

99102
- [Track an experiment](how-to-log-view-metrics.md)

0 commit comments

Comments
 (0)