编译模型 (Amazon SageMaker SDK) - Amazon SageMaker
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

编译模型 (Amazon SageMaker SDK)

您可以使用适用于 Python 的 Amazon SageMaker 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 模型。Neo 模型编译示例笔记本部分提供了使用 Python SDK 的示例笔记本。