

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 로컬 모드를 사용하여 파이프라인 실행
<a name="pipelines-local-mode"></a>

SageMaker Pipelines 로컬 모드는 관리형 SageMaker AI 서비스에서 파이프라인을 실행하기 전에 훈련, 처리, 추론 스크립트, [파이프라인 파라미터](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#pipeline-parameters)의 런타임 호환성을 테스트할 수 있는 쉬운 방법입니다. 로컬 모드를 사용하면 더 작은 데이터세트를 사용하여 SageMaker AI 파이프라인을 로컬에서 테스트할 수 있습니다. 이렇게 하면 관리 서비스 사용 비용을 들이지 않고도 사용자 스크립트와 파이프라인 정의 자체의 오류를 빠르고 쉽게 디버깅할 수 있습니다. 다음 주제에서는 파이프라인을 로컬에서 정의하고 실행하는 방법을 보여줍니다.

파이프라인 로컬 모드는 내부적으로 [SageMaker AI 작업 로컬 모드](https://sagemaker.readthedocs.io/en/stable/overview.html#local-mode)를 활용합니다. 이는 SageMaker Python SDK의 기능으로, Docker 컨테이너를 사용하여 SageMaker AI 내장 이미지 또는 사용자 지정 이미지를 로컬에서 실행할 수 있습니다. 파이프라인 로컬 모드는 SageMaker AI 작업 로컬 모드를 기반으로 구축됩니다. 따라서 해당 작업을 개별적으로 실행하는 것과 동일한 결과를 기대할 수 있습니다. 예를 들어 로컬 모드에서는 여전히 Amazon S3를 사용하여 모델 아티팩트를 업로드하고 출력을 처리합니다. 로컬 작업에서 생성된 데이터를 로컬 디스크에 저장하려는 경우 [로컬 모드](https://sagemaker.readthedocs.io/en/stable/overview.html#local-mode)에 언급된 설정을 사용할 수 있습니다.

파이프라인 로컬 모드는 현재 다음 단계 유형을 지원합니다.
+ [훈련 단계](build-and-manage-steps-types.md#step-type-training)
+ [처리 단계](build-and-manage-steps-types.md#step-type-processing)
+ [변환 단계](build-and-manage-steps-types.md#step-type-transform)
+ [모델 단계](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-steps.html#step-type-model-create)(모델 생성 인수만 사용)
+ [조건 단계](build-and-manage-steps-types.md#step-type-condition)
+ [실패 단계](build-and-manage-steps-types.md#step-type-fail)

[병렬 처리 구성](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#parallelism-configuration)을 사용하여 여러 단계를 병렬로 실행할 수 있는 관리형 파이프라인 서비스와 달리, 로컬 파이프라인 실행기는 단계를 순차적으로 실행합니다. 따라서 로컬 파이프라인의 전체 실행 성능은 클라우드에서 실행되는 파이프라인보다 낮을 수 있으며, 이는 주로 데이터세트의 크기, 알고리즘, 로컬 컴퓨터의 성능에 따라 달라집니다. 또한 로컬 모드에서 실행된 파이프라인은 [SageMaker 실험](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-experiments.html)에 기록되지 않는다는 점에 유의하시기 바랍니다.

**참고**  
파이프라인 로컬 모드는 XGBoost와 같은 SageMaker AI 알고리즘과 호환되지 않습니다. 이러한 알고리즘을 사용하려면 [스크립트 모드](https://sagemaker-examples.readthedocs.io/en/latest/sagemaker-script-mode/sagemaker-script-mode.html)에서 사용해야 합니다.

파이프라인을 로컬에서 실행하려면 파이프라인 단계와 관련된 `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 서비스에서 파이프라인을 실행할 준비가 되면 이전 코드 스니펫의 `LocalPipelineSession`을 `PipelineSession`(다음 코드 샘플 참조)으로 변경하고 코드를 다시 실행하여 실행할 수 있습니다.

```
from sagemaker.workflow.pipeline_context import PipelineSession

pipeline_session = PipelineSession()
```