DEV Community

Awwal
Awwal

Posted on

Comprehensive Guide: Deploying Prebuilt Models using Amazon SageMaker

Objective

The objective of this article is to provide a step-by-step guide on deploying an end-to-end machine learning model using a prebuilt AWS Jump Start model. The focus will be on leveraging low-code and no-code options provided by AWS. The article covers various aspects of the deployment process, including the creation of a SageMaker domain, deploying Jump Start models to SageMaker Inference Endpoint, and interacting with the deployed model in an open SageMaker notebook.

Introduction

Overview:

Image description: Architecture diagram

Source

This article is part of a three-part series that aims to demonstrate how to deploy machine learning models using AWS's low-code and no-code options. Specifically, this article focuses on deploying a prebuilt AWS Jump Start model and hosting it on a Streamlit server.

In this part of the article series, you will learn the following based on SageMaker:

  1. How to create a SageMaker domain.
  2. How to deploy Jump Start models to the SageMaker Inference Endpoint.
  3. How to interact with the deployed model in an open SageMaker notebook (optional).

Assumptions: You are familiar with navigating the AWS console and have an AWS account with SageMaker Full Access. If you don't have an account, you can sign up for one using the following link

Cost:
Please note that the labs from the workshop page costs around $10 if completed within 2 hours.

How to Get Free Access SageMaker (Optional):

  1. Utilize the AWS Free Tier.
  2. For students, consider joining the AWS DeepRacer Challenge or AWS Educate.
  3. Participate in AWS events to receive free credits.
  4. Attend AWS workshops to gain access to temporary accounts.

Jump Start

SageMaker Jump Start is a repository of pretrained end-to-end models that serve as baseline models for building upon. This low-code, no-code solution allows you to quickly leverage ready-to-use models for various use cases, including tabular regression, classification, and state-of-the-art models from Amazon and its partners like Stability AI, Cohere, AI21, and AlexTM. You can also enhance these models by performing additional training on them. Examples of JumpStart models can be found on the JumpStart landing page, which showcases available end-to-end machine learning solutions, pretrained models, and example notebooks.
Image description: Jump Start model

Domain

In SageMaker, a domain refers to a logical grouping of files and resources within a workspace. It provides a structured environment for managing machine learning deployments. Each domain in SageMaker consists of a collection of resources specifically tailored to facilitate machine learning workflows.

Model Endpoint

A SageMaker Endpoint is an API that allows you to access a model for inference. It serves as the interface for making predictions using your trained model. When deploying a model, SageMaker provides the necessary infrastructure based on your chosen deployment type. For prebuilt models, the infrastructure specifications are already defined. However, if you are creating your own model, you will need to specify the infrastructure type required to host your model. SageMaker leverages Docker containers for hosting the models, ensuring scalability and flexibility.

Model Parsing

Model parsing is the process of interpreting and analyzing the structure and content of a model. It involves understanding the input and output formats, data transformations, and any pre- or post-processing steps required. Accurate model parsing is essential for seamless integration and efficient utilization of the model.

Stable Diffusion

Stable Diffusion is a text-to-image model that utilizes generative modeling techniques to generate photorealistic images based on text prompts. It offers a powerful solution for transforming textual descriptions into visually compelling images. To learn more about Stable Diffusion and its capabilities, refer to this blog

Creating a SageMaker Domain

  1. Open the AWS Management Console and enter "Sagemaker" in the search bar. Click on "Amazon SageMaker" to access the SageMaker console.

  2. On the left navigation pane, click on "Domains" to go to the SageMaker Domain configuration page.
    Image description: Navigating to the Domains page

  3. Create a new domain by clicking on the "Create domain" button. Then, click on "Quick setup" (default) for easier domain configuration.
    Image description: Creating a new domain

  4. In the "Quick Setup" section, leave the default settings as they are.

  5. Enter a name for your domain in the "Domain name" text box.

  6. Under "User profile," you can enter a friendly user name or use the default name provided.

  7. In the "Execution role" section, click on the "Create new role" option.
    Image description: Creating a new execution role

  8. In the "Create an Execution role" dialog, select "Any S3 bucket" and leave the defaults as they are. Then, click the "Create role" button.
    Image description: Creating a new execution role

  9. You'll see a message confirming the successful creation of the IAM role.

  10. Scroll to the bottom of the page and click the "Submit" button to create the domain.
    Image description: Submitting the domain creation

  11. Wait for the domain creation process to complete. Once the domain is created, click on the domain you just created.

By following these steps, you will be able to create a SageMaker domain and proceed with configuring and utilizing it for your machine learning workflows.

Launching SageMaker Studio

  1. On the SageMaker Domain page, click on the newly created domain. This will redirect you to the domain details page.
    Image description: Domain details page
    Image description domain details

  2. Look for the "User profiles" section on the page.

Under "User profiles," click on the "Launch" button located on the right side of the page.

  1. From the dropdown list that appears, select "Studio." This will launch a SageMaker Studio notebook.

Image description: Launching SageMaker Studio

Please note that launching the SageMaker Studio may take some time to complete.

Once SageMaker Studio has launched successfully, you will be redirected to the SageMaker Studio landing page, as shown below.
Image description: SageMaker Studio landing page

Deploying JumpStart Models

  1. On the SageMaker Studio page, navigate to the left navigation pane and click on "SageMaker JumpStart" to expand the menu.

  2. Click on "Models, Notebooks, Solutions" to access the JumpStart models.
    Image description: Selecting JumpStart Models

  3. On the next screen, select "Stable Diffusion 2.1 base" from the available models, as shown in the image below.
    Image description: Selecting Stable Diffusion model

  4. On the Stable Diffusion details page, click the "Deploy" button to deploy the model. This will create an endpoint that can be used to interact with the model. The deployment process will also launch an instance to host the endpoint.
    Image description: Deploying the model

  5. Click "Deploy" to initiate the deployment process. Please note that the deployment may take some time to complete.

By following these steps, you will be able to deploy the JumpStart model, specifically the Stable Diffusion 2.1 base model. Once deployed, you will have an endpoint that can be used to interact with the model for inference tasks.

Setting Up the Model's Notebook

  1. Once the endpoint is deployed and in service. You can click "Open Notebook" button to interact with the model.

  2. After starting the model's new notebook, please allow some time for the notebook to initialize.

  3. Scroll down to the setup section and run the first cells as indicated in the notebook.
    Image description: run cells

Please note: Running the first cells and testing the model on a notebook are optional and can be done if desired.

Deploying the Flan-T5 XL Model

To deploy the Flan model, follow these steps:

  1. Search for "Flan-t5 xl" in the available models.

  2. Click on the "Flan-t5 xl" model to access the Flan-t5 xl model details page.

  3. On the Flan model details page, click on the "Deploy" button to initiate the deployment process.

  4. The flan-t5 xl model is deployed just as the stable diffusion model was deployed.
    Image description: Deploying the Flan model

By following these steps, you will be able to set up the model's notebook, run the necessary setup cells, and deploy the Flan model for further usage.

Viewing Endpoints

  1. On the SageMaker homepage, navigate to the "Inference" section and select "Endpoints". This will take you to the page displaying all the endpoints.
    Image description: Selecting Endpoints

  2. The endpoints page provides an overview of the endpoints that have been created. This will be useful in Part 2 of this tutorial.
    Image description: endpoints

By following these steps, you will be able to navigate to the endpoints page on the SageMaker homepage, which will be useful for the subsequent parts of this tutorial.

Top comments (0)