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

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

编译模型(亚马逊 SageMaker SDK)

您可以使用适用于 Python 的 Amazon SageMaker 开发工具包中的 compile_modelAPI 来编译经过训练的模型,并针对特定的目标硬件对其进行优化。应该在模型训练期间,在使用的估算器对象上调用 API。

注意

使用 MxNet 或编译模型500时,必须将MMS_DEFAULT_RESPONSE_TIMEOUT环境变量设置为。 PyTorch不需要环境变量 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 的示例笔记本。