Skip to content

add tensorflow serving docs #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 10, 2018
Merged

add tensorflow serving docs #468

merged 12 commits into from
Nov 10, 2018

Conversation

jesterhazy
Copy link
Contributor

Description of changes:

  • add tensorflow serving docs
  • add content_type to tensorflow.serving.Predictor
  • add additional tests

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated the changelog with a description of my changes (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-io
Copy link

codecov-io commented Nov 9, 2018

Codecov Report

Merging #468 into master will decrease coverage by 0.04%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #468      +/-   ##
==========================================
- Coverage   93.98%   93.94%   -0.05%     
==========================================
  Files          57       57              
  Lines        4259     4261       +2     
==========================================
  Hits         4003     4003              
- Misses        256      258       +2
Impacted Files Coverage Δ
src/sagemaker/tensorflow/serving.py 98.33% <ø> (ø) ⬆️
src/sagemaker/local/local_session.py 87.25% <33.33%> (-1.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 576af44...5980332. Read the comment docs.

@jesterhazy jesterhazy removed the request for review from mvsusp November 9, 2018 18:21
CHANGELOG.rst Outdated
@@ -5,6 +5,8 @@ CHANGELOG
1.14.2-dev
==========

* enhancement: add content_type parameter to sagemaker.tensorflow.serving.Predictor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd make content_type and sagemaker.tensorflow.serving.Predictor monospace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -229,7 +228,7 @@ More details on how to create input functions can be find in `Building Input Fun
Creating a ``serving_input_fn``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``serving_input_fn`` is used to define the shapes and types of the inputs the model accepts when the model is exported for Tensorflow Serving. It is optional, but required for deploying the trained model to a SageMaker endpoint.
``serving_input_fn`` is used to define the shapes and types of the inputs the model accepts when the model is exported for Tensorflow Serving. It is optional, but is required to create the SavedModel bundle needed to deploying the trained model to a SageMaker endpoint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it sounds a little weird to have "it is optional, but is required". maybe something like "it is required only for x; otherwise it is optional" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

estimator.
will generate a `TensorFlow SavedModel <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md>`_
bundle ready for deployment. Your model will be available in S3 at the ``output_path`` location
that you specified when you created your `sagemaker.tensorflow.TensorFlow` estimator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add another set of backticks around sagemaker.tensorflow.TensorFlow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -614,188 +612,25 @@ Note that TensorBoard is not supported when passing wait=False to ``fit``.
Deploying TensorFlow Serving models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a ``TensorFlow`` Estimator has been fit, it saves a ``TensorFlow Serving`` model in
the S3 location defined by ``output_path``. You can call ``deploy`` on a ``TensorFlow``
After a TensorFlow Estimator has been fit, it saves a TensorFlow ``SavedModel`` in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Estimator" needs to be capitalized here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Deploying directly from model artifacts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- The first option uses a Python-based server that allows you to specify your own custom
input and output handling functions in a python script. This is the default option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize "Python"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

The common functionality can be extended by the addiction of the following two functions to your training script:

Overriding input preprocessing with an ``input_fn``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend the header lines on ll. 153 and 172

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Deploying from an Estimator
~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a TensorFlow Estimator has been fit, it saves a TensorFlow ``SavedModel`` in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same capitalization comment about "Estimator"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

'predictions': [3.5, 4.0, 5.5]
}

The format of the input and the output data correspond directly to the request and response formats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either s/format/formats or s/correspond/corresponds (I think it depends on if you count "data" as plural there)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

The format of the input and the output data correspond directly to the request and response formats
of the ``Predict`` method in the `TensorFlow Serving REST API <https://www.tensorflow.org/serving/api_rest>`_.

If your SavedModel includes the right ``signature_def``, you can also make Classify or Regress requests:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should "SavedModel" be monospace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not. I Corrected the one or two places where it was to match.

you are likely to have `./multi/model1/export/Servo/...` and `./multi/model2/export/Servo/...`. In both cases,
"Servo" is the base name for the SaveModel files. When serving multiple models, each model needs a unique
basename, so one or both of these will need to be changed. The `/export/` part of the path isn't needed
either, so you can simplify the layout at the same time:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double backticks for rst

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aargh again!! ok

@jesterhazy jesterhazy removed the request for review from eslesar-aws November 9, 2018 22:25
- Starts ``initial_instance_count`` EC2 instances of the type ``instance_type``.
- On each instance, it will do the following steps:

- start a Docker container optimized for TensorFlow Serving, see `SageMaker TensorFlow Serving containers <https://github.com/aws/sagemaker-tensorflow-serving-container>`_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this repo exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will soon

To use this feature, you will need to:

#. create a multi-model archive file
#. create a SageMaker and deploy it to an Endpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a SageMaker model**

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

# result is prediction from 'model2'
result = model2_predictor.predict(...)

Making predictions with the AWS CLI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken this doesn't work with localmode. I think we should make that clear here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. there is a way to make it work with local mode, but it requires a change to local mode. I will add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

The ``predictor.predict`` method call takes one parameter, the input ``data`` for which you want the SageMaker Endpoint
to provide inference. ``predict`` will serialize the input data, and send it in as request to the SageMaker Endpoint by
an ``InvokeEndpoint`` SageMaker operation. ``InvokeEndpoint`` operation requests can be made by ``predictor.predict``, by
boto3 ``sageMaker.runtime`` client or by AWS CLI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be "SageMaker Runtime client". if you want, could also add a link to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker-runtime.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -614,188 +617,25 @@ Note that TensorBoard is not supported when passing wait=False to ``fit``.
Deploying TensorFlow Serving models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a ``TensorFlow`` Estimator has been fit, it saves a ``TensorFlow Serving`` model in
the S3 location defined by ``output_path``. You can call ``deploy`` on a ``TensorFlow``
After a TensorFlow estimator has been fit, it saves a TensorFlow ``SavedModel`` in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another SavedModel in backticks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Deploying from an Estimator
~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a TensorFlow estimator has been fit, it saves a TensorFlow ``SavedModel`` in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and another monospaced SavedModel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -164,14 +164,19 @@ def __init__(self, config=None):
self.config = config
self.serving_port = get_config_value('local.serving_port', config) or 8080

def invoke_endpoint(self, Body, EndpointName, ContentType, Accept): # pylint: disable=unused-argument
def invoke_endpoint(self, Body, EndpointName, # pylint: disable=unused-argument
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have agreed on adding some unit tests in a follow up pr for this later.

icywang86rui
icywang86rui previously approved these changes Nov 10, 2018
laurenyu
laurenyu previously approved these changes Nov 10, 2018
Copy link
Contributor

@laurenyu laurenyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. not sure if @icywang86rui still has comments

edit: see she beat me to it

@jesterhazy jesterhazy dismissed stale reviews from laurenyu and icywang86rui via 0ca9c32 November 10, 2018 01:04
@jesterhazy jesterhazy merged commit 4f08a3d into aws:master Nov 10, 2018
@jesterhazy jesterhazy deleted the je-tfs-docs branch November 10, 2018 06:27
metrizable pushed a commit to metrizable/sagemaker-python-sdk that referenced this pull request Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants