All Projects β†’ aws β†’ Sagemaker Inference Toolkit

aws / Sagemaker Inference Toolkit

Licence: apache-2.0
Serve machine learning models within a 🐳 Docker container using 🧠 Amazon SageMaker.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Sagemaker Inference Toolkit

Amazon Sagemaker Examples
Example πŸ““ Jupyter notebooks that demonstrate how to build, train, and deploy machine learning models using 🧠 Amazon SageMaker.
Stars: ✭ 6,346 (+6183.17%)
Mutual labels:  aws, inference
Mivisionx
MIVisionX toolkit is a set of comprehensive computer vision and machine intelligence libraries, utilities, and applications bundled into a single toolkit. AMD MIVisionX also delivers a highly optimized open-source implementation of the Khronos OpenVXβ„’ and OpenVXβ„’ Extensions.
Stars: ✭ 100 (-0.99%)
Mutual labels:  inference
Lambroll
lambroll is a minimal deployment tool for AWS Lambda.
Stars: ✭ 97 (-3.96%)
Mutual labels:  aws
Diamondb
[WIP] DiamonDB: Rebuild of time series database on AWS.
Stars: ✭ 98 (-2.97%)
Mutual labels:  aws
Sagemaker Python Sdk
A library for training and deploying machine learning models on Amazon SageMaker
Stars: ✭ 1,344 (+1230.69%)
Mutual labels:  aws
Etcd Backup Restore
Collection of components to backup and restore the Etcd of a Kubernetes cluster
Stars: ✭ 99 (-1.98%)
Mutual labels:  aws
Streamx
kafka-connect-s3 : Ingest data from Kafka to Object Stores(s3)
Stars: ✭ 96 (-4.95%)
Mutual labels:  aws
Lambdauth
A sample authentication service implemented with a server-less architecture, using AWS Lambda to host and execute the code and Amazon DynamoDB as persistent storage. This provides a cost-efficient solution that is scalable and highly available and can be used with Amazon Cognito for Developer Authenticated Identities.
Stars: ✭ 1,365 (+1251.49%)
Mutual labels:  aws
Awesome Aws Security
Curated list of links, references, books videos, tutorials (Free or Paid), Exploit, CTFs, Hacking Practices etc. which are related to AWS Security
Stars: ✭ 100 (-0.99%)
Mutual labels:  aws
Awesome Cloud Security
Curated list of awesome cloud security blogs, podcasts, standards, projects, and examples.
Stars: ✭ 98 (-2.97%)
Mutual labels:  aws
Awstaghelper
AWS bulk tagging tool
Stars: ✭ 98 (-2.97%)
Mutual labels:  aws
Node Athena
a nodejs simple aws athena client
Stars: ✭ 97 (-3.96%)
Mutual labels:  aws
Serverless Chat
A serverless web chat built using AWS Lambda, AWS IoT (for WebSockets) and Amazon DynamoDB
Stars: ✭ 99 (-1.98%)
Mutual labels:  aws
Ops Aws Vpn
Serverless OpenVPN Certificate Authority running on AWS
Stars: ✭ 97 (-3.96%)
Mutual labels:  aws
Siac
SIAC is an enterprise SIEM built on open-source technology.
Stars: ✭ 100 (-0.99%)
Mutual labels:  aws
Attacking Cloudgoat2
A step-by-step walkthrough of CloudGoat 2.0 scenarios.
Stars: ✭ 97 (-3.96%)
Mutual labels:  aws
Kglab
Graph-Based Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, RDFlib, pySHACL, RAPIDS, NetworkX, iGraph, PyVis, pslpython, pyarrow, etc.
Stars: ✭ 98 (-2.97%)
Mutual labels:  inference
Ddns Route53
Dynamic DNS for Amazon Route 53 on a time-based schedule
Stars: ✭ 98 (-2.97%)
Mutual labels:  aws
Foundatio
Pluggable foundation blocks for building distributed apps.
Stars: ✭ 1,365 (+1251.49%)
Mutual labels:  aws
Aws K8s Kops Ansible
Kubernetes setup on Amazon AWS using Kops and Ansible
Stars: ✭ 101 (+0%)
Mutual labels:  aws

SageMaker

SageMaker Inference Toolkit

Latest Version Supported Python Versions Code Style: Black

Serve machine learning models within a Docker container using Amazon SageMaker.

πŸ“š Background

Amazon SageMaker is a fully managed service for data science and machine learning (ML) workflows. You can use Amazon SageMaker to simplify the process of building, training, and deploying ML models.

Once you have a trained model, you can include it in a Docker container that runs your inference code. A container provides an effectively isolated environment, ensuring a consistent runtime regardless of where the container is deployed. Containerizing your model and code enables fast and reliable deployment of your model.

The SageMaker Inference Toolkit implements a model serving stack and can be easily added to any Docker container, making it deployable to SageMaker. This library's serving stack is built on Multi Model Server, and it can serve your own models or those you trained on SageMaker using machine learning frameworks with native SageMaker support. If you use a prebuilt SageMaker Docker image for inference, this library may already be included.

For more information, see the Amazon SageMaker Developer Guide sections on building your own container with Multi Model Server and using your own models.

πŸ›  Installation

To install this library in your Docker image, add the following line to your Dockerfile:

RUN pip3 install multi-model-server sagemaker-inference

Here is an example of a Dockerfile that installs SageMaker Inference Toolkit.

πŸ’» Usage

Implementation Steps

To use the SageMaker Inference Toolkit, you need to do the following:

  1. Implement an inference handler, which is responsible for loading the model and providing input, predict, and output functions. (Here is an example of an inference handler.)

    from sagemaker_inference import content_types, decoder, default_inference_handler, encoder, errors
    
    class DefaultPytorchInferenceHandler(default_inference_handler.DefaultInferenceHandler):
    
        def default_model_fn(self, model_dir):
            """Loads a model. For PyTorch, a default function to load a model cannot be provided.
            Users should provide customized model_fn() in script.
    
            Args:
                model_dir: a directory where model is saved.
    
            Returns: A PyTorch model.
            """
            raise NotImplementedError(textwrap.dedent("""
            Please provide a model_fn implementation.
            See documentation for model_fn at https://github.com/aws/sagemaker-python-sdk
            """))
    
        def default_input_fn(self, input_data, content_type):
            """A default input_fn that can handle JSON, CSV and NPZ formats.
    
            Args:
                input_data: the request payload serialized in the content_type format
                content_type: the request content_type
    
            Returns: input_data deserialized into torch.FloatTensor or torch.cuda.FloatTensor depending if cuda is available.
            """
            return decoder.decode(input_data, content_type)
    
        def default_predict_fn(self, data, model):
            """A default predict_fn for PyTorch. Calls a model on data deserialized in input_fn.
            Runs prediction on GPU if cuda is available.
    
            Args:
                data: input data (torch.Tensor) for prediction deserialized by input_fn
                model: PyTorch model loaded in memory by model_fn
    
            Returns: a prediction
            """
            return model(input_data)
    
        def default_output_fn(self, prediction, accept):
            """A default output_fn for PyTorch. Serializes predictions from predict_fn to JSON, CSV or NPY format.
    
            Args:
                prediction: a prediction result from predict_fn
                accept: type which the output data needs to be serialized
    
            Returns: output data serialized
            """
            return encoder.encode(prediction, accept)
    
  2. Implement a handler service that is executed by the model server. (Here is an example of a handler service.) For more information on how to define your HANDLER_SERVICE file, see the MMS custom service documentation.

    from sagemaker_inference.default_handler_service import DefaultHandlerService
    from sagemaker_inference.transformer import Transformer
    from sagemaker_pytorch_serving_container.default_inference_handler import DefaultPytorchInferenceHandler
    
    
    class HandlerService(DefaultHandlerService):
        """Handler service that is executed by the model server.
        Determines specific default inference handlers to use based on model being used.
        This class extends ``DefaultHandlerService``, which define the following:
            - The ``handle`` method is invoked for all incoming inference requests to the model server.
            - The ``initialize`` method is invoked at model server start up.
        Based on: https://github.com/awslabs/multi-model-server/blob/master/docs/custom_service.md
        """
        def __init__(self):
            transformer = Transformer(default_inference_handler=DefaultPytorchInferenceHandler())
            super(HandlerService, self).__init__(transformer=transformer)
    
  3. Implement a serving entrypoint, which starts the model server. (Here is an example of a serving entrypoint.)

    from sagemaker_inference import model_server
    
    model_server.start_model_server(handler_service=HANDLER_SERVICE)
    
  4. Define the location of the entrypoint in your Dockerfile.

    ENTRYPOINT ["python", "/usr/local/bin/entrypoint.py"]
    

Complete Example

Here is a complete example demonstrating usage of the SageMaker Inference Toolkit in your own container for deployment to a multi-model endpoint.

πŸ“œ License

This library is licensed under the Apache 2.0 License. For more details, please take a look at the LICENSE file.

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines if you'd like to open an issue or submit a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].