sagemaker.core.model_monitor.monitoring_files#

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.

Classes

ConstraintViolations(body_dict, ...[, ...])

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

Constraints(body_dict, constraints_file_s3_uri)

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

ModelMonitoringFile(body_dict, file_s3_uri, ...)

Represents a file with a body and an S3 uri.

Statistics(body_dict, statistics_file_s3_uri)

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

class sagemaker.core.model_monitor.monitoring_files.ConstraintViolations(body_dict, constraint_violations_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Bases: ModelMonitoringFile

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

classmethod from_file_path(constraint_violations_file_path, kms_key=None, sagemaker_session=None)[source]#

Initializes a ConstraintViolations object from a file path.

Parameters:
  • constraint_violations_file_path (str) – The path to the constraint violations file.

  • kms_key (str) – The kms_key to use when encrypting the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of ConstraintViolations

generated from the local file path.

Return type:

sagemaker.model_monitor.ConstraintViolations

classmethod from_s3_uri(constraint_violations_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Generates a ConstraintViolations object from an s3 uri.

Parameters:
  • constraint_violations_file_s3_uri (str) – The uri of the constraint violations JSON file.

  • kms_key (str) – The kms key to be used to decrypt the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

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)[source]#

Generates a ConstraintViolations object from an s3 uri.

Parameters:
  • constraint_violations_file_string (str) – The uri of the constraint violations JSON file.

  • kms_key (str) – The kms key to be used to encrypt the file in S3.

  • file_name (str) – The file name to use when uploading to S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of ConstraintViolations

generated from the s3 uri.

Return type:

sagemaker.model_monitor.ConstraintViolations

class sagemaker.core.model_monitor.monitoring_files.Constraints(body_dict, constraints_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Bases: ModelMonitoringFile

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

classmethod from_file_path(constraints_file_path, kms_key=None, sagemaker_session=None)[source]#

Initializes a Constraints object from a file path.

Parameters:
  • constraints_file_path (str) – The path to the constraints file.

  • kms_key (str) – The kms_key to use when encrypting the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of Constraints generated from

the local file path.

Return type:

sagemaker.model_monitor.Constraints

classmethod from_s3_uri(constraints_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Generates a Constraints object from an s3 uri.

Parameters:
  • constraints_file_s3_uri (str) – The uri of the constraints JSON file.

  • kms_key (str) – The kms key to be used to decrypt the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

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)[source]#

Generates a Constraints object from an s3 uri.

Parameters:
  • constraints_file_string (str) – The uri of the constraints JSON file.

  • kms_key (str) – The kms key to be used to encrypt the file in S3.

  • file_name (str) – The file name to use when uploading to S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of Constraints generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Constraints

set_monitoring(enable_monitoring, feature_name=None)[source]#

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:
  • enable_monitoring (bool) – Whether to enable monitoring or not.

  • feature_name (str) – Sets the feature-level monitoring flag if provided. Otherwise, sets the file-level override.

class sagemaker.core.model_monitor.monitoring_files.ModelMonitoringFile(body_dict, file_s3_uri, kms_key, sagemaker_session)[source]#

Bases: object

Represents a file with a body and an S3 uri.

save(new_save_location_s3_uri=None)[source]#

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.core.model_monitor.monitoring_files.Statistics(body_dict, statistics_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Bases: ModelMonitoringFile

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

classmethod from_file_path(statistics_file_path, kms_key=None, sagemaker_session=None)[source]#

Initializes a Statistics object from a file path.

Parameters:
  • statistics_file_path (str) – The path to the statistics file.

  • kms_key (str) – The kms_key to use when encrypting the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of Statistics generated from

the local file path.

Return type:

sagemaker.model_monitor.Statistics

classmethod from_s3_uri(statistics_file_s3_uri, kms_key=None, sagemaker_session=None)[source]#

Generates a Statistics object from an s3 uri.

Parameters:
  • statistics_file_s3_uri (str) – The uri of the statistics JSON file.

  • kms_key (str) – The kms key to be used to decrypt the file in S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

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)[source]#

Generates a Statistics object from an s3 uri.

Parameters:
  • statistics_file_string (str) – The uri of the statistics JSON file.

  • kms_key (str) – The kms key to be used to encrypt the file in S3.

  • file_name (str) – The file name to use when uploading to S3.

  • sagemaker_session (sagemaker.core.helper.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Returns:

The instance of Statistics generated from

the s3 uri.

Return type:

sagemaker.model_monitor.Statistics