SageMaker MLOps Project Walkthrough - Amazon SageMaker
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

SageMaker MLOps Project Walkthrough

This walkthrough demonstrates how to use MLOps projects to create a CI/CD system to build, train, and deploy models.

Prerequisites

To complete this walkthrough, you need:

Step 1: Create the Project

In this step, you create a SageMaker MLOps project by using a SageMaker-provided project template to build, train, and deploy models.

To create the SageMaker MLOps project

  1. Sign in to Studio. For more information, see Onboard to Amazon SageMaker Domain.

  2. Choose Components and registries, and then select Projects from the dropdown list.

  3. Choose Create project.

    The Create project tab appears.

  4. For SageMaker project templates, choose Organization templates, then choose MLOps template for model building, training, and deployment.

  5. For Project details, enter a name and description for your project.

When the project appears in the Projects list with a Status of Created, move on to the next step.

Step 2: Clone the Code Repository

After you create the project, two CodeCommit repositories are created in the project. One of the repositories contains code to build and train a model, and one contains code to deploy the model. In this step, you clone the repository to your local SageMaker project that contains the code to build and train the model to the local Studio environment so that you can work with the code.

To clone the code repository

  1. Choose Components and registries, and then select Projects from the dropdown list.

  2. Find the name of the project you created in the previous step and double-click on it to open the project tab for your project.

  3. In the project tab, choose Repositories, and in the Local path column for the repository that ends with modelbuild, choose clone repo....

  4. In the dialog box that appears, accept the defaults and choose Clone repository.

    When clone of the repository is complete, the local path appears in the Local path column. Choose the path to open the local folder that contains the repository code in Studio.

Step 3: Make a Change in the Code

Now make a change to the pipeline code that builds the model and check in the change to initiate a new pipeline run. The pipeline run registers a new model version.

To make a code change

  1. In Studio, choose the file browser icon ( ), and navigate to the pipelines/abalone folder. Double-click pipeline.py to open the code file.

  2. In the pipeline.py file, find the line that sets the training instance type.

    training_instance_type = ParameterString( name="TrainingInstanceType", default_value="ml.m5.xlarge"

    Change ml.m5.xlarge to ml.m5.large, then type Ctrl+S to save the change.

  3. Choose the Git icon ( ). Stage, commit, and push the change in pipeline.py. For information about using Git in Studio, see Clone a Git Repository in SageMaker Studio.

After pushing your code change, the MLOps system initiates a run of the pipeline that creates a new model version. In the next step, you approve the new model version to deploy it to production.

Step 4: Approve the Model

Now you approve the new model version that was created in the previous step to initiate a deployment of the model version to a SageMaker endpoint.

To approve the model version

  1. Choose Components and registries, and then select Projects from the dropdown list.

  2. Find the name of the project you created in the first step and double-click on it to open the project tab for your project.

  3. In the project tab, choose Model groups, then double-click the name of the model group that appears.

    The model group tab appears.

  4. In the model group tab, double-click Version 2. The Version 2 tab opens. Choose Update status

  5. In the model Update model version status dialog box, in the Status dropdown list, select Approve, then choose Update status.

    Approving the model version causes the MLOps system to deploy the model to staging. To view the endpoint, choose the Endpoints tab on the project tab.

(Optional) Step 5: Deploy the Model Version to Production

Now you can deploy the model version to the production environment.

Note

To complete this step, you need to be an administrator in your Studio domain. If you are not an administrator, skip this step.

To deploy the model version to the production environment

  1. Log in to the CodePipeline console at https://console.amazonaws.cn/codepipeline/

  2. Choose Pipelines, then choose the pipeline with the name sagemaker-projectname-projectid-modeldeploy, where projectname is the name of your project, and projectid is the ID of your project.

  3. In the DeployStaging stage, choose Review.

  4. In the Review dialog box, choose Approve.

    Approving the DeployStaging stage causes the MLOps system to deploy the model to production. To view the endpoint, choose the Endpoints tab on the project tab in Studio.

Step 6: Clean Up Resources

To stop incurring charges, clean up the resources that were created in this walkthrough. To do this, complete the following steps.

Note

To delete the Amazon CloudFormation stack and the Amazon S3 bucket, you need to be an administrator in Studio. If you are not an administrator, ask your administrator to complete those steps.

  1. In the Studio sidebar, choose the SageMaker resources icon ( ).

  2. Choose Projects from the dropdown list.

  3. Select the target project from the dropdown list. If you don’t see your project, type the project name and apply the filter to find your project.

  4. There are two ways to delete a project in Studio:

    1. You can delete the project from the projects list.

      Right-click the target project and choose Delete from the dropdown list.

    2. You can delete a project from the Project details section.

      1. When you've found your project, double-click it to view its details in the main panel.

      2. Choose Delete from the Actions menu.

  5. Confirm your choice by choosing Delete from the Delete Project window.

    This deletes the Amazon Service Catalog provisioned product that the project created. This includes the CodeCommit, CodePipeline, and CodeBuild resources created for the project.

  6. Delete the Amazon CloudFormation stacks that the project created. There are two stacks, one for staging and one for production. The names of the stacks are sagemaker-projectname-project-id-deploy-staging and sagemaker-projectname-project-id-deploy-prod, where projectname is the name of your project, and project-id is the ID of your project.

    For information about how to delete a Amazon CloudFormation stack, see Deleting a stack on the Amazon CloudFormation console in the Amazon CloudFormation User Guide.

  7. Delete the Amazon S3 bucket that the project created. The name of the bucket is sagemaker-project-project-id, where project-id is the ID of your project.