4

With an sagemaker.estimator.Estimator, I want to re-deploy a model after retraining (calling fit with new data).

When I call this

estimator.deploy(initial_instance_count=1, instance_type='ml.m5.xlarge')

I get an error

botocore.exceptions.ClientError: An error occurred (ValidationException) 
when calling the CreateEndpoint operation: 
Cannot create already existing endpoint "arn:aws:sagemaker:eu-east- 
1:1776401913911:endpoint/zyx".

Apparently I want to use functionality like UpdateEndpoint. How do I access that functionality from this API?

2 Answers 2

6

Yes, under the hood the model.deploy creates a model, an endpoint configuration and an endpoint. When you call again the method from an already-deployed, trained estimator it will create an error because a similarly-configured endpoint is already deployed. What I encourage you to try:

  • use the update_endpoint=True parameter. From the SageMaker SDK doc: "Additionally, it is possible to deploy a different endpoint configuration, which links to your model, to an already existing SageMaker endpoint. This can be done by specifying the existing endpoint name for the endpoint_name parameter along with the update_endpoint parameter as True within your deploy() call."

  • Alternatively, if you want to create a separate model you can specify a new model_name in your deploy

Sign up to request clarification or add additional context in comments.

2 Comments

This method of adding update_endpoint=True to the .deploy() call does not appear to work if deploying from a ModelPackage obj. docs.aws.amazon.com/sagemaker/latest/dg/…
This is a very good answer. I have a question though, if I have real time inference requests and the update endpoint is set to true, knowing that I have a few dozen requests per second, how would sagemaker handle inference while re-deploying ? would it use the old model to make inferences while updating is still in progress? thanks!
5

update_endpoint has been deprecated since AFAIK . To re-create the UpdateEndpoint functionality from this API itself and deploy a newly fit training job to an existing endpoint , we could do something like this (this example uses the sagemaker sklearn API):

from sagemaker.sklearn.estimator import SKLearn

sklearn_estimator = SKLearn(
    entry_point=model.py,
    instance_type=<instance_type>,
    framework_version=<framework_version>,
    role=<role>,
    dependencies=[
         <comma seperated names of files>
    ],
    hyperparameters={
         'key_1':value,
         'key_2':value,
         ...
    }
)

sklearn_estimator.fit()

sm_client = boto3.client('sagemaker')

# Create the model
sklearn_model = sklearn_estimator.create_model()

# Define an endpoint config and an endpoint
endpoint_config_name = 'endpoint-' + datetime.utcnow().strftime("%Y%m%d%H%m%s")
current_endpoint = endpoint_config_name

# From the Model : create the endpoint config and the endpoint
sklearn_model.deploy(
    initial_instance_count=<count>,
    instance_type=<instance_type>,
    endpoint_name=current_endpoint
)

# Update the existing endpoint if it exists or create a new one
try:
    sm_client.update_endpoint(
        EndpointName=DESIRED_ENDPOINT_NAME, # The Prod/Existing Endpoint Name
        EndpointConfigName=endpoint_config_name
    )
except Exception as e:
    try:
        sm_client.create_endpoint(
            EndpointName=DESIRED_ENDPOINT_NAME, # The Prod Endpoint name
            EndpointConfigName=endpoint_config_name
        )
    except Exception as e:
        logger.info(e)

sm_client.delete_endpoint(EndpointName=current_endpoint)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.