Jos*_*Fox 4 amazon-web-services python-3.x amazon-sagemaker
使用sagemaker.estimator.Estimator,我想在重新训练后重新部署模型(fit使用新数据调用)。
当我调用这个
estimator.deploy(initial_instance_count=1, instance_type='ml.m5.xlarge')
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
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".
Run Code Online (Sandbox Code Playgroud)
显然我想使用像UpdateEndpoint这样的功能。如何从此 API 访问该功能?
是的,在底层model.deploy创建了一个模型、一个端点配置和一个端点。当您从已部署的、经过训练的估计器再次调用该方法时,它将产生错误,因为已经部署了类似配置的端点。我鼓励你尝试:
使用update_endpoint=True参数。来自SageMaker SDK 文档:
“此外,可以将链接到您的模型的不同端点配置部署到现有的 SageMaker 端点。这可以通过指定参数的现有端点名称endpoint_name以及
update_endpoint参数来完成:真实的你的deploy()呼召。”
或者,如果您想创建一个单独的模型,您可以model_name在您的deploy
update_endpoint自 AFAIK 以来已被弃用。要从此 API 本身重新创建UpdateEndpoint功能并将新的训练作业部署到现有端点,我们可以执行以下操作(此示例使用API):sagemaker sklearn
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4647 次 |
| 最近记录: |