aws / sagemaker-tensorflow-serving-container

A TensorFlow Serving solution for use in SageMaker. This repo is now deprecated.
Apache License 2.0
174 stars 101 forks source link

More clarity on using Context in pre/post-processing scripts #184

Open nathanielrindlaub opened 3 years ago

nathanielrindlaub commented 3 years ago

What did you find confusing? Please describe. I am trying to make use of the model_name attribute in the Context object that gets passed into my input handler, which the documentation indicates is created by the Python service, but the docs do not indicate where those attribute values come from or how to set them when deploying a model endpoint. In my case, I get Context object with very little useful information, and it would be helpful to know how to set those values. Here's what my Context looks like printed out when a request comes in:

Context(model_name=None, model_version=None, method=None, rest_uri='http://localhost:10001/v1/models/Servo:predict', grpc_port='10000', custom_attributes=None, request_content_type='application/x-image', accept_header='*/*', content_length=1417)

I've tried a bunch of things (setting the name parameter when creating the Model, setting the endpoint_name param when calling model.deploy(), passing env: {'SAGEMAKER_TFS_DEFAULT_MODEL_NAME': '<model-name>'} into the Model as described in this gist) to no avail.

Describe how documentation can be improved A little more guidance on how to manipulate and use the Context object would be awesome.

Additional context Note: my endpoints are single-model endpoints, not multi-model endpoints. Not sure if that is relevant or not.

schenqian commented 3 years ago

I think you can refer two these two links: https://github.com/aws/sagemaker-tensorflow-serving-container/blob/2921d8a46c60687ce9dc29755d683ecd6f4fba4d/docker/build_artifacts/sagemaker/python_service.py#L243, https://github.com/aws/sagemaker-tensorflow-serving-container/blob/2921d8a46c60687ce9dc29755d683ecd6f4fba4d/docker/build_artifacts/sagemaker/tfs_utils.py#L39 Context is created by python_service.py.