

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

# モデルをコンパイルする (Amazon SageMaker AI SDK)
<a name="neo-job-compilation-sagemaker-sdk"></a>

 [Amazon SageMaker AI SDK for Python](https://sagemaker.readthedocs.io/en/stable/) の [https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html?#sagemaker.estimator.Estimator.compile_model](https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html?#sagemaker.estimator.Estimator.compile_model) API を使って、トレーニング済みモデルをコンパイルし、特定のターゲットハードウェアに合わせて最適化できます。API は、モデルトレーニングで使われる推定器オブジェクトで呼び出されます。

**注記**  
MXNet または PyTorch を使ってモデルをコンパイルする場合は、`MMS_DEFAULT_RESPONSE_TIMEOUT` 環境変数 を `500` に設定する必要があります。この環境変数は、TensorFlow には必要ありません。

 以下は、`trained_model_estimator` オブジェクトを使ってモデルをコンパイルする方法の例を示しています。

```
# 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
compiled_model = trained_model_estimator.compile_model(target_instance_family='ml_c5',
        input_shape=expected_trained_model_input,
        output_path='insert s3 output path',
        env={'MMS_DEFAULT_RESPONSE_TIMEOUT': '500'})
```

このコードはモデルをコンパイルし、最適化されたモデルを `output_path` に保存し、エンドポイントにデプロイできる SageMaker AI モデルを作成します。