AWS SageMaker MLOps Project Walkthrough

AWS SageMaker MLOps Project Walkthrough

This walkthrough uses the template MLOps template for model building, training, and deployment to demonstrate using MLOps projects to create a CI/CD system to build, train, and deploy models.

Prerequisites

To complete this walkthrough, you need:

Topics

  • Step 1: Create the Project

  • Step 2: Clone the Code Repository

  • Step 3: Make a Change in the Code

  • Step 4: Approve the Model

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

  • Step 6: Clean Up Resources

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. In the Studio sidebar, choose the Home icon ( ).

  3. Select Deployments from the menu, and then select Projects.

  4. Choose Create project.

    The Create project tab appears.

  5. If not selected already, choose SageMaker templates, then choose MLOps template for model building, training, and deployment.

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

When the project appears in the Projects list with a Status of Create completed, 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. In the Studio sidebar, choose the Home icon ( ).

  2. Select Deployments from the menu, and then select Projects.

  3. Select the project you created in the previous step to open the project tab for your project.

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

  5. 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. Also, enter a summary in the Summary field and an optional description in the Description field.

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. In the Studio sidebar, choose the Home icon ( ).

  2. Select Deployments from the menu, and then select Projects.

  3. Select the name of the project you created in the first step to open the project tab for your project.

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

    The model group tab appears.

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

  6. 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.aws.amazon.com/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 AWS 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 Home icon ( ).

  2. Select Deployments from the menu, and then select Projects.

  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. You can delete a Studio project in one of the following ways:

    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 AWS Service Catalog provisioned product that the project created. This includes the CodeCommit, CodePipeline, and CodeBuild resources created for the project.

  6. Delete the AWS 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 AWS CloudFormation stack, see Deleting a stack on the AWS CloudFormation console in the AWS 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.

Conclusion

I hope this blog has been helpful. I'll see you in the next blog.

Community and Social Footprints :

Did you find this article valuable?

Support Cloudnloud Tech Community by becoming a sponsor. Any amount is appreciated!