View a markdown version of this page

モデルをコンパイルする (Amazon SageMaker AI SDK) - Amazon SageMaker AI

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

モデルをコンパイルする (Amazon SageMaker AI SDK)

Amazon SageMaker AI SDK for Pythoncompile_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 モデルを作成します。