

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# パイプラインを実行する
<a name="pipelines-step-decorator-run-pipeline"></a>

次のページでは、Amazon SageMaker Pipelines を使用して、SageMaker AI リソースで、またはローカルでパイプラインを実行する方法について説明します。

従来の SageMaker AI パイプライン実行と同様に、`pipeline.start()` 関数を使用して新しいパイプライン実行を開始します。`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)」を参照してください。ローカルモードを使用するには、次の例に示されるとおり、パイプライン定義に `SageMakerSession` ではなく、`LocalPipelineSession` を指定します。

```
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()
```