View a markdown version of this page

모델 컴파일(Amazon SageMaker AI SDK) - Amazon SageMaker AI

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

모델 컴파일(Amazon SageMaker AI SDK)

Amazon SageMaker Python SDK의 compile_model API를 사용하여 훈련된 모델을 컴파일하고 특정 대상 하드웨어에 맞게 최적화할 수 있습니다. 모델 훈련 중에 사용되는 예측기 객체에서 API를 호출해야 합니다.

참고

MXNet 또는 PyTorch로 모델을 컴파일할 때는 MMS_DEFAULT_RESPONSE_TIMEOUT 환경 변수를 500으로 설정해야 합니다. TensorFlow에는 환경 변수가 필요하지 않습니다.

다음은 trained_model_estimator 객체를 사용하여 모델을 컴파일하는 방법의 예시입니다.

# Neo compilation in V3 uses ModelBuilder.optimize() with compilation_config from sagemaker.serve import ModelBuilder # Replace the value of expected_trained_model_input below and # specify the name & shape of the expected inputs for your trained model # in json dictionary form expected_trained_model_input = {'data':[1, 784]} # Replace the example target_instance_family below to your preferred target_instance_family model_builder = ModelBuilder( model=trained_model, role_arn=role, instance_type='ml.c5.xlarge', ) optimized_model = model_builder.optimize( instance_type='ml.c5.xlarge', output_path='insert s3 output path', compilation_config={ 'OverrideEnvironment': { 'OPTION_TARGET_INSTANCE_FAMILY': 'ml_c5', 'MMS_DEFAULT_RESPONSE_TIMEOUT': '500', }, }, )

코드는 모델을 컴파일하고, 최적화된 모델을 output_path에 저장하고, 엔드포인트에 배포할 수 있는 SageMaker AI 모델을 만듭니다.