{"id":1073,"date":"2021-10-23T08:41:54","date_gmt":"2021-10-23T08:41:54","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2021\/10\/23\/improve-your-data-science-workflow-with-a-multi-branch-training-mlops-pipeline-using-aws\/"},"modified":"2021-10-23T08:41:54","modified_gmt":"2021-10-23T08:41:54","slug":"improve-your-data-science-workflow-with-a-multi-branch-training-mlops-pipeline-using-aws","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2021\/10\/23\/improve-your-data-science-workflow-with-a-multi-branch-training-mlops-pipeline-using-aws\/","title":{"rendered":"Improve your data science workflow with a multi-branch training MLOps pipeline using AWS"},"content":{"rendered":"<div id=\"\">\n<p>In this post, you will learn how to create a multi-branch training MLOps continuous integration and continuous delivery (CI\/CD) pipeline using <a href=\"https:\/\/aws.amazon.com\/codepipeline\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS CodePipeline<\/a> and <a href=\"https:\/\/aws.amazon.com\/codecommit\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS CodeCommit<\/a>, in addition to Jenkins and GitHub. I discuss the concept of experiment branches, where data scientists can work in parallel and eventually merge their experiment back into the main branch. I also show you how to create an <a href=\"https:\/\/aws.amazon.com\/sagemaker\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker<\/a> projects template that you can use from within <a href=\"https:\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/studio.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Studio<\/a>.<\/p>\n<p>SageMaker projects give organizations the ability to set up and standardize developer environments for data scientists and CI\/CD systems for MLOps engineers. With SageMaker projects, MLOps engineers or organization admins can define templates that bootstrap the machine learning (ML) workflow with source version control, automated ML pipelines, and a set of code to start iterating over ML use cases. With SageMaker projects, organizations can set up dependency management, code repository management, build reproducibility, and artifact sharing and management. SageMaker projects are provisioned using AWS Service Catalog products.<\/p>\n<p>SageMaker projects already provides a few MLOps CI\/CD pipeline templates, which are the recommended way to get started with CI\/CD in SageMaker. These training templates let you modify a single predefined branch called main, and all changes to this branch launch a training job. In some cases, though, you may want to use a multi-branch (trunk-based) training pipeline. This type of pipeline lets you get more flexibility and better performance with a thorough review of the code and experiment results before approving models and merging changes into main. This solution enables you to create several experimental branches that each launch their own training job and create their own model artifact. We can then use pull requests to approve some of these models, using a modified SageMaker template available in <a href=\"https:\/\/github.com\/aws-samples\/sagemaker-custom-project-templates\/tree\/main\/multi-branch-mlops-train\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>.<\/p>\n<p>When data scientists are working on a new model, that work is often experimental, meaning that unsuccessful experiments may be discarded and those with good results can go into production. Each data scientist may be working on a particular attempt at improving the current objective function. While one may be trying out a different architecture, another may be trying a new set of hyperparameters, for instance.<\/p>\n<p>Whatever may be the case, these <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/amazon-sagemaker-experiments-organize-track-and-compare-your-machine-learning-trainings\/\" target=\"_blank\" rel=\"noopener noreferrer\">experiments should be version controlled, tracked, and automated<\/a>. When the winning experiment is found and becomes eligible to be merged into the main branch, it can be assessed by a lead data scientist. They can view the exact code that was run, identify the key metrics output by the experiment, and have the results of any automated tests before model approval and release. When each experiment has its own branch, you can automate training whenever a Git push is run. This way, we can make sure that all metrics and tests for the model are stored in Studio.<\/p>\n<p>The following image illustrates a potential Git history of two data scientists experimenting on the same project.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image001.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29515\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image001.jpg\" alt=\"\" width=\"622\" height=\"449\"><\/a><\/p>\n<p>This post includes the following sections:<\/p>\n<ul>\n<li>Architecture overview<\/li>\n<li>Deploy the baseline stack<\/li>\n<li>Configure the template to be used from within Studio<\/li>\n<li>Create a new project<\/li>\n<li>Create and release a new experiment with CodePipeline and CodeCommit<\/li>\n<li>Configure the Jenkins instance (optional)<\/li>\n<li>Create and release a new experiment with Jenkins and GitHub (optional)<\/li>\n<li>Review experiments from pull requests<\/li>\n<\/ul>\n<h2>Architecture overview<\/h2>\n<p>The following architecture shows how you can automate the creation of a new CodePipeline pipeline whenever someone creates a new branch. The pipeline also runs when changes are made to that specific branch. Additionally, the architecture shows a release pipeline that runs when a merge happens in the main branch and marks the related model as approved in the model registry.<\/p>\n<p>This is all based on the concept of <a href=\"https:\/\/aws.amazon.com\/blogs\/devops\/multi-branch-codepipeline-strategy-with-event-driven-architecture\/\" target=\"_blank\" rel=\"noopener noreferrer\">feature branches in trunk-based development<\/a>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image002.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29516\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image002.png\" alt=\"\" width=\"1183\" height=\"780\"><\/a><\/p>\n<p>The architecture workflow includes the following steps:<\/p>\n<ol>\n<li>The data scientist makes a Git push of a new experiment branch to the remote repository in CodeCommit.<\/li>\n<li><a href=\"https:\/\/aws.amazon.com\/eventbridge\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon EventBridge<\/a> listens for branch create events and invokes an <a href=\"http:\/\/aws.amazon.com\/lambda\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Lambda<\/a> function.<\/li>\n<li>The function invokes <a href=\"http:\/\/aws.amazon.com\/cloudformation\" target=\"_blank\" rel=\"noopener noreferrer\">AWS CloudFormation<\/a> to create a new stack that contains the CodePipeline definition that is used for the new branch.<\/li>\n<li>The CodePipeline pipeline is triggered automatically after creation. In the final stage, the pipeline triggers CodeBuild, which builds a Docker image, pushes it to <a href=\"http:\/\/aws.amazon.com\/ecr\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Elastic Container Registry<\/a> (Amazon ECR), updates the SageMaker pipeline, and invokes it.<\/li>\n<li>The SageMaker pipeline runs all the steps required to train the model and store it in the model registry.<\/li>\n<li>After the pipeline runs, the model awaits approval.<\/li>\n<li>The data scientist creates a pull request in the CodeCommit repository, to have the new branch merge with the main branch.<\/li>\n<li>The lead data scientist approves the pull request if the model is satisfactory.<\/li>\n<li>Another Lambda function is triggered as part of releasing the model pipeline.<\/li>\n<li>The function approves the model in the model registry.<\/li>\n<\/ol>\n<p>Optionally, you may not want to use CodePipeline and CodeCommit for the CI\/CD pipeline. For that purpose, we also provide the required template to provision the necessary infrastructure to integrate with a Jenkins and GitHub option, as shown in the following diagram.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image003.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29517\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image003.png\" alt=\"\" width=\"991\" height=\"324\"><\/a><\/p>\n<p>This architecture includes the following workflow:<\/p>\n<ol>\n<li>The data scientist creates a new branch with the <code>experiment\/<\/code> prefix and commits their experiment code, pushing the changes to the remote repository.<\/li>\n<li>CodeBuild launches the job in <a href=\"https:\/\/aws.amazon.com\/sagemaker\/pipelines\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Pipelines<\/a>.<\/li>\n<li>The pipeline trains the model and stores it in the model registry.<\/li>\n<li>The model is stored with the status <code>Pending<\/code>.<\/li>\n<li>If the experiment is successful, the data scientist creates a pull request to the main branch.<\/li>\n<li>When the pull request is approved, it triggers the release pipeline.<\/li>\n<li>The release pipeline invokes a Lambda function that approves the model in the model registry.<\/li>\n<\/ol>\n<h2>Prerequisites<\/h2>\n<p>For this walkthrough, you should have the following prerequisites:<\/p>\n<h2>Deploy the baseline stack<\/h2>\n<p>The purpose of the baseline stack is to provision the standard resources used as seed by the SageMaker projects template to create new projects.<\/p>\n<p>Clone the sample repository and deploy the baseline stack with the following code:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">git clone https:\/\/github.com\/aws-samples\/sagemaker-custom-project-templates.git\nmkdir sample-multi-branch-train\ncp -r sagemaker-custom-project-templates\/multi-branch-mlops-train\/* sample-multi-branch-train\ncd sample-multi-branch-train\n.\/deploy.sh -p code_pipeline+code_commit\n<\/code><\/pre>\n<\/p><\/div>\n<p>In the preceding example, you may instead deploy the stack to support Jenkins and GitHub by using <code>.\/deploy.sh -p jenkins<\/code>.<\/p>\n<h2>Configure the template to use in Studio<\/h2>\n<p>To configure your template, complete the following steps:<\/p>\n<ol>\n<li>Create a portfolio in the AWS Service Catalog, providing entries for <strong>Portfolio name<\/strong>, <strong>Description<\/strong>, and <strong>Owner<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image004.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29518\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image004.png\" alt=\"\" width=\"898\" height=\"599\"><\/a><\/li>\n<li>Assign a new product by choosing <strong>Upload new product<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image005.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29519\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image005.png\" alt=\"\" width=\"1358\" height=\"611\"><\/a><\/li>\n<li>Enter the details for <strong>Product name<\/strong>, <strong>Description<\/strong>, and <strong>Owner<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image006.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29520\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image006.png\" alt=\"\" width=\"989\" height=\"584\"><\/a><\/li>\n<\/ol>\n<p>You also specify the CloudFormation template to be used by Service Catalog in provisioning the product.<\/p>\n<ol start=\"4\">\n<li>For <strong>Choose a method<\/strong>, select <strong>Use a CloudFormation template<\/strong>.<\/li>\n<li>Enter the CloudFormation template deployed by the baseline stack: <code>https:\/\/cloud-formation-&lt;<span>AWS-ACCOUNT-ID<\/span>&gt;-us-east-1.s3.amazonaws.com\/model_train.yaml<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image007.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29521\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image007.png\" alt=\"\" width=\"989\" height=\"626\"><\/a><\/li>\n<li>On the navigation pane, choose <strong>Products<\/strong>.<\/li>\n<li>On the <strong>Tags<\/strong> tab, add the SageMaker visibility tag <code>sagemaker:studio-visibility<\/code> to the product with value <code>true<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image008.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29522\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image008.png\" alt=\"\" width=\"1371\" height=\"617\"><\/a><\/li>\n<li>In the navigation pane, choose <strong>Portfolios<\/strong>.<\/li>\n<li>On the <strong>Constraints<\/strong> tab, choose <strong>Create constraint<\/strong>.<\/li>\n<li>Select the role that was created by the baseline stack (<code>MultiBranchTrainMLOpsLaunchRole<\/code>).<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image009.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29523\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image009.png\" alt=\"\" width=\"1371\" height=\"617\"><\/a><\/li>\n<\/ol>\n<p>Next, you need to add permission to groups, roles, and users to use the product.<\/p>\n<ol start=\"11\">\n<li>Choose <strong>Portfolios<\/strong> in the navigation pane.<\/li>\n<li>On the <strong>Groups, roles, and users<\/strong> tab, choose <strong>Add groups, roles, users<\/strong>.<\/li>\n<li>Add the relevant groups, roles, and users that should have permission to provision the product (for this list, I add the role <code>Admin<\/code> and my SageMaker execution role).<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image010.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29524\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image010.png\" alt=\"\" width=\"1378\" height=\"608\"><\/a><\/li>\n<\/ol>\n<p>The template is now available in Studio.<\/p>\n<ol start=\"14\">\n<li>Open Studio and navigate to the <strong>Create project<\/strong> page.<\/li>\n<li>Choose <strong>Organization templates<\/strong>.<\/li>\n<\/ol>\n<p>You can see the AWS Service Catalog product you created.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image011.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29525\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image011.png\" alt=\"\" width=\"1032\" height=\"390\"><\/a><\/p>\n<h2>Create a new project<\/h2>\n<p>You\u2019re now ready to create a new project.<\/p>\n<ol>\n<li>Choose the template you created.<\/li>\n<li>Choose <strong>Create project<\/strong>.<\/li>\n<li>For <strong>Name<\/strong>, enter a name.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image012.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29526\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image012.png\" alt=\"\" width=\"2720\" height=\"1144\"><\/a><\/li>\n<\/ol>\n<p>Wait for the project to be created. You should see the project with the status <code>Creating<\/code>.<\/p>\n<p><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image013.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29527 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image013-300x282.png\" alt=\"\" width=\"300\" height=\"282\"><\/a><\/p>\n<ol start=\"4\">\n<li>Add the sample code to the created repository (continue from the previously used terminal):<\/li>\n<\/ol>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">git init\ngit stage .\ngit commit -m \"adds sample code\"\ngit remote add origin https:\/\/git-codecommit.us-east-1.amazonaws.com\/v1\/repos\/model-mymodel-train\ngit push --set-upstream origin main<\/code><\/pre>\n<\/p><\/div>\n<h2>Create and release a new experiment with CodePipeline and CodeCommit<\/h2>\n<p>To create and release a new experiment, complete the following steps:<\/p>\n<ol>\n<li>Either clone the CodeCommit repository or start from the previous terminal to submit the experiment code to the repository:<\/li>\n<\/ol>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">git checkout -b experiment\/myexperiment\n&lt;make some changes to the code&gt;\ngit stage &lt;created and modified files&gt;\ngit commit -m \"adds some change\"\ngit push --set-upstream origin experiment\/myexperiment<\/code><\/pre>\n<\/p><\/div>\n<p>After a few seconds, a new pipeline is created in CodePipeline.<\/p>\n<p>You can see the pipeline running, and you should see the <strong>Train<\/strong> step update to <code>In progress<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image014.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29528\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image014.png\" alt=\"\" width=\"2782\" height=\"1166\"><\/a><\/p>\n<p>The <strong>Train<\/strong> step of the pipeline launches a new SageMaker Pipelines pipeline that trains the model.<\/p>\n<p>In Studio, under <strong>SageMaker resources<\/strong>, choose <strong>Pipelines<\/strong> on the drop-down menu. You should see the pipeline running.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image015.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29529\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image015.png\" alt=\"\" width=\"2782\" height=\"776\"><\/a><\/p>\n<p>When the pipeline is complete, a new model gets stored in the SageMaker Model Registry with <code>Pending<\/code> status.<\/p>\n<p>You can choose <strong>Model registry<\/strong> on the drop-down menu to view the model on the <strong>SageMaker resources<\/strong> page.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image016.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29530\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image016.png\" alt=\"\" width=\"2782\" height=\"776\"><\/a><\/p>\n<p>At this point, the data scientist can assess the experiment results and push subsequent commits, attempting to achieve better results for the experiment goal. When doing so, the pipeline is triggered again and new model versions are stored in the model registry.<\/p>\n<p>If the data scientist deems the experiment successful, they can create a pull request, asking to merge the changes from the <code>experiment\/myexperiment<\/code> branch into <code>main<\/code>.<\/p>\n<ol start=\"2\">\n<li>On the CodeCommit console, under <strong>Repositories<\/strong> in the navigation pane, choose your repository.<\/li>\n<li>Choose <strong>Code<\/strong> in the navigation pane.<\/li>\n<li>Choose <strong>Create pull request<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image017.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29531\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image017.png\" alt=\"\" width=\"2782\" height=\"1054\"><\/a><\/li>\n<li>Choose the destination, generally main, and the source branch, which in this case is <code>experiment\/myexperiment<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image018.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29532\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image018.png\" alt=\"\" width=\"2778\" height=\"954\"><\/a><\/li>\n<\/ol>\n<p>After you create the pull request, you can review both the code and the experiment\u2019s results, by using <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/amazon-sagemaker-experiments-organize-track-and-compare-your-machine-learning-trainings\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Experiments<\/a>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image019.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29533\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image019.png\" alt=\"\" width=\"2778\" height=\"890\"><\/a><\/p>\n<p>You can also find the experiment results by using the Git commit ID of the latest commit in the branch that is being merged. With this ID, you can go to Studio, under <strong>SageMaker resources<\/strong>, and choose <strong>Experiments and trials<\/strong>. You can find all the experiments for your model, in this case named <code>model-mymodel<\/code>, and also the trials, named after the commit ID.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29534\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\" alt=\"\" width=\"2078\" height=\"774\"><\/a><\/p>\n<ol start=\"6\">\n<li>On the CodeCommit console, choose <strong>Merge<\/strong>.<\/li>\n<li>Select <strong>Fast forward merge<\/strong>.<\/li>\n<li>Choose <strong>Merge pull request<\/strong>.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image021.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29535\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image021.png\" alt=\"\" width=\"2778\" height=\"1252\"><\/a><\/p>\n<p>When the merge is complete, the respective model gets approved automatically in the model registry. Also, because we chose to delete the experiment branch after the merge, the provisioned experiment pipeline is automatically deleted.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image022.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29536\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image022.png\" alt=\"\" width=\"2778\" height=\"714\"><\/a><\/p>\n<h2>Configure the Jenkins instance (optional)<\/h2>\n<p>To configure the Jenkins instance, you must install the required plugins, configure the train pipeline, and configure the release pipeline.<\/p>\n<h3>Install the required plugins<\/h3>\n<p>On the dashboard, choose <strong>Manage Jenkins<\/strong>, <strong>Manage Plugins<\/strong>, and <strong>Available<\/strong>. Install the following plugins:<\/p>\n<h3>Configure the train pipeline<\/h3>\n<p>To configure the train pipeline, complete the following steps:<\/p>\n<ol>\n<li>On the dashboard, choose <strong>New item<\/strong>.<\/li>\n<li>Enter the name <code>model-mymodel-train<\/code>.<\/li>\n<li>Select <strong>Freestyle Project<\/strong>.<\/li>\n<li>In the <strong>Source Code Management <\/strong>section, select <strong>Git<\/strong>.<\/li>\n<li>For <strong>Repository URL<\/strong>, enter your URL.<\/li>\n<li>For <strong>Branches to build<\/strong>, enter <code>*\/experiment\/*<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image023.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29537\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image023.png\" alt=\"\" width=\"1852\" height=\"1132\"><\/a><\/li>\n<li>In the <strong>Build Triggers<\/strong> section, select <strong>Poll SCM<\/strong>.<\/li>\n<li>For <strong>Schedule<\/strong>, enter <code>H\/2 * * * *<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image024.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29538 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image024-300x279.png\" alt=\"\" width=\"300\" height=\"279\"><\/a><\/li>\n<li>In the <strong>Build Environment<\/strong> section, select <strong>Delete workspace before build starts<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image025.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29539 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image025-300x236.png\" alt=\"\" width=\"300\" height=\"236\"><\/a><\/li>\n<li>Now you add a build step of type <strong>AWS CodeBuild<\/strong>.<\/li>\n<li>To generate the credentials, go to <a href=\"https:\/\/console.aws.amazon.com\/iam\/home#\/users\/jenkins-model-mymodel?section=security_credentials\" target=\"_blank\" rel=\"noopener noreferrer\">the user page<\/a> and choose <strong>Create access key<\/strong>.<\/li>\n<li>Make sure to store the secret to use again in a later step.<\/li>\n<li>In the <strong>AWS Configuration<\/strong> section, select <strong>Manually specify access and secret keys<\/strong>.<\/li>\n<li>Enter keys for <strong>AWS Access Key<\/strong> and <strong>AWS Secret Key<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image026.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29540 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image026-229x300.png\" alt=\"\" width=\"229\" height=\"300\"><\/a><\/li>\n<li>In the <strong>Project Configuration <\/strong>section, provide the Region and project name (in this case, <code>model-mymodel-train<\/code>).<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image027.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29541 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image027-300x212.png\" alt=\"\" width=\"300\" height=\"212\"><\/a><\/li>\n<li>Select <strong>Use Jenkins source<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image028.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29542 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image028-300x122.png\" alt=\"\" width=\"300\" height=\"122\"><\/a><\/li>\n<li>For <strong>Environment Variables Override<\/strong>, enter the required environment variables for the build script:<\/li>\n<\/ol>\n<p><code>[ { BRANCH_NAME, ${GIT_BRANCH} }, { COMMIT_HASH, ${GIT_COMMIT} } ]<\/code><br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image029.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29543 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image029-300x86.png\" alt=\"\" width=\"300\" height=\"86\"><\/a><\/p>\n<p>Next, you add a file operation build step to delete any remaining files after the build.<\/p>\n<ol start=\"18\">\n<li>Choose <strong>Add build step<\/strong> and <strong>File Operations<\/strong>.<\/li>\n<li>On the <strong>Add<\/strong> menu, choose <strong>File Delete<\/strong>.<\/li>\n<li>For <strong>Include File Pattern<\/strong>, enter *.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image030.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29544 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image030-250x300.png\" alt=\"\" width=\"250\" height=\"300\"><\/a><\/li>\n<\/ol>\n<h3>Configure the release pipeline<\/h3>\n<p>You\u2019re now ready to configure the release pipeline.<\/p>\n<ol>\n<li>On the dashboard, choose <strong>New Item<\/strong>.<\/li>\n<li>Enter the name <code>model-mymodel-release<\/code>.<\/li>\n<li>Select <strong>Freestyle Project<\/strong>.<\/li>\n<li>In the <strong>Source Code Management <\/strong>section, select <strong>Git<\/strong>.<\/li>\n<li>For <strong>Repository URL<\/strong>, enter your URL.<\/li>\n<li>For <strong>Branches to build<\/strong>, enter <code>*\/main*<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image031.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29545 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image031-280x300.png\" alt=\"\" width=\"280\" height=\"300\"><\/a><\/li>\n<li>In the <strong>Build Triggers<\/strong> section, select <strong>Poll SCM<\/strong>.<\/li>\n<li>For <strong>Schedule<\/strong>, enter <code>H\/2 * * * *<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image024.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29538 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image024-300x279.png\" alt=\"\" width=\"300\" height=\"279\"><\/a><\/li>\n<li>In the <strong>Build Environment<\/strong> section, select <strong>Delete workspace before build starts<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image025.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29539 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image025-300x236.png\" alt=\"\" width=\"300\" height=\"236\"><\/a><\/li>\n<li>Add a build step of type <strong>Execute shell<\/strong>.<\/li>\n<li>In the <strong>Command<\/strong> field, add the following command:<\/li>\n<\/ol>\n<p><code>echo \"MERGE_PARENT=$(git rev-parse HEAD^2)\" &gt;&gt; env.properties<\/code><br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image032.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29546 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image032-300x115.png\" alt=\"\" width=\"300\" height=\"115\"><\/a><\/p>\n<ol start=\"12\">\n<li>Add build step of type <strong>Inject environment variables<\/strong>.<\/li>\n<li>For <strong>Properties File Path<\/strong>, enter <code>env.properties<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image033.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29547 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image033-300x130.png\" alt=\"\" width=\"300\" height=\"130\"><\/a><\/li>\n<li>Add a build step of type <strong>AWS Lambda invocation<\/strong>.<\/li>\n<li>For <strong>AWS Region<\/strong>, enter your Region.<\/li>\n<li>For <strong>Function name<\/strong>, enter the name of your function (for this post, <code>release-model-package-mymodel<\/code>).<\/li>\n<li>For <strong>Payload in json format<\/strong>, enter <code>{\"commit_id\": \"${MERGE_PARENT}\"}<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image034.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29548\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image034.png\" alt=\"\" width=\"1804\" height=\"442\"><\/a><\/li>\n<li>Lastly, you add a <strong>File Delete <\/strong>build step.<\/li>\n<li>For <strong>Include File Pattern<\/strong>, enter *.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image035.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29549 size-medium\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image035-300x212.png\" alt=\"\" width=\"300\" height=\"212\"><\/a><\/li>\n<\/ol>\n<h2>Create and release a new experiment with Jenkins and GitHub (optional)<\/h2>\n<p>To create and release a new experiment with Jenkins and GitHub, you first submit the experiment code to the repository, then open a pull request with the successful experiment code.<\/p>\n<h3>Submit experiment code to the repository<\/h3>\n<p>Either clone the GitHub repository or start from the previous terminal:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">git checkout -b experiment\/myexperiment\n&lt;make some changes to the code&gt;\ngit stage &lt;created and modified files&gt;\ngit commit -m \"adds some change\"\ngit push --set-upstream origin experiment\/myexperiment<\/code><\/pre>\n<\/p><\/div>\n<p>After a few seconds, the CodeBuild build starts running.<\/p>\n<p>The status of the CodeBuild <code>model-mymodel-train<\/code> project changes to <code>In Progress<\/code>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image036.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29550\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image036.png\" alt=\"\" width=\"2778\" height=\"652\"><\/a><\/p>\n<p>If you look in Studio, in the <strong>SageMaker resources<\/strong> section, you can see that the pipeline <code>mymodel-experiment-myexperiment<\/code> is running.<\/p>\n<p>When the pipeline is complete, a new model gets stored in the SageMaker Model Registry with <code>Pending<\/code> status.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image037.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29551\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image037.png\" alt=\"\" width=\"2778\" height=\"816\"><\/a><\/p>\n<p>Looking in the Jenkins UI, if we select the <code>model-mymodel-train<\/code> pipeline and then choose <strong>Status<\/strong>, we should see that the pipeline ran successfully.<\/p>\n<p><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image038.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-29552 size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image038.png\" alt=\"\" width=\"2868\" height=\"1206\"><\/a><\/p>\n<p>After the pipeline runs, if we go to Studio in the <strong>SageMaker resources<\/strong> section and choose <strong>Model registry<\/strong>, we should see the created model with <code>Pending<\/code> status.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image039.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29553\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image039.png\" alt=\"\" width=\"2778\" height=\"816\"><\/a><\/p>\n<p>At this point, the data scientist can assess the <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/amazon-sagemaker-experiments-organize-track-and-compare-your-machine-learning-trainings\/\" target=\"_blank\" rel=\"noopener noreferrer\">experiment results<\/a> and push subsequent commits, attempting to achieve better results for the experiment goal. When doing so, the pipeline starts again and new model versions are stored in the model registry.<\/p>\n<p>If the data scientist deems the experiment successful, they can create a pull request, asking to merge the changes from the <code>experiment\/myexperiment<\/code> branch into main.<\/p>\n<h3>Open a pull request with the successful experiment code<\/h3>\n<p>In the GitHub UI, you can open a pull request from the experiment branch <code>experiment\/myexperiment<\/code> into the <code>main<\/code> branch.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image040.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29554\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image040.png\" alt=\"\" width=\"2046\" height=\"1270\"><\/a><\/p>\n<p>When the pull request gets created, both the code and the results of the experiment can be reviewed in the <strong>SageMaker resources<\/strong> section under <strong>Experiments and trials<\/strong>. This includes information such as charts, metrics, parameters, artifacts, debugger, model explainability, and bias reports.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29534\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\" alt=\"\" width=\"2078\" height=\"774\"><\/a><\/p>\n<p>If everything looks good, we can merge the pull request by choosing <strong>Create a merge commit<\/strong> and then choosing <strong>Merge pull request<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image041.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29555\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image041.png\" alt=\"\" width=\"2046\" height=\"1218\"><\/a><\/p>\n<p>As soon as the merge is complete, the respective model gets approved automatically in the model registry. You can view it in <strong>SageMaker resources<\/strong> under <strong>Model registry<\/strong>.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image042.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29556\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image042.png\" alt=\"\" width=\"2868\" height=\"1134\"><\/a><br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image043.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29557\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image043.png\" alt=\"\" width=\"2708\" height=\"710\"><\/a><\/p>\n<h2>Review experiments from pull requests<\/h2>\n<p>To review experiments from a pull request, data scientists need to identify the commit ID of the latest commit in the pull request. After doing so, they can find the trial with the given commit ID. Alternatively, teams can customize the trial name by <a href=\"https:\/\/github.com\/aws-samples\/sagemaker-custom-project-templates\/blob\/main\/multi-branch-mlops-train\/pipelines\/abalone\/pipeline.py#L164\" target=\"_blank\" rel=\"noopener noreferrer\">building a string and assigning it<\/a>.<\/p>\n<p>In <strong>Studio resources<\/strong>, in the <strong>Experiments and trials<\/strong> section, SageMaker allows you to see several different types of metadata and information that can be associated with a model.<br \/><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29534\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/ML-5217-image020.png\" alt=\"\" width=\"2078\" height=\"774\"><\/a><\/p>\n<p>There are different aspects of an experiment that can be tracked and considered for approval.<\/p>\n<h3>Charts and metrics<\/h3>\n<p>You may want to store experiment metrics into the trial using the <a href=\"https:\/\/sagemaker-experiments.readthedocs.io\/en\/latest\/tracker.html#smexperiments.tracker.Tracker.log_metric\" target=\"_blank\" rel=\"noopener noreferrer\">SageMaker Experiments SDK<\/a>:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">for epoch in range(5):\n    my_loss = ...\n    tracker.log_metric(\n        metric_name='loss',\n        value=my_loss,\n        iteration_number=epoch\n    )\n<\/code><\/pre>\n<\/p><\/div>\n<p>Experiments is integrated with Studio. When you use Studio, Experiments automatically tracks your experiments and trials and presents visualizations of the tracked data and an interface to search the data.<\/p>\n<p>Experiments automatically organizes, ranks, and sorts trials based on a chosen metric using the concept of a trial leaderboard. Studio produces real-time data visualizations, such as metric charts and graphs, to quickly compare and identify the best performing models. These are updated in real time as the experiment progresses.<\/p>\n<h3>Parameters<\/h3>\n<p>You can log which parameters were used during the experiment using the <a href=\"https:\/\/sagemaker-experiments.readthedocs.io\/en\/latest\/tracker.html#smexperiments.tracker.Tracker.log_parameters\" target=\"_blank\" rel=\"noopener noreferrer\">log_parameters<\/a> function of the SDK.<\/p>\n<h3>Artifacts<\/h3>\n<p>Optionally, you may want to add additional arbitrary data tied to the experiment, such as custom charts or visualizations. These are stored by SageMaker in <a href=\"https:\/\/aws.amazon.com\/s3\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Simple Storage Service<\/a> (Amazon S3) at the end of the training job. To store them, you can simply use <a href=\"https:\/\/sagemaker-experiments.readthedocs.io\/en\/latest\/tracker.html#smexperiments.tracker.Tracker.log_artifacts\" target=\"_blank\" rel=\"noopener noreferrer\">log_artifacts<\/a>.<\/p>\n<h3>Debugger<\/h3>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/train-debugger.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Debugger<\/a> allows you to monitor training jobs in real time. You can detect suboptimal resource utilization as well as issues causing your model to not converge.<\/p>\n<h3>Model explainability and bias report<\/h3>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/clarify-detect-post-training-bias.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker Clarify<\/a> provides tools to help explain how ML models make predictions. These tools can help ML modelers and developers and other internal stakeholders understand model characteristics before deployment and debug predictions provided by the model after it\u2019s deployed.<\/p>\n<h2>Clean up<\/h2>\n<p>To clean up the resources created as part of this post, make sure to delete all the created stacks. To do that, empty the S3 buckets manually first, in addition to deleting the models from the model registry.<\/p>\n<p>You can also delete the SageMaker project with the following code:<\/p>\n<p><code>aws sagemaker delete-project \u2013-project-name mymodel<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>In this post, I discussed how you can create a model training pipeline fully integrated with Git, using either CodePipeline and CodeCommit, or Jenkins and GitHub. Different data scientists can use this pipeline concurrently so that each of them can experiment independently. When a winning model is found, they can create a pull request and merge their changes into the main branch.<\/p>\n<p>Additionally, because the pipeline is fully automated, ML engineers can add metadata and information about the experiments that is useful from a governance standpoint. For instance, they can <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/amazon-sagemaker-experiments-organize-track-and-compare-your-machine-learning-trainings\/\" target=\"_blank\" rel=\"noopener noreferrer\">collect metrics about the experiments<\/a> and attach them with the model artifact or <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/new-amazon-sagemaker-clarify-detects-bias-and-increases-the-transparency-of-machine-learning-models\/\" target=\"_blank\" rel=\"noopener noreferrer\">detect unwanted bias in the model<\/a>. Try it out and tell us what you think in the comments!<\/p>\n<hr>\n<h3>About the Author<\/h3>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/bRUNO-kLEIN.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-29558 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/10\/19\/bRUNO-kLEIN.jpg\" alt=\"\" width=\"100\" height=\"100\"><\/a>Bruno Klein<\/strong> is a Machine Learning Engineer in the AWS ProServe team. He particularly enjoys creating automations and improving the lifecycle of models in production. In his free time, he likes to spend time outdoors and hiking.<\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/improve-your-data-science-workflow-with-a-multi-branch-training-mlops-pipeline-using-aws\/<\/p>\n","protected":false},"author":0,"featured_media":1074,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1073"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1073"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1074"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}