{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Track all models in a model registry\n", "\n", "In this section we will walk through how you can register your model to the SageMaker Model Registry. \n", "\n", "The SageMaker Model Registry is structured as several model groups with model packages in each group. Each model package in a model group corresponds to a trained model. The version of each model package is a numerical value that starts at 1 and is incremented with each new model package added to a model group. For example, if 5 model packages are added to a model group, the model package versions will be 1, 2, 3, 4, and 5. The example Model Registry shown in the following image contains 3 model groups, where each group contains the model packages related to a particular ML problem." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install \"sagemaker>=2.123.0\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "import boto3\n", "import numpy as np \n", "import pandas as pd \n", "import os \n", "from sagemaker import get_execution_role\n", "from datetime import datetime\n", "\n", "# Get default bucket\n", "bucket = sagemaker.Session().default_bucket()\n", "prefix = 'sagemaker/mlops-workshop'\n", "\n", "# Get SageMaker Execution Role\n", "role = get_execution_role()\n", "region = boto3.Session().region_name\n", "\n", "# SageMaker Session\n", "sagemaker_session = sagemaker.session.Session()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Retrieve variables" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store -r" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(trained_model_uri)\n", "print(training_image)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from sagemaker.model import Model\n", "\n", "model = Model(\n", " image_uri = training_image,\n", " model_data = trained_model_uri,\n", " role = role,\n", " sagemaker_session = sagemaker_session\n", ")" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Register Model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_package = model.register(\n", " description = \"This is a model to detect the liklihood of someone getting approved for a loan\",\n", " model_package_group_name = \"model-group-module-1\",\n", " customer_metadata_properties = {\n", " 'ModelType' : 'Decision Tree',\n", " 'Algorithm' : 'XGBoost'\n", " },\n", " inference_instances = ['ml.m5.xlarge'],\n", " approval_status = 'PendingManualApproval',\n", " content_types = ['text/csv'],\n", " response_types = ['text/csv']\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_package_arn = model_package.model_package_arn" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Model Package arn: \", model_package_arn)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store model_package_arn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### You can now move to the next section of the module `Deploy your models for inference`\n", "\n", "The notebook used in that section is `sagemaker-deploy.ipynb`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "instance_type": "ml.t3.medium", "kernelspec": { "display_name": "Python 3 (Data Science)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-2:429704687514:image/datascience-1.0" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }