Model: Model Class

ModelR Documentation

Model Class

Description

A SageMaker “Model“ that can be deployed to an “Endpoint“.

Super class

sagemaker.mlcore::ModelBase -> Model

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this [R6][R6::R6Class] class.

Usage
Model$new(
  image_uri,
  model_data = NULL,
  role = NULL,
  predictor_cls = NULL,
  env = NULL,
  name = NULL,
  vpc_config = NULL,
  sagemaker_session = NULL,
  enable_network_isolation = FALSE,
  model_kms_key = NULL,
  image_config = NULL
)
Arguments
image_uri

(str): A Docker image URI.

model_data

(str): The S3 location of a SageMaker model data “.tar.gz“ file.

role

(str): An AWS IAM role (either name or full ARN). The Amazon SageMaker training jobs and APIs that create Amazon SageMaker endpoints use this role to access training data and model artifacts. After the endpoint is created, the inference code might use the IAM role if it needs to access some AWS resources. It can be null if this is being used to create a Model to pass to a “PipelineModel“ which has its own Role field. (Default: NULL)

predictor_cls

(callable[string, :Session]): A function to call to create a predictor (default: None). If not None, “deploy“ will return the result of invoking this function on the created endpoint name.

env

(dict[str, str]): Environment variables to run with “image“ when hosted in SageMaker (Default: NULL).

name

(str): The model name. If None, a default model name will be selected on each “deploy“.

vpc_config

(dict[str, list[str]]): The VpcConfig set on the model (Default: NULL)

  • 'Subnets' (list[str]) List of subnet ids.

  • 'SecurityGroupIds' (list[str]): List of security group ids.

sagemaker_session

(:Session): A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

enable_network_isolation

(Boolean): Default False. if True, enables network isolation in the endpoint, isolating the model container. No inbound or outbound network calls can be made to or from the model container.

model_kms_key

(str): KMS key ARN used to encrypt the repacked model archive file if the model is repacked

image_config

(dict[str, str]): Specifies whether the image of model container is pulled from ECR, or private registry in your VPC. By default it is set to pull model container image from ECR. (default: None).


Method register()

Creates a model package for creating SageMaker models or listing on Marketplace.

Usage
Model$register(
  content_types,
  response_types,
  inference_instances,
  transform_instances,
  model_package_name = NULL,
  model_package_group_name = NULL,
  image_uri = NULL,
  model_metrics = NULL,
  metadata_properties = NULL,
  marketplace_cert = FALSE,
  approval_status = NULL,
  description = NULL,
  drift_check_baselines = NULL
)
Arguments
content_types

(list): The supported MIME types for the input data (default: None).

response_types

(list): The supported MIME types for the output data (default: None).

inference_instances

(list): A list of the instance types that are used to generate inferences in real-time (default: None).

transform_instances

(list): A list of the instance types on which a transformation job can be run or on which an endpoint can be deployed (default: None).

model_package_name

(str): Model Package name, exclusive to 'model_package_group_name', using 'model_package_name' makes the Model Package un-versioned (default: None).

model_package_group_name

(str): Model Package Group name, exclusive to 'model_package_name', using 'model_package_group_name' makes the Model Package versioned (default: None).

image_uri

(str): Inference image uri for the container. Model class' self.image will be used if it is None (default: None).

model_metrics

(ModelMetrics): ModelMetrics object (default: None).

metadata_properties

(MetadataProperties): MetadataProperties object (default: None).

marketplace_cert

(bool): A boolean value indicating if the Model Package is certified for AWS Marketplace (default: False).

approval_status

(str): Model Approval Status, values can be "Approved", "Rejected", or "PendingManualApproval" (default: "PendingManualApproval").

description

(str): Model Package description (default: None).

drift_check_baselines

(DriftCheckBaselines): DriftCheckBaselines object (default: None).

Returns

str: A string of SageMaker Model Package ARN.


Method prepare_container_def()

Return a dict created by “sagemaker.container_def()“ for deploying this model to a specified instance type. Subclasses can override this to provide custom container definitions for deployment to a specific instance type. Called by “deploy()“.

Usage
Model$prepare_container_def(instance_type, accelerator_type = NULL)
Arguments
instance_type

(str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge'.

accelerator_type

(str): The Elastic Inference accelerator type to deploy to the instance for loading and making inferences to the model. For example, 'ml.eia1.medium'.

Returns

dict: A container definition object usable with the CreateModel API.


Method enable_network_isolation()

Whether to enable network isolation when creating this Model

Usage
Model$enable_network_isolation()
Returns

bool: If network isolation should be enabled or not.


Method check_neo_region()

Check if this “Model“ in the available region where neo support.

Usage
Model$check_neo_region(region)
Arguments
region

(str): Specifies the region where want to execute compilation

Returns

bool: boolean value whether if neo is available in the specified region


Method package_for_edge()

Package this “Model“ with SageMaker Edge. Creates a new EdgePackagingJob and wait for it to finish. model_data will now point to the packaged artifacts.

Usage
Model$package_for_edge(
  output_path,
  model_name,
  model_version,
  role = NULL,
  job_name = NULL,
  resource_key = NULL,
  s3_kms_key = NULL,
  tags = NULL
)
Arguments
output_path

(str): Specifies where to store the packaged model

model_name

(str): the name to attach to the model metadata

model_version

(str): the version to attach to the model metadata

role

(str): Execution role

job_name

(str): The name of the edge packaging job

resource_key

(str): the kms key to encrypt the disk with

s3_kms_key

(str): the kms key to encrypt the output with

tags

(list[dict]): List of tags for labeling an edge packaging job. For more, see https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html.

Returns

sagemaker.model.Model: A SageMaker “Model“ object. See :func:'~sagemaker.model.Model' for full details.


Method compile()

Compile this “Model“ with SageMaker Neo.

Usage
Model$compile(
  target_instance_family,
  input_shape,
  output_path,
  role,
  tags = NULL,
  job_name = NULL,
  compile_max_run = 5 * 60,
  framework = NULL,
  framework_version = NULL,
  target_platform_os = NULL,
  target_platform_arch = NULL,
  target_platform_accelerator = NULL,
  compiler_options = NULL
)
Arguments
target_instance_family

(str): Identifies the device that you want to run your model after compilation, for example: ml_c5. For allowed strings see https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html.

input_shape

(list): Specifies the name and shape of the expected inputs for your trained model in json dictionary form, for example: list('data'= list(1,3,1024,1024)), or list('var1'= list(1,1,28,28), 'var2'= list(1,1,28,28))

output_path

(str): Specifies where to store the compiled model

role

(str): Execution role

tags

(list[dict]): List of tags for labeling a compilation job. For more, see https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html.

job_name

(str): The name of the compilation job

compile_max_run

(int): Timeout in seconds for compilation (default: 3 * 60). After this amount of time Amazon SageMaker Neo terminates the compilation job regardless of its current status.

framework

(str): The framework that is used to train the original model. Allowed values: 'mxnet', 'tensorflow', 'keras', 'pytorch', 'onnx', 'xgboost'

framework_version

(str):

target_platform_os

(str): Target Platform OS, for example: 'LINUX'. For allowed strings see https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html. It can be used instead of target_instance_family.

target_platform_arch

(str): Target Platform Architecture, for example: 'X86_64'. For allowed strings see https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html. It can be used instead of target_instance_family.

target_platform_accelerator

(str, optional): Target Platform Accelerator, for example: 'NVIDIA'. For allowed strings see https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html. It can be used instead of target_instance_family.

compiler_options

(dict, optional): Additional parameters for compiler. Compiler Options are TargetPlatform / target_instance_family specific. See https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html for details.

Returns

sagemaker.model.Model: A SageMaker “Model“ object. See :func:'~sagemaker.model.Model' for full details.


Method deploy()

Deploy this “Model“ to an “Endpoint“ and optionally return a “Predictor“. Create a SageMaker “Model“ and “EndpointConfig“, and deploy an “Endpoint“ from this “Model“. If “self.predictor_cls“ is not None, this method returns a the result of invoking “self.predictor_cls“ on the created endpoint name. The name of the created model is accessible in the “name“ field of this “Model“ after deploy returns The name of the created endpoint is accessible in the “endpoint_name“ field of this “Model“ after deploy returns.

Usage
Model$deploy(
  initial_instance_count = NULL,
  instance_type = NULL,
  serializer = NULL,
  deserializer = NULL,
  accelerator_type = NULL,
  endpoint_name = NULL,
  tags = NULL,
  kms_key = NULL,
  wait = TRUE,
  data_capture_config = NULL,
  serverless_inference_config = NULL,
  ...
)
Arguments
initial_instance_count

(int): The initial number of instances to run in the “Endpoint“ created from this “Model“.

instance_type

(str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge', or 'local' for local mode.

serializer

(:class:'~sagemaker.serializers.BaseSerializer'): A serializer object, used to encode data for an inference endpoint (default: None). If “serializer“ is not None, then “serializer“ will override the default serializer. The default serializer is set by the “predictor_cls“.

deserializer

(:class:'~sagemaker.deserializers.BaseDeserializer'): A deserializer object, used to decode data from an inference endpoint (default: None). If “deserializer“ is not None, then “deserializer“ will override the default deserializer. The default deserializer is set by the “predictor_cls“.

accelerator_type

(str): Type of Elastic Inference accelerator to deploy this model for model loading and inference, for example, 'ml.eia1.medium'. If not specified, no Elastic Inference accelerator will be attached to the endpoint. For more information: https://docs.aws.amazon.com/sagemaker/latest/dg/ei.html

endpoint_name

(str): The name of the endpoint to create (Default: NULL). If not specified, a unique endpoint name will be created.

tags

(List[dict[str, str]]): The list of tags to attach to this specific endpoint.

kms_key

(str): The ARN of the KMS key that is used to encrypt the data on the storage volume attached to the instance hosting the endpoint.

wait

(bool): Whether the call should wait until the deployment of this model completes (default: True).

data_capture_config

(sagemaker.model_monitor.DataCaptureConfig): Specifies configuration related to Endpoint data capture for use with Amazon SageMaker Model Monitoring. Default: None.

serverless_inference_config

(sagemaker.serverless.ServerlessInferenceConfig): Specifies configuration related to serverless endpoint. Use this configuration when trying to create serverless endpoint and make serverless inference. If empty object passed through, we will use pre-defined values in “ServerlessInferenceConfig“ class to deploy serverless endpoint (default: None)

...

: pass deprecated parameters.

Returns

callable[string, sagemaker.session.Session] or None: Invocation of “self.predictor_cls“ on the created endpoint name, if “self.predictor_cls“ is not None. Otherwise, return None.


Method transformer()

Return a “Transformer“ that uses this Model.

Usage
Model$transformer(
  instance_count,
  instance_type,
  strategy = NULL,
  assemble_with = NULL,
  output_path = NULL,
  output_kms_key = NULL,
  accept = NULL,
  env = NULL,
  max_concurrent_transforms = NULL,
  max_payload = NULL,
  tags = NULL,
  volume_kms_key = NULL
)
Arguments
instance_count

(int): Number of EC2 instances to use.

instance_type

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

strategy

(str): The strategy used to decide how to batch records in a single request (default: None). Valid values: 'MultiRecord' and 'SingleRecord'.

assemble_with

(str): How the output is assembled (default: None). Valid values: 'Line' or 'None'.

output_path

(str): S3 location for saving the transform result. If not specified, results are stored to a default bucket.

output_kms_key

(str): Optional. KMS key ID for encrypting the transform output (default: None).

accept

(str): The accept header passed by the client to the inference endpoint. If it is supported by the endpoint, it will be the format of the batch transform output.

env

(dict): Environment variables to be set for use during the transform job (default: None).

max_concurrent_transforms

(int): The maximum number of HTTP requests to be made to each individual transform container at one time.

max_payload

(int): Maximum size of the payload in a single HTTP request to the container in MB.

tags

(list[dict]): List of tags for labeling a transform job. If none specified, then the tags used for the training job are used for the transform job.

volume_kms_key

(str): Optional. KMS key ID for encrypting the volume attached to the ML compute instance (default: None).


Method delete_model()

Delete an Amazon SageMaker Model.

Usage
Model$delete_model()

Method .create_sagemaker_model()

Create a SageMaker Model Entity

Usage
Model$.create_sagemaker_model(
  instance_type,
  accelerator_type = NULL,
  tags = NULL
)
Arguments
instance_type

(str): The EC2 instance type that this Model will be used for, this is only used to determine if the image needs GPU support or not.

accelerator_type

(str): Type of Elastic Inference accelerator to attach to an endpoint for model loading and inference, for example, 'ml.eia1.medium'. If not specified, no Elastic Inference accelerator will be attached to the endpoint.

tags

(List[dict[str, str]]): Optional. The list of tags to add to the model. Example: >>> tags = ['Key': 'tagname', 'Value': 'tagvalue'] For more information about tags, see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.add_tags.


Method clone()

The objects of this class are cloneable with this method.

Usage
Model$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.