|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
15 | 15 | import os
|
| 16 | +import re |
16 | 17 |
|
17 |
| -import boto3 |
18 | 18 | import pytest
|
19 | 19 | from botocore.exceptions import WaiterError
|
20 | 20 |
|
@@ -91,13 +91,19 @@ def test_automl_step(pipeline_session, role, pipeline_name):
|
91 | 91 | name="ModelPackageName", default_value="AutoMlModelPackageGroup"
|
92 | 92 | )
|
93 | 93 | model_approval_status = ParameterString(name="ModelApprovalStatus", default_value="Approved")
|
| 94 | + model_insights_json_report_path = ( |
| 95 | + automl_step.properties.BestCandidateProperties.ModelInsightsJsonReportPath |
| 96 | + ) |
| 97 | + explainability_json_report_path = ( |
| 98 | + automl_step.properties.BestCandidateProperties.ExplainabilityJsonReportPath |
| 99 | + ) |
94 | 100 | model_metrics = ModelMetrics(
|
95 | 101 | model_statistics=MetricsSource(
|
96 |
| - s3_uri=automl_step.properties.BestCandidateProperties.ModelInsightsJsonReportPath, |
| 102 | + s3_uri=model_insights_json_report_path, |
97 | 103 | content_type="application/json",
|
98 | 104 | ),
|
99 | 105 | explainability=MetricsSource(
|
100 |
| - s3_uri=automl_step.properties.BestCandidateProperties.ExplainabilityJsonReportPath, |
| 106 | + s3_uri=explainability_json_report_path, |
101 | 107 | content_type="application/json",
|
102 | 108 | ),
|
103 | 109 | )
|
@@ -139,19 +145,45 @@ def test_automl_step(pipeline_session, role, pipeline_name):
|
139 | 145 | assert step["StepStatus"] == "Succeeded"
|
140 | 146 | if "AutoMLJob" in step["Metadata"]:
|
141 | 147 | has_automl_job = True
|
142 |
| - assert step["Metadata"]["AutoMLJob"]["Arn"] is not None |
| 148 | + automl_job_arn = step["Metadata"]["AutoMLJob"]["Arn"] |
| 149 | + assert automl_job_arn is not None |
| 150 | + automl_job_name = re.findall(r"(?<=automl-job/).*", automl_job_arn)[0] |
| 151 | + auto_ml_desc = auto_ml.describe_auto_ml_job(job_name=automl_job_name) |
| 152 | + model_insights_json_from_automl = ( |
| 153 | + auto_ml_desc["BestCandidate"]["CandidateProperties"][ |
| 154 | + "CandidateArtifactLocations" |
| 155 | + ]["ModelInsights"] |
| 156 | + + "/statistics.json" |
| 157 | + ) |
| 158 | + explainability_json_from_automl = ( |
| 159 | + auto_ml_desc["BestCandidate"]["CandidateProperties"][ |
| 160 | + "CandidateArtifactLocations" |
| 161 | + ]["Explainability"] |
| 162 | + + "/analysis.json" |
| 163 | + ) |
143 | 164 |
|
144 | 165 | assert has_automl_job
|
145 | 166 | assert len(execution_steps) == 3
|
| 167 | + sagemaker_client = pipeline_session.boto_session.client("sagemaker") |
| 168 | + model_package = sagemaker_client.list_model_packages( |
| 169 | + ModelPackageGroupName="AutoMlModelPackageGroup" |
| 170 | + )["ModelPackageSummaryList"][0] |
| 171 | + response = sagemaker_client.describe_model_package( |
| 172 | + ModelPackageName=model_package["ModelPackageArn"] |
| 173 | + ) |
| 174 | + model_insights_json_report_path = response["ModelMetrics"]["ModelQuality"]["Statistics"][ |
| 175 | + "S3Uri" |
| 176 | + ] |
| 177 | + explainability_json_report_path = response["ModelMetrics"]["Explainability"]["Report"][ |
| 178 | + "S3Uri" |
| 179 | + ] |
| 180 | + |
| 181 | + assert model_insights_json_report_path == model_insights_json_from_automl |
| 182 | + assert explainability_json_report_path == explainability_json_from_automl |
| 183 | + |
146 | 184 | finally:
|
147 | 185 | try:
|
148 |
| - sagemaker_client = boto3.client("sagemaker") |
149 |
| - for model_package in sagemaker_client.list_model_packages( |
150 |
| - ModelPackageGroupName="AutoMlModelPackageGroup" |
151 |
| - )["ModelPackageSummaryList"]: |
152 |
| - sagemaker_client.delete_model_package( |
153 |
| - ModelPackageName=model_package["ModelPackageArn"] |
154 |
| - ) |
| 186 | + sagemaker_client.delete_model_package(ModelPackageName=model_package["ModelPackageArn"]) |
155 | 187 | sagemaker_client.delete_model_package_group(
|
156 | 188 | ModelPackageGroupName="AutoMlModelPackageGroup"
|
157 | 189 | )
|
|
0 commit comments