管道步驟的選取性執行 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

管道步驟的選取性執行

當您使用 P SageMaker ipeline 建立工作流程並協調機器學習訓練步驟時,您可能需要進行多個實驗階段。您可能只想重複某些步驟,而不是每次執行完整管線。使用配 SageMaker 管,您可以選擇性地執行管線步驟。這有助於優化您的 ML 培訓。選取性執行在下列情況下很有用:

  • 您想使用更新後的執行個體類型、超參數或其他變數來重新啟動特定步驟,同時保留上游步驟中的參數。

  • 您的管道會在中間步驟失敗。執行中的先前步驟 (例如資料準備或特徵擷取) 的重新執行成本很高。您可能需要引入修正程式,然後手動重新執行某些步驟以完成管道。

使用選取性執行,您可以選擇執行任何步驟子集,只要這些步驟子集在管道的有向無環圖 (DAG) 中已連線即可。下列 DAG 顯示管道工作流程範例:

範例管道的有向無環圖 (DAG)。

您可以選取步驟AbaloneTrainAbaloneEval選擇性執行,但您無法只選取AbaloneTrainAbaloneMSECond步驟,因為 DAG 中未連線這些步驟。對於工作流程中未選取的步驟,選擇性執行會重新使用參照配管執行的輸出,而不是重新執行步驟。此外,位於所選取步驟下游的未選取步驟不會在選取性執行中執行。

如果您選擇在管線中執行中繼步驟的子集,您的步驟可能取決於先前的步驟。 SageMaker 需要一個參考管道執行,以從中獲得這些依賴關係。例如,如果您選擇執行AbaloneProcess步驟 AbaloneTrainAbaloneEval,則需要步驟中的輸出。您可以提供參照執行 ARN,也可以直 SageMaker 接使用最新的管線執行,這是預設行為。如果您有引用執行,則還可以從引用運行中構建運行時參數,並將它們提供給帶有覆蓋的選擇性執行運行。如需詳細資訊,請參閱 重複使用參考執行中的執行期參數值

詳細地說,您可以使用SelectiveExecutionConfig. 如果您在參照管線執行中包含 ARN (含source_pipeline_execution_arn引數),則 SageMaker會使用您提供的管線執行中的先前步驟相依性。如果不包括 ARN 且存在最新的管線執行,則依預設 SageMaker 會使用它作為參照。如果您不包含 ARN 且不想 SageMaker 使用最新的管線執行,請reference_latest_execution將設定為False。最 SageMaker 終用作參照的管線執行,無論是最新的還是使用者指定的,都必須處於SuccessFailed狀態。

下表摘要說明如何 SageMaker 選擇參考執行。

source_pipeline_execution_arn 引數值 reference_latest_execution 引數值 使用的參考執行
管道 AARN

True 或未指定

指定的管道 ARN

管道 AARN

False

指定的管道 ARN

null 或未指定

True 或未指定

最新管道執行

null 或未指定

False

無 - 在此情況下,請選取沒有上游相依性的步驟

如需有關選擇性執行組態需求的詳細資訊,請參閱下載程式。 SelectiveExecutionConfig 文檔。

以下討論內容涵蓋您想執行下列動作的情況範例:指定管道參考執行、使用最新管道執行作為參考,或在沒有參考管道執行的情況下執行選取性執行。

使用使用者指定之管道參考的選取性執行

下面的例子演示了選擇性的步驟執行AbaloneTrainAbaloneEval使用引用管道執行。

from sagemaker.workflow.selective_execution_config import SelectiveExecutionConfig selective_execution_config = SelectiveExecutionConfig( source_pipeline_execution_arn="arn:aws:sagemaker:us-west-2:123123123123:pipeline/abalone/execution/123ab12cd3ef", selected_steps=["AbaloneTrain", "AbaloneEval"] ) selective_execution = pipeline.start( execution_display_name=f"Sample-Selective-Execution-1", parameters={"MaxDepth":6, "NumRound":60}, selective_execution_config=selective_execution_config, )

以最新的管道執行作為參考的選取性執行

下列範例會示範選擇性執行步驟,AbaloneTrainAbaloneEval使用最新的管線執行作為參照。由於預設情況下 SageMaker 使用最新的管線執行,因此您可以選擇將reference_latest_execution引數設定為True

# Prepare a new selective execution. Select only the first step in the pipeline without providing source_pipeline_execution_arn. selective_execution_config = SelectiveExecutionConfig( selected_steps=["AbaloneTrain", "AbaloneEval"], # optional reference_latest_execution=True ) # Start pipeline execution without source_pipeline_execution_arn pipeline.start( execution_display_name=f"Sample-Selective-Execution-1", parameters={"MaxDepth":6, "NumRound":60}, selective_execution_config=selective_execution_config, )

沒有參考管道的選取性執行

下列範例會示範選擇性執行步驟,AbaloneProcessAbaloneTrain不提供參照 ARN,以及關閉使用最新管線執行作為參照的選項。 SageMaker 允許此配置,因為這個步驟子集不依賴於先前的步驟。

# Prepare a new selective execution. Select only the first step in the pipeline without providing source_pipeline_execution_arn. selective_execution_config = SelectiveExecutionConfig( selected_steps=["AbaloneProcess", "AbaloneTrain"], reference_latest_execution=False ) # Start pipeline execution without source_pipeline_execution_arn pipeline.start( execution_display_name=f"Sample-Selective-Execution-1", parameters={"MaxDepth":6, "NumRound":60}, selective_execution_config=selective_execution_config, )

重複使用參考執行中的執行期參數值

您可以使用 build_parameters_from_execution 透過參考管道執行建置參數,並將結果提供給您的選取性執行管道。您可以使用參考執行中的原始參數,或使用 parameter_value_overrides 引數套用任何覆寫。

下列範例示範如何透過參考執行建置參數,以及如何套用 MseThreshold 參數的覆寫。

# Prepare a new selective execution. selective_execution_config = SelectiveExecutionConfig( source_pipeline_execution_arn="arn:aws:sagemaker:us-west-2:123123123123:pipeline/abalone/execution/123ab12cd3ef", selected_steps=["AbaloneTrain", "AbaloneEval", "AbaloneMSECond"], ) # Define a new parameters list to test. new_parameters_mse={ "MseThreshold": 5, } # Build parameters from reference execution and override with new parameters to test. new_parameters = pipeline.build_parameters_from_execution( pipeline_execution_arn="arn:aws:sagemaker:us-west-2:123123123123:pipeline/abalone/execution/123ab12cd3ef", parameter_value_overrides=new_parameters_mse ) # Start pipeline execution with new parameters. execution = pipeline.start( selective_execution_config=selective_execution_config, parameters=new_parameters )