簡體   English   中英

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

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

我已經訓練了一個 XGBoost 模型,對其進行了微調、評估並使用 aws sagemaker 管道對其進行了注冊。 現在我想部署模型。 但是,模型工件的位置保存為Join對象,因為best_model.deploy(...)無法進行部署。 關於如何部署最佳訓練模型的任何建議。

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)


best_model.deploy(...)的問題是tuning_step.get_top_model_s3_uri(top_k=0,s3_bucket=model_bucket_key)是一個 Join 對象。 部署需要 s3 存儲桶位置作為字符串。 所以這行不通。

我還嘗試使用部署注冊模型

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')

這給了我錯誤

...

/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'

我也懷疑出於同樣的原因。

我非常關注本教程

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

有兩種方法可以做到這一點 -

1/ 在模型注冊表中從調優作業注冊最佳模型后,通過 Lambda 步驟運行模型部署代碼。 是一個如何做到這一點的例子。 將注冊步驟的輸出作為 Lambda 步驟的輸入傳遞,並在 Lambda 函數中調用您的模型部署代碼。

2/ 在您的 sagemaker 管道執行並注冊模型后,使用模型注冊表中注冊的模型 ARN 並調用部署代碼。 您不能在 Pipeline 執行的上下文之外使用register_step.properties.ModelPackageArn

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM