CommandStep 类

创建运行命令的 Azure ML 管道步骤。

创建运行命令的 Azure ML 管道步骤。

继承
azureml.pipeline.core._python_script_step_base._PythonScriptStepBase
CommandStep

构造函数

CommandStep(command=None, name=None, compute_target=None, runconfig=None, runconfig_pipeline_params=None, inputs=None, outputs=None, params=None, source_directory=None, allow_reuse=True, version=None)

参数

command
liststr
默认值: None

要运行的命令,或可执行文件/脚本的路径(相对于 source_directory)。 除非与 .runconfig 一起提供,否则此项是必需的。 可以在单个字符串中将它与字符串参数一起指定,或者在列表中将它与输入/输出/PipelineParameter 一起指定。

name
str
默认值: None

步骤的名称。 如果未指定,则使用 command 中的第一个单词。

compute_target
DsvmComputeAmlComputeRemoteComputeHDInsightComputestrtuple
默认值: None

要使用的计算目标。 如果未指定,将使用 runconfig 中的目标。 此参数可以指定为计算目标对象或工作区中计算目标的字符串名称。 (可选)如果计算目标在管道创建时不可用,可能需要指定一个元组 ('compute target name', 'compute target type') 以避免提取计算目标对象(AmlCompute 类型为“AmlCompute”,RemoteCompute 类型为“VirtualMachine”)。

runconfig
ScriptRunConfigRunConfiguration
默认值: None

可选配置对象,用于封装在试验中提交训练运行所需的信息。

runconfig_pipeline_params
<xref:<xref:{str: PipelineParameter}>>
默认值: None

在运行时使用键值对重写 runconfig 属性,每个键值对分别具有 runconfig 属性的名称和该属性的 PipelineParameter。

支持的值:“NodeCount”、“MpiProcessCountPerNode”、“TensorflowWorkerCount”、“TensorflowParameterServerCount”

inputs
list[InputPortBindingDataReferencePortDataReferencePipelineData 或 <xref:azureml.pipeline.core.pipeline_output_dataset.PipelineOutputDataset> 或 DatasetConsumptionConfig]
默认值: None

输入端口绑定的列表。

outputs
list[PipelineDataOutputDatasetConfigPipelineOutputAbstractDatasetOutputPortBinding]
默认值: None

输出端口绑定的列表。

params
dict
默认值: None

使用“AML_PARAMETER_”注册为环境变量的名称/值对的字典。

source_directory
str
默认值: None

包含脚本、conda env 和步骤中使用的其他资源的文件夹。

allow_reuse
bool
默认值: True

指示当使用相同的设置重新运行时,该步骤是否应重用以前的结果。 默认情况下启用重用。 如果步骤内容(脚本/依赖项)以及输入和参数保持不变,则重用此步骤以前运行的输出。 重用该步骤时,不是将作业提交到计算,而是使前一运行的结果立即可供后续步骤使用。 如果使用 Azure 机器学习数据集作为输入,则重用取决于数据集的定义是否已更改,而不是基础数据是否已更改。

version
str
默认值: None

一个可选的版本标记,用于表示该步骤的功能更改。

command
liststr
必需

要运行的命令,或可执行文件/脚本的路径(相对于 source_directory)。 除非与 .runconfig 一起提供,否则此项是必需的。 可以在单个字符串中将它与字符串参数一起指定,或者在列表中将它与输入/输出/PipelineParameter 一起指定。

name
str
必需

步骤的名称。 如果未指定,则使用 command 中的第一个单词。

compute_target
DsvmComputeAmlComputeRemoteComputeHDInsightComputestrtuple
必需

要使用的计算目标。 如果未指定,将使用 runconfig 中的目标。 此参数可以指定为计算目标对象或工作区中计算目标的字符串名称。 (可选)如果计算目标在管道创建时不可用,可能需要指定一个元组 ('compute target name', 'compute target type') 以避免提取计算目标对象(AmlCompute 类型为“AmlCompute”,RemoteCompute 类型为“VirtualMachine”)。

runconfig
ScriptRunConfigRunConfiguration
必需

可选配置对象,用于封装在试验中提交训练运行所需的信息。

runconfig_pipeline_params
<xref:<xref:{str: PipelineParameter}>>
必需

在运行时使用键值对重写 runconfig 属性,每个键值对分别具有 runconfig 属性的名称和该属性的 PipelineParameter。

支持的值:“NodeCount”、“MpiProcessCountPerNode”、“TensorflowWorkerCount”、“TensorflowParameterServerCount”

inputs
list[InputPortBindingDataReferencePortDataReferencePipelineData 或 <xref:azureml.pipeline.core.pipeline_output_dataset.PipelineOutputDataset> 或 DatasetConsumptionConfig]
必需

输入端口绑定的列表。

outputs
list[PipelineDataOutputDatasetConfigPipelineOutputAbstractDatasetOutputPortBinding]
必需

输出端口绑定的列表。

params
dict
必需

使用“AML_PARAMETER_”注册为环境变量的名称/值对的字典。

source_directory
str
必需

包含脚本、conda env 和步骤中使用的其他资源的文件夹。

allow_reuse
bool
必需

指示当使用相同的设置重新运行时,该步骤是否应重用以前的结果。 默认情况下启用重用。 如果步骤内容(脚本/依赖项)以及输入和参数保持不变,则重用此步骤以前运行的输出。 重用该步骤时,不是将作业提交到计算,而是使前一运行的结果立即可供后续步骤使用。 如果使用 Azure 机器学习数据集作为输入,则重用取决于数据集的定义是否已更改,而不是基础数据是否已更改。

version
str
必需

一个可选的版本标记,用于表示该步骤的功能更改。

注解

CommandStep 是在给定计算目标上运行命令的基本内置步骤。 它采用某个用作参数的命令,或者从其他参数(例如 runconfig)取值。 它还接受其他可选参数,例如计算目标、输入和输出。 应使用 ScriptRunConfigRunConfiguration 来指定 CommandStep 的要求,例如自定义 docker 映像。

使用 CommandStep 的最佳做法是为可执行文件或脚本使用单独的文件夹来运行与步骤关联的任何相关文件,并使用 source_directory 参数指定该文件夹。 遵循此最佳做法有两个好处。 首先,它有助于减少为该步骤创建的快照的大小,因为只有该步骤需要进行快照操作。 其次,如果 source_directory 没有任何更改会触发快照的重新上传,则可以重用前一次运行的步骤输出。

对于系统已知的命令,source_directory 不是必需的,但你仍可为它提供与步骤关联的任何相关文件。

以下代码示例演示如何在机器学习训练方案中使用 CommandStep。 列出 Linux 中的文件:


   from azureml.pipeline.steps import CommandStep

   trainStep = CommandStep(name='list step',
                           command='ls -lrt',
                           compute_target=compute_target)

运行 Python 脚本:


   from azureml.pipeline.steps import CommandStep

   trainStep = CommandStep(name='train step',
                           command='python train.py arg1 arg2',
                           source_directory=project_folder,
                           compute_target=compute_target)

通过 ScriptRunConfig 运行 Python 脚本:


   from azureml.core import ScriptRunConfig
   from azureml.pipeline.steps import CommandStep

   train_src = ScriptRunConfig(source_directory=script_folder,
                               command='python train.py arg1 arg2',
                               environment=my_env)
   trainStep = CommandStep(name='train step',
                           runconfig=train_src)

有关创建管道的更多详细信息,请参阅 https://aka.ms/pl-first-pipeline

方法

create_node

为 CommandStep 创建节点并将其添加到指定的图。

此方法不能直接使用。 通过此步骤实例化管道时,Azure ML 会自动通过此方法传递所需的参数,以便可以将步骤添加到表示工作流的管道图中。

create_node

为 CommandStep 创建节点并将其添加到指定的图。

此方法不能直接使用。 通过此步骤实例化管道时,Azure ML 会自动通过此方法传递所需的参数,以便可以将步骤添加到表示工作流的管道图中。

create_node(graph, default_datastore, context)

参数

graph
Graph
必需

要添加节点的图形对象。

default_datastore
AbstractAzureStorageDatastoreAzureDataLakeDatastore
必需

默认数据存储。

context
<xref:_GraphContext>
必需

图形上下文。

返回

创建的节点。

返回类型