{ "cells": [ { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# Amazon SageMaker Clarify Model Explainability Monitor for Batch Transform" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook. \n", "\n", "![This us-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/us-west-2/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Runtime\n", "\n", "This notebook takes approximately 60 minutes to run." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Contents\n", "\n", "* [Introduction](#Introduction)\n", "* [General Setup](#General-Setup)\n", " * [Imports](#Imports)\n", " * [Handful of configuration](#Handful-of-configuration)\n", " * [Data files](#Data-files)\n", " * [SageMaker model](#SageMaker-model)\n", "* [Batch Transform Job](#Batch-Transform-Job)\n", " * [Captured data](#Captured-data)\n", " * [Transform input](#Transform-input)\n", "* [Model Explainability Monitor](#Model-Explainability-Monitor)\n", " * [Baselining job](#Baselining-job)\n", " * [Configurations](#Configurations)\n", " * [Kick off baselining job](#Kick-off-baselining-job)\n", " * [Monitoring Schedule](#Monitoring-Schedule)\n", " * [Wait for the first execution](#Wait-for-the-first-execution)\n", " * [Wait for the execution to finish](#Wait-for-the-execution-to-finish)\n", " * [Inspect execution results](#Inspect-execution-results)\n", "* [Cleanup](#Cleanup)" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Introduction\n", "\n", "[Amazon SageMaker Model Monitor](https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html) continuously monitors the quality of Amazon SageMaker machine learning models in production. It enables developers to set alerts for when there are deviations in the model quality. Early and pro-active detection of these deviations enables corrective actions, such as retraining models, auditing upstream systems, or fixing data quality issues without having to monitor models manually or build additional tooling. \n", "\n", "[Amazon SageMaker Clarify Model Explainability Monitor](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-model-monitor-feature-attribution-drift.html) is a model monitor that helps data scientists and ML engineers monitor predictions for feature attribution drift on a regular basis. A drift in the distribution of live data for models in production can result in a corresponding drift in the feature attribution values. As the model is monitored, customers can view exportable reports and graphs detailing feature attributions in SageMaker Studio and configure alerts in Amazon CloudWatch to receive notifications if it is detected that the attribution values drift beyond a certain threshold. \n", "\n", "This notebook demonstrates the process for setting up a [SageMaker Clarify Feature Attribution Drift Monitor](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-model-monitor-feature-attribution-drift.html) for continuous monitoring of feature attribution drift of the data and model used by a regularly running [SageMaker Batch Transform](https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform.html) job. The model input and output are in CSV format.\n", "\n", "In general, you can use the model explainability monitor for batch transform in this way,\n", "\n", "1. Schedule a model explainability monitor to monitor a data capture S3 location\n", "1. Regularly run transform jobs with data capture enabled, the jobs save captured data to the data capture S3 URI\n", "\n", "The monitor executes processing jobs regularly to do feature attribution analysis, and then generate analysis reports and publish metrics to CloudWatch." ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## General Setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The notebook uses the [SageMaker Python SDK](https://github.com/aws/sagemaker-python-sdk). The following cell upgrades the SDK and its dependencies. Then you may need to restart the kernel and rerun the notebook to pick up the up-to-date APIs, if the notebook is executed in the SageMaker Studio." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "!pip install -U sagemaker\n", "!pip install -U boto3\n", "!pip install -U botocore" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Imports\n", "\n", "The following cell imports the APIs to be used by the notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "import pandas as pd\n", "import copy\n", "import datetime\n", "import io\n", "import json\n", "import os\n", "import pprint\n", "import time" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Handful of configuration\n", "\n", "To begin, ensure that these prerequisites have been completed.\n", "\n", "* Specify an AWS Region to host the model.\n", "* Specify an IAM role to execute jobs.\n", "* Define the S3 URIs that stores the model file, input data and output data. For demonstration purposes, this notebook uses the same bucket for them. In reality, they could be separated with different security policies." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sagemaker_session = sagemaker.Session()\n", "\n", "region = sagemaker_session.boto_region_name\n", "print(f\"AWS region: {region}\")\n", "\n", "role = sagemaker.get_execution_role()\n", "print(f\"RoleArn: {role}\")\n", "\n", "# A different bucket can be used, but make sure the role for this notebook has\n", "# the s3:PutObject permissions. This is the bucket into which the data is captured\n", "bucket = sagemaker_session.default_bucket()\n", "print(f\"Demo Bucket: {bucket}\")\n", "prefix = sagemaker.utils.unique_name_from_base(\"sagemaker/DEMO-ClarifyModelMonitor\")\n", "print(f\"Demo Prefix: {prefix}\")\n", "s3_key = f\"s3://{bucket}/{prefix}\"\n", "print(f\"Demo S3 key: {s3_key}\")\n", "\n", "data_capture_s3_uri = f\"{s3_key}/data-capture\"\n", "transform_output_s3_uri = f\"{s3_key}/transform-output\"\n", "baselining_output_s3_uri = f\"{s3_key}/baselining-output\"\n", "monitor_output_s3_uri = f\"{s3_key}/monitor-output\"\n", "\n", "print(f\"The transform job will save the results to: {transform_output_s3_uri}\")\n", "print(f\"The transform job will save the captured data to: {data_capture_s3_uri}\")\n", "print(f\"The baselining job will save the analysis results to: {baselining_output_s3_uri}\")\n", "print(f\"The monitor will save the analysis results to: {monitor_output_s3_uri}\")" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Data files\n", "\n", "This example includes two dataset files, both in CSV format.\n", "\n", "* The train dataset has header row, and it has a target column followed by the feature columns.\n", "* The test dataset is not headers, and it only has feature columns." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "isConfigCell": true }, "outputs": [], "source": [ "train_dataset_path = \"test_data/validation-dataset-with-header.csv\"\n", "test_dataset_path = \"test_data/test-dataset-input-cols.csv\"\n", "dataset_type = \"text/csv\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(train_dataset_path)\n", "df.head(5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Read headers\n", "all_headers = list(df.columns)\n", "label_header = all_headers[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To verify that the execution role for this notebook has the necessary permissions to proceed, put a simple test object into the S3 bucket specified above. If this command fails, update the role to have `s3:PutObject` permission on the bucket and try again." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sagemaker.s3.S3Uploader.upload_string_as_file_body(\n", " body=\"hello\",\n", " desired_s3_uri=f\"{s3_key}/upload-test-file.txt\",\n", " sagemaker_session=sagemaker_session,\n", ")\n", "print(\"Success! We are all set to proceed with uploading to S3.\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then upload the data files to S3 so that they can be used by SageMaker jobs." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "train_data_s3_uri = sagemaker.s3.S3Uploader.upload(\n", " local_path=train_dataset_path,\n", " desired_s3_uri=s3_key,\n", " sagemaker_session=sagemaker_session,\n", ")\n", "print(f\"Train data is uploaded to: {train_data_s3_uri}\")\n", "test_data_s3_uri = sagemaker.s3.S3Uploader.upload(\n", " local_path=test_dataset_path,\n", " desired_s3_uri=s3_key,\n", " sagemaker_session=sagemaker_session,\n", ")\n", "print(f\"Test data is uploaded to: {test_data_s3_uri}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### SageMaker model\n", "\n", "This example includes a pre-built [SageMaker XGBoost](https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost.html) model file trained by [XGBoost Churn Prediction Notebook](https://github.com/aws/amazon-sagemaker-examples/blob/master/introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb). The following cell uploads the file to S3 and then creates a SageMaker model using it. The model support CSV data format, the input are customer attributes, and the output is the probability of customer churn (a float number between zero and one)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_file = \"model/xgb-churn-prediction-model.tar.gz\"\n", "model_url = sagemaker.s3.S3Uploader.upload(\n", " local_path=model_file,\n", " desired_s3_uri=s3_key,\n", " sagemaker_session=sagemaker_session,\n", ")\n", "print(f\"Model file has been uploaded to {model_url}\")\n", "\n", "model_name = sagemaker.utils.unique_name_from_base(\"DEMO-xgb-churn-pred-model-monitor\")\n", "print(f\"SageMaker model name: {model_name}\")\n", "\n", "image_uri = sagemaker.image_uris.retrieve(\"xgboost\", region, \"0.90-1\")\n", "print(f\"SageMaker XGBoost image: {image_uri}\")\n", "\n", "model = sagemaker.model.Model(image_uri=image_uri, model_data=model_url, role=role)\n", "container_def = model.prepare_container_def()\n", "sagemaker_session.create_model(model_name, role, container_def)\n", "print(\"SageMaker model created\")" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Batch Transform Job\n", "\n", "For continuous monitoring, batch transform jobs should be executed regularly with the latest data. But for demonstration purpose, the following cell only executes the job once before the monitor is scheduled, so that the first monitoring execution has captured data to process. \n", "\n", "See [Transformer](https://sagemaker.readthedocs.io/en/stable/api/inference/transformer.html#sagemaker.transformer.Transformer.transform) for the API reference. The `destination_s3_uri` is used to specify the data capture S3 URI which is a key connection between the job and the monitor.\n", "\n", "**NOTE**: The following cell takes about 5 minutes to run." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "transfomer = model.transformer(\n", " instance_count=1,\n", " instance_type=\"ml.m5.xlarge\",\n", " accept=dataset_type, # The transform output data format\n", " assemble_with=\"Line\", # CSV records are terminated by new lines\n", " output_path=transform_output_s3_uri,\n", ")\n", "\n", "transfomer.transform(\n", " data=test_data_s3_uri,\n", " content_type=dataset_type, # The transform input format\n", " split_type=\"Line\", # CSV records are terminated by new lines\n", " batch_data_capture_config=sagemaker.inputs.BatchDataCaptureConfig(\n", " destination_s3_uri=data_capture_s3_uri,\n", " ),\n", " wait=True, # In real world you don't have to wait, but for demo purpose we wait for the output\n", " logs=False, # You can change it to True to view job logs inline\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Captured data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once the transform job completed, an \"input\" folders is created under `data_capture_s3_uri`, to includes the captured data files of transform input. Note that, batch transform data capture is unlike endpoint data capture, it does not capture the data for real as it will create tremendous amount of duplications. Instead, it generates [manifest](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_S3DataSource.html#sagemaker-Type-S3DataSource-S3Uri) files which refer to the transform output S3 location." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now list the captured data files stored in Amazon S3. There should be different files from different time periods organized based on the hour in which the batch transformation occurred. The format of the Amazon S3 path is:\n", "\n", "`s3://{data_capture_s3_uri}/input/yyyy/mm/dd/hh/filename.jsonl`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_capture_output = f\"{data_capture_s3_uri}/input\"\n", "captured_data_files = sorted(\n", " sagemaker.s3.S3Downloader.list(\n", " s3_uri=data_capture_output,\n", " sagemaker_session=sagemaker_session,\n", " )\n", ")\n", "print(\"Found capture data files:\")\n", "print(\"\\n \".join(captured_data_files[-5:]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "captured_data_file = captured_data_files[-1]\n", "captured_data_file_content = sagemaker.s3.S3Downloader.read_file(\n", " s3_uri=captured_data_files[-1],\n", " sagemaker_session=sagemaker_session,\n", ")\n", "data_capture_input_dict = json.loads(captured_data_file_content)\n", "print(json.dumps(data_capture_input_dict, indent=4))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "def upload_captured_data(offset):\n", " yyyy_mm_dd_hh = \"%Y/%m/%d/%H\"\n", " file_path, file_name = os.path.split(captured_data_file)\n", " this_hour_str = file_path[len(data_capture_output) + 1 :] # like \"2023/01/18/22\"\n", " this_hour = datetime.datetime.strptime(this_hour_str, yyyy_mm_dd_hh)\n", " next_hour = this_hour + datetime.timedelta(hours=offset)\n", " next_hour_str = next_hour.strftime(yyyy_mm_dd_hh) # like \"2023/01/18/23\"\n", " sagemaker.s3.S3Uploader.upload_string_as_file_body(\n", " body=captured_data_file_content,\n", " desired_s3_uri=f\"{data_capture_output}/{next_hour_str}/{file_name}\",\n", " sagemaker_session=sagemaker_session,\n", " )\n", "\n", "\n", "# For demostration purpose, only needed for this example\n", "# copy the captured file to the last hour's folder, just in case the first monitoring execution is started in this hour.\n", "upload_captured_data(-1)\n", "# copy the captured file to the next hour's folder, just in case the first monitoring execution is started after next hour.\n", "upload_captured_data(1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Transform input\n", "\n", "The captured data file refers to the transform input file. The cell below shows the first few records of the file." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "transform_input = data_capture_input_dict[0][\"prefix\"]\n", "transform_input_body = sagemaker.s3.S3Downloader.read_file(\n", " s3_uri=transform_input,\n", " sagemaker_session=sagemaker_session,\n", ")\n", "transform_input_df = pd.read_csv(io.StringIO(transform_input_body), header=None)\n", "transform_input_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Model Explainability Monitor\n", "\n", "Similar to the other monitoring types, the standard procedure of creating a [feature attribution drift monitor](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-model-monitor-feature-attribution-drift.html) is first run a baselining job, and then schedule the monitor." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_monitor = sagemaker.model_monitor.ModelExplainabilityMonitor(\n", " role=role,\n", " sagemaker_session=sagemaker_session,\n", " max_runtime_in_seconds=3600,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Baselining job\n", "\n", "A baselining job runs predictions on training dataset and suggests constraints. The `suggest_baseline()` method of `ModelExplainabilityMonitor` starts a SageMaker Clarify processing job to generate the constraints.\n", "\n", "The step is not mandatory, but providing constraints file to the monitor can enable violations file generation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Configurations\n", "\n", "Information about the input data need to be provided to the processor." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`DataConfig` stores information about the dataset to be analyzed. For example, the dataset file, its format (like CSV), headers and label (ground truth label is not needed for the explainability analysis, the parameter is specified so that the job knows it should be excluded from the dataset)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_config = sagemaker.clarify.DataConfig(\n", " s3_data_input_path=train_data_s3_uri,\n", " s3_output_path=baselining_output_s3_uri,\n", " label=label_header,\n", " headers=all_headers,\n", " dataset_type=dataset_type,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`ModelConfig` is configuration related to model to be used for inferencing. In order to compute SHAP values, the SageMaker Clarify explainer generates synthetic dataset and then get its predictions for the SageMaker model. To accomplish this, the processing job will use the model to create an ephemeral endpoint (also known as \"shadow endpoint\"). The processing job will delete the shadow endpoint after the computations are completed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_config = sagemaker.clarify.ModelConfig(\n", " model_name=model_name, # The name of the SageMaker model\n", " instance_count=1, # The instance count of the shadow endpoint\n", " instance_type=\"ml.m5.xlarge\", # The instance type of the shadow endpoint\n", " content_type=dataset_type, # The data format of the model input\n", " accept_type=dataset_type, # The data format of the model output\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Currently, the SageMaker Clarify explainer offers a scalable and efficient implementation of SHAP, so the explainability config is `SHAPConfig`, including\n", "\n", "* `baseline`: A list of records (at least one) to be used as the baseline dataset in the Kernel SHAP algorithm, each record is a list of features. It can also be a S3 object URI, the S3 file should be in the same format as dataset, and it should contain only the feature columns/values and omit the label column/values.\n", "* `num_samples`: Number of samples to be used in the Kernel SHAP algorithm. This number determines the size of the generated synthetic dataset to compute the SHAP values.\n", "* `agg_method`: Aggregation method for global SHAP values. Valid values are\n", " * \"mean_abs\" (mean of absolute SHAP values for all instances),\n", " * \"median\" (median of SHAP values for all instances) and\n", " * \"mean_sq\" (mean of squared SHAP values for all instances).\n", "* `use_logit`: Indicator of whether the logit function is to be applied to the model predictions. Default is False. If \"use_logit\" is true then the SHAP values will have log-odds units.\n", "* `save_local_shap_values`: Indicator of whether to save the local SHAP values in the output location. Default is True." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Here use the mean value of train dataset as SHAP baseline\n", "shap_baseline = [list(df.drop([label_header], axis=1).mean().round().astype(int))]\n", "print(f\"SHAP baseline: {shap_baseline}\")\n", "\n", "shap_config = sagemaker.clarify.SHAPConfig(\n", " baseline=shap_baseline,\n", " num_samples=100,\n", " agg_method=\"mean_abs\",\n", " save_local_shap_values=False,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Kick off baselining job" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Call the `suggest_baseline()` method to start the baselining job. The example model returns a single probability value between `0` and `1`. So, the `model_scores` parameter is set to zero, which is the index of the probability value in the CSV model output." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_monitor.suggest_baseline(\n", " explainability_config=shap_config,\n", " data_config=data_config,\n", " model_config=model_config,\n", " model_scores=0, # The zero-based index of the probability (score) in model output\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NOTE**: The following cell waits until the baselining job is completed (in about 10 minutes). It then inspects the suggested constraints. This step can be skipped, because the monitor to be scheduled will automatically pick up baselining job name and wait for it before monitoring execution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_monitor.latest_baselining_job.wait(logs=False)\n", "print()\n", "model_explainability_constraints = model_explainability_monitor.suggested_constraints()\n", "print(f\"Suggested constraints: {model_explainability_constraints.file_s3_uri}\")\n", "print(\n", " sagemaker.s3.S3Downloader.read_file(\n", " s3_uri=model_explainability_constraints.file_s3_uri,\n", " sagemaker_session=sagemaker_session,\n", " )\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Monitoring Schedule\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With above constraints collected, now call `create_monitoring_schedule()` method to schedule an hourly model explainability monitor." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If a baselining job has been submitted, then the monitor object will automatically pick up the analysis configuration from the baselining job. But if the baselining step is skipped, or if the capture dataset has different nature than the training dataset, then analysis configuration has to be provided.\n", "\n", "`ModelConfig` is required by `ExplainabilityAnalysisConfig` for the same reason as it is required by the baselining job. Note that only features are required for computing feature attribution, so ground truth label should be excluded.\n", "\n", "Highlights,\n", "\n", "* `data_capture_s3_uri` is the location of data captured by the batch transform job\n", "* `probability_attribute` stores the index of the probability value in model output, similar to the `model_scores` parameter of the `suggest_baseline()` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "schedule_expression = sagemaker.model_monitor.CronExpressionGenerator.hourly()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_analysis_config = None\n", "if not model_explainability_monitor.latest_baselining_job:\n", " # Remove label because only features are required for the analysis\n", " headers_without_label_header = copy.deepcopy(all_headers)\n", " headers_without_label_header.remove(label_header)\n", " model_explainability_analysis_config = sagemaker.model_monitor.ExplainabilityAnalysisConfig(\n", " explainability_config=shap_config,\n", " model_config=model_config,\n", " headers=headers_without_label_header,\n", " )\n", "model_explainability_monitor.create_monitoring_schedule(\n", " analysis_config=model_explainability_analysis_config,\n", " batch_transform_input=sagemaker.model_monitor.BatchTransformInput(\n", " data_captured_destination_s3_uri=data_capture_s3_uri,\n", " destination=\"/opt/ml/processing/transform\",\n", " dataset_format=sagemaker.model_monitor.MonitoringDatasetFormat.csv(header=False),\n", " ),\n", " output_s3_uri=monitor_output_s3_uri,\n", " schedule_cron_expression=schedule_expression,\n", ")\n", "print(\n", " f\"Model explainability monitoring schedule: {model_explainability_monitor.monitoring_schedule_name}\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Wait for the first execution\n", "\n", "The schedule starts jobs at the previously specified intervals. Code below waits until time crosses the hour boundary (in UTC) to see executions kick off.\n", "\n", "Note: Even for an hourly schedule, Amazon SageMaker has a buffer period of 20 minutes to schedule executions. The execution might start in anywhere from zero to ~20 minutes from the hour boundary. This is expected and done for load balancing in the backend." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def wait_for_execution_to_start(model_monitor):\n", " print(\n", " \"An hourly schedule was created above and it will kick off executions ON the hour (plus 0 - 20 min buffer).\"\n", " )\n", "\n", " print(\"Waiting for the first execution to happen\", end=\"\")\n", " schedule_desc = model_monitor.describe_schedule()\n", " while \"LastMonitoringExecutionSummary\" not in schedule_desc:\n", " schedule_desc = model_monitor.describe_schedule()\n", " print(\".\", end=\"\", flush=True)\n", " time.sleep(60)\n", " print()\n", " print(\"Done! Execution has been created\")\n", "\n", " print(\"Now waiting for execution to start\", end=\"\")\n", " while schedule_desc[\"LastMonitoringExecutionSummary\"][\"MonitoringExecutionStatus\"] in \"Pending\":\n", " schedule_desc = model_monitor.describe_schedule()\n", " print(\".\", end=\"\", flush=True)\n", " time.sleep(10)\n", "\n", " print()\n", " print(\"Done! Execution has started\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NOTE**: The following cell waits until the first monitoring execution is started. As explained above, the wait could take more than 60 minutes." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wait_for_execution_to_start(model_explainability_monitor)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In real world, a monitoring schedule is supposed to be active all the time. But in this example, it can be stopped to avoid incurring extra charges. A stopped schedule will not trigger further executions, but the ongoing execution will continue. And if needed, the schedule can be restarted by `start_monitoring_schedule()`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_monitor.stop_monitoring_schedule()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Wait for the execution to finish\n", "\n", "In the previous cell, the first execution has started. This section waits for the execution to finish so that its analysis results are available. Here are the possible terminal states and what each of them mean:\n", "\n", "* `Completed` - This means the monitoring execution completed, and no issues were found in the violations report.\n", "* `CompletedWithViolations` - This means the execution completed, but constraint violations were detected.\n", "* `Failed` - The monitoring execution failed, maybe due to client error (perhaps incorrect role permissions) or infrastructure issues. Further examination of `FailureReason` and `ExitMessage` is necessary to identify what exactly happened.\n", "* `Stopped` - job exceeded max runtime or was manually stopped." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Waits for the schedule to have last execution in a terminal status.\n", "def wait_for_execution_to_finish(model_monitor):\n", " schedule_desc = model_monitor.describe_schedule()\n", " execution_summary = schedule_desc.get(\"LastMonitoringExecutionSummary\")\n", " if execution_summary is not None:\n", " print(\"Waiting for execution to finish\", end=\"\")\n", " while execution_summary[\"MonitoringExecutionStatus\"] not in [\n", " \"Completed\",\n", " \"CompletedWithViolations\",\n", " \"Failed\",\n", " \"Stopped\",\n", " ]:\n", " print(\".\", end=\"\", flush=True)\n", " time.sleep(60)\n", " schedule_desc = model_monitor.describe_schedule()\n", " execution_summary = schedule_desc[\"LastMonitoringExecutionSummary\"]\n", " print()\n", " print(f\"Done! Execution Status: {execution_summary['MonitoringExecutionStatus']}\")\n", " else:\n", " print(\"Last execution not found\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NOTE**: The following cell takes about 10 minutes." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wait_for_execution_to_finish(model_explainability_monitor)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Inspect execution results\n", "\n", "List the generated reports,\n", "\n", "* analysis.json includes the global SHAP values.\n", "* report.* files are static report files to visualize the SHAP values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "schedule_desc = model_explainability_monitor.describe_schedule()\n", "execution_summary = schedule_desc.get(\"LastMonitoringExecutionSummary\")\n", "if execution_summary and execution_summary[\"MonitoringExecutionStatus\"] in [\n", " \"Completed\",\n", " \"CompletedWithViolations\",\n", "]:\n", " last_model_explainability_monitor_execution = model_explainability_monitor.list_executions()[-1]\n", " last_model_explainability_monitor_execution_report_uri = (\n", " last_model_explainability_monitor_execution.output.destination\n", " )\n", " print(f\"Report URI: {last_model_explainability_monitor_execution_report_uri}\")\n", " last_model_explainability_monitor_execution_report_files = sorted(\n", " sagemaker.s3.S3Downloader.list(\n", " s3_uri=last_model_explainability_monitor_execution_report_uri,\n", " sagemaker_session=sagemaker_session,\n", " )\n", " )\n", " print(\"Found Report Files:\")\n", " print(\"\\n \".join(last_model_explainability_monitor_execution_report_files))\n", "else:\n", " last_model_explainability_monitor_execution = None\n", " print(\n", " \"====STOP==== \\n No completed executions to inspect further. Please wait till an execution completes or investigate previously reported failures.\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If there are any violations compared to the baseline, they are listed here. See [Feature Attribution Drift Violations](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-model-monitor-model-attribution-drift-violations.html) for the schema of the file, and how violations are detected." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "violations = model_explainability_monitor.latest_monitoring_constraint_violations()\n", "if violations is not None:\n", " pprint.PrettyPrinter(indent=4).pprint(violations.body_dict)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, the analysis results are also published to CloudWatch, see [CloudWatch Metrics for Feature Attribution Drift Analysis](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-feature-attribute-drift-cw.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cleanup\n", "\n", "If there is no plan to collect more data for feature attribution drift monitoring, then the monitor should be stopped (and deleted) to avoid incurring additional charges. Note that deleting the monitor does not delete the data in S3." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_explainability_monitor.stop_monitoring_schedule()\n", "wait_for_execution_to_finish(model_explainability_monitor)\n", "model_explainability_monitor.delete_monitoring_schedule()\n", "sagemaker_session.delete_model(model_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Notebook CI Test Results\n", "\n", "This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.\n", "\n", "![This us-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/us-east-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This us-east-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/us-east-2/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This us-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/us-west-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ca-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ca-central-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This sa-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/sa-east-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This eu-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/eu-west-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This eu-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/eu-west-2/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This eu-west-3 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/eu-west-3/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This eu-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/eu-central-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This eu-north-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/eu-north-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ap-southeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ap-southeast-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ap-southeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ap-southeast-2/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ap-northeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ap-northeast-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ap-northeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ap-northeast-2/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n", "\n", "![This ap-south-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://h75twx4l60.execute-api.us-west-2.amazonaws.com/sagemaker-nb/ap-south-1/sagemaker_model_monitor|fairness_and_explainability|SageMaker-Monitoring-Feature-Attribution-Drift-for-Batch-Transform.ipynb)\n" ] } ], "metadata": { "anaconda-cloud": {}, "availableInstances": [ { "_defaultOrder": 0, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.t3.medium", "vcpuNum": 2 }, { "_defaultOrder": 1, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.t3.large", "vcpuNum": 2 }, { "_defaultOrder": 2, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.t3.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 3, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.t3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 4, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5.large", "vcpuNum": 2 }, { "_defaultOrder": 5, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 6, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 7, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 8, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 9, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 10, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 11, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 12, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5d.large", "vcpuNum": 2 }, { "_defaultOrder": 13, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5d.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 14, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5d.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 15, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5d.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 16, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5d.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 17, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5d.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 18, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5d.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 19, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5d.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 20, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": true, "memoryGiB": 0, "name": "ml.geospatial.interactive", "supportedImageNames": [ "sagemaker-geospatial-v1-0" ], "vcpuNum": 0 }, { "_defaultOrder": 21, "_isFastLaunch": true, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.c5.large", "vcpuNum": 2 }, { "_defaultOrder": 22, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.c5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 23, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.c5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 24, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.c5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 25, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 72, "name": "ml.c5.9xlarge", "vcpuNum": 36 }, { "_defaultOrder": 26, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 96, "name": "ml.c5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 27, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 144, "name": "ml.c5.18xlarge", "vcpuNum": 72 }, { "_defaultOrder": 28, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.c5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 29, "_isFastLaunch": true, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g4dn.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 30, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g4dn.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 31, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g4dn.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 32, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g4dn.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 33, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g4dn.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 34, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g4dn.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 35, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 61, "name": "ml.p3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 36, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 244, "name": "ml.p3.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 37, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 488, "name": "ml.p3.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 38, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.p3dn.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 39, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.r5.large", "vcpuNum": 2 }, { "_defaultOrder": 40, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.r5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 41, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.r5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 42, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.r5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 43, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.r5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 44, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.r5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 45, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 512, "name": "ml.r5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 46, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.r5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 47, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 48, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 49, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 50, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 51, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 52, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 53, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.g5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 54, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.g5.48xlarge", "vcpuNum": 192 }, { "_defaultOrder": 55, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 1152, "name": "ml.p4d.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 56, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 1152, "name": "ml.p4de.24xlarge", "vcpuNum": 96 } ], "kernelspec": { "display_name": "Python 3 (Data Science 3.0)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-west-2:236514542706:image/sagemaker-data-science-310-v1" }, "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.10.6" }, "notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." }, "nbformat": 4, "nbformat_minor": 4 }