View a markdown version of this page

編譯模型 (Amazon SageMaker AI SDK) - Amazon SageMaker AI

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

編譯模型 (Amazon SageMaker AI SDK)

您可以使用 Amazon SageMaker AI 適用於 Python 的 SDK中的 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 模型。