

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 运行管道
<a name="pipelines-step-decorator-run-pipeline"></a>

以下页面介绍如何使用 Amazon Pipelines 运行 SageMaker 管道，无论是使用 SageMaker AI 资源还是本地运行。

使用该`pipeline.start()`函数开始新的管道运行，就像传统的 A SageMaker I 管道运行一样。有关 `start()` 函数的信息，请参阅 [sagemaker.workflow.pipeline.Pipeline.start](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.pipeline.Pipeline.start)。

**注意**  
使用 `@step` 装饰器定义的步骤将作为训练作业运行。因此，请注意以下限制：  
账户中的实例限制和训练作业限制。相应更新您的限制，以避免任何节流或资源限制问题。
管道中每运行一个训练步骤的相关货币成本。有关更多详情，请参阅 [Amazon SageMaker 定价](https://aws.amazon.com/sagemaker/pricing/)。

## 从本地运行的管道中读取结果
<a name="pipelines-step-decorator-run-pipeline-retrieve"></a>

要查看管道运行的任何步骤的结果，请使用 [execution.result()](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.pipeline._PipelineExecution.result           )，如以下代码段所示：

```
execution = pipeline.start()
execution.result(step_name="train")
```

**注意**  
Pipelines 在本地模式下不支持 `execution.result()`。

每次只能检索一个步骤的结果。如果步骤名称由 SageMaker AI 生成，则可以通过以下方式调用`list_steps`来检索步骤名称：

```
execution.list_step()
```

## 在本地运行管道
<a name="pipelines-step-decorator-run-pipeline-local"></a>

您可以像运行传统管道步骤一样，在本地运行带有 `@step` 装饰步骤的管道。有关本地模式管道运行的详细信息，请参阅 [使用本地模式运行管道](pipelines-local-mode.md)。要使用本地模式，请在管道定义中使用 `LocalPipelineSession` 代替 `SageMakerSession`，如下例所示：

```
from sagemaker.workflow.function_step import step
from sagemaker.workflow.pipeline import Pipeline
from sagemaker.workflow.pipeline_context import LocalPipelineSession

@step
def train():
    training_data = s3.download(....)
    ...
    return trained_model
    
step_train_result = train()

local_pipeline_session = LocalPipelineSession()

local_pipeline = Pipeline(
    name="<pipeline-name>",
    steps=[step_train_result],
    sagemaker_session=local_pipeline_session # needed for local mode
)

local_pipeline.create(role_arn="role_arn")

# pipeline runs locally
execution = local_pipeline.start()
```