简体   繁体   English

如何将重新训练的 Sagemaker model 部署到端点?

[英]How can I deploy a re-trained Sagemaker model to an endpoint?

With an sagemaker.estimator.Estimator , I want to re- deploy a model after retraining (calling fit with new data).使用sagemaker.estimator.Estimator ,我想在重新训练后重新部署model(调用新数据fit )。

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 .显然我想使用像UpdateEndpoint这样的功能。 How do I access that functionality from this API?我如何从这个 API 访问该功能?

update_endpoint has been deprecated since AFAIK. update_endpoint自 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):要从这个 API 本身重新创建UpdateEndpoint功能并将新的适合训练作业部署到现有端点,我们可以这样做(此示例使用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)

Yes, under the hood the model.deploy creates a model, an endpoint configuration and an endpoint.是的,在model.deploy创建了一个模型、一个端点配置和一个端点。 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.使用update_endpoint=True参数。 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."来自SageMaker SDK 文档“此外,可以将链接到您的模型的不同端点配置部署到现有的 SageMaker 端点。这可以通过为endpoint_name参数指定现有端点名称以及update_endpoint在您的deploy()调用中参数为 True。”

  • Alternatively, if you want to create a separate model you can specify a new model_name in your deploy或者,如果您想创建一个单独的模型,您可以在deploy指定一个新的model_name

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 AWS sagemaker 上部署预训练的 sklearn model? (端点停留在创建) - How do I deploy a pre trained sklearn model on AWS sagemaker? (Endpoint stuck on creating) 如何使用新训练的 Model 更新 Sagemaker Endpoint? - How to update Sagemaker Endpoint with the newly Trained Model? 部署 TensorFlow 概率回归 model 作为 Sagemaker 端点 - Deploy TensorFlow probability regression model as Sagemaker endpoint 无法在 AWS Sagemaker 上部署本地训练的逻辑回归 model - Unable to deploy locally trained Logistic Regression model on AWS Sagemaker 在 Sagemaker 和 Huggingface 中训练一个已经训练过的 model 而无需重新初始化 - Train an already trained model in Sagemaker and Huggingface without re-initialising 如何在 AWS sagemaker 中为 yolov5 推理创建端点 - How can I create an endpoint for yolov5 inference in AWS sagemaker 使用自定义训练的 Keras model 和 Sagemaker 端点结果 ModelError:调用 InvokeEndpoint 操作时发生错误(ModelError): - Using custom trained Keras model with Sagemaker endpoint results ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: 为 PyTorch Model 调用 SageMaker 端点 - Invoking SageMaker Endpoint for PyTorch Model 如何从端点内访问 sagemaker 模型注册表指标 - How to access sagemaker model registry metrics from within the endpoint 如何通过sagemaker pipeline部署抱脸model - How to deploy the hugging face model via sagemaker pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM