排程模型品質監控工作 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

排程模型品質監控工作

建立基準之後,您可以呼叫 ModelQualityMonitor 類別執行個體的 create_monitoring_schedule() 方法來排程每小時的模型品質監控。以下各節說明如何為部署到即時端點的模型以及批次轉換工作建立模型品質監控。

重要

在建立監控排程時,您可以指定批次轉換輸入或端點輸入,但不能同時指定兩者。

與資料品質監控不同,如果要監控模型品質,需要提供 Ground Truth 標籤。但是,Ground Truth 標籤可能會延遲。若要解決此問題,請在建立監控排程時指定偏移。

模型監控偏移

模型品質工作包括 StartTimeOffsetEndTimeOffset,這些是 create_model_quality_job_definition 方法的 ModelQualityJobInput 參數欄位,其運作方式如下:

  • StartTimeOffset - 如果指定,工作會從開始時間減去這個時間。

  • EndTimeOffset - 如果指定,工作會從結束時間減去這個時間。

例如,偏移的格式為 -PT7H,其中 7H 為 7 小時。您可以使用 -PT#H 或 -P#D,其中 H = 小時、D = 天、M = 分鐘和 # 是數字。此外,偏移應採用 ISO 8601 持續時間格式

例如,如果您的 Ground Truth 在 1 天後開始出現,但在一周內未完成,則將 StartTimeOffset設為 -P8D,並將 EndTimeOffset 設為 -P1D。然後,如果您排定在 2020-01-09T13:00 要執行的工作,會分析 2020-01-01T13:002020-01-08T13:00 之間的資料。

重要

排程節奏應該讓一個執行在下一個執行開始之前完成,讓執行的 Ground Truth 合併工作和監控工作可以完成。執行的執行時間上限會分配在兩個工作之間,因此對於每小時的模型品質監控工作,指定為一部分 StoppingConditionMaxRuntimeInSeconds 值不應超過 1800。

部署至即時端點的模型的模型品質監控

若要為即時端點排程模型品質監控,請將 EndpointInput 執行個體傳遞至 ModelQualityMonitor 執行個體的 endpoint_input 引數,如下列程式碼範例所示:

from sagemaker.model_monitor import CronExpressionGenerator model_quality_model_monitor = ModelQualityMonitor( role=sagemaker.get_execution_role(), ... ) schedule = model_quality_model_monitor.create_monitoring_schedule( monitor_schedule_name=schedule_name, post_analytics_processor_script=s3_code_postprocessor_uri, output_s3_uri=s3_report_path, schedule_cron_expression=CronExpressionGenerator.hourly(), statistics=model_quality_model_monitor.baseline_statistics(), constraints=model_quality_model_monitor.suggested_constraints(), schedule_cron_expression=CronExpressionGenerator.hourly(), enable_cloudwatch_metrics=True, endpoint_input=EndpointInput( endpoint_name=endpoint_name, destination="/opt/ml/processing/input/endpoint", start_time_offset="-PT2D", end_time_offset="-PT1D", ) )

批次轉換工作的模型品質監控

若要為批次轉換工作排程模型品質監控,請將 BatchTransformInput 執行個體傳遞至 ModelQualityMonitor 執行個體的 batch_transform_input 引數,如下列程式碼範例所示:

from sagemaker.model_monitor import CronExpressionGenerator model_quality_model_monitor = ModelQualityMonitor( role=sagemaker.get_execution_role(), ... ) schedule = model_quality_model_monitor.create_monitoring_schedule( monitor_schedule_name=mon_schedule_name, batch_transform_input=BatchTransformInput( data_captured_destination_s3_uri=s3_capture_upload_path, destination="/opt/ml/processing/input", dataset_format=MonitoringDatasetFormat.csv(header=False), # the column index of the output representing the inference probablity probability_attribute="0", # the threshold to classify the inference probablity to class 0 or 1 in # binary classification problem probability_threshold_attribute=0.5, # look back 6 hour for transform job outputs. start_time_offset="-PT6H", end_time_offset="-PT0H" ), ground_truth_input=gt_s3_uri, output_s3_uri=s3_report_path, problem_type="BinaryClassification", constraints = constraints_path, schedule_cron_expression=CronExpressionGenerator.hourly(), enable_cloudwatch_metrics=True, )