CommandStep 类
创建运行命令的 Azure ML 管道步骤。
创建运行命令的 Azure ML 管道步骤。
- 继承
-
azureml.pipeline.core._python_script_step_base._PythonScriptStepBaseCommandStep
构造函数
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)
参数
要运行的命令,或可执行文件/脚本的路径(相对于 source_directory
)。
除非与 .runconfig 一起提供,否则此项是必需的。 可以在单个字符串中将它与字符串参数一起指定,或者在列表中将它与输入/输出/PipelineParameter 一起指定。
- compute_target
- DsvmCompute 或 AmlCompute 或 RemoteCompute 或 HDInsightCompute 或 str 或 tuple
要使用的计算目标。 如果未指定,将使用 runconfig
中的目标。 此参数可以指定为计算目标对象或工作区中计算目标的字符串名称。
(可选)如果计算目标在管道创建时不可用,可能需要指定一个元组 ('compute target name', 'compute target type') 以避免提取计算目标对象(AmlCompute 类型为“AmlCompute”,RemoteCompute 类型为“VirtualMachine”)。
- runconfig_pipeline_params
- <xref:<xref:{str: PipelineParameter}>>
在运行时使用键值对重写 runconfig 属性,每个键值对分别具有 runconfig 属性的名称和该属性的 PipelineParameter。
支持的值:“NodeCount”、“MpiProcessCountPerNode”、“TensorflowWorkerCount”、“TensorflowParameterServerCount”
- inputs
- list[InputPortBinding 或 DataReference 或 PortDataReference 或 PipelineData 或 <xref:azureml.pipeline.core.pipeline_output_dataset.PipelineOutputDataset> 或 DatasetConsumptionConfig]
输入端口绑定的列表。
- outputs
- list[PipelineData 或 OutputDatasetConfig 或 PipelineOutputAbstractDataset 或 OutputPortBinding]
输出端口绑定的列表。
- allow_reuse
- bool
指示当使用相同的设置重新运行时,该步骤是否应重用以前的结果。 默认情况下启用重用。 如果步骤内容(脚本/依赖项)以及输入和参数保持不变,则重用此步骤以前运行的输出。 重用该步骤时,不是将作业提交到计算,而是使前一运行的结果立即可供后续步骤使用。 如果使用 Azure 机器学习数据集作为输入,则重用取决于数据集的定义是否已更改,而不是基础数据是否已更改。
要运行的命令,或可执行文件/脚本的路径(相对于 source_directory
)。
除非与 .runconfig 一起提供,否则此项是必需的。 可以在单个字符串中将它与字符串参数一起指定,或者在列表中将它与输入/输出/PipelineParameter 一起指定。
- compute_target
- DsvmCompute 或 AmlCompute 或 RemoteCompute 或 HDInsightCompute 或 str 或 tuple
要使用的计算目标。 如果未指定,将使用 runconfig
中的目标。 此参数可以指定为计算目标对象或工作区中计算目标的字符串名称。
(可选)如果计算目标在管道创建时不可用,可能需要指定一个元组 ('compute target name', 'compute target type') 以避免提取计算目标对象(AmlCompute 类型为“AmlCompute”,RemoteCompute 类型为“VirtualMachine”)。
- runconfig_pipeline_params
- <xref:<xref:{str: PipelineParameter}>>
在运行时使用键值对重写 runconfig 属性,每个键值对分别具有 runconfig 属性的名称和该属性的 PipelineParameter。
支持的值:“NodeCount”、“MpiProcessCountPerNode”、“TensorflowWorkerCount”、“TensorflowParameterServerCount”
- inputs
- list[InputPortBinding 或 DataReference 或 PortDataReference 或 PipelineData 或 <xref:azureml.pipeline.core.pipeline_output_dataset.PipelineOutputDataset> 或 DatasetConsumptionConfig]
输入端口绑定的列表。
- outputs
- list[PipelineData 或 OutputDatasetConfig 或 PipelineOutputAbstractDataset 或 OutputPortBinding]
输出端口绑定的列表。
- allow_reuse
- bool
指示当使用相同的设置重新运行时,该步骤是否应重用以前的结果。 默认情况下启用重用。 如果步骤内容(脚本/依赖项)以及输入和参数保持不变,则重用此步骤以前运行的输出。 重用该步骤时,不是将作业提交到计算,而是使前一运行的结果立即可供后续步骤使用。 如果使用 Azure 机器学习数据集作为输入,则重用取决于数据集的定义是否已更改,而不是基础数据是否已更改。
注解
CommandStep 是在给定计算目标上运行命令的基本内置步骤。 它采用某个用作参数的命令,或者从其他参数(例如 runconfig)取值。 它还接受其他可选参数,例如计算目标、输入和输出。 应使用 ScriptRunConfig 或 RunConfiguration 来指定 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)
参数
- context
- <xref:_GraphContext>
图形上下文。
返回
创建的节点。
返回类型
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈