パイプラインを実行する - Amazon SageMaker

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

パイプラインを実行する

SageMaker Python SDK を使用してパイプライン定義を作成したら、 SageMaker それをに送信して実行を開始できます。以下のチュートリアルでは、パイプラインの送信、実行の開始、その実行結果の確認、パイプラインの削除方法を説明します。

前提条件

このチュートリアルでは、以下が必要です。

  • SageMaker ノートブックインスタンス。 

  • SageMaker パイプラインパイプライン定義。このチュートリアルは、「パイプラインを定義する」チュートリアルを実行して作成したパイプライン定義を使用することを前提としています。

ステップ 1: パイプラインを開始する

最初に、パイプラインを開始する必要があります。

パイプラインを開始するには
  1. JSON パイプラインの定義を調べて、フォーマットに誤りがないことを確認します。

    import json json.loads(pipeline.definition())
  2. パイプライン定義を SageMaker Pipelines サービスに送信してパイプラインが存在しない場合は作成し、存在する場合はパイプラインを更新します。 渡されたロールは、 SageMaker Pipelines がステップで定義したすべてのジョブを作成するために使用されます。

    pipeline.upsert(role_arn=role)
  3. パイプラインの実行を開始します。

    execution = pipeline.start()

ステップ 2: パイプラインの実行を確認する

次に、パイプラインの実行を確認する必要があります。

パイプラインの実行を確認するには
  1. パイプラインの実行ステータスを書き留め、パイプラインが正常に作成され、開始されたことを確認します。

    execution.describe()
  2. 実行が終了するまで待ちます。

    execution.wait()
  3. 実行ステップとそのステータスをリストします。

    execution.list_steps()

    出力は次のようになります。

    [{'StepName': 'AbaloneTransform', 'StartTime': datetime.datetime(2020, 11, 21, 2, 41, 27, 870000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 45, 50, 492000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'TransformJob': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:transform-job/pipelines-cfvy1tjuxdq8-abalonetransform-ptyjoef3jy'}}}, {'StepName': 'AbaloneRegisterModel', 'StartTime': datetime.datetime(2020, 11, 21, 2, 41, 26, 929000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 41, 28, 15000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'RegisterModel': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:model-package/abalonemodelpackagegroupname/1'}}}, {'StepName': 'AbaloneCreateModel', 'StartTime': datetime.datetime(2020, 11, 21, 2, 41, 26, 895000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 41, 27, 708000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'Model': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:model/pipelines-cfvy1tjuxdq8-abalonecreatemodel-jl94rai0ra'}}}, {'StepName': 'AbaloneMSECond', 'StartTime': datetime.datetime(2020, 11, 21, 2, 41, 25, 558000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 41, 26, 329000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'Condition': {'Outcome': 'True'}}}, {'StepName': 'AbaloneEval', 'StartTime': datetime.datetime(2020, 11, 21, 2, 37, 34, 767000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 41, 18, 80000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'ProcessingJob': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:processing-job/pipelines-cfvy1tjuxdq8-abaloneeval-zfraozhmny'}}}, {'StepName': 'AbaloneTrain', 'StartTime': datetime.datetime(2020, 11, 21, 2, 34, 55, 867000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 37, 34, 34000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'TrainingJob': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:training-job/pipelines-cfvy1tjuxdq8-abalonetrain-tavd6f3wdf'}}}, {'StepName': 'AbaloneProcess', 'StartTime': datetime.datetime(2020, 11, 21, 2, 30, 27, 160000, tzinfo=tzlocal()), 'EndTime': datetime.datetime(2020, 11, 21, 2, 34, 48, 390000, tzinfo=tzlocal()), 'StepStatus': 'Succeeded', 'CacheHitResult': {'SourcePipelineExecutionArn': ''}, 'Metadata': {'ProcessingJob': {'Arn': 'arn:aws:sagemaker:us-east-2:111122223333:processing-job/pipelines-cfvy1tjuxdq8-abaloneprocess-mgqyfdujcj'}}}]
  4. パイプラインの実行が完了したら、Amazon S3 から結果の evaluation.json ファイルをダウンロードして、レポートを確認します。

    evaluation_json = sagemaker.s3.S3Downloader.read_file("{}/evaluation.json".format( step_eval.arguments["ProcessingOutputConfig"]["Outputs"][0]["S3Output"]["S3Uri"] )) json.loads(evaluation_json)

ステップ 3: パイプラインの実行のデフォルトパラメータをオーバーライドする

異なるパイプラインパラメータを指定して追加のパイプラインの実行を動作させると、デフォルトをオーバーライドできます。

デフォルトパラメータをオーバーライドするには
  1. パイプラインの実行を作成します。これにより、モデル承認ステータスのオーバーライドが「承認済み」に設定された状態で別のパイプライン実行が開始されます。つまり、RegisterModelステップによって生成されたモデルパッケージバージョンは、プロジェクトなどの CI/CD パイプラインを通じて自動的にデプロイできるようになります。 SageMaker 詳細については、「プロジェクトによる MLOP の自動化 SageMaker 」を参照してください。

    execution = pipeline.start( parameters=dict( ModelApprovalStatus="Approved", ) )
  2. 実行が終了するまで待ちます。

    execution.wait()
  3. 実行ステップとそのステータスをリストします。

    execution.list_steps()
  4. パイプラインの実行が完了したら、Amazon S3 から結果の evaluation.json ファイルをダウンロードして、レポートを確認します。

    evaluation_json = sagemaker.s3.S3Downloader.read_file("{}/evaluation.json".format( step_eval.arguments["ProcessingOutputConfig"]["Outputs"][0]["S3Output"]["S3Uri"] )) json.loads(evaluation_json)

ステップ 4: パイプラインの実行を停止して削除する

パイプラインの処理が終了したら、継続中の実行を停止し、パイプラインを削除できます。

パイプラインの実行を停止して削除するには
  1. パイプラインの実行を停止します。

    execution.stop()
  2. パイプラインを削除します。

    pipeline.delete()