Skip to content

Commit 58dbab3

Browse files
committed
screenshots etc
1 parent c4f278f commit 58dbab3

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

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

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,70 @@ Hyperparameters are adjustable parameters that let you control the model trainin
2323

2424
## Prerequisites
2525

26-
- Understand the concepts of pipelines and hyperparameter tuning. For more information, see [Azure Machine Learning pipelines](concept-ml-pipelines.md) and [Hyperparameter tuning a model](how-to-tune-hyperparameters.md).
27-
- Have an Azure Machine Learning pipeline with a command component that takes hyperparameters as inputs. For more information, see [Create and run machine learning pipelines using components with the Azure Machine Learning CLI](how-to-create-component-pipelines-cli.md) or [Create and run machine learning pipelines using components with the Azure Machine Learning SDK v2](how-to-create-component-pipeline-python.md)
26+
- Have an Azure Machine Learning account and workspace.
27+
- Understand [Azure Machine Learning pipelines](concept-ml-pipelines.md) and [hyperparameter tuning a model](how-to-tune-hyperparameters.md).
2828

2929
## Create a pipeline with a hyperparameter sweep step
3030

31-
### CLI v2
31+
# [Azure CLI](#tab/cli)
3232

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.
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).
3434

35-
Assume you already have a command component defined in *train.yml*. The following code shows the two-step `train` and `predict` *pipeline.yml* file, with the `sweep_step` for hyperparameter tuning highlighted.
35+
# [Python SDK](#tab/python)
3636

37-
In the `sweep_step` code, the step type must be `sweep`. The `search_space` field shows three hyperparameters, `c_value`, `kernel`, and `coef`, and `trial` refers to the command component defined in *train.yml*.
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).
3838

39-
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep/pipeline.yml" highlight="7-48":::
39+
---
4040

41-
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 `sweep_step`. See [CLI (v2) sweep job YAML schema](reference-yaml-job-sweep.md) for the full sweep job schema.
41+
### Create a command component with hyperparameter inputs
4242

43-
The following code shows the `trial` component definition in the *train.yml* file.
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 in the *./train-src* folder.
4444

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

47-
The hyperparameters added to `search_space` in *pipeline.yml* must be inputs for the `trial` component. The source code of the trial component is under the *./train-src* folder. In this example, the code is a single *train.py* file. This code is executed in every trial of the sweep job.
48-
49-
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.yml* 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).
50-
51-
The following example shows the trial component source code.
47+
In this example, the source code is a single *train.py* file. This code executes in every trial of the sweep job. The following example shows the trial component source code:
5248

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

55-
### Python SDK
51+
### Create the pipeline job with hyperparameter sweep step
52+
53+
# [Azure CLI](#tab/cli)
54+
55+
Given the command component defined in *train.yml*, the following code shows a two-step `train` and `predict` *pipeline.yml* file with the hyperparameter tuning `sweep_step` highlighted. 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`.
5656

57-
The following Python SDK example comes 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.
57+
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/pipeline_with_hyperparameter_sweep/pipeline.yml" highlight="7-48":::
58+
59+
# [Python SDK](#tab/python)
5860

59-
In Azure Machine Learning Python SDK v2, you can enable hyperparameter tuning for any command component by the calling `.sweep()` method. The following code snippet shows how to enable sweep for `train_model`.
61+
In the v2 SDK, you can enable hyperparameter tuning for any command component by calling the `.sweep()` method. The following pipeline definition shows how to enable sweep for `train_model`.
6062

61-
The example first loads the `train_component_func` defined in the *train.yml* file. To create the `train_model`, the code adds `c_value`, `kernel`, and `coef0` into the search space. The `sweep_step` defines the `primary_metric`, `sampling_algorithm`, and other parameters.
63+
The example first loads the `train_component_func` defined in the *train.yml* file. To create the `train_model`, the code adds the `c_value`, `kernel`, and `coef0` hyperparameters into the search space. The `sweep_step` defines the `primary_metric`, `sampling_algorithm`, and other parameters.
6264

6365
[!notebook-python[] (~/azureml-examples-main/sdk/python/jobs/pipelines/1c_pipeline_with_hyperparameter_sweep/pipeline_with_hyperparameter_sweep.ipynb?name=enable-sweep)]
6466

67+
---
68+
>[!NOTE]
69+
>Make sure to log the metrics in the trial component source code with exactly the same names 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).
70+
71+
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`. See [CLI (v2) sweep job YAML schema](reference-yaml-job-sweep.md) for the full sweep job schema.
72+
6573
## Check a pipeline job with sweep step in studio
6674

67-
After you submit a pipeline job, the SDK or CLI widget provides a web URL link to the Azure Machine Learning studio UI. The link takes you to the pipeline graph view by default.
75+
After you submit a pipeline job, the SDK or CLI widget provides a web URL link to the pipeline graph view in the Azure Machine Learning studio UI.
6876

69-
To check details of the sweep step, double click the sweep step and navigate to the **Child jobs** tab in the detail panel.
77+
To check details of the sweep step, double click the sweep step in the graph and select the **Child jobs** tab in the detail panel.
7078

7179
:::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":::
7280

73-
Select a child job to go to the job page, and then select the **Child runs** tab,
81+
Select the child job to go to the job page, and then select the **Trials** tab to see and compare metrics for all the child runs. Select any of the child runs to see more details for that run.
7482

75-
:::image type="content" source="./media/how-to-use-sweep-in-pipeline/sweep-job.png" alt-text="Screenshot of the child job page with the child runs tab." lightbox= "./media/how-to-use-sweep-in-pipeline/sweep-job.png":::
83+
:::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":::
7684

77-
If a child job failed, select the **Outputs + logs** tab on the child job page to see useful debug information.
85+
If a child run failed, select the **Outputs + logs** tab on the child run page to see useful debug information.
7886

79-
:::image type="content" source="./media/how-to-use-sweep-in-pipeline/child-run.png" alt-text="Screenshot of the output + logs tab of a child run." lightbox= "./media/how-to-use-sweep-in-pipeline/child-run.png":::
87+
:::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":::
8088

81-
## Other sample notebooks
89+
## Other example notebooks
8290

8391
- [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)
8492
- [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)
-113 KB
Loading
-45.8 KB
Loading
-115 KB
Loading

0 commit comments

Comments
 (0)