Model Monitor — sagemaker 2.247.0 documentation (original) (raw)

This module contains code related to Amazon SageMaker Model Monitoring.

These classes assist with suggesting baselines and creating monitoring schedules for data captured by SageMaker Endpoints.

class sagemaker.model_monitor.model_monitoring.ModelMonitor(role=None, image_uri=None, instance_count=1, instance_type='ml.m5.xlarge', entrypoint=None, volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: object

Sets up Amazon SageMaker Monitoring Schedules and baseline suggestions.

Use this class when you want to provide your own container image containing the code you’d like to run, in order to produce your own statistics and constraint validation files. For a more guided experience, consider using the DefaultModelMonitor class instead.

Initializes a Monitor instance.

The Monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

run_baseline(baseline_inputs, output, arguments=None, wait=True, logs=True, job_name=None)

Run a processing job meant to baseline your dataset.

Parameters:

create_monitoring_schedule(endpoint_input=None, output=None, statistics=None, constraints=None, monitor_schedule_name=None, schedule_cron_expression=None, batch_transform_input=None, arguments=None, data_analysis_start_time=None, data_analysis_end_time=None)

Creates a monitoring schedule to monitor an Amazon SageMaker Endpoint.

If constraints and statistics are provided, or if they are able to be retrieved from a previous baselining job associated with this monitor, those will be used. If constraints and statistics cannot be automatically retrieved, baseline_inputs will be required in order to kick off a baselining job.

Parameters:

update_monitoring_schedule(endpoint_input=None, output=None, statistics=None, constraints=None, schedule_cron_expression=None, instance_count=None, instance_type=None, entrypoint=None, volume_size_in_gb=None, volume_kms_key=None, output_kms_key=None, arguments=None, max_runtime_in_seconds=None, env=None, network_config=None, role=None, image_uri=None, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Updates the existing monitoring schedule.

If more options than schedule_cron_expression are to be updated, a new job definition will be created to hold them. The old job definition will not be deleted.

Parameters:

start_monitoring_schedule()

Starts the monitoring schedule.

stop_monitoring_schedule()

Stops the monitoring schedule.

delete_monitoring_schedule()

Deletes the monitoring schedule (subclass is responsible for deleting job definition)

baseline_statistics(file_name='statistics.json')

Returns a Statistics object representing the statistics json file

Object is generated by the latest baselining job.

Parameters:

file_name (str) – The name of the .json statistics file

Returns:

The Statistics object representing the file that

was generated by the job.

Return type:

sagemaker.model_monitor.Statistics

suggested_constraints(file_name='constraints.json')

Returns a Statistics object representing the constraints json file.

Object is generated by the latest baselining job

Parameters:

file_name (str) – The name of the .json constraints file

Returns:

The Constraints object representing the file that

was generated by the job.

Return type:

sagemaker.model_monitor.Constraints

latest_monitoring_statistics(file_name='statistics.json')

Returns the sagemaker.model_monitor.

Statistics generated by the latest monitoring execution.

Parameters:

file_name (str) – The name of the statistics file to be retrieved. Only override if generating a custom file name.

Returns:

The Statistics object representing the file

generated by the latest monitoring execution.

Return type:

sagemaker.model_monitoring.Statistics

latest_monitoring_constraint_violations(file_name='constraint_violations.json')

Returns the sagemaker.model_monitor.

ConstraintViolations generated by the latest monitoring execution.

Parameters:

file_name (str) – The name of the constraint violdations file to be retrieved. Only override if generating a custom file name.

Returns:

The ConstraintViolations object

representing the file generated by the latest monitoring execution.

Return type:

sagemaker.model_monitoring.ConstraintViolations

describe_latest_baselining_job()

Describe the latest baselining job kicked off by the suggest workflow.

describe_schedule()

Describes the schedule that this object represents.

Returns:

A dictionary response with the monitoring schedule description.

Return type:

dict

list_executions()

Get the list of the latest monitoring executions in descending order of “ScheduledTime”.

Statistics or violations can be called following this example: .. rubric:: Example

my_executions = my_monitor.list_executions() second_to_last_execution_statistics = my_executions[-1].statistics() second_to_last_execution_violations = my_executions[-1].constraint_violations()

Returns:

List of MonitoringExecutions in

descending order of “ScheduledTime”.

Return type:

[sagemaker.model_monitor.MonitoringExecution]

get_latest_execution_logs(wait=False)

Get the processing job logs for the most recent monitoring execution

Parameters:

wait (bool) – Whether the call should wait until the job completes (default: False).

Raises:

ValueError – If no execution job or processing job for the last execution has run

Returns: None

update_monitoring_alert(monitoring_alert_name, data_points_to_alert, evaluation_period)

Update the monitoring schedule alert.

Args:

monitoring_alert_name (str): The name of the monitoring alert to update. data_points_to_alert (int): The data point to alert. evaluation_period (int): The period to evaluate the alert status.

Returns: None

Parameters:

list_monitoring_alerts(next_token=None, max_results=10)

List the monitoring alerts.

Parameters:

Returns:

list of monitoring alert history. str: Next token.

Return type:

List[MonitoringAlertSummary]

list_monitoring_alert_history(monitoring_alert_name=None, sort_by='CreationTime', sort_order='Descending', next_token=None, max_results=10, creation_time_before=None, creation_time_after=None, status_equals=None)

Lists the alert history associated with the given schedule_name and alert_name.

Parameters:

Returns:

list of monitoring alert history. str: Next token.

Return type:

List[MonitoringAlertHistorySummary]

classmethod attach(monitor_schedule_name, sagemaker_session=None)

Set this object’s schedule name point to the Amazon Sagemaker Monitoring Schedule name.

This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Parameters:

classmethod monitoring_type()

Type of the monitoring job.

class sagemaker.model_monitor.model_monitoring.DefaultModelMonitor(role=None, instance_count=1, instance_type='ml.m5.xlarge', volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: ModelMonitor

Sets up Amazon SageMaker Monitoring Schedules and baseline suggestions.

Use this class when you want to utilize Amazon SageMaker Monitoring’s plug-and-play solution that only requires your dataset and optional pre/postprocessing scripts. For a more customized experience, consider using the ModelMonitor class instead.

Initializes a Monitor instance.

The Monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

JOB_DEFINITION_BASE_NAME = 'data-quality-job-definition'

classmethod monitoring_type()

Type of the monitoring job.

suggest_baseline(baseline_dataset, dataset_format, record_preprocessor_script=None, post_analytics_processor_script=None, output_s3_uri=None, wait=True, logs=True, job_name=None, monitoring_config_override=None)

Suggest baselines for use with Amazon SageMaker Model Monitoring Schedules.

Parameters:

Returns:

The ProcessingJob object representing the

baselining job.

Return type:

sagemaker.processing.ProcessingJob

create_monitoring_schedule(endpoint_input=None, record_preprocessor_script=None, post_analytics_processor_script=None, output_s3_uri=None, constraints=None, statistics=None, monitor_schedule_name=None, schedule_cron_expression=None, enable_cloudwatch_metrics=True, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Creates a monitoring schedule to monitor an Amazon SageMaker Endpoint.

If constraints and statistics are provided, or if they are able to be retrieved from a previous baselining job associated with this monitor, those will be used. If constraints and statistics cannot be automatically retrieved, baseline_inputs will be required in order to kick off a baselining job.

Parameters:

update_monitoring_schedule(endpoint_input=None, record_preprocessor_script=None, post_analytics_processor_script=None, output_s3_uri=None, statistics=None, constraints=None, schedule_cron_expression=None, instance_count=None, instance_type=None, volume_size_in_gb=None, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, env=None, network_config=None, enable_cloudwatch_metrics=None, role=None, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Updates the existing monitoring schedule.

Parameters:

delete_monitoring_schedule()

Deletes the monitoring schedule and its job definition.

run_baseline()

Not implemented.

‘.run_baseline()’ is only allowed for ModelMonitor objects. Please usesuggest_baseline for DefaultModelMonitor objects, instead.

Raises:

NotImplementedError

classmethod attach(monitor_schedule_name, sagemaker_session=None)

Sets this object’s schedule name to the name provided.

This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Parameters:

latest_monitoring_statistics()

Returns the sagemaker.model_monitor.Statistics.

These are the statistics generated by the latest monitoring execution.

Returns:

The Statistics object representing the file

generated by the latest monitoring execution.

Return type:

sagemaker.model_monitoring.Statistics

latest_monitoring_constraint_violations()

Returns the sagemaker.model_monitor.

ConstraintViolations generated by the latest monitoring execution.

Returns:

The ConstraintViolations object

representing the file generated by the latest monitoring execution.

Return type:

sagemaker.model_monitoring.ConstraintViolations

class sagemaker.model_monitor.model_monitoring.ModelQualityMonitor(role=None, instance_count=1, instance_type='ml.m5.xlarge', volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: ModelMonitor

Amazon SageMaker model monitor to monitor quality metrics for an endpoint.

Please see the __init__ method of its base class for how to instantiate it.

Initializes a monitor instance.

The monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

JOB_DEFINITION_BASE_NAME = 'model-quality-job-definition'

classmethod monitoring_type()

Type of the monitoring job.

suggest_baseline(baseline_dataset, dataset_format, problem_type, inference_attribute=None, probability_attribute=None, ground_truth_attribute=None, probability_threshold_attribute=None, post_analytics_processor_script=None, output_s3_uri=None, wait=False, logs=False, job_name=None)

Suggest baselines for use with Amazon SageMaker Model Monitoring Schedules.

Parameters:

Returns:

The ProcessingJob object representing the

baselining job.

Return type:

sagemaker.processing.ProcessingJob

create_monitoring_schedule(endpoint_input=None, ground_truth_input=None, problem_type=None, record_preprocessor_script=None, post_analytics_processor_script=None, output_s3_uri=None, constraints=None, monitor_schedule_name=None, schedule_cron_expression=None, enable_cloudwatch_metrics=True, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Creates a monitoring schedule.

Parameters:

update_monitoring_schedule(endpoint_input=None, ground_truth_input=None, problem_type=None, record_preprocessor_script=None, post_analytics_processor_script=None, output_s3_uri=None, constraints=None, schedule_cron_expression=None, enable_cloudwatch_metrics=None, role=None, instance_count=None, instance_type=None, volume_size_in_gb=None, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, env=None, network_config=None, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Updates the existing monitoring schedule.

If more options than schedule_cron_expression are to be updated, a new job definition will be created to hold them. The old job definition will not be deleted.

Parameters:

delete_monitoring_schedule()

Deletes the monitoring schedule and its job definition.

classmethod attach(monitor_schedule_name, sagemaker_session=None)

Sets this object’s schedule name to the name provided.

This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Parameters:

class sagemaker.model_monitor.model_monitoring.BaseliningJob(sagemaker_session, job_name, inputs, outputs, output_kms_key=None)

Bases: ProcessingJob

Provides functionality to retrieve baseline-specific files output from baselining job.

Initializes a Baselining job.

It tracks a baselining job kicked off by the suggest workflow.

Parameters:

classmethod from_processing_job(processing_job)

Initializes a Baselining job from a processing job.

Parameters:

processing_job (sagemaker.processing.ProcessingJob) – The ProcessingJob used for baselining instance.

Returns:

The instance of ProcessingJob created

using the current job name.

Return type:

sagemaker.processing.BaseliningJob

baseline_statistics(file_name='statistics.json', kms_key=None)

Returns a sagemaker.model_monitor.

Statistics object representing the statistics JSON file generated by this baselining job.

Parameters:

Returns:

The Statistics object representing the file that

was generated by the job.

Return type:

sagemaker.model_monitor.Statistics

Raises:

UnexpectedStatusException – This is thrown if the job is not in a ‘Complete’ state.

suggested_constraints(file_name='constraints.json', kms_key=None)

Returns a sagemaker.model_monitor.

Constraints object representing the constraints JSON file generated by this baselining job.

Parameters:

Returns:

The Constraints object representing the file that

was generated by the job.

Return type:

sagemaker.model_monitor.Constraints

Raises:

UnexpectedStatusException – This is thrown if the job is not in a ‘Complete’ state.

class sagemaker.model_monitor.model_monitoring.MonitoringExecution(sagemaker_session, job_name, inputs, output, output_kms_key=None)

Bases: ProcessingJob

Provides functionality to retrieve monitoring-specific files from monitoring executions.

Initializes a MonitoringExecution job that tracks a monitoring execution.

Its kicked off by an Amazon SageMaker Model Monitoring Schedule.

Parameters:

classmethod from_processing_arn(sagemaker_session, processing_job_arn)

Initializes a Baselining job from a processing arn.

Parameters:

Returns:

The instance of ProcessingJob created

using the current job name.

Return type:

sagemaker.processing.BaseliningJob

statistics(file_name='statistics.json', kms_key=None)

Returns a sagemaker.model_monitor.

Statistics object representing the statistics JSON file generated by this monitoring execution.

Parameters:

Returns:

The Statistics object representing the file that

was generated by the execution.

Return type:

sagemaker.model_monitor.Statistics

Raises:

UnexpectedStatusException – This is thrown if the job is not in a ‘Complete’ state.

constraint_violations(file_name='constraint_violations.json', kms_key=None)

Returns a sagemaker.model_monitor.

ConstraintViolations object representing the constraint violations JSON file generated by this monitoring execution.

Parameters:

Returns:

The ConstraintViolations object

representing the file that was generated by the monitoring execution.

Return type:

sagemaker.model_monitor.ConstraintViolations

Raises:

UnexpectedStatusException – This is thrown if the job is not in a ‘Complete’ state.

class sagemaker.model_monitor.model_monitoring.EndpointInput(endpoint_name, destination, s3_input_mode='File', s3_data_distribution_type='FullyReplicated', start_time_offset=None, end_time_offset=None, features_attribute=None, inference_attribute=None, probability_attribute=None, probability_threshold_attribute=None, exclude_features_attribute=None)

Bases: object

Accepts parameters that specify an endpoint input for monitoring execution.

It also provides a method to turn those parameters into a dictionary.

Initialize an EndpointInput instance.

EndpointInput accepts parameters that specify an endpoint input for a monitoring job and provides a method to turn those parameters into a dictionary.

Parameters:

class sagemaker.model_monitor.model_monitoring.MonitoringInput(start_time_offset, end_time_offset, features_attribute, inference_attribute, probability_attribute, probability_threshold_attribute)

Bases: object

Accepts parameters specifying batch transform or endpoint inputs for monitoring execution.

MonitoringInput accepts parameters that specify additional parameters while monitoring jobs. It also provides a method to turn those parameters into a dictionary.

Parameters:

Method generated by attrs for class MonitoringInput.

start_time_offset_: str_

end_time_offset_: str_

features_attribute_: str_

inference_attribute_: str_

probability_attribute_: str | int_

probability_threshold_attribute_: float_

class sagemaker.model_monitor.model_monitoring.BatchTransformInput(data_captured_destination_s3_uri, destination, dataset_format, s3_input_mode='File', s3_data_distribution_type='FullyReplicated', start_time_offset=None, end_time_offset=None, features_attribute=None, inference_attribute=None, probability_attribute=None, probability_threshold_attribute=None, exclude_features_attribute=None)

Bases: MonitoringInput

Accepts parameters that specify a batch transform input for monitoring schedule.

It also provides a method to turn those parameters into a dictionary.

Initialize a BatchTransformInput instance.

Parameters:

class sagemaker.model_monitor.model_monitoring.MonitoringOutput(source, destination=None, s3_upload_mode='Continuous')

Bases: object

Accepts parameters that specify an S3 output for a monitoring job.

It also provides a method to turn those parameters into a dictionary.

Initialize a MonitoringOutput instance.

MonitoringOutput accepts parameters that specify an S3 output for a monitoring job and provides a method to turn those parameters into a dictionary.

Parameters:

This module contains code related to the ModelMonitoringFile class.

Codes are used for managing the constraints and statistics JSON files generated and consumed by Amazon SageMaker Model Monitoring Schedules.

class sagemaker.model_monitor.monitoring_files.ModelMonitoringFile(body_dict, file_s3_uri, kms_key, sagemaker_session)

Bases: object

Represents a file with a body and an S3 uri.

Initializes a file with a body and an S3 uri.

Parameters:

save(new_save_location_s3_uri=None)

Save the current instance’s body to s3 using the instance’s s3 path.

The S3 path can be overridden by providing one. This also overrides the default save location for this object.

Parameters:

new_save_location_s3_uri (str) – Optional. The S3 path to save the file to. If not provided, the file is saved in place in S3. If provided, the file’s S3 path is permanently updated.

Returns:

The s3 location to which the file was saved.

Return type:

str

class sagemaker.model_monitor.monitoring_files.Statistics(body_dict, statistics_file_s3_uri, kms_key=None, sagemaker_session=None)

Bases: ModelMonitoringFile

Represents the statistics JSON file used in Amazon SageMaker Model Monitoring.

Initializes the Statistics object used in Amazon SageMaker Model Monitoring.

Parameters:

classmethod from_s3_uri(statistics_file_s3_uri, kms_key=None, sagemaker_session=None)

Generates a Statistics object from an s3 uri.

Parameters:

Returns:

The instance of Statistics generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Statistics

classmethod from_string(statistics_file_string, kms_key=None, file_name=None, sagemaker_session=None)

Generates a Statistics object from an s3 uri.

Parameters:

Returns:

The instance of Statistics generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Statistics

classmethod from_file_path(statistics_file_path, kms_key=None, sagemaker_session=None)

Initializes a Statistics object from a file path.

Parameters:

Returns:

The instance of Statistics generated from

the local file path.

Return type:

sagemaker.model_monitor.Statistics

class sagemaker.model_monitor.monitoring_files.Constraints(body_dict, constraints_file_s3_uri, kms_key=None, sagemaker_session=None)

Bases: ModelMonitoringFile

Represents the constraints JSON file used in Amazon SageMaker Model Monitoring.

Initializes the Constraints object used in Amazon SageMaker Model Monitoring.

Parameters:

classmethod from_s3_uri(constraints_file_s3_uri, kms_key=None, sagemaker_session=None)

Generates a Constraints object from an s3 uri.

Parameters:

Returns:

The instance of Constraints generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Constraints

classmethod from_string(constraints_file_string, kms_key=None, file_name=None, sagemaker_session=None)

Generates a Constraints object from an s3 uri.

Parameters:

Returns:

The instance of Constraints generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Constraints

classmethod from_file_path(constraints_file_path, kms_key=None, sagemaker_session=None)

Initializes a Constraints object from a file path.

Parameters:

Returns:

The instance of Constraints generated from

the local file path.

Return type:

sagemaker.model_monitor.Constraints

set_monitoring(enable_monitoring, feature_name=None)

Sets the monitoring flags on this Constraints object.

If feature-name is provided, modify the feature-level override. Else, modify the top-level monitoring flag.

Parameters:

class sagemaker.model_monitor.monitoring_files.ConstraintViolations(body_dict, constraint_violations_file_s3_uri, kms_key=None, sagemaker_session=None)

Bases: ModelMonitoringFile

Represents the constraint violations JSON file used in Amazon SageMaker Model Monitoring.

Initializes the ConstraintViolations object used in Amazon SageMaker Model Monitoring.

Parameters:

classmethod from_s3_uri(constraint_violations_file_s3_uri, kms_key=None, sagemaker_session=None)

Generates a ConstraintViolations object from an s3 uri.

Parameters:

Returns:

The instance of ConstraintViolations

generated from the s3 uri.

Return type:

sagemaker.model_monitor.ConstraintViolations

classmethod from_string(constraint_violations_file_string, kms_key=None, file_name=None, sagemaker_session=None)

Generates a ConstraintViolations object from an s3 uri.

Parameters:

Returns:

The instance of ConstraintViolations

generated from the s3 uri.

Return type:

sagemaker.model_monitor.ConstraintViolations

classmethod from_file_path(constraint_violations_file_path, kms_key=None, sagemaker_session=None)

Initializes a ConstraintViolations object from a file path.

Parameters:

Returns:

The instance of ConstraintViolations

generated from the local file path.

Return type:

sagemaker.model_monitor.ConstraintViolations

This module contains code related to the DatasetFormat class.

Codes are used for managing the constraints JSON file generated and consumed by Amazon SageMaker Model Monitoring Schedules.

class sagemaker.model_monitor.dataset_format.DatasetFormat

Bases: object

Represents a Dataset Format that is used when calling a DefaultModelMonitor.

static csv(header=True, output_columns_position='START')

Returns a DatasetFormat JSON string for use with a DefaultModelMonitor.

Parameters:

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

static json(lines=True)

Returns a DatasetFormat JSON string for use with a DefaultModelMonitor.

Parameters:

lines (bool) – Whether the file should be read as a json object per line. Default: True.

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

static sagemaker_capture_json()

Returns a DatasetFormat SageMaker Capture Json string for use with a DefaultModelMonitor.

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

class sagemaker.model_monitor.dataset_format.MonitoringDatasetFormat

Bases: object

Represents a Dataset Format that is used when calling a DefaultModelMonitor.

static csv(header=True)

Returns a DatasetFormat JSON string for use with a DefaultModelMonitor.

Parameters:

header (bool) – Whether the csv dataset to baseline and monitor has a header. Default: True.

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

static json(lines=True)

Returns a DatasetFormat JSON string for use with a DefaultModelMonitor.

Parameters:

lines (bool) – Whether the file should be read as a json object per line. Default: True.

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

static parquet()

Returns a DatasetFormat SageMaker Capture Json string for use with a DefaultModelMonitor.

Returns:

JSON string containing DatasetFormat to be used by DefaultModelMonitor.

Return type:

dict

This module contains code related to the DataCaptureConfig class.

Codes are used for configuring capture, collection, and storage, for prediction requests and responses for models hosted on SageMaker Endpoints.

class sagemaker.model_monitor.data_capture_config.DataCaptureConfig(enable_capture, sampling_percentage=20, destination_s3_uri=None, kms_key_id=None, capture_options=None, csv_content_types=None, json_content_types=None, sagemaker_session=None)

Bases: object

Configuration object passed in when deploying models to Amazon SageMaker Endpoints.

This object specifies configuration related to endpoint data capture for use with Amazon SageMaker Model Monitoring.

Initialize a DataCaptureConfig object for capturing data from Amazon SageMaker Endpoints.

Parameters:

API_MAPPING = {'REQUEST': 'Input', 'RESPONSE': 'Output'}

This module contains code related to the CronExpressionGenerator class.

Codes are used for generating cron expressions compatible with Amazon SageMaker Model Monitoring Schedules.

class sagemaker.model_monitor.cron_expression_generator.CronExpressionGenerator

Bases: object

Generates cron expression strings for the SageMaker Model Monitoring Schedule API.

static hourly()

Generates hourly cron expression that denotes that a job runs at the top of every hour.

Returns:

The cron expression format accepted by the Amazon SageMaker Model Monitoring

Schedule API.

Return type:

str

static daily(hour=0)

Generates daily cron expression that denotes that a job runs at the top of every hour.

Parameters:

hour (int) –

The hour in HH24 format (UTC) to run the job at, on a daily schedule. .. rubric:: Examples

Returns:

The cron expression format accepted by the Amazon SageMaker Model Monitoring

Schedule API.

Return type:

str

static daily_every_x_hours(hour_interval, starting_hour=0)

Generates “daily every x hours” cron expression.

That denotes that a job runs every day at the specified hour, and then every x hours, as specified in hour_interval.

Example:

daily_every_x_hours(hour_interval=2, starting_hour=0) This will run every 2 hours starting at midnight.

daily_every_x_hours(hour_interval=10, starting_hour=0) This will run at midnight, 10am, and 8pm every day.

Parameters:

Returns:

The cron expression format accepted by the Amazon SageMaker Model Monitoring

Schedule API.

Return type:

str

static now()

Returns the string used to depict the one-time schedule

This module contains code related to Amazon SageMaker Explainability AI Model Monitoring.

These classes assist with suggesting baselines and creating monitoring schedules for monitoring bias metrics and feature attribution of SageMaker Endpoints.

class sagemaker.model_monitor.clarify_model_monitoring.ClarifyModelMonitor(role=None, instance_count=1, instance_type='ml.m5.xlarge', volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: ModelMonitor

Base class of Amazon SageMaker Explainability API model monitors.

This class is an abstract base class, please instantiate its subclasses if you want to monitor bias metrics or feature attribution of an endpoint.

Initializes a monitor instance.

The monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

run_baseline(**_)

Not implemented.

‘.run_baseline()’ is only allowed for ModelMonitor objects. Please use suggest_baseline instead.

Raises:

NotImplementedError

latest_monitoring_statistics(**_)

Not implemented.

The class doesn’t support statistics.

Raises:

NotImplementedError

list_executions()

Get the list of the latest monitoring executions in descending order of “ScheduledTime”.

Returns:

List of

ClarifyMonitoringExecution in descending order of “ScheduledTime”.

Return type:

[sagemaker.model_monitor.ClarifyMonitoringExecution]

get_latest_execution_logs(wait=False)

Get the processing job logs for the most recent monitoring execution

Parameters:

wait (bool) – Whether the call should wait until the job completes (default: False).

Raises:

ValueError – If no execution job or processing job for the last execution has run

Returns: None

class sagemaker.model_monitor.clarify_model_monitoring.ModelBiasMonitor(role=None, instance_count=1, instance_type='ml.m5.xlarge', volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: ClarifyModelMonitor

Amazon SageMaker model monitor to monitor bias metrics of an endpoint.

Please see the __init__ method of its base class for how to instantiate it.

Initializes a monitor instance.

The monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

JOB_DEFINITION_BASE_NAME = 'model-bias-job-definition'

classmethod monitoring_type()

Type of the monitoring job.

suggest_baseline(data_config, bias_config, model_config, model_predicted_label_config=None, wait=False, logs=False, job_name=None, kms_key=None)

Suggests baselines for use with Amazon SageMaker Model Monitoring Schedules.

Parameters:

Returns:

The ProcessingJob object representing the

baselining job.

Return type:

sagemaker.processing.ProcessingJob

create_monitoring_schedule(endpoint_input=None, ground_truth_input=None, analysis_config=None, output_s3_uri=None, constraints=None, monitor_schedule_name=None, schedule_cron_expression=None, enable_cloudwatch_metrics=True, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Creates a monitoring schedule.

Parameters:

update_monitoring_schedule(endpoint_input=None, ground_truth_input=None, analysis_config=None, output_s3_uri=None, constraints=None, schedule_cron_expression=None, enable_cloudwatch_metrics=None, role=None, instance_count=None, instance_type=None, volume_size_in_gb=None, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, env=None, network_config=None, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Updates the existing monitoring schedule.

If more options than schedule_cron_expression are to be updated, a new job definition will be created to hold them. The old job definition will not be deleted.

Parameters:

delete_monitoring_schedule()

Deletes the monitoring schedule and its job definition.

classmethod attach(monitor_schedule_name, sagemaker_session=None)

Sets this object’s schedule name to the name provided.

This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Parameters:

class sagemaker.model_monitor.clarify_model_monitoring.BiasAnalysisConfig(bias_config, headers=None, label=None)

Bases: object

Analysis configuration for ModelBiasMonitor.

Creates an analysis config dictionary.

Parameters:

class sagemaker.model_monitor.clarify_model_monitoring.ModelExplainabilityMonitor(role=None, instance_count=1, instance_type='ml.m5.xlarge', volume_size_in_gb=30, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, base_job_name=None, sagemaker_session=None, env=None, tags=None, network_config=None)

Bases: ClarifyModelMonitor

Amazon SageMaker model monitor to monitor feature attribution of an endpoint.

Please see the __init__ method of its base class for how to instantiate it.

Initializes a monitor instance.

The monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Parameters:

JOB_DEFINITION_BASE_NAME = 'model-explainability-job-definition'

classmethod monitoring_type()

Type of the monitoring job.

suggest_baseline(data_config, explainability_config, model_config, model_scores=None, wait=False, logs=False, job_name=None, kms_key=None)

Suggest baselines for use with Amazon SageMaker Model Monitoring Schedules.

Parameters:

Returns:

The ProcessingJob object representing the

baselining job.

Return type:

sagemaker.processing.ProcessingJob

create_monitoring_schedule(endpoint_input=None, analysis_config=None, output_s3_uri=None, constraints=None, monitor_schedule_name=None, schedule_cron_expression=None, enable_cloudwatch_metrics=True, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Creates a monitoring schedule.

Parameters:

update_monitoring_schedule(endpoint_input=None, analysis_config=None, output_s3_uri=None, constraints=None, schedule_cron_expression=None, enable_cloudwatch_metrics=None, role=None, instance_count=None, instance_type=None, volume_size_in_gb=None, volume_kms_key=None, output_kms_key=None, max_runtime_in_seconds=None, env=None, network_config=None, batch_transform_input=None, data_analysis_start_time=None, data_analysis_end_time=None)

Updates the existing monitoring schedule.

If more options than schedule_cron_expression are to be updated, a new job definition will be created to hold them. The old job definition will not be deleted.

Parameters:

delete_monitoring_schedule()

Deletes the monitoring schedule and its job definition.

classmethod attach(monitor_schedule_name, sagemaker_session=None)

Sets this object’s schedule name to the name provided.

This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Parameters:

class sagemaker.model_monitor.clarify_model_monitoring.ExplainabilityAnalysisConfig(explainability_config, model_config, headers=None, label_headers=None)

Bases: object

Analysis configuration for ModelExplainabilityMonitor.

Creates an analysis config dictionary.

Parameters:

class sagemaker.model_monitor.clarify_model_monitoring.ClarifyBaseliningConfig(analysis_config, features_attribute=None, inference_attribute=None, probability_attribute=None, probability_threshold_attribute=None)

Bases: object

Data class to hold some essential analysis configuration of ClarifyBaseliningJob

Initialization.

Parameters:

class sagemaker.model_monitor.clarify_model_monitoring.ClarifyBaseliningJob(processing_job)

Bases: BaseliningJob

Provides functionality to retrieve baseline-specific output from Clarify baselining job.

Initializes a ClarifyBaseliningJob that tracks a baselining job by suggest_baseline()

Parameters:

processing_job (sagemaker.processing.ProcessingJob) – The ProcessingJob used for baselining instance.

baseline_statistics(**_)

Not implemented.

The class doesn’t support statistics.

Raises:

NotImplementedError

suggested_constraints(file_name=None, kms_key=None)

Returns a sagemaker.model_monitor.

Constraints object representing the constraints JSON file generated by this baselining job.

Parameters:

Returns:

The Constraints object representing the file that

was generated by the job.

Return type:

sagemaker.model_monitor.Constraints

Raises:

UnexpectedStatusException – This is thrown if the job is not in a ‘Complete’ state.

class sagemaker.model_monitor.clarify_model_monitoring.ClarifyMonitoringExecution(sagemaker_session, job_name, inputs, output, output_kms_key=None)

Bases: MonitoringExecution

Provides functionality to retrieve monitoring-specific files output from executions.

Initializes an object that tracks a monitoring execution by a Clarify model monitor

Parameters:

statistics(**_)

Not implemented.

The class doesn’t support statistics.

Raises:

NotImplementedError

This file contains code related to model metrics, including metric source and file source.

class sagemaker.model_metrics.ModelMetrics(model_statistics=None, model_constraints=None, model_data_statistics=None, model_data_constraints=None, bias=None, explainability=None, bias_pre_training=None, bias_post_training=None)

Bases: object

Accepts model metrics parameters for conversion to request dict.

Initialize a ModelMetrics instance and turn parameters into dict.

Parameters:

class sagemaker.model_metrics.MetricsSource(content_type, s3_uri, content_digest=None)

Bases: object

Accepts metrics source parameters for conversion to request dict.

Initialize a MetricsSource instance and turn parameters into dict.

Parameters:

class sagemaker.model_metrics.FileSource(s3_uri, content_digest=None, content_type=None)

Bases: object

Accepts file source parameters for conversion to request dict.

Initialize a FileSource instance and turn parameters into dict.

Parameters:

This file contains code related to drift check baselines

class sagemaker.drift_check_baselines.DriftCheckBaselines(model_statistics=None, model_constraints=None, model_data_statistics=None, model_data_constraints=None, bias_config_file=None, bias_pre_training_constraints=None, bias_post_training_constraints=None, explainability_constraints=None, explainability_config_file=None)

Bases: object

Accepts drift check baselines parameters for conversion to request dict.

Initialize a DriftCheckBaselines instance and turn parameters into dict.

Parameters:

This module contains code related to the MonitoringConfig of constraints file.

Code is used to represent the Monitoring Config object and its parameters suggested in constraints file by Model Monitor Container in data quality analysis.

class sagemaker.model_monitor.data_quality_monitoring_config.DataQualityDistributionConstraints(categorical_drift_method=None)

Bases: object

Represents the distribution_constraints object of monitoring_config in constraints file.

Parameters:

categorical_drift_method (str) –

static valid_distribution_constraints(distribution_constraints)

Checks whether distribution_constraints are valid or not.

static valid_categorical_drift_method(categorical_drift_method)

Checks whether categorical_drift_method is valid or not.

class sagemaker.model_monitor.data_quality_monitoring_config.DataQualityMonitoringConfig(distribution_constraints=None)

Bases: object

Represents monitoring_config object in constraints file.

Parameters:

distribution_constraints (DataQualityDistributionConstraints) –

static valid_monitoring_config(monitoring_config)

Checks whether monitoring_config is valid or not.