简体   繁体   English

如何使用 sagemaker 管道部署最佳调整模型?

[英]How to deploy the best tuned model using sagemaker pipelines?

I have trained an XGBoost model, finetuned it, evaluated it and registered it using aws sagemaker pipeline.我已经训练了一个 XGBoost 模型,对其进行了微调、评估并使用 aws sagemaker 管道对其进行了注册。 Now I want to deploy the model.现在我想部署模型。 However, the location of the model artefact is saved as Join object because of which deployment is not working by best_model.deploy(...) .但是,模型工件的位置保存为Join对象,因为best_model.deploy(...)无法进行部署。 Any suggestions on how to deploy the best trained model.关于如何部署最佳训练模型的任何建议。

tuning_step = TuningStep(name="HPTuning",
                        tuner=tuner_log,
                        inputs={
                            "train":...,
                            "validation":...
                        },
                        cache_config=cache_config)


best_model = Model(image_uri=image_uri, 
                  model_data=tuning_step.get_top_model_s3_uri(top_k=0,s3_bucket=model_bucket_key),
                  sagemaker_session=sm_session,
                  role=role,
                  predictor_cls=XGBoostPredictor)


register_step = RegisterModel(name="RegisterBestChurnModel",
                             estimator=xgb_estimator,
                             model_data=tuning_step.get_top_model_s3_uri(top_k=0, s3_bucket=model_bucket_key),
                             content_types=["text/csv"],
                             response_types=["test/csv"],
                             inference_instances=["ml.t2.medium", "ml.m5.large"],
                             transform_instances=["ml.m5.large"],
                             approval_status="Approved",
                             model_metrics=model_metrics)


The problem with best_model.deploy(...) is that tuning_step.get_top_model_s3_uri(top_k=0,s3_bucket=model_bucket_key) is a Join object. best_model.deploy(...)的问题是tuning_step.get_top_model_s3_uri(top_k=0,s3_bucket=model_bucket_key)是一个 Join 对象。 And deploy needs the s3 bucket location as a string.部署需要 s3 存储桶位置作为字符串。 So that doesn't work.所以这行不通。

I was also trying to deploy the registered model using我还尝试使用部署注册模型

model_package_arn = register_step.properties.ModelPackageArn,
model = ModelPackage(role=role, 
                     model_package_arn=create_top_step.properties.ModelArn, 
                     sagemaker_session=session)
model.deploy(initial_instance_count=1, instance_type='ml.m5.xlarge')

which is giving me the error这给了我错误

...

/opt/conda/lib/python3.7/site-packages/sagemaker/model.py in _create_sagemaker_model(self, *args, **kwargs)
   1532             container_def["Environment"] = self.env
   1533 
-> 1534         self._ensure_base_name_if_needed(model_package_name.split("/")[-1])
   1535         self._set_model_name_if_needed()
   1536 

AttributeError: 'tuple' object has no attribute 'split'

Which I also suspect arise for the same reason.我也怀疑出于同样的原因。

I followed this tutorial pretty much我非常关注本教程

https://github.com/aws/amazon-sagemaker-examples/blob/main/sagemaker-pipelines/tabular/tuning-step/sagemaker-pipelines-tuning-step.ipynb https://github.com/aws/amazon-sagemaker-examples/blob/main/sagemaker-pipelines/tabular/tuning-step/sagemaker-pipelines-tuning-step.ipynb

There are two ways to do this -有两种方法可以做到这一点 -

1/ Once you have registered the best model from the Tuning Job in the Model Registry, run your model deployment code through the Lambda Step. 1/ 在模型注册表中从调优作业注册最佳模型后,通过 Lambda 步骤运行模型部署代码。 Here is an example of how to do that. 是一个如何做到这一点的例子。 Pass the output of the register step as the input of the Lambda step and call your model deployment code in the Lambda function.将注册步骤的输出作为 Lambda 步骤的输入传递,并在 Lambda 函数中调用您的模型部署代码。

2/ After your sagemaker pipeline executes and you have registered the model, use the registered model ARN from the Model Registry and call the deployment code. 2/ 在您的 sagemaker 管道执行并注册模型后,使用模型注册表中注册的模型 ARN 并调用部署代码。 You can not use register_step.properties.ModelPackageArn outside the context of the Pipeline execution.您不能在 Pipeline 执行的上下文之外使用register_step.properties.ModelPackageArn

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM