本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用本機模式執行管道
在受管 SageMaker SageMaker Pipelines 本機模式是測試訓練、處理和推論指令碼以及管道參數
管道本機模式利用 SageMaker AI 在機罩下任務本機模式
管道本機模式目前支援下列步驟類型:
與允許使用平行組態
注意
管道本機模式與 XGBoost 等 SageMaker AI 演算法不相容。如果想要使用這些演算法,則必須在指令碼模式
為了在本機執行管道,與管道步驟和管道本身相關聯的 sagemaker_session
欄位的類型必須是 LocalPipelineSession
。下列範例示範如何定義要在本機執行的 SageMaker AI 管道。
from sagemaker.workflow.pipeline_context import LocalPipelineSession from sagemaker.pytorch import PyTorch from sagemaker.workflow.steps import TrainingStep from sagemaker.workflow.pipeline import Pipeline local_pipeline_session = LocalPipelineSession() pytorch_estimator = PyTorch( sagemaker_session=local_pipeline_session, role=sagemaker.get_execution_role(), instance_type="ml.c5.xlarge", instance_count=1, framework_version="1.8.0", py_version="py36", entry_point="./entry_point.py", ) step = TrainingStep( name="MyTrainingStep", step_args=pytorch_estimator.fit( inputs=TrainingInput(s3_data="s3://
amzn-s3-demo-bucket/my-data/train
"), ) ) pipeline = Pipeline( name="MyPipeline", steps=[step], sagemaker_session=local_pipeline_session ) pipeline.create( role_arn=sagemaker.get_execution_role(), description="local pipeline example" ) // pipeline will execute locally execution = pipeline.start() steps = execution.list_steps() training_job_name = steps['PipelineExecutionSteps'][0]['Metadata']['TrainingJob']['Arn'] step_outputs = pipeline_session.sagemaker_client.describe_training_job(TrainingJobName = training_job_name)
準備好在受管的 SageMaker Pipelines 服務上執行管道之後,您可以使用 PipelineSession
(如下列程式碼範例所示) 取代先前的程式碼片段 LocalPipelineSession
,然後重新執行程式碼。
from sagemaker.workflow.pipeline_context import PipelineSession pipeline_session = PipelineSession()