Predictor: Predictor Class

PredictorR Documentation

Predictor Class

Description

Make prediction requests to an Amazon SageMaker endpoint.

Super class

sagemaker.mlcore::PredictorBase -> Predictor

Public fields

endpoint_name

Name of the Amazon SageMaker endpoint

sagemaker_session

A SageMaker Session object

serializer

Class to convert data into raw to send to endpoint

deserializer

Class to convert raw data back from the endpoint

Active bindings

content_type

The MIME type of the data sent to the inference endpoint.

accept

The content type(s) that are expected from the inference endpoint.

endpoint

Deprecated attribute. Please use endpoint_name.

Methods

Public methods

Inherited methods

Method new()

Initialize a “Predictor“. Behavior for serialization of input data and deserialization of result data can be configured through initializer arguments. If not specified, a sequence of bytes is expected and the API sends it in the request body without modifications. In response, the API returns the sequence of bytes from the prediction result without any modifications.

Usage
Predictor$new(
  endpoint_name,
  sagemaker_session = NULL,
  serializer = IdentitySerializer$new(),
  deserializer = BytesDeserializer$new(),
  ...
)
Arguments
endpoint_name

(str): Name of the Amazon SageMaker endpoint_name to which requests are sent.

sagemaker_session

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

serializer

(callable): Accepts a single argument, the input data, and returns a sequence of bytes. It may provide a “content_type“ attribute that defines the endpoint request content type. If not specified, a sequence of bytes is expected for the data. (default: “IdentitySerializer“)

deserializer

(callable): Accepts two arguments, the result data and the response content type, and returns a sequence of bytes. It may provide a “content_type“ attribute that defines the endpoint response's "Accept" content type. If not specified, a sequence of bytes is expected for the data. (default: “BytesDeserializer“)

...

Any other parameters, including and deprecate parameters from sagemaker v-1.


Method predict()

Return the inference from the specified endpoint.

Usage
Predictor$predict(
  data,
  initial_args = NULL,
  target_model = NULL,
  target_variant = NULL,
  inference_id = NULL
)
Arguments
data

(object): Input data for which you want the model to provide inference. If a serializer was specified when creating the Predictor, the result of the serializer is sent as input data. Otherwise the data must be sequence of bytes, and the predict method then sends the bytes in the request body as is.

initial_args

(list[str,str]): Optional. Default arguments for boto3 “invoke_endpoint“ call. Default is NULL (no default arguments).

target_model

(str): S3 model artifact path to run an inference request on, in case of a multi model endpoint. Does not apply to endpoints hosting single model (Default: NULL)

target_variant

(str): The name of the production variant to run an inference request on (Default: NULL). Note that the ProductionVariant identifies the model you want to host and the resources you want to deploy for hosting it.

inference_id

(str): If you provide a value, it is added to the captured data when you enable data capture on the endpoint (Default: None).

Returns

object: Inference for the given input. If a deserializer was specified when creating the Predictor, the result of the deserializer is returned. Otherwise the response returns the sequence of bytes as is.


Method update_endpoint()

Update the existing endpoint with the provided attributes. This creates a new EndpointConfig in the process. If “initial_instance_count“, “instance_type“, “accelerator_type“, or “model_name“ is specified, then a new ProductionVariant configuration is created; values from the existing configuration are not preserved if any of those parameters are specified.

Usage
Predictor$update_endpoint(
  initial_instance_count = NULL,
  instance_type = NULL,
  accelerator_type = NULL,
  model_name = NULL,
  tags = NULL,
  kms_key = NULL,
  data_capture_config_dict = NULL,
  wait = TRUE
)
Arguments
initial_instance_count

(int): The initial number of instances to run in the endpoint. This is required if “instance_type“, “accelerator_type“, or “model_name“ is specified. Otherwise, the values from the existing endpoint configuration's ProductionVariants are used.

instance_type

(str): The EC2 instance type to deploy the endpoint to. This is required if “initial_instance_count“ or “accelerator_type“ is specified. Otherwise, the values from the existing endpoint configuration's “ProductionVariants“ are used.

accelerator_type

(str): The type of Elastic Inference accelerator to attach to the endpoint, e.g. "ml.eia1.medium". If not specified, and “initial_instance_count“, “instance_type“, and “model_name“ are also “None“, the values from the existing endpoint configuration's “ProductionVariants“ are used. Otherwise, no Elastic Inference accelerator is attached to the endpoint.

model_name

(str): The name of the model to be associated with the endpoint. This is required if “initial_instance_count“, “instance_type“, or “accelerator_type“ is specified and if there is more than one model associated with the endpoint. Otherwise, the existing model for the endpoint is used.

tags

(list[dict[str, str]]): The list of tags to add to the endpoint config. If not specified, the tags of the existing endpoint configuration are used. If any of the existing tags are reserved AWS ones (i.e. begin with "aws"), they are not carried over to the new endpoint configuration.

kms_key

(str): The KMS key that is used to encrypt the data on the storage volume attached to the instance hosting the endpoint If not specified, the KMS key of the existing endpoint configuration is used.

data_capture_config_dict

(dict): The endpoint data capture configuration for use with Amazon SageMaker Model Monitoring. If not specified, the data capture configuration of the existing endpoint configuration is used.

wait

(boolean): Waits for endpoint to update.


Method delete_endpoint()

Delete the Amazon SageMaker endpoint backing this predictor. Also delete the endpoint configuration attached to it if delete_endpoint_config is True.

Usage
Predictor$delete_endpoint(delete_endpoint_config = TRUE)
Arguments
delete_endpoint_config

(bool, optional): Flag to indicate whether to delete endpoint configuration together with endpoint. Defaults to True. If True, both endpoint and endpoint configuration will be deleted. If False, only endpoint will be deleted.


Method delete_predictor()

Delete the Amazon SageMaker endpoint backing this predictor. Also delete the endpoint configuration attached to it if delete_endpoint_config is True.

Usage
Predictor$delete_predictor(delete_endpoint_config = TRUE)
Arguments
delete_endpoint_config

(bool, optional): Flag to indicate whether to delete endpoint configuration together with endpoint. Defaults to True. If True, both endpoint and endpoint configuration will be deleted. If False, only endpoint will be deleted.


Method delete_model()

Deletes the Amazon SageMaker models backing this predictor.

Usage
Predictor$delete_model()

Method enable_data_capture()

Updates the DataCaptureConfig for the Predictor's associated Amazon SageMaker Endpoint to enable data capture. For a more customized experience, refer to update_data_capture_config, instead.

Usage
Predictor$enable_data_capture()

Method disable_data_capture()

Updates the DataCaptureConfig for the Predictor's associated Amazon SageMaker Endpoint to disable data capture. For a more customized experience, refer to update_data_capture_config, instead.

Usage
Predictor$disable_data_capture()

Method update_data_capture_config()

Updates the DataCaptureConfig for the Predictor's associated Amazon SageMaker Endpoint with the provided DataCaptureConfig.

Usage
Predictor$update_data_capture_config(data_capture_config = NULL)
Arguments
data_capture_config

(sagemaker.model_monitor.DataCaptureConfig): The DataCaptureConfig to update the predictor's endpoint to use.


Method list_monitors()

Generates ModelMonitor objects (or DefaultModelMonitors). Objects are generated based on the schedule(s) associated with the endpoint that this predictor refers to.

Usage
Predictor$list_monitors()
Returns

[sagemaker.model_monitor.model_monitoring.ModelMonitor]: A list of ModelMonitor (or DefaultModelMonitor) objects.


Method endpoint_context()

Retrieves the lineage context object representing the endpoint.

Usage
Predictor$endpoint_context()
Returns

ContextEndpoint: The context for the endpoint.


Method format()

format class

Usage
Predictor$format()

Method clone()

The objects of this class are cloneable with this method.

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