ModelMonitor: Sets up Amazon SageMaker Monitoring Schedules and baseline...

ModelMonitorR Documentation

Sets up Amazon SageMaker Monitoring Schedules and baseline suggestions.

Description

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.

Methods

Public methods


Method new()

Initializes a “Monitor“ instance. The Monitor handles baselining datasets and creating Amazon SageMaker Monitoring Schedules to monitor SageMaker endpoints.

Usage
ModelMonitor$new(
  role = NULL,
  image_uri = NULL,
  instance_count = 1,
  instance_type = "ml.m5.xlarge",
  entrypoint = NULL,
  volume_size_in_gb = 30,
  volume_kms_key = NULL,
  output_kms_key = NULL,
  max_runtime_in_seconds = NULL,
  base_job_name = NULL,
  sagemaker_session = NULL,
  env = NULL,
  tags = NULL,
  network_config = NULL
)
Arguments
role

(str): An AWS IAM role. The Amazon SageMaker jobs use this role.

image_uri

(str): The uri of the image to use for the jobs started by the Monitor.

instance_count

(int): The number of instances to run the jobs with.

instance_type

(str): Type of EC2 instance to use for the job, for example, 'ml.m5.xlarge'.

entrypoint

([str]): The entrypoint for the job.

volume_size_in_gb

(int): Size in GB of the EBS volume to use for storing data during processing (default: 30).

volume_kms_key

(str): A KMS key for the job's volume.

output_kms_key

(str): The KMS key id for the job's outputs.

max_runtime_in_seconds

(int): Timeout in seconds. After this amount of time, Amazon SageMaker terminates the job regardless of its current status. Default: 3600

base_job_name

(str): Prefix for the job name. If not specified, a default name is generated based on the training image name and current timestamp.

sagemaker_session

(sagemaker.session.Session): Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created using the default AWS configuration chain.

env

(dict): Environment variables to be passed to the job.

tags

([dict]): List of tags to be passed to the job.

network_config

(sagemaker.network.NetworkConfig): A NetworkConfig object that configures network isolation, encryption of inter-container traffic, security group IDs, and subnets.


Method run_baseline()

Run a processing job meant to baseline your dataset.

Usage
ModelMonitor$run_baseline(
  baseline_inputs,
  output,
  arguments = NULL,
  wait = TRUE,
  logs = TRUE,
  job_name = NULL
)
Arguments
baseline_inputs

([sagemaker.processing.ProcessingInput]): Input files for the processing job. These must be provided as ProcessingInput objects.

output

(sagemaker.processing.ProcessingOutput): Destination of the constraint_violations and statistics json files.

arguments

([str]): A list of string arguments to be passed to a processing job.

wait

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

logs

(bool): Whether to show the logs produced by the job. Only meaningful when wait is True (default: True).

job_name

(str): Processing job name. If not specified, the processor generates a default job name, based on the image name and current timestamp.


Method create_monitoring_schedule()

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.

Usage
ModelMonitor$create_monitoring_schedule(
  endpoint_input,
  output,
  statistics = NULL,
  constraints = NULL,
  monitor_schedule_name = NULL,
  schedule_cron_expression = NULL
)
Arguments
endpoint_input

(str or sagemaker.model_monitor.EndpointInput): The endpoint to monitor. This can either be the endpoint name or an EndpointInput.

output

(sagemaker.model_monitor.MonitoringOutput): The output of the monitoring schedule.

statistics

(sagemaker.model_monitor.Statistic or str): If provided alongside constraints, these will be used for monitoring the endpoint. This can be a sagemaker.model_monitor.Constraints object or an S3 uri pointing to a constraints JSON file.

constraints

(sagemaker.model_monitor.Constraints or str): If provided alongside statistics, these will be used for monitoring the endpoint. This can be a sagemaker.model_monitor.Constraints object or an S3 uri pointing to a constraints JSON file.

monitor_schedule_name

(str): Schedule name. If not specified, the processor generates a default job name, based on the image name and current timestamp.

schedule_cron_expression

(str): The cron expression that dictates the frequency that this job runs at. See sagemaker.model_monitor.CronExpressionGenerator for valid expressions. Default: Daily.


Method update_monitoring_schedule()

Updates the existing monitoring schedule.

Usage
ModelMonitor$update_monitoring_schedule(
  endpoint_input = NULL,
  output = NULL,
  statistics = NULL,
  constraints = NULL,
  schedule_cron_expression = NULL,
  instance_count = NULL,
  instance_type = NULL,
  entrypoint = NULL,
  volume_size_in_gb = NULL,
  volume_kms_key = NULL,
  output_kms_key = NULL,
  arguments = NULL,
  max_runtime_in_seconds = NULL,
  env = NULL,
  network_config = NULL,
  role = NULL,
  image_uri = NULL
)
Arguments
endpoint_input

(str or sagemaker.model_monitor.EndpointInput): The endpoint to monitor. This can either be the endpoint name or an EndpointInput.

output

(sagemaker.model_monitor.MonitoringOutput): The output of the monitoring schedule.

statistics

(sagemaker.model_monitor.Statistic or str): If provided alongside constraints, these will be used for monitoring the endpoint. This can be a sagemaker.model_monitor.Constraints object or an S3 uri pointing to a constraints JSON file.

constraints

(sagemaker.model_monitor.Constraints or str): If provided alongside statistics, these will be used for monitoring the endpoint. This can be a sagemaker.model_monitor.Constraints object or an S3 uri pointing to a constraints JSON file.

schedule_cron_expression

(str): The cron expression that dictates the frequency that this job runs at. See sagemaker.model_monitor.CronExpressionGenerator for valid expressions.

instance_count

(int): The number of instances to run the jobs with.

instance_type

(str): Type of EC2 instance to use for the job, for example, 'ml.m5.xlarge'.

entrypoint

(str): The entrypoint for the job.

volume_size_in_gb

(int): Size in GB of the EBS volume to use for storing data during processing (default: 30).

volume_kms_key

(str): A KMS key for the job's volume.

output_kms_key

(str): The KMS key id for the job's outputs.

arguments

([str]): A list of string arguments to be passed to a processing job.

max_runtime_in_seconds

(int): Timeout in seconds. After this amount of time, Amazon SageMaker terminates the job regardless of its current status. Default: 3600

env

(dict): Environment variables to be passed to the job.

network_config

(sagemaker.network.NetworkConfig): A NetworkConfig object that configures network isolation, encryption of inter-container traffic, security group IDs, and subnets.

role

(str): An AWS IAM role name or ARN. The Amazon SageMaker jobs use this role.

image_uri

(str): The uri of the image to use for the jobs started by the Monitor.


Method start_monitoring_schedule()

Starts the monitoring schedule.

Usage
ModelMonitor$start_monitoring_schedule()

Method stop_monitoring_schedule()

Stops the monitoring schedule.

Usage
ModelMonitor$stop_monitoring_schedule()

Method delete_monitoring_schedule()

Deletes the monitoring schedule.

Usage
ModelMonitor$delete_monitoring_schedule()

Method baseline_statistics()

Returns a Statistics object representing the statistics json file generated by the latest baselining job.

Usage
ModelMonitor$baseline_statistics(file_name = STATISTICS_JSON_DEFAULT_FILE_NAME)
Arguments
file_name

(str): The name of the .json statistics file

Returns

sagemaker.model_monitor.Statistics: The Statistics object representing the file that was generated by the job.


Method suggested_constraints()

Returns a Statistics object representing the constraints json file generated by the latest baselining job

Usage
ModelMonitor$suggested_constraints(
  file_name = CONSTRAINTS_JSON_DEFAULT_FILE_NAME
)
Arguments
file_name

(str): The name of the .json constraints file

sagemaker.model_monitor.Constraints:

The Constraints object representing the file that was generated by the job.


Method latest_monitoring_statistics()

Returns the sagemaker.model_monitor.Statistics generated by the latest monitoring execution.

Usage
ModelMonitor$latest_monitoring_statistics(
  file_name = STATISTICS_JSON_DEFAULT_FILE_NAME
)
Arguments
file_name

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

Returns

sagemaker.model_monitoring.Statistics: The Statistics object representing the file generated by the latest monitoring execution.


Method latest_monitoring_constraint_violations()

Returns the sagemaker.model_monitor.ConstraintViolations generated by the latest monitoring execution.

Usage
ModelMonitor$latest_monitoring_constraint_violations(
  file_name = CONSTRAINT_VIOLATIONS_JSON_DEFAULT_FILE_NAME
)
Arguments
file_name

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

Returns

sagemaker.model_monitoring.ConstraintViolations: The ConstraintViolations object representing the file generated by the latest monitoring execution.


Method describe_latest_baselining_job()

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

Usage
ModelMonitor$describe_latest_baselining_job()

Method describe_schedule()

Describes the schedule that this object represents.

Usage
ModelMonitor$describe_schedule()
Returns

dict: A dictionary response with the monitoring schedule description.


Method list_executions()

Get the list of the latest monitoring executions in descending order of "ScheduledTime". Statistics or violations can be called following this example: 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()

Usage
ModelMonitor$list_executions()
Returns

[sagemaker.model_monitor.MonitoringExecution]: List of MonitoringExecutions in descending order of "ScheduledTime".


Method attach()

Sets this object's schedule name to point to the Amazon Sagemaker Monitoring Schedule name provided. This allows subsequent describe_schedule or list_executions calls to point to the given schedule.

Usage
ModelMonitor$attach(monitor_schedule_name, sagemaker_session = NULL)
Arguments
monitor_schedule_name

(str): The name of the schedule to attach to.

sagemaker_session

(sagemaker.session.Session): Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created using the default AWS configuration chain.


Method monitoring_type()

Type of the monitoring job.

Usage
ModelMonitor$monitoring_type()

Method format()

format class

Usage
ModelMonitor$format()

Method clone()

The objects of this class are cloneable with this method.

Usage
ModelMonitor$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


DyfanJones/sagemaker-r-mlcore documentation built on May 3, 2022, 10:08 a.m.