

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

# Pipelines のステップ
<a name="build-and-manage-steps"></a>

Pipelines は、複数のステップで構成されています。これらのステップでは、プロパティを使用して、パイプラインが実行するアクションとステップ間の関係を定義します。次のページでは、ステップのタイプ、プロパティ、ステップ間の関係性について説明します。

**Topics**
+ [ステップを追加する](build-and-manage-steps-types.md)
+ [統合の追加](build-and-manage-steps-integration.md)
+ [ステップのプロパティ](#build-and-manage-properties)
+ [ステップの並列処理](#build-and-manage-parallelism)
+ [ステップ間のデータ依存関係](#build-and-manage-data-dependency)
+ [ステップ間のカスタム依存関係](#build-and-manage-custom-dependency)
+ [ステップでのカスタムイメージ](#build-and-manage-images)

## ステップのプロパティ
<a name="build-and-manage-properties"></a>

`properties` 属性は、パイプラインのステップ間にデータの依存関係を追加するために使用されます。Pipelines は、これらのデータ依存関係をパイプライン定義から DAG を構築するために使用します。これらのプロパティはプレースホルダー値として参照でき、実行時に解決されます。

Pipelines ステップの `properties` 属性は、対応する SageMaker AI ジョブタイプに対する `Describe` コールが返すオブジェクトと一致します。ジョブタイプごとに、`Describe` 呼び出しは次のレスポンスオブジェクトを返します。
+ `ProcessingStep` - [DescribeProcessingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeProcessingJob.html)
+ `TrainingStep` - [DescribeTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeTrainingJob.html)
+ `TransformStep` - [DescribeTransformJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeTransformJob.html)

データ依存関係の作成時に各ステップタイプでどのプロパティが参照可能かを確認するには、「[Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable)」の「[Data Dependency - Property Reference](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#data-dependency-property-reference)」を参照してください。**

## ステップの並列処理
<a name="build-and-manage-parallelism"></a>

ステップは、他のステップに依存していない場合、パイプライン実行時に直ちに実行されます。ただし、同時に実行するパイプラインステップが多すぎると、使用可能なリソースがすぐに使い果たされる可能性があります。`ParallelismConfiguration` を使用して、パイプラインの同時実行ステップ数を制御します。

次の例では `ParallelismConfiguration` を使用して同時実行ステップの上限数を 5 に設定しています。

```
pipeline.create(
    parallelism_config=ParallelismConfiguration(5),
)
```

## ステップ間のデータ依存関係
<a name="build-and-manage-data-dependency"></a>

DAG の構造を定義するには、ステップ間のデータ関係を指定します。ステップ間にデータ依存関係を作成するには、パイプラインのあるステップのプロパティを別のステップに入力として渡します。入力を受け取るステップは、入力を提供するステップの実行が終了するまで開始されません。

データ依存関係は、次の形式の JsonPath 表記で表されます。この形式は JSON プロパティファイルをトラバースします。つまり、ファイル内にネストされた目的のプロパティにアクセスするのに必要な数の {{<property>}} インスタンスを追加できます。JsonPath 表記の詳細については、「[JsonPath リポジトリ](https://github.com/json-path/JsonPath)」を参照してください。

```
{{<step_name>}}.properties.{{<property>}}.{{<property>}}
```

処理ステップの `ProcessingOutputConfig` プロパティを使用して Amazon S3 バケットを指定する方法を以下に示します。

```
step_process.properties.ProcessingOutputConfig.Outputs["train_data"].S3Output.S3Uri
```

データ依存関係を作成するには、以下のようにバケットをトレーニングステップに渡します。

```
from sagemaker.workflow.pipeline_context import PipelineSession

sklearn_train = SKLearn(..., sagemaker_session=PipelineSession())

step_train = TrainingStep(
    name="CensusTrain",
    step_args=sklearn_train.fit(inputs=TrainingInput(
        s3_data=step_process.properties.ProcessingOutputConfig.Outputs[
            "train_data"].S3Output.S3Uri
    ))
)
```

データ依存関係の作成時に各ステップタイプでどのプロパティが参照可能かを確認するには、「[Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable)」の「[Data Dependency - Property Reference](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#data-dependency-property-reference)」を参照してください。**

## ステップ間のカスタム依存関係
<a name="build-and-manage-custom-dependency"></a>

データ依存関係を指定すると、Pipelines がステップ間のデータ接続を提供します。別の方法として、Pipelines を直接使用せずに、あるステップから以前のステップのデータにアクセスすることもできます。この場合、別のステップの実行が終了するまでステップを開始しないように Pipelines に指示するカスタム依存関係を作成できます。カスタム依存関係を作成するには、ステップの`DependsOn` 属性を指定します。

以下の例では、ステップ `A` とステップ `B` の両方が実行を終了してから開始されるステップ `C` を定義します。

```
{
  'Steps': [
    {'Name':'A', ...},
    {'Name':'B', ...},
    {'Name':'C', 'DependsOn': ['A', 'B']}
  ]
}
```

依存関係により循環依存関係が生まれると、Pipelines で検証例外がスローされます。

以下の例では、処理ステップの実行が終了した後に開始されるトレーニングステップを作成します。

```
processing_step = ProcessingStep(...)
training_step = TrainingStep(...)

training_step.add_depends_on([processing_step])
```

以下の例では、2 つの異なる処理ステップの実行が終了するまで開始されないトレーニングステップを作成します。

```
processing_step_1 = ProcessingStep(...)
processing_step_2 = ProcessingStep(...)

training_step = TrainingStep(...)

training_step.add_depends_on([processing_step_1, processing_step_2])
```

以下は、カスタム依存関係を作成する別の方法です。

```
training_step.add_depends_on([processing_step_1])
training_step.add_depends_on([processing_step_2])
```

以下の例では、ある処理ステップから入力を受け取り、別の処理ステップの実行が終了するまで待機するトレーニングステップを作成します。

```
processing_step_1 = ProcessingStep(...)
processing_step_2 = ProcessingStep(...)

training_step = TrainingStep(
    ...,
    inputs=TrainingInput(
        s3_data=processing_step_1.properties.ProcessingOutputConfig.Outputs[
            "train_data"
        ].S3Output.S3Uri
    )

training_step.add_depends_on([processing_step_2])
```

以下の例では、ステップのカスタム依存関係の文字列リストを取得する方法を示しています。

```
custom_dependencies = training_step.depends_on
```

## ステップでのカスタムイメージ
<a name="build-and-manage-images"></a>

 パイプラインでステップを作成する際に利用可能な SageMaker AI の[深層学習コンテナイメージ](https://github.com/aws/deep-learning-containers/blob/master/available_images.md)のいずれかを使用できます。

パイプラインのステップでは独自のコンテナを使用することもできます。Studio Classic 内からイメージを作成することはできないため、Pipelines で使用する前に別の方法でイメージを作成しておく必要があります。

パイプラインのステップの作成時に独自のコンテナを使用する場合は、推定器定義にイメージ URI を追加します。SageMaker AI で独自のコンテナを使用する方法については、「[SageMaker AI で Docker コンテナを使用する](https://docs.aws.amazon.com/sagemaker/latest/dg/docker-containers.html)」を参照してください。