我已经使用SageMaker脚本模式训练了一个tensorflow.keras模型,如下所示:
import os
import sagemaker
from sagemaker.tensorflow import TensorFlow
estimator = TensorFlow(entry_point='train.py',
source_dir='src',
train_instance_type=train_instance_type,
train_instance_count=1,
hyperparameters=hyperparameters,
role=sagemaker.get_execution_role(),
framework_version='1.12.0',
py_version='py3',
script_mode=True)
但是,当我调用estimator.deploy()
时,如何指定服务代码是什么?默认情况下它是什么?还有没有办法使用脚本模式修改nginx.conf?
Tensorflow容器是开源的: https://github.com/aws/sagemaker-tensorflow-container 您可以准确查看它的工作原理。当然,您可以调整它,在本地构建它,将其推送到 ECR 并在 SageMaker :) 上使用它
通常,可以通过两种方式进行部署:
-
基于 Python 的端点:https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_python.rst
-
TensorFlow Serve endpoints: https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst
我还建议在这里查看TensorFlow示例:https://github.com/awslabs/amazon-sagemaker-examples/tree/master/sagemaker-python-sdk
在脚本模式下,默认的服务方法是基于 TensorFlow Serving 的方法:https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/estimator.py#L393基于 TFS 的容器不允许使用自定义脚本。您可以使用serving_input_receiver_fn指定如何处理输入数据,如下所述:https://www.tensorflow.org/guide/saved_model
至于修改ngnix.conf,没有支持的方法。根据您要在配置文件中更改的内容,您可以破解sagemaker-python-sdk,为这些环境变量传递不同的值:https://github.com/aws/sagemaker-tensorflow-serving-container/blob/3fd736aac4b0d97df5edaea48d37c49a1688ad6e/container/sagemaker/serve.py#L29
您可以在此处覆盖环境变量:https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/serving.py#L130