Skip to content

documentation: Document LambdaModel and LambdaPredictor classes #2558

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 7 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/inference/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ Model
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: sagemaker.serverless.model.LambdaModel
:members:
:undoc-members:
:show-inheritance:
5 changes: 5 additions & 0 deletions doc/api/inference/predictors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ Make real-time predictions against SageMaker endpoints with Python objects
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: sagemaker.serverless.predictor.LambdaPredictor
:members:
:undoc-members:
:show-inheritance:
44 changes: 44 additions & 0 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,50 @@ You can also find these notebooks in the **Advanced Functionality** section of t
For information about using sample notebooks in a SageMaker notebook instance, see `Use Example Notebooks <https://docs.aws.amazon.com/sagemaker/latest/dg/howitworks-nbexamples.html>`__
in the AWS documentation.

********************
Serverless Inference
********************

You can use the SageMaker Python SDK to perform serverless inference on Lambda.

To deploy models to Lambda, you must complete the following prerequisites:

- `Package your model and inference code as a container image. <https://docs.aws.amazon.com/lambda/latest/dg/images-create.html>`_
- `Create a role that lists Lambda as a trusted entity. <https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html#permissions-executionrole-console>`_

After completing the prerequisites, you can deploy your model to Lambda using
the `LambdaModel`_ class.

.. code:: python

from sagemaker.serverless import LambdaModel

image_uri = "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-lambda-repository:latest"
role = "arn:aws:iam::123456789012:role/MyLambdaExecutionRole"

model = LambdaModel(image_uri=image_uri, role=role)
predictor = model.deploy("my-lambda-function", timeout=20, memory_size=4092)

The ``deploy`` method returns a `LambdaPredictor`_ instance. Use the
`LambdaPredictor`_ ``predict`` method to perform inference on Lambda.

.. code:: python

url = "https://example.com/cat.jpeg"
predictor.predict({"url": url}) # {'class': 'tabby'}

Once you are done performing inference on Lambda, free the `LambdaModel`_ and
`LambdaPredictor`_ resources using the ``delete_model`` and ``delete_predictor``
methods.

.. code:: python

model.delete_model()
predictor.delete_predictor()

.. _LambdaModel : https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.serverless.model.LambdaModel
.. _LambdaPredictor : https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html#sagemaker.serverless.predictor.LambdaPredictor

******************
SageMaker Workflow
******************
Expand Down