Skip to content

Commit 16ee8fb

Browse files
Merge pull request #246395 from Blackmist/expressions
adding info about expressions
2 parents cdc4cec + 1cbd50b commit 16ee8fb

File tree

7 files changed

+86
-5
lines changed

7 files changed

+86
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: 'SDK and CLI v2 expressions'
3+
titleSuffix: Azure Machine Learning
4+
description: SDK and CLI v2 use expressions when a value may not be known when authoring a job or component.
5+
services: machine-learning
6+
ms.service: machine-learning
7+
ms.subservice: core
8+
ms.topic: conceptual
9+
ms.author: zhanxia
10+
author: xiaoharper
11+
ms.reviewer: larryfr
12+
ms.date: 07/26/2023
13+
ms.custom: cliv2, sdkv2
14+
---
15+
16+
# Expressions in Azure Machine Learning SDK and CLI v2
17+
18+
With Azure Machine Learning SDK and CLI v2, you can use _expressions_ when a value may not be known when you're authoring a job or component. When you submit a job or call a component, the expression is evaluated and the value is substituted.
19+
20+
The format for an expression is `${{ <expression> }}`. Some expressions are evaluated on the _client_, when submitting the job or component. Other expressions are evaluated on the _server_ (the compute where the job or component is running.)
21+
22+
## Client expressions
23+
24+
> [!NOTE]
25+
> The "client" that evaluates the expression is where the job is submitted or component is ran. For example, your local machine or a compute instance.
26+
27+
| Expression | Description | Scope |
28+
| ---- | ---- | ---- |
29+
| `${{inputs.<input_name>}}` | References to an input data asset or model. | Works for all jobs. |
30+
| `${{outputs.<output_name>}}` | References to an output data asset or model. | Works for all jobs. |
31+
| `${{search_space.<hyperparameter>}}` | References the hyperparameters to use in a sweep job. The hyperparameter values for each trial are selected based on the `search_space`. | Sweep jobs only. |
32+
| `${{parent.inputs.<input_name>}}` | Binds the inputs of a child job (pipeline step) in a pipeline to the inputs of the top-level parent pipeline job. | Pipeline jobs only. |
33+
| `${{parent.outputs.<output_name>}}` | Binds the outputs of a child job (pipeline step) in a pipeline to the outputs of the top-level parent pipeline job. | Pipeline jobs only. |
34+
| `${{parent.jobs.<step-name>.inputs.<input-name>}}` | Binds to the inputs of another step in the pipeline. | Pipeline jobs only. |
35+
| `${{parent.jobs.<step-name>.outputs.<output-name>}}` | Binds to the outputs of another step in the pipeline. | Pipeline jobs only. |
36+
37+
## Server expressions
38+
39+
[!INCLUDE [output-path-expressions](includes/output-path-expressions.md)]
40+
41+
## Next steps
42+
43+
For more information on these expressions, see the following articles and examples:
44+
45+
* [CLI v2 core YAML syntax](reference-yaml-core-syntax.md#expression-syntax-for-configuring-azure-machine-learning-jobs-and-components)
46+
* [Hyperparameter tuning a model](how-to-tune-hyperparameters.md)
47+
* [Tutorial: ML pipelines with Python SDK v2](tutorial-pipeline-python-sdk.md)
48+
* [Create and run component-based ML pipelines (CLI)](how-to-create-component-pipelines-cli.md)
49+
* [Example: Iris batch prediction notebook](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/parallel/2a_iris_batch_prediction/iris_batch_prediction.ipynb)
50+
* [Example: Pipeline YAML file](https://github.com/Azure/azureml-examples/blob/main/cli/jobs/pipelines-with-components/nyc_taxi_data_regression/pipeline.yml)

articles/machine-learning/concept-ml-pipelines.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Azure Machine Learning pipelines are a powerful facility that begins delivering
7878
+ [Define pipelines with Designer](./how-to-create-component-pipelines-ui.md)
7979
+ Try out [CLI v2 pipeline example](https://github.com/Azure/azureml-examples/tree/sdk-preview/cli/jobs/pipelines-with-components)
8080
+ Try out [Python SDK v2 pipeline example](https://github.com/Azure/azureml-examples/tree/main/sdk/python/jobs/pipelines)
81+
+ Learn about [SDK and CLI v2 expressions](concept-expressions.md) that can be used in a pipeline.
8182
:::moniker-end
8283
:::moniker range="azureml-api-1"
8384
+ [Create and run machine learning pipelines](v1/how-to-create-machine-learning-pipelines.md)

articles/machine-learning/how-to-train-model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ curl -X PUT \
180180

181181
# [Python SDK](#tab/python)
182182

183-
To run this script, you'll use a `command` that executes main.py Python script located under ./sdk/python/jobs/single-step/lightgbm/iris/src/. The command will be run by submitting it as a `job` to Azure ML.
183+
To run this script, you'll use a `command` that executes main.py Python script located under ./sdk/python/jobs/single-step/lightgbm/iris/src/. The command will be run by submitting it as a `job` to Azure Machine Learning.
184184

185185
> [!NOTE]
186186
> To use [serverless compute (preview)](./how-to-use-serverless-compute.md), delete `compute="cpu-cluster"` in this code.
@@ -193,7 +193,7 @@ In the above examples, you configured:
193193
- `code` - path where the code to run the command is located
194194
- `command` - command that needs to be run
195195
- `environment` - the environment needed to run the training script. In this example, we use a curated or ready-made environment provided by Azure Machine Learning called `AzureML-lightgbm-3.2-ubuntu18.04-py37-cpu`. We use the latest version of this environment by using the `@latest` directive. You can also use custom environments by specifying a base docker image and specifying a conda yaml on top of it.
196-
- `inputs` - dictionary of inputs using name value pairs to the command. The key is a name for the input within the context of the job and the value is the input value. Inputs are referenced in the `command` using the `${{inputs.<input_name>}}` expression. To use files or folders as inputs, you can use the `Input` class.
196+
- `inputs` - dictionary of inputs using name value pairs to the command. The key is a name for the input within the context of the job and the value is the input value. Inputs are referenced in the `command` using the `${{inputs.<input_name>}}` expression. To use files or folders as inputs, you can use the `Input` class. For more information, see [SDK and CLI v2 expressions](concept-expressions.md).
197197

198198
For more information, see the [reference documentation](/python/api/azure-ai-ml/azure.ai.ml#azure-ai-ml-command).
199199

@@ -212,7 +212,7 @@ The `az ml job create` command used in this example requires a YAML job definiti
212212
In the above, you configured:
213213
- `code` - path where the code to run the command is located
214214
- `command` - command that needs to be run
215-
- `inputs` - dictionary of inputs using name value pairs to the command. The key is a name for the input within the context of the job and the value is the input value. Inputs are referenced in the `command` using the `${{inputs.<input_name>}}` expression.
215+
- `inputs` - dictionary of inputs using name value pairs to the command. The key is a name for the input within the context of the job and the value is the input value. Inputs are referenced in the `command` using the `${{inputs.<input_name>}}` expression. For more information, see [SDK and CLI v2 expressions](concept-expressions.md).
216216
- `environment` - the environment needed to run the training script. In this example, we use a curated or ready-made environment provided by Azure Machine Learning called `AzureML-sklearn-0.24-ubuntu18.04-py37-cpu`. We use the latest version of this environment by using the `@latest` directive. You can also use custom environments by specifying a base docker image and specifying a conda yaml on top of it.
217217
To submit the job, use the following command. The run ID (name) of the training job is stored in the `$run_id` variable:
218218

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: machine-learning
5+
author: blackmist
6+
ms.service: machine-learning
7+
ms.author: larryfr
8+
ms.custom: "include file"
9+
ms.topic: "include"
10+
ms.date: 07/26/2023
11+
---
12+
13+
> [!IMPORTANT]
14+
> The following expressions are resolved on the _server_ side, not the _client_ side. For scheduled jobs where the job _creation time_ and job _submission time_ are different, the expressions are resolved when the job is submitted. Since these expressions are resolved on the server side, they use the _current_ state of the workspace, not the state of the workspace when the scheduled job was created. For example, if you change the default datastore of the workspace after you create a scheduled job, the expression `${{default_datastore}}` is resolved to the new default datastore, not the default datastore when the scheduled job was created.
15+
16+
| Expression | Description | Scope |
17+
| --- | --- | --- |
18+
| `${{default_datastore}}` | If pipeline default datastore is configured, is resolved as pipeline default datastore name; otherwise is resolved as workspace default datastore name. <br><br> Pipeline default datastore can be controlled using `pipeline_job.settings.default_datastore`. | Works for all jobs. <br><br> Pipeline jobs have a configurable pipeline default datastore. |
19+
| `${{name}}` | The job name. For pipelines, it's the step job name, not the pipeline job name. | Works for all jobs |
20+
| `${{output_name}}` | The job output name | Works for all jobs |
21+
22+
For example, if `azureml://datastores/${{default_datastore}}/paths/{{$name}}/${{output_name}}` is used as the output path, at runtime it's resolved as a path of `azureml://datastores/workspaceblobstore/paths/<job-name>/model_path`.

articles/machine-learning/reference-yaml-core-syntax.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Similar to the `command` for a job, the `command` for a component can also be pa
213213

214214
#### Define optional inputs in command line
215215
When the input is set as `optional = true`, you need use `$[[]]` to embrace the command line with inputs. For example `$[[--input1 ${{inputs.input1}}]`. The command line at runtime may have different inputs.
216-
- If you are using only specify the required `training_data` and `model_output` parameters, the command line will look like:
216+
- If you are using only the required `training_data` and `model_output` parameters, the command line will look like:
217217

218218
```cli
219219
python train.py --training_data some_input_path --learning_rate 0.01 --learning_rate_schedule time-based --model_output some_output_path
@@ -226,6 +226,12 @@ If no value is specified at runtime, `learning_rate` and `learning_rate_schedule
226226
python train.py --training_data some_input_path --max_epocs 10 --learning_rate 0.01 --learning_rate_schedule time-based --model_output some_output_path
227227
```
228228

229+
### Output path expressions
230+
231+
The following expressions can be used in the output path of your job:
232+
233+
[!INCLUDE [output path expressions](includes/output-path-expressions.md)]
234+
229235
## Next steps
230236

231237
* [Install and use the CLI (v2)](how-to-configure-cli.md)

articles/machine-learning/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@
516516
href: how-to-train-model.md
517517
- name: Training with UI
518518
href: how-to-train-with-ui.md
519+
- name: CLI and Python SDK v2 expressions
520+
href: concept-expressions.md
519521
- name: Using secrets in training
520522
href: how-to-use-secrets-in-runs.md
521523
- name: Custom Training

articles/machine-learning/tutorial-pipeline-python-sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ if __name__ == "__main__":
326326

327327
Now that you have a script that can perform the desired task, create an Azure Machine Learning Component from it.
328328

329-
Use the general purpose `CommandComponent` that can run command line actions. This command line action can directly call system commands or run a script. The inputs/outputs are specified on the command line via the `${{ ... }}` notation.
329+
Use the general purpose `CommandComponent` that can run command line actions. This command line action can directly call system commands or run a script. The inputs/outputs are specified on the command line via the `${{ ... }}` (expression) notation. For more information, see [SDK and CLI v2 expressions](concept-expressions.md).
330330

331331

332332

0 commit comments

Comments
 (0)