Make real-time predictions against SageMaker endpoints with Python objects
Predictor(endpoint_name, sagemaker_session=None, serializer=<sagemaker.serializers.IdentitySerializer object>, deserializer=<sagemaker.deserializers.BytesDeserializer object>)¶
Make prediction requests to an Amazon SageMaker endpoint.
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.
endpoint_name (str) – Name of the Amazon SageMaker endpoint to which requests are sent.
sagemaker_session (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.
predict(data, initial_args=None, target_model=None, target_variant=None)¶
Return the inference from the specified endpoint.
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.
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: None)
target_variant (str) – The name of the production variant to run an inference
on (Default (request) – None). Note that the ProductionVariant identifies the model
want to host and the resources you want to deploy for hosting it. (you) –
- 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.
- Return type
update_endpoint(initial_instance_count=None, instance_type=None, accelerator_type=None, model_name=None, tags=None, kms_key=None, data_capture_config_dict=None, wait=True)¶
Update the existing endpoint with the provided attributes.
This creates a new EndpointConfig in the process. If
model_nameis specified, then a new ProductionVariant configuration is created; values from the existing configuration are not preserved if any of those parameters are specified.
initial_instance_count (int) – The initial number of instances to run in the endpoint. This is required if
model_nameis 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
accelerator_typeis specified. Otherwise, the values from the existing endpoint configuration’s
accelerator_type (str) – The type of Elastic Inference accelerator to attach to the endpoint, e.g. “ml.eia1.medium”. If not specified, and
None, the values from the existing endpoint configuration’s
ProductionVariantsare 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
accelerator_typeis 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.
ValueError – If there is not enough information to create a new
ProductionVariant: - If
model_nameis specified, but
None. - If
accelerator_typeis specified and either
Noneor there are multiple models associated with the endpoint.
Delete the Amazon SageMaker endpoint backing this predictor. Also delete the endpoint configuration attached to it if delete_endpoint_config is True.
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.
Deletes the Amazon SageMaker models backing this predictor.
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.
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.
Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint with the provided DataCaptureConfig.
data_capture_config (sagemaker.model_monitor.DataCaptureConfig) – The DataCaptureConfig to update the predictor’s endpoint to use.
Generates ModelMonitor objects (or DefaultModelMonitors) based on the schedule(s) associated with the endpoint that this predictor refers to.
- A list of
ModelMonitor (or DefaultModelMonitor) objects.
- Return type
The MIME type of the data sent to the inference endpoint.
The content type(s) that are expected from the inference endpoint.