

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

# 단계 캐싱을 활성화합니다.
<a name="pipelines-caching-enabling"></a>

단계 캐싱을 켜려면 단계 정의에 `CacheConfig` 속성을 추가해야 합니다. `CacheConfig` 속성은 파이프라인 정의 파일에서 다음 형식을 사용합니다.

```
{
    "CacheConfig": {
        "Enabled": false,
        "ExpireAfter": "<time>"
    }
}
```

이 `Enabled`필드는 특정 단계에서 캐싱이 켜져 있는지 여부를 나타냅니다. 필드를 `true`로 설정하면 SageMaker AI가 동일한 속성을 가진 이전 단계 실행을 찾으려고 시도하도록 지시할 수 있습니다. 또는 필드를 `false`로 설정하여 파이프라인이 실행될 때마다 SageMaker AI가 단계를 실행하도록 지시할 수 있습니다. `ExpireAfter`는 제한 기간을 정의하는 [ISO 8601 기간](https://en.wikipedia.org/wiki/ISO_8601#Durations) 형식의 문자열입니다. `ExpireAfter` 기간은 년, 월, 주, 일, 시간 또는 분 값일 수 있습니다. 각 값은 숫자 다음에 기간 단위를 나타내는 문자로 구성됩니다. 예제:
+ "30d" = 30일
+ "5y" = 5년
+ "T16m" = 16분
+ "30dT5h" = 30일 5시간.

다음 설명에서는 Amazon SageMaker Python SDK를 사용하여 새 파이프라인 또는 기존 파이프라인에 대한 캐싱을 활성화하는 절차를 설명합니다.

**새 파이프라인 캐싱 활성화**

새 파이프라인의 경우 `enable_caching=True`를 사용하여 `CacheConfig`인스턴스를 초기화하고 이를 파이프라인 단계의 입력으로 제공합니다. 다음 예시에서는 훈련 단계에 1시간의 제한 시간을 두고 캐싱을 활성화합니다.

```
from sagemaker.workflow.pipeline_context import PipelineSession
from sagemaker.workflow.steps import CacheConfig
      
cache_config = CacheConfig(enable_caching=True, expire_after="PT1H")
estimator = Estimator(..., sagemaker_session=PipelineSession())

step_train = TrainingStep(
    name="TrainAbaloneModel",
    step_args=estimator.fit(inputs=inputs),
    cache_config=cache_config
)
```

**기존 파이프라인 캐싱 활성화**

사전 정의된 기존 파이프라인의 캐싱을 활성화려면 해당 단계의 `enable_caching`속성을 켜고 `expire_after`를 시간 제한 값으로 설정합니다. 마지막으로 `pipeline.upsert()`또는 `pipeline.update()`를 사용하여 파이프라인을 업데이트합니다. 다시 실행하면 다음 코드 예제가 훈련 단계에 대해 1시간의 제한 시간을 두고 캐싱을 활성화합니다.

```
from sagemaker.workflow.pipeline_context import PipelineSession
from sagemaker.workflow.steps import CacheConfig
from sagemaker.workflow.pipeline import Pipeline

cache_config = CacheConfig(enable_caching=True, expire_after="PT1H")
estimator = Estimator(..., sagemaker_session=PipelineSession())

step_train = TrainingStep(
    name="TrainAbaloneModel",
    step_args=estimator.fit(inputs=inputs),
    cache_config=cache_config
)

# define pipeline
pipeline = Pipeline(
    steps=[step_train]
)

# additional step for existing pipelines
pipeline.update()
# or, call upsert() to update the pipeline
# pipeline.upsert()
```

또는 (기존) 파이프라인을 이미 정의한 후 캐시 구성을 업데이트하여 한 번의 연속 코드 실행을 허용합니다. 다음 코드 샘플은 이 방법을 보여줍니다.

```
# turn on caching with timeout period of one hour
pipeline.steps[0].cache_config.enable_caching = True 
pipeline.steps[0].cache_config.expire_after = "PT1H" 

# additional step for existing pipelines
pipeline.update()
# or, call upsert() to update the pipeline
# pipeline.upsert()
```

Python SDK 파라미터가 캐싱에 미치는 영향에 대한 자세한 코드 예제와 설명은 Amazon SageMaker Python SDK 설명서의 [캐싱 구성](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#caching-configuration)을 참조하세요.