Lesson 3 of 4 Model Deployment and Inference

Sharing Endpoints with Multi-Model, Multi-Container and Inference Components

This lesson explains the SageMaker AI options for sharing infrastructure among many models or models used together, instead of hosting each model on its own endpoint.

Learning outcomes

After completing this lesson, you will be able to:

  • Serve many same-framework models from a multi-model endpoint.
  • Use multi-container endpoints and inference pipelines.
  • Allocate resources per model with inference components.

Multi-model endpoints

A multi-model endpoint (MME) serves many models that use the same framework container from one endpoint. Model artefacts sit in an S3 prefix; the caller names the model with TargetModel, and SageMaker AI loads it into memory on first use and unloads rarely used models when memory is needed. MMEs suit thousands of similar models, such as one per customer or region, where each model is called infrequently. The first call to an unloaded model has extra latency.

The following diagram shows a multi-model endpoint that serves 4,000 per-store models, the models it holds in memory and the S3 prefix behind it.

One multi-model endpoint serving 4,000 per-store models. The artefacts sit under one S3 prefix; each request names its model with TargetModel; SageMaker AI loads a model into memory on first use and unloads rarely used ones when memory is needed. A first call to an unloaded model takes longer, which this workload accepts.
Which models are loaded at a given moment is illustrative.
Scenario questions

Share the endpoint

Exam skills 3.1.2

Choose the endpoint design for each set of models.

Log in to try this activity Interactive activities are free with an account.

Multi-container endpoints and inference pipelines

A multi-container endpoint hosts up to 15 different containers, for example models built with different frameworks, on one endpoint, which shares its instances and reduces cost. With direct invocation, the caller chooses which container handles each request with the TargetContainerHostname parameter.

With serial invocation, the containers form an inference pipeline: the output of one becomes the input of the next, such as pre-processing, then the model, then post-processing. This lets the same feature transformation code used in training run at inference, which prevents skew between how features are computed in training and in production.

Inference components

Inference components deploy several models onto one endpoint's instances, each with its own container, its own allocation of accelerators, CPU and memory, its own number of copies and its own scaling policy. This allows GPUs to be shared between models, each model to be updated independently, and individual models to scale to zero when unused.

Inference components are therefore the preferred approach for hosting several foundation models or deep learning models together, where dedicating a GPU instance to each model would waste capacity. The following table compares the options.

OptionModelsInvocationBest for
Multi-model endpointMany, same frameworkTargetModelThousands of infrequently used similar models
Multi-container (direct)Up to 15, different containersTargetContainerHostnameDifferent frameworks on one endpoint
Inference pipeline (serial)Up to 15 in sequenceSingle callPre-processing, model, post-processing
Inference componentsSeveral, each with own resourcesInferenceComponentNameSharing GPUs, independent scaling
True or false

Inference components

Exam skills 3.1.2 · 3.1.7

Check what inference components add to an endpoint.

Log in to try this activity Interactive activities are free with an account.
Worked example

Per-store forecasting models

A retailer trains a small XGBoost demand model for each of its 4,000 stores. Each store's model is called a few times an hour. Hosting 4,000 endpoints is unaffordable.

s3://models/demand/store-0001.tar.gz ... store-4000.tar.gz
runtime.invoke_endpoint(EndpointName="demand-mme",
                        TargetModel="store-1872.tar.gz",
                        ContentType="text/csv", Body=features)

One multi-model endpoint on a few instances serves all 4,000 models, loading them as needed. The occasional extra latency on first load is acceptable for this use case.

Check yourself

Which endpoint type runs pre-processing and a model in sequence?

Show answer

A serial inference pipeline.

Exam Tips

Remember for the exam

  • Thousands of similar models: multi-model endpoint with TargetModel.
  • Different frameworks on one endpoint: multi-container endpoint.
  • Pre-processing plus model in sequence: serial inference pipeline.
  • Several models sharing GPUs with independent scaling: inference components.
  • MMEs add latency when a model is loaded for the first time.