aws / aws/amazon-sagemaker-examples

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

Open
#3,489 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
11k
Forks
7k
Avg merge
8h 29m
Merged PRs (30d)
8

Description

I have trained an XGBoost model, fine-tuned it, evaluated it and registered it using aws sagemaker pipeline. Now I want to deploy the model which performs the best. However, the location of the model artefact is saved as Join object because of which deployment is not working by best_model.deploy(...). Any suggestions on how to deploy the best trained model.

This is what I have done so far:

```

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. And deploy needs the s3 bucket location as a string. 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

Contributor guide

Open the contributing guide

Research direction

Start with sagemaker-pipelines/tabular/tuning-step/sagemaker-pipelines-tuning-step.ipynb and reproduce the TuningStep, RegisterModel, and ModelPackage entry points shown in the issue. Trace how the Join object and ModelPackageArn are passed into deployment; done means the example or its documentation provides a reproducible, verified path for deploying the selected model.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, jupyter-notebook, python
Domain
cloud, devops, machine-learning
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.