Skip to content

Commit d7c7ff3

Browse files
Zhenshan-JinZhenshan Jin
authored andcommitted
fix: FinalMetricDataList is missing from the training job search resu… (aws#733)
Co-authored-by: Zhenshan Jin <[email protected]>
1 parent 3393e02 commit d7c7ff3

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/sagemaker/model_card/model_card.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ def _create_training_details(training_job_data: dict, cls: "TrainingDetails", **
439439
"training_metrics": [
440440
TrainingMetric(i["MetricName"], i["Value"])
441441
for i in training_job_data["FinalMetricDataList"]
442-
],
442+
]
443+
if "FinalMetricDataList" in training_job_data
444+
else [],
443445
}
444446
kwargs.update({"training_job_details": TrainingJobDetails(**job)})
445447
instance = cls(**kwargs)

tests/unit/test_model_card.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,44 @@
367367
},
368368
}
369369

370+
SEARCH_TRAINING_JOB_AUTOPILOT_EXAMPLE = {
371+
"Results": [
372+
{
373+
"TrainingJob": {
374+
"TrainingJobName": TRAINING_JOB_NAME,
375+
"TrainingJobArn": TRAINING_JOB_ARN,
376+
"ModelArtifacts": {"S3ModelArtifacts": "s3://example"},
377+
"TrainingJobOutput": {"S3TrainingJobOutput": "s3://example"},
378+
"TrainingJobStatus": "Completed",
379+
"SecondaryStatus": "Completed",
380+
"HyperParameters": {
381+
"processor_module": "candidate_data_processors.dpp2",
382+
"sagemaker_program": "candidate_data_processors.trainer",
383+
"sagemaker_submit_directory": "/opt/ml/input/data/code",
384+
},
385+
"AlgorithmSpecification": {
386+
"TrainingImage": TRAINING_IMAGE,
387+
"TrainingInputMode": "File",
388+
"MetricDefinitions": [],
389+
"EnableSageMakerMetricsTimeSeries": False,
390+
},
391+
"CreatedBy": {},
392+
}
393+
}
394+
],
395+
"ResponseMetadata": {
396+
"RequestId": "b43aacee-c846-4ca6-b5c0-d9413cebda33",
397+
"HTTPStatusCode": 200,
398+
"HTTPHeaders": {
399+
"x-amzn-requestid": "b43aacee-c846-4ca6-b5c0-d9413cebda33",
400+
"content-type": "application/x-amz-json-1.1",
401+
"content-length": "6199",
402+
"date": "Tue, 20 Sep 2022 19:59:50 GMT",
403+
},
404+
"RetryAttempts": 0,
405+
},
406+
}
407+
370408
DESCRIBE_TRAINING_JOB_EXAMPLE = SEARCH_TRAINING_JOB_EXAMPLE["Results"][0]["TrainingJob"]
371409
MISSING_TRAINING_JOB_CLIENT_ERROR = ClientError(
372410
error_response={
@@ -995,6 +1033,22 @@ def test_training_details_autodiscovery_from_model_overview(
9951033
) in caplog.text
9961034

9971035

1036+
@patch("sagemaker.Session")
1037+
def test_training_details_autodiscovery_from_model_overview_autopilot(
1038+
session, model_overview_example, caplog
1039+
):
1040+
session.sagemaker_client.search.side_effect = [
1041+
SEARCH_TRAINING_JOB_AUTOPILOT_EXAMPLE,
1042+
]
1043+
1044+
model_overview_example.model_artifact = [MODEL_ARTIFACT[0]]
1045+
training_details = TrainingDetails.from_model_overview(
1046+
model_overview=model_overview_example, sagemaker_session=session
1047+
)
1048+
1049+
assert len(training_details.training_job_details.training_metrics) == 0
1050+
1051+
9981052
@patch("sagemaker.Session")
9991053
def test_training_details_autodiscovery_from_job_name(session):
10001054
session.sagemaker_client.describe_training_job.side_effect = [

0 commit comments

Comments
 (0)