PipelineParameter 类
在管道执行中定义参数。
使用 PipelineParameters 构造通用管道,以后可以使用不同的参数值重新提交这些管道。
初始化管道参数。
构造函数
PipelineParameter(name, default_value)
参数
名称 | 说明 |
---|---|
name
必需
|
管道参数的名称。 |
default_value
必需
|
管道参数的默认值。 |
name
必需
|
管道参数的名称。 |
default_value
必需
|
管道参数的默认值。 |
注解
在构造管道时,可以将 PipelineParameters 添加到任何步骤。 提交管道后,可以指定这些参数的值。
将 PipelineParameter 添加到步骤的示例如下所示:
from azureml.pipeline.steps import PythonScriptStep
from azureml.pipeline.core import PipelineParameter
pipeline_param = PipelineParameter(name="pipeline_arg", default_value="default_val")
train_step = PythonScriptStep(script_name="train.py",
arguments=["--param1", pipeline_param],
target=compute_target,
source_directory=project_folder)
在此示例中,将名为“pipeline_arg”的 PipelineParameter 添加到 PythonScriptStep 的参数中。 运行 Python 脚本时,PipelineParameter 的值将通过命令行参数提供。 还可以将此 PipelineParameter 添加到管道中的其他步骤中,以便为管道中的多个步骤提供通用值。 管道可以指定多个 PipelineParameter。
若要提交此管道并指定“pipeline_arg”PipelineParameter 使用的值:
pipeline = Pipeline(workspace=ws, steps=[train_step])
pipeline_run = Experiment(ws, 'train').submit(pipeline, pipeline_parameters={"pipeline_arg": "test_value"})
注意:如果未在pipeline_parameters字典中指定“pipeline_arg”,则使用构造管道时提供的 PipelineParameter 的默认值(在本例中提供的默认值为“default_val”)。
多行参数不能用作 PipelineParameters。
PipelineParameters 还可用于 DataPath 和 DataPathComputeBinding 指定步骤输入。 这使管道可以使用不同的输入数据运行。
将 DataPath 与 PipelineParameters 配合使用的示例如下所示:
from azureml.core.datastore import Datastore
from azureml.data.datapath import DataPath, DataPathComputeBinding
from azureml.pipeline.steps import PythonScriptStep
from azureml.pipeline.core import PipelineParameter
datastore = Datastore(workspace=workspace, name="workspaceblobstore")
datapath = DataPath(datastore=datastore, path_on_datastore='input_data')
data_path_pipeline_param = (PipelineParameter(name="input_data", default_value=datapath),
DataPathComputeBinding(mode='mount'))
train_step = PythonScriptStep(script_name="train.py",
arguments=["--input", data_path_pipeline_param],
inputs=[data_path_pipeline_param],
compute_target=compute_target,
source_directory=project_folder)
在这种情况下,“input_data”参数的默认值引用名为“input_data”的“workspaceblobstore”上的文件。 如果提交管道时未为此 PipelineParameter 指定值,将使用默认值。 若要提交此管道并指定“input_data”PipelineParameter 使用的值:
from azureml.pipeline.core import Pipeline
from azureml.data.datapath import DataPath
pipeline = Pipeline(workspace=ws, steps=[train_step])
new_data_path = DataPath(datastore=datastore, path_on_datastore='new_input_data')
pipeline_run = experiment.submit(pipeline,
pipeline_parameters={"input_data": new_data_path})