

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

# 再試行ポリシーを設定する
<a name="pipelines-configuring-retry-policy"></a>

SageMaker Pipelines は機械学習ワークフローのオーケストレーションのための堅牢かつ自動化された方法を提供するとはいえ、実行時に失敗する場合もあります。このようなシナリオを適切に処理し、パイプラインの信頼性を向上させるために、例外が発生した後に特定のステップを自動的に再試行する方法とタイミングを定義する再試行ポリシーを設定できます。再試行ポリシーでは、再試行する例外のタイプ、再試行の最大回数、再試行の間隔、再試行の間隔を引き上げるためのバックオフ率を指定できます。次のセクションでは、JSON と SageMaker Python SDK の両方を使用して、パイプライン内のトレーニングステップの再試行ポリシーを設定する方法の例を説明します。

以下は、再試行ポリシーを使用したトレーニングステップの例です。

```
{
    "Steps": [
        {
            "Name": "{{MyTrainingStep}}",
            "Type": "Training",
            "RetryPolicies": [
                {
                    "ExceptionType": [
                        "{{SageMaker.JOB_INTERNAL_ERROR}}",
                        "{{SageMaker.CAPACITY_ERROR}}"
                    ],
                    "IntervalSeconds": {{1}},
                    "BackoffRate": {{2}},
                    "MaxAttempts": {{5}}
                }
            ]
        }
    ]
}
```



以下は、再試行ポリシーを使用して SDK for Python (Boto3) に `TrainingStep` を構築する方法の例です。

```
from sagemaker.workflow.retry import (
    StepRetryPolicy, 
    StepExceptionTypeEnum,
    SageMakerJobExceptionTypeEnum,
    SageMakerJobStepRetryPolicy
)

step_train = TrainingStep(
    name="{{MyTrainingStep}}",
    xxx,
    retry_policies=[
        // override the default 
        StepRetryPolicy(
            exception_types=[
                {{StepExceptionTypeEnum.SERVICE_FAULT}}, 
                {{StepExceptionTypeEnum.THROTTLING}}
            ],
            expire_after_mins={{5}},
            interval_seconds={{10}},
            backoff_rate={{2.0}} 
        ),
        // retry when resource limit quota gets exceeded
        SageMakerJobStepRetryPolicy(
            exception_types=[{{SageMakerJobExceptionTypeEnum.RESOURCE_LIMIT}}],
            expire_after_mins={{120}},
            interval_seconds={{60}},
            backoff_rate={{2.0}}
        ),
        // retry when job failed due to transient error or EC2 ICE.
        SageMakerJobStepRetryPolicy(
            failure_reason_types=[
                {{SageMakerJobExceptionTypeEnum.INTERNAL_ERROR}},
                {{SageMakerJobExceptionTypeEnum.CAPACITY_ERROR}},
            ],
            max_attempts={{10}},
            interval_seconds={{30}},
            backoff_rate={{2.0}}
        )
    ]
)
```

特定のステップタイプの再試行動作の設定の詳細については、「Amazon SageMaker Python SDK ドキュメント」の「[Amazon SageMaker Pipelines - Retry Policy](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#retry-policy)」を参照してください。**