共用方式為


PipelineParameter 類別

定義管線執行中的參數。

使用 PipelineParameters 建構多用途的 Pipelines,稍後可以使用不同的參數值重新提交。

初始化管線參數。

建構函式

PipelineParameter(name, default_value)

參數

名稱 Description
name
必要
str

管線參數的名稱。

default_value
必要

管線參數的預設值。

name
必要
str

管線參數的名稱。

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 新增至管線中的其他步驟,以提供一般值給管線中的多個步驟。 管線可以指定多個 PipelineParameters。

若要提交此管線,並指定 「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使用,以指定步驟輸入。 這可讓管線以不同的輸入數據執行。

搭配 PipelineParameters 使用 DataPath 的範例如下:


   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})