learn

AI PROJECT-1.7 How to Deploy the Model?

Learn how to How to Deploy the Model

Prerequisite

STEP-1: Create Deployable Model Endpoint

  • First, we will import CSVSerializer class from the SageMaker SDK, which will help us to serialize input data in CSV format.
  • Also, we will create an object "xgb_predictor" as a SageMaker Predictor, representing deployed model endpoint. We can use this object to make predictions on new data.
code
from sagemaker.serializers import CSVSerializer
xgb_predictor=xgb_model.deploy(
    initial_instance_count=1,
    instance_type='ml.m5.large',
    serializer=CSVSerializer()
)

where

  • xgb_model.deploy: Method used to deploy trained XGBoost model as an endpoint on SageMaker for making predictions.

  • initial_instance_count=1: Specifies initial number of instances (containers) to deploy. In our case, we set it to 1.

  • instance_type='ml.m5.large': Specifies the compute instance type used for hosting the model. Availability and pricing vary by AWS Region.

  • serializer=CSVSerializer(): Specifies serializer to be used for input data of various formats (a NumPy array, list, file, or buffer). The CSVSerializer is chosen, indicating that input data should be formatted as CSV.

  • The deploy method creates a deployable model, configures the SageMaker hosting services endpoint, and launches the endpoint to host the model.

STEP-2: Retrieve Endpoint Name

code
xgb_predictor.endpoint_name
  • This will return the endpoint name of the xgb_predictor. The format of the endpoint name is "sagemaker-xgboost-YYYY-MM-DD-HH-MM-SS-SSS".

NEXT STEP

Learning checkpoint

Mark this guide complete to include it in your local Engineering Journey.

Knowledge path

Connected concepts

Explore the knowledge graph

WATCH WITH THIS TOPIC